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 eos='/afs/cern.ch/project/eos/installation/cms/bin/eos.select'
56 export X509_USER_PROXY=.oO[scriptsdir]Oo./.user_proxy
57 cd .oO[CMSSW_BASE]Oo./src
58 export SCRAM_ARCH=.oO[SCRAM_ARCH]Oo.
59 eval `scramv1 ru -sh`
60 #rfmkdir -p .oO[datadir]Oo. &>! /dev/null
61 
62 #remove possible result file from previous runs
63 previous_results=$($eos ls /store/caf/user/$USER/.oO[eosdir]Oo.)
64 for file in ${previous_results}
65 do
66  if [ ${file} = /store/caf/user/$USER/.oO[eosdir]Oo./.oO[outputFile]Oo. ]
67  then
68  xrdcp -f root://eoscms//eos/cms${file} root://eoscms//eos/cms${file}.bak
69  fi
70 done
71 
72 if [[ $HOSTNAME = lxplus[0-9]*[.a-z0-9]* ]] # check for interactive mode
73 then
74  rfmkdir -p .oO[workdir]Oo.
75  rm -f .oO[workdir]Oo./*
76  cd .oO[workdir]Oo.
77 else
78  mkdir -p $LSFWORKDIR/TkAllInOneTool
79  cd $LSFWORKDIR/TkAllInOneTool
80 fi
81 
82 # rm -f .oO[workdir]Oo./*
83 # cd .oO[workdir]Oo.
84 
85 #run
86 pwd
87 df -h .
88 .oO[CommandLine]Oo.
89 echo "----"
90 echo "List of files in $(pwd):"
91 ls -ltr
92 echo "----"
93 echo ""
94 
95 
96 #retrieve
97 rfmkdir -p .oO[logdir]Oo. >&! /dev/null
98 gzip -f LOGFILE_*_.oO[name]Oo..log
99 find . -maxdepth 1 -name "LOGFILE*.oO[alignmentName]Oo.*" -print | xargs -I {} bash -c "rfcp {} .oO[logdir]Oo."
100 
101 #copy root files to eos
102 $eos mkdir -p /store/caf/user/$USER/.oO[eosdir]Oo.
103 if [ .oO[parallelJobs]Oo. -eq 1 ]
104 then
105  root_files=$(ls --color=never -d *.oO[alignmentName]Oo.*.root)
106 else
107  root_files=$(ls --color=never -d *.oO[alignmentName]Oo._.oO[nIndex]Oo.*.root)
108 fi
109 echo ${root_files}
110 
111 for file in ${root_files}
112 do
113  xrdcp -f ${file} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo.
114  echo ${file}
115 done
116 
117 #cleanup
118 if [[ $HOSTNAME = lxplus[0-9]*[.a-z0-9]* ]] # check for interactive mode
119 then
120  rm -rf .oO[workdir]Oo.
121 fi
122 echo "done."
123 """
124 
125 
126 ######################################################################
127 ######################################################################
128 cfgTemplate="""
129 import FWCore.ParameterSet.Config as cms
130 
131 process = cms.Process(".oO[ProcessName]Oo.")
132 
133 .oO[datasetDefinition]Oo.
134 .oO[Bookkeeping]Oo.
135 .oO[LoadBasicModules]Oo.
136 .oO[TrackSelectionRefitting]Oo.
137 .oO[LoadGlobalTagTemplate]Oo.
138 .oO[condLoad]Oo.
139 .oO[ValidationConfig]Oo.
140 .oO[FileOutputTemplate]Oo.
141 
142 .oO[DefinePath]Oo.
143 """
144 
145 
146 ######################################################################
147 ######################################################################
148 Bookkeeping = """
149 process.options = cms.untracked.PSet(
150  wantSummary = cms.untracked.bool(False),
151  Rethrow = cms.untracked.vstring("ProductNotFound"), # make this exception fatal
152  fileMode = cms.untracked.string('NOMERGE') # no ordering needed, but calls endRun/beginRun etc. at file boundaries
153 )
154 
155 process.load("FWCore.MessageLogger.MessageLogger_cfi")
156 process.MessageLogger.destinations = ['cout', 'cerr']
157 process.MessageLogger.cerr.FwkReport.reportEvery = 1000
158 process.MessageLogger.statistics.append('cout')
159 """
160 
161 
162 ######################################################################
163 ######################################################################
164 CommonTrackSelectionRefitting = """
165 import Alignment.CommonAlignment.tools.trackselectionRefitting as trackselRefit
166 process.seqTrackselRefit = trackselRefit.getSequence(process, '.oO[trackcollection]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 
178 
179 ######################################################################
180 ######################################################################
181 SingleTrackRefitter = """
182 process.load("RecoTracker.TrackProducer.TrackRefitters_cff")
183 process.TrackRefitter.src = ".oO[TrackCollection]Oo."
184 process.TrackRefitter.TTRHBuilder = ".oO[ttrhbuilder]Oo."
185 process.TrackRefitter.NavigationSchool = ""
186 """
187 
188 
189 ######################################################################
190 ######################################################################
191 LoadBasicModules = """
192 process.load("RecoVertex.BeamSpotProducer.BeamSpot_cff")
193 process.load("Configuration.Geometry.GeometryDB_cff")
194 process.load('Configuration.StandardSequences.Services_cff')
195 process.load("Configuration.StandardSequences..oO[magneticField]Oo._cff")
196 """
197 
198 
199 ######################################################################
200 ######################################################################
201 FileOutputTemplate = """
202 process.TFileService = cms.Service("TFileService",
203  fileName = cms.string('.oO[outputFile]Oo.')
204 )
205 """
206 
207 
208 ######################################################################
209 ######################################################################
210 DefinePath_CommonSelectionRefitting = """
211 process.p = cms.Path(
212 process.seqTrackselRefit*.oO[ValidationSequence]Oo.)
213 """
214 
215 ######################################################################
216 ######################################################################
217 mergeTemplate="""
218 #!/bin/bash
219 eos='/afs/cern.ch/project/eos/installation/cms/bin/eos.select'
220 CWD=`pwd -P`
221 cd .oO[CMSSW_BASE]Oo./src
222 export SCRAM_ARCH=.oO[SCRAM_ARCH]Oo.
223 eval `scramv1 ru -sh`
224 
225 #create results-directory and copy used configuration there
226 rfmkdir -p .oO[datadir]Oo.
227 rfcp .oO[logdir]Oo./usedConfiguration.ini .oO[datadir]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=$($eos ls /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 mergeParallelResults="""
269 
270 .oO[beforeMerge]Oo.
271 .oO[doMerge]Oo.
272 
273 # create log file
274 ls -al .oO[mergeParallelFilePrefixes]Oo. > .oO[datadir]Oo./log_rootfilelist.txt
275 
276 # Remove parallel job files
277 .oO[rmUnmerged]Oo.
278 """
279 
280 
281 ######################################################################
282 ######################################################################
283 compareAlignmentsExecution="""
284 #merge for .oO[validationId]Oo. if it does not exist or is not up-to-date
285 echo -e "\n\nComparing validations"
286 $eos mkdir -p /store/caf/user/$USER/.oO[eosdir]Oo./
287 cp .oO[Alignment/OfflineValidation]Oo./scripts/compareFileAges.C .
288 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.\\\")"
289 comparisonNeeded=${?}
290 
291 if [[ ${comparisonNeeded} -eq 1 ]]
292 then
293  cp .oO[compareAlignmentsPath]Oo. .
294  root -x -q -b -l '.oO[compareAlignmentsName]Oo.++(\".oO[compareStrings]Oo.\", ".oO[legendheader]Oo.", ".oO[customtitle]Oo.", ".oO[customrighttitle]Oo.", .oO[bigtext]Oo.)'
295  mv result.root .oO[validationId]Oo._result.root
296  xrdcp -f .oO[validationId]Oo._result.root root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo.
297 else
298  echo ".oO[validationId]Oo._result.root is up-to-date, no need to compare again."
299  xrdcp -f root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./.oO[validationId]Oo._result.root .
300 fi
301 """
302 
303 
304 ######################################################################
305 ######################################################################
306 crabCfgTemplate="""
307 [CRAB]
308 jobtype = cmssw
309 scheduler = caf
310 use_server = 0
311 
312 [CMSSW]
313 datasetpath = .oO[dataset]Oo.
314 pset = .oO[cfgFile]Oo.
315 total_number_of_.oO[McOrData]Oo.
316 number_of_jobs = .oO[numberOfJobs]Oo.
317 output_file = .oO[outputFile]Oo.
318 runselection = .oO[runRange]Oo.
319 lumi_mask = .oO[JSON]Oo.
320 
321 [USER]
322 return_data = 0
323 copy_data = 1
324 storage_element = T2_CH_CERN
325 user_remote_dir = .oO[eosdir]Oo.
326 ui_working_dir = .oO[crabWorkingDir]Oo.
327 # script_exe = .oO[script]Oo.
328 # .oO[email]Oo.
329 
330 [CAF]
331 queue = .oO[queue]Oo.
332 """
333 
334 
335 
336 
337 ######################################################################
338 ######################################################################
339 ### ###
340 ### Alternate Templates ###
341 ### ###
342 ######################################################################
343 ######################################################################
344 
345 
346 def alternateTemplate( templateName, alternateTemplateName ):
347 
348  if not templateName in globals().keys():
349  msg = "unknown template to replace %s"%templateName
350  raise AllInOneError(msg)
351  if not alternateTemplateName in globals().keys():
352  msg = "unknown template to replace %s"%alternateTemplateName
353  raise AllInOneError(msg)
354  globals()[ templateName ] = globals()[ alternateTemplateName ]
355  # = eval("configTemplates.%s"%"alternateTemplate")
def alternateTemplate(templateName, alternateTemplateName)
Alternate Templates ###