CMS 3D CMS Logo

configTemplates.py
Go to the documentation of this file.
1 from alternateValidationTemplates import *
2 from offlineValidationTemplates import *
3 from primaryVertexValidationTemplates import *
4 from geometryComparisonTemplates import *
5 from monteCarloValidationTemplates import *
6 from trackSplittingValidationTemplates import *
7 from zMuMuValidationTemplates import *
8 from TkAlExceptions import AllInOneError
9 
10 ######################################################################
11 ######################################################################
12 ### ###
13 ### General Templates ###
14 ### ###
15 ######################################################################
16 ######################################################################
17 
18 ######################################################################
19 ######################################################################
20 loadGlobalTagTemplate="""
21 #Global tag
22 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
23 from Configuration.AlCa.GlobalTag import GlobalTag
24 process.GlobalTag = GlobalTag(process.GlobalTag,".oO[GlobalTag]Oo.")
25 """
26 
27 
28 ######################################################################
29 ######################################################################
30 conditionsTemplate="""
31 process.conditionsIn.oO[rcdName]Oo. = CalibTracker.Configuration.Common.PoolDBESSource_cfi.poolDBESSource.clone(
32  connect = cms.string('.oO[connectString]Oo.'),
33  toGet = cms.VPSet(cms.PSet(record = cms.string('.oO[rcdName]Oo.'),
34  tag = cms.string('.oO[tagName]Oo.')
35  )
36  )
37  )
38 process.prefer_conditionsIn.oO[rcdName]Oo. = cms.ESPrefer("PoolDBESSource", "conditionsIn.oO[rcdName]Oo.")
39 """
40 
41 
42 ######################################################################
43 ######################################################################
44 #batch job execution
45 scriptTemplate="""
46 #!/bin/bash
47 #init
48 #ulimit -v 3072000
49 #export STAGE_SVCCLASS=cmscafuser
50 #save path to the LSF batch working directory (/pool/lsf)
51 
52 export LSFWORKDIR=`pwd -P`
53 echo LSF working directory is $LSFWORKDIR
54 source /afs/cern.ch/cms/caf/setup.sh
55 export X509_USER_PROXY=.oO[scriptsdir]Oo./.user_proxy
56 cd .oO[CMSSW_BASE]Oo./src
57 export SCRAM_ARCH=.oO[SCRAM_ARCH]Oo.
58 eval `scramv1 ru -sh`
59 #rfmkdir -p .oO[datadir]Oo. &>! /dev/null
60 
61 #remove possible result file from previous runs
62 previous_results=$(ls /eos/cms/store/caf/user/$USER/.oO[eosdir]Oo.)
63 for file in ${previous_results}
64 do
65  if [ ${file} = /eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./.oO[outputFile]Oo. ]
66  then
67  xrdcp -f root://eoscms//eos/cms${file} root://eoscms//eos/cms${file}.bak
68  fi
69 done
70 
71 if [[ $HOSTNAME = lxplus[0-9]*[.a-z0-9]* ]] # check for interactive mode
72 then
73  rfmkdir -p .oO[workdir]Oo.
74  rm -f .oO[workdir]Oo./*
75  cd .oO[workdir]Oo.
76 else
77  mkdir -p $LSFWORKDIR/TkAllInOneTool
78  cd $LSFWORKDIR/TkAllInOneTool
79 fi
80 
81 # rm -f .oO[workdir]Oo./*
82 # cd .oO[workdir]Oo.
83 
84 #run
85 pwd
86 df -h .
87 .oO[CommandLine]Oo.
88 echo "----"
89 echo "List of files in $(pwd):"
90 ls -ltr
91 echo "----"
92 echo ""
93 
94 
95 #retrieve
96 rfmkdir -p .oO[logdir]Oo. >&! /dev/null
97 gzip -f LOGFILE_*_.oO[name]Oo..log
98 find . -maxdepth 1 -name "LOGFILE*.oO[alignmentName]Oo.*" -print | xargs -I {} bash -c "rfcp {} .oO[logdir]Oo."
99 
100 #copy root files to eos
101 mkdir -p /eos/cms/store/caf/user/$USER/.oO[eosdir]Oo.
102 if [ .oO[parallelJobs]Oo. -eq 1 ]
103 then
104  root_files=$(ls --color=never -d *.oO[alignmentName]Oo.*.root)
105 else
106  root_files=$(ls --color=never -d *.oO[alignmentName]Oo._.oO[nIndex]Oo.*.root)
107 fi
108 echo ${root_files}
109 
110 for file in ${root_files}
111 do
112  xrdcp -f ${file} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo.
113  echo ${file}
114 done
115 
116 #cleanup
117 if [[ $HOSTNAME = lxplus[0-9]*[.a-z0-9]* ]] # check for interactive mode
118 then
119  rm -rf .oO[workdir]Oo.
120 fi
121 echo "done."
122 """
123 
124 
125 ######################################################################
126 ######################################################################
127 cfgTemplate="""
128 import FWCore.ParameterSet.Config as cms
129 
130 process = cms.Process(".oO[ProcessName]Oo.")
131 
132 .oO[datasetDefinition]Oo.
133 .oO[Bookkeeping]Oo.
134 .oO[LoadBasicModules]Oo.
135 .oO[TrackSelectionRefitting]Oo.
136 .oO[LoadGlobalTagTemplate]Oo.
137 .oO[condLoad]Oo.
138 .oO[ValidationConfig]Oo.
139 .oO[FileOutputTemplate]Oo.
140 
141 .oO[DefinePath]Oo.
142 """
143 
144 
145 ######################################################################
146 ######################################################################
147 Bookkeeping = """
148 process.options = cms.untracked.PSet(
149  wantSummary = cms.untracked.bool(False),
150  Rethrow = cms.untracked.vstring("ProductNotFound"), # make this exception fatal
151  fileMode = cms.untracked.string('NOMERGE') # no ordering needed, but calls endRun/beginRun etc. at file boundaries
152 )
153 
154 process.load("FWCore.MessageLogger.MessageLogger_cfi")
155 process.MessageLogger.destinations = ['cout', 'cerr']
156 process.MessageLogger.cerr.FwkReport.reportEvery = 1000
157 process.MessageLogger.statistics.append('cout')
158 """
159 
160 
161 ######################################################################
162 ######################################################################
163 CommonTrackSelectionRefitting = """
164 import Alignment.CommonAlignment.tools.trackselectionRefitting as trackselRefit
165 process.seqTrackselRefit = trackselRefit.getSequence(process, '.oO[trackcollection]Oo.',
166  isPVValidation=.oO[ispvvalidation]Oo.,
167  TTRHBuilder='.oO[ttrhbuilder]Oo.',
168  usePixelQualityFlag=.oO[usepixelqualityflag]Oo.,
169  openMassWindow=.oO[openmasswindow]Oo.,
170  cosmicsDecoMode=.oO[cosmicsdecomode]Oo.,
171  cosmicsZeroTesla=.oO[cosmics0T]Oo.,
172  momentumConstraint=.oO[momentumconstraint]Oo.,
173  cosmicTrackSplitting=.oO[istracksplitting]Oo.,
174  use_d0cut=.oO[use_d0cut]Oo.,
175  )
176 
177 .oO[trackhitfiltercommands]Oo.
178 """
179 
180 
181 ######################################################################
182 ######################################################################
183 SingleTrackRefitter = """
184 process.load("RecoTracker.TrackProducer.TrackRefitters_cff")
185 process.TrackRefitter.src = ".oO[TrackCollection]Oo."
186 process.TrackRefitter.TTRHBuilder = ".oO[ttrhbuilder]Oo."
187 process.TrackRefitter.NavigationSchool = ""
188 """
189 
190 
191 ######################################################################
192 ######################################################################
193 LoadBasicModules = """
194 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
195 process.load("Configuration.Geometry.GeometryDB_cff")
196 process.load('Configuration.StandardSequences.Services_cff')
197 process.load("Configuration.StandardSequences..oO[magneticField]Oo._cff")
198 """
199 
200 
201 ######################################################################
202 ######################################################################
203 FileOutputTemplate = """
204 process.TFileService = cms.Service("TFileService",
205  fileName = cms.string('.oO[outputFile]Oo.')
206 )
207 """
208 
209 
210 ######################################################################
211 ######################################################################
212 DefinePath_CommonSelectionRefitting = """
213 process.p = cms.Path(
214 process.seqTrackselRefit*.oO[ValidationSequence]Oo.)
215 """
216 
217 ######################################################################
218 ######################################################################
219 mergeTemplate="""
220 #!/bin/bash
221 CWD=`pwd -P`
222 cd .oO[CMSSW_BASE]Oo./src
223 export SCRAM_ARCH=.oO[SCRAM_ARCH]Oo.
224 eval `scramv1 ru -sh`
225 
226 
227 .oO[createResultsDirectory]Oo.
228 
229 if [[ $HOSTNAME = lxplus[0-9]*[.a-z0-9]* ]] # check for interactive mode
230 then
231  mkdir -p .oO[workdir]Oo.
232  cd .oO[workdir]Oo.
233 else
234  cd $CWD
235 fi
236 echo "Working directory: $(pwd -P)"
237 
238 ###############################################################################
239 # download root files from eos
240 root_files=$(ls /eos/cms/store/caf/user/$USER/.oO[eosdir]Oo. \
241  | grep ".root$" | grep -v "result.root$")
242 #for file in ${root_files}
243 #do
244 # xrdcp -f root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./${file} .
245 # echo ${file}
246 #done
247 
248 
249 #run
250 .oO[DownloadData]Oo.
251 .oO[CompareAlignments]Oo.
252 
253 .oO[RunValidationPlots]Oo.
254 
255 # clean-up
256 # ls -l *.root
257 rm -f *.root
258 
259 #zip stdout and stderr from the farm jobs
260 cd .oO[logdir]Oo.
261 find . -name "*.stderr" -exec gzip -f {} \;
262 find . -name "*.stdout" -exec gzip -f {} \;
263 """
264 
265 
266 
267 ######################################################################
268 ######################################################################
269 mergeParallelOfflineTemplate="""
270 #!/bin/bash
271 CWD=`pwd -P`
272 cd .oO[CMSSW_BASE]Oo./src
273 export SCRAM_ARCH=.oO[SCRAM_ARCH]Oo.
274 eval `scramv1 ru -sh`
275 
276 if [[ $HOSTNAME = lxplus[0-9]*[.a-z0-9]* ]] # check for interactive mode
277 then
278  mkdir -p .oO[workdir]Oo.
279  cd .oO[workdir]Oo.
280 else
281  cd $CWD
282 fi
283 echo "Working directory: $(pwd -P)"
284 
285 ###############################################################################
286 # download root files from eos
287 root_files=$(ls /eos/cms/store/caf/user/$USER/.oO[eosdir]Oo. \
288  | grep ".root$" | grep -v "result.root$")
289 #for file in ${root_files}
290 #do
291 # xrdcp -f root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./${file} .
292 # echo ${file}
293 #done
294 
295 
296 #run
297 .oO[DownloadData]Oo.
298 """
299 
300 ######################################################################
301 ######################################################################
302 createResultsDirectoryTemplate="""
303 #create results-directory and copy used configuration there
304 rfmkdir -p .oO[datadir]Oo.
305 rfcp .oO[logdir]Oo./usedConfiguration.ini .oO[datadir]Oo.
306 """
307 
308 
309 ######################################################################
310 ######################################################################
311 mergeParallelResults="""
312 
313 .oO[beforeMerge]Oo.
314 .oO[doMerge]Oo.
315 
316 # create log file
317 ls -al .oO[mergeParallelFilePrefixes]Oo. > .oO[datadir]Oo./log_rootfilelist.txt
318 
319 # Remove parallel job files
320 .oO[rmUnmerged]Oo.
321 """
322 
323 
324 ######################################################################
325 ######################################################################
326 compareAlignmentsExecution="""
327 #merge for .oO[validationId]Oo. if it does not exist or is not up-to-date
328 echo -e "\n\nComparing validations"
329 mkdir -p /eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./
330 cp .oO[Alignment/OfflineValidation]Oo./scripts/compareFileAges.C .
331 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.\\\")"
332 comparisonNeeded=${?}
333 
334 if [[ ${comparisonNeeded} -eq 1 ]]
335 then
336  cp .oO[compareAlignmentsPath]Oo. .
337  root -x -q -b -l '.oO[compareAlignmentsName]Oo.++(\".oO[compareStrings]Oo.\", ".oO[legendheader]Oo.", ".oO[customtitle]Oo.", ".oO[customrighttitle]Oo.", .oO[bigtext]Oo.)'
338  mv result.root .oO[validationId]Oo._result.root
339  xrdcp -f .oO[validationId]Oo._result.root root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo.
340 else
341  echo ".oO[validationId]Oo._result.root is up-to-date, no need to compare again."
342  xrdcp -f root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./.oO[validationId]Oo._result.root .
343 fi
344 """
345 
346 
347 ######################################################################
348 ######################################################################
349 crabCfgTemplate="""
350 [CRAB]
351 jobtype = cmssw
352 scheduler = caf
353 use_server = 0
354 
355 [CMSSW]
356 datasetpath = .oO[dataset]Oo.
357 pset = .oO[cfgFile]Oo.
358 total_number_of_.oO[McOrData]Oo.
359 number_of_jobs = .oO[numberOfJobs]Oo.
360 output_file = .oO[outputFile]Oo.
361 runselection = .oO[runRange]Oo.
362 lumi_mask = .oO[JSON]Oo.
363 
364 [USER]
365 return_data = 0
366 copy_data = 1
367 storage_element = T2_CH_CERN
368 user_remote_dir = .oO[eosdir]Oo.
369 ui_working_dir = .oO[crabWorkingDir]Oo.
370 # script_exe = .oO[script]Oo.
371 # .oO[email]Oo.
372 
373 [CAF]
374 queue = .oO[queue]Oo.
375 """
376 
377 
378 
379 
380 ######################################################################
381 ######################################################################
382 ### ###
383 ### Alternate Templates ###
384 ### ###
385 ######################################################################
386 ######################################################################
387 
388 
389 def alternateTemplate( templateName, alternateTemplateName ):
390 
391  if not templateName in globals().keys():
392  msg = "unknown template to replace %s"%templateName
393  raise AllInOneError(msg)
394  if not alternateTemplateName in globals().keys():
395  msg = "unknown template to replace %s"%alternateTemplateName
396  raise AllInOneError(msg)
397  globals()[ templateName ] = globals()[ alternateTemplateName ]
398  # = eval("configTemplates.%s"%"alternateTemplate")
def alternateTemplate(templateName, alternateTemplateName)
Alternate Templates ###