CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
configTemplates.py
Go to the documentation of this file.
1 from alternateValidationTemplates import *
2 from offlineValidationTemplates import *
3 from geometryComparisonTemplates import *
4 from monteCarloValidationTemplates import *
5 from trackSplittingValidationTemplates import *
6 from zMuMuValidationTemplates import *
7 from TkAlExceptions import AllInOneError
8 
9 
10 ######################################################################
11 ######################################################################
12 ### ###
13 ### General Templates ###
14 ### ###
15 ######################################################################
16 ######################################################################
17 
18 ######################################################################
19 ######################################################################
20 conditionsTemplate="""
21 process.conditionsIn.oO[rcdName]Oo. = CalibTracker.Configuration.Common.PoolDBESSource_cfi.poolDBESSource.clone(
22  connect = cms.string('.oO[connectString]Oo.'),
23  toGet = cms.VPSet(cms.PSet(record = cms.string('.oO[rcdName]Oo.'),
24  tag = cms.string('.oO[tagName]Oo.')
25  )
26  )
27  )
28 process.prefer_conditionsIn.oO[rcdName]Oo. = cms.ESPrefer("PoolDBESSource", "conditionsIn.oO[rcdName]Oo.")
29 """
30 
31 
32 ######################################################################
33 ######################################################################
34 #batch job execution
35 scriptTemplate="""
36 #!/bin/bash
37 #init
38 #ulimit -v 3072000
39 #export STAGE_SVCCLASS=cmscafuser
40 #save path to the LSF batch working directory (/pool/lsf)
41 export LSFWORKDIR=`pwd -P`
42 echo LSF working directory is $LSFWORKDIR
43 source /afs/cern.ch/cms/caf/setup.sh
44 cd .oO[CMSSW_BASE]Oo./src
45 export SCRAM_ARCH=.oO[SCRAM_ARCH]Oo.
46 eval `scramv1 ru -sh`
47 #rfmkdir -p .oO[datadir]Oo. &>! /dev/null
48 
49 #remove possible result file from previous runs
50 previous_results=$(cmsLs -l /store/caf/user/$USER/.oO[eosdir]Oo. | awk '{print $5}')
51 for file in ${previous_results}
52 do
53  if [ ${file} = /store/caf/user/$USER/.oO[eosdir]Oo./.oO[outputFile]Oo. ]
54  then
55  cmsStage -f ${file} ${file}.bak
56  fi
57 done
58 
59 if [[ $HOSTNAME = lxplus[0-9]*\.cern\.ch ]] # check for interactive mode
60 then
61  rfmkdir -p .oO[workdir]Oo.
62  rm -f .oO[workdir]Oo./*
63  cd .oO[workdir]Oo.
64 else
65  mkdir -p $LSFWORKDIR/TkAllInOneTool
66  cd $LSFWORKDIR/TkAllInOneTool
67 fi
68 
69 # rm -f .oO[workdir]Oo./*
70 # cd .oO[workdir]Oo.
71 
72 #run
73 pwd
74 df -h .
75 .oO[CommandLine]Oo.
76 echo "----"
77 echo "List of files in $(pwd):"
78 ls -ltr
79 echo "----"
80 echo ""
81 
82 
83 #retrieve
84 rfmkdir -p .oO[logdir]Oo. >&! /dev/null
85 gzip -f LOGFILE_*_.oO[name]Oo..log
86 find . -maxdepth 1 -name "LOGFILE*.oO[alignmentName]Oo.*" -print | xargs -I {} bash -c "rfcp {} .oO[logdir]Oo."
87 
88 #copy root files to eos
89 cmsMkdir /store/caf/user/$USER/.oO[eosdir]Oo.
90 if [ .oO[parallelJobs]Oo. -eq 1 ]
91 then
92  root_files=$(ls --color=never -d *.oO[alignmentName]Oo.*.root)
93 else
94  root_files=$(ls --color=never -d *.oO[alignmentName]Oo._.oO[nIndex]Oo.*.root)
95 fi
96 echo ${root_files}
97 
98 for file in ${root_files}
99 do
100  cmsStage -f ${file} /store/caf/user/$USER/.oO[eosdir]Oo.
101  echo ${file}
102 done
103 
104 #cleanup
105 if [[ $HOSTNAME = lxplus[0-9]*\.cern\.ch ]] # check for interactive mode
106 then
107  rm -rf .oO[workdir]Oo.
108 fi
109 echo "done."
110 """
111 
112 
113 ######################################################################
114 ######################################################################
115 mergeTemplate="""
116 #!/bin/bash
117 CWD=`pwd -P`
118 cd .oO[CMSSW_BASE]Oo./src
119 export SCRAM_ARCH=.oO[SCRAM_ARCH]Oo.
120 eval `scramv1 ru -sh`
121 
122 #create results-directory and copy used configuration there
123 rfmkdir -p .oO[datadir]Oo.
124 rfcp .oO[logdir]Oo./usedConfiguration.ini .oO[datadir]Oo.
125 
126 if [[ $HOSTNAME = lxplus[0-9]*\.cern\.ch ]] # check for interactive mode
127 then
128  mkdir -p .oO[workdir]Oo.
129  cd .oO[workdir]Oo.
130 else
131  cd $CWD
132 fi
133 echo "Working directory: $(pwd -P)"
134 
135 ###############################################################################
136 # download root files from eos
137 root_files=$(cmsLs -l /store/caf/user/$USER/.oO[eosdir]Oo. | awk '{print $5}' \
138  | grep ".root$" | grep -v "result.root$")
139 for file in ${root_files}
140 do
141  cmsStage -f ${file} .
142  # echo ${file}
143 done
144 
145 
146 #run
147 .oO[DownloadData]Oo.
148 .oO[CompareAlignments]Oo.
149 
150 .oO[RunExtendedOfflineValidation]Oo.
151 .oO[RunTrackSplitPlot]Oo.
152 
153 # clean-up
154 # ls -l *.root
155 rm -f *.root
156 
157 #zip stdout and stderr from the farm jobs
158 cd .oO[logdir]Oo.
159 find . -name "*.stderr" -exec gzip -f {} \;
160 find . -name "*.stdout" -exec gzip -f {} \;
161 """
162 
163 
164 ######################################################################
165 ######################################################################
166 mergeParallelResults="""
167 
168 .oO[copyMergeScripts]Oo.
169 .oO[haddLoop]Oo.
170 
171 # create log file
172 ls -al .oO[mergeParallelFilePrefixes]Oo. > .oO[datadir]Oo./log_rootfilelist.txt
173 
174 # Remove parallel job files
175 .oO[rmUnmerged]Oo.
176 """
177 
178 
179 ######################################################################
180 ######################################################################
181 compareAlignmentsExecution="""
182 #merge for .oO[validationId]Oo. if it does not exist or is not up-to-date
183 echo -e "\n\nComparing validations"
184 cmsMkdir /store/caf/user/$USER/.oO[eosdir]Oo./
185 cp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation/scripts/compareFileAges.C .
186 root -x -q -b -l "compareFileAges.C(\\\"root://eoscms.cern.ch//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./.oO[validationId]Oo._result.root\\\", \\\".oO[compareStringsPlain]Oo.\\\")"
187 comparisonNeeded=${?}
188 
189 if [[ ${comparisonNeeded} -eq 1 ]]
190 then
191  cp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation/scripts/compareAlignments.cc .
192  root -x -q -b -l 'compareAlignments.cc++(\".oO[compareStrings]Oo.\")'
193  mv result.root .oO[validationId]Oo._result.root
194  cmsStage -f .oO[validationId]Oo._result.root /store/caf/user/$USER/.oO[eosdir]Oo.
195 else
196  echo ".oO[validationId]Oo._result.root is up-to-date, no need to compare again."
197  cmsStage -f /store/caf/user/$USER/.oO[eosdir]Oo./.oO[validationId]Oo._result.root .
198 fi
199 """
200 
201 
202 ######################################################################
203 ######################################################################
204 extendedValidationExecution="""
205 #run extended offline validation scripts
206 echo -e "\n\nRunning extended offline validation"
207 if [[ $HOSTNAME = lxplus[0-9]*\.cern\.ch ]] # check for interactive mode
208 then
209  rfmkdir -p .oO[workdir]Oo./ExtendedOfflineValidation_Images
210 else
211  mkdir -p ExtendedOfflineValidation_Images
212 fi
213 
214 rfcp .oO[extendedValScriptPath]Oo. .
215 rfcp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation/macros/PlotAlignmentValidation.C .
216 root -x -b -q -l TkAlExtendedOfflineValidation.C
217 rfmkdir -p .oO[datadir]Oo./ExtendedOfflineValidation_Images
218 
219 if [[ $HOSTNAME = lxplus[0-9]*\.cern\.ch ]] # check for interactive mode
220 then
221  image_files=$(ls --color=never | find .oO[workdir]Oo./ExtendedOfflineValidation_Images/ -name \*ps -o -name \*root)
222  echo -e "\n\nProduced plot files:"
223  #echo ${image_files}
224  ls .oO[workdir]Oo./ExtendedOfflineValidation_Images
225 else
226  image_files=$(ls --color=never | find ExtendedOfflineValidation_Images/ -name \*ps -o -name \*root)
227  echo -e "\n\nProduced plot files:"
228  #echo ${image_files}
229  ls ExtendedOfflineValidation_Images
230 fi
231 
232 for image in ${image_files}
233 do
234  cp ${image} .oO[datadir]Oo./ExtendedOfflineValidation_Images
235 done
236 """
237 
238 
239 ######################################################################
240 ######################################################################
241 extendedValidationTemplate="""
242 #include ".oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation/macros/PlotAlignmentValidation.C"
243 void TkAlExtendedOfflineValidation()
244 {
245  // load framework lite just to find the CMSSW libs...
246  gSystem->Load("libFWCoreFWLite");
247  FWLiteEnabler::enable();
248  //compile the makro
249  //gROOT->ProcessLine(".L .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation/macros/PlotAlignmentValidation.C++");
250  // gROOT->ProcessLine(".L ./PlotAlignmentValidation.C++");
251 
252  .oO[extendedInstantiation]Oo.
253  p.setOutputDir("./ExtendedOfflineValidation_Images");
254  p.setTreeBaseDir(".oO[OfflineTreeBaseDir]Oo.");
255  p.plotDMR(".oO[DMRMethod]Oo.",.oO[DMRMinimum]Oo.,".oO[DMROptions]Oo.");
256  p.plotSurfaceShapes(".oO[SurfaceShapes]Oo.");
257  p.plotChi2("root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./.oO[resultPlotFile]Oo._result.root");
258 }
259 """
260 
261 
262 ######################################################################
263 ######################################################################
264 crabCfgTemplate="""
265 [CRAB]
266 jobtype = cmssw
267 scheduler = caf
268 use_server = 0
269 
270 [CMSSW]
271 datasetpath = .oO[dataset]Oo.
272 pset = .oO[cfgFile]Oo.
273 total_number_of_.oO[McOrData]Oo.
274 number_of_jobs = .oO[numberOfJobs]Oo.
275 output_file = .oO[outputFile]Oo.
276 runselection = .oO[runRange]Oo.
277 lumi_mask = .oO[JSON]Oo.
278 
279 [USER]
280 return_data = 0
281 copy_data = 1
282 storage_element = T2_CH_CERN
283 user_remote_dir = .oO[eosdir]Oo.
284 ui_working_dir = .oO[crabWorkingDir]Oo.
285 # script_exe = .oO[script]Oo.
286 # .oO[email]Oo.
287 
288 [CAF]
289 queue = .oO[queue]Oo.
290 """
291 
292 
293 
294 
295 ######################################################################
296 ######################################################################
297 ### ###
298 ### Alternate Templates ###
299 ### ###
300 ######################################################################
301 ######################################################################
302 
303 
304 def alternateTemplate( templateName, alternateTemplateName ):
305 
306  if not templateName in globals().keys():
307  msg = "unknown template to replace %s"%templateName
308  raise AllInOneError(msg)
309  if not alternateTemplateName in globals().keys():
310  msg = "unknown template to replace %s"%alternateTemplateName
311  raise AllInOneError(msg)
312  globals()[ templateName ] = globals()[ alternateTemplateName ]
313  # = eval("configTemplates.%s"%"alternateTemplate")
def alternateTemplate
### Alternate Templates ###