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