CMS 3D CMS Logo

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