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 #set directory to which TkAlOfflineJobsMerge.C saves the merged file
169 # export OUTPUTDIR=.oO[datadir]Oo.
170 export OUTPUTDIR=.
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 cp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation/scripts/compareFileAges.C .
188 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.\\\")"
189 comparisonNeeded=${?}
190 
191 if [[ ${comparisonNeeded} -eq 1 ]]
192 then
193  cp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation/scripts/compareAlignments.cc .
194  root -x -q -b -l 'compareAlignments.cc++(\".oO[compareStrings]Oo.\")'
195  mv result.root .oO[validationId]Oo._result.root
196  cmsStage -f .oO[validationId]Oo._result.root /store/caf/user/$USER/.oO[eosdir]Oo.
197 else
198  echo ".oO[validationId]Oo._result.root is up-to-date, no need to compare again."
199  cmsStage -f /store/caf/user/$USER/.oO[eosdir]Oo./.oO[validationId]Oo._result.root .
200 fi
201 """
202 
203 
204 ######################################################################
205 ######################################################################
206 extendedValidationExecution="""
207 #run extended offline validation scripts
208 echo -e "\n\nRunning extended offline validation"
209 if [[ $HOSTNAME = lxplus[0-9]*\.cern\.ch ]] # check for interactive mode
210 then
211  rfmkdir -p .oO[workdir]Oo./ExtendedOfflineValidation_Images
212 else
213  mkdir -p ExtendedOfflineValidation_Images
214 fi
215 
216 rfcp .oO[extendedValScriptPath]Oo. .
217 rfcp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation/macros/PlotAlignmentValidation.C .
218 root -x -b -q -l TkAlExtendedOfflineValidation.C
219 rfmkdir -p .oO[datadir]Oo./ExtendedOfflineValidation_Images
220 
221 if [[ $HOSTNAME = lxplus[0-9]*\.cern\.ch ]] # check for interactive mode
222 then
223  image_files=$(ls --color=never | find .oO[workdir]Oo./ExtendedOfflineValidation_Images/ -name \*ps -o -name \*root)
224  echo -e "\n\nProduced plot files:"
225  #echo ${image_files}
226  ls .oO[workdir]Oo./ExtendedOfflineValidation_Images
227 else
228  image_files=$(ls --color=never | find ExtendedOfflineValidation_Images/ -name \*ps -o -name \*root)
229  echo -e "\n\nProduced plot files:"
230  #echo ${image_files}
231  ls ExtendedOfflineValidation_Images
232 fi
233 
234 for image in ${image_files}
235 do
236  cp ${image} .oO[datadir]Oo./ExtendedOfflineValidation_Images
237 done
238 """
239 
240 
241 ######################################################################
242 ######################################################################
243 extendedValidationTemplate="""
244 void TkAlExtendedOfflineValidation()
245 {
246  // load framework lite just to find the CMSSW libs...
247  gSystem->Load("libFWCoreFWLite");
248  AutoLibraryLoader::enable();
249  //compile the makro
250  gROOT->ProcessLine(".L .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation/macros/PlotAlignmentValidation.C++");
251  // gROOT->ProcessLine(".L ./PlotAlignmentValidation.C++");
252 
253  .oO[extendedInstantiation]Oo.
254  p.setOutputDir("./ExtendedOfflineValidation_Images");
255  p.setTreeBaseDir(".oO[OfflineTreeBaseDir]Oo.");
256  p.plotDMR(".oO[DMRMethod]Oo.",.oO[DMRMinimum]Oo.,".oO[DMROptions]Oo.");
257  p.plotSurfaceShapes(".oO[SurfaceShapes]Oo.");
258  p.plotChi2(".oO[resultPlotFile]Oo._result.root");
259 }
260 """
261 
262 
263 ######################################################################
264 ######################################################################
265 crabCfgTemplate="""
266 [CRAB]
267 jobtype = cmssw
268 scheduler = caf
269 use_server = 0
270 
271 [CMSSW]
272 datasetpath = .oO[dataset]Oo.
273 pset = .oO[cfgFile]Oo.
274 total_number_of_.oO[McOrData]Oo.
275 number_of_jobs = .oO[numberOfJobs]Oo.
276 output_file = .oO[outputFile]Oo.
277 runselection = .oO[runRange]Oo.
278 lumi_mask = .oO[JSON]Oo.
279 
280 [USER]
281 return_data = 0
282 copy_data = 1
283 storage_element = T2_CH_CERN
284 user_remote_dir = .oO[eosdir]Oo.
285 ui_working_dir = .oO[crabWorkingDir]Oo.
286 # script_exe = .oO[script]Oo.
287 # .oO[email]Oo.
288 
289 [CAF]
290 queue = .oO[queue]Oo.
291 """
292 
293 
294 
295 
296 ######################################################################
297 ######################################################################
298 ### ###
299 ### Alternate Templates ###
300 ### ###
301 ######################################################################
302 ######################################################################
303 
304 
305 def alternateTemplate( templateName, alternateTemplateName ):
306 
307  if not templateName in globals().keys():
308  msg = "unknown template to replace %s"%templateName
309  raise AllInOneError(msg)
310  if not alternateTemplateName in globals().keys():
311  msg = "unknown template to replace %s"%alternateTemplateName
312  raise AllInOneError(msg)
313  globals()[ templateName ] = globals()[ alternateTemplateName ]
314  # = eval("configTemplates.%s"%"alternateTemplate")
def alternateTemplate
### Alternate Templates ###