CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
cmsDriverOptions.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 # A Pyrelval Wrapper
4 
5 import optparse
6 import sys
7 import os
8 import re
9 import Configuration.PyReleaseValidation
10 from Configuration.PyReleaseValidation.ConfigBuilder import ConfigBuilder, defaultOptions
11 import traceback
12 # Prepare a parser to read the options
13 usage=\
14 """%prog <TYPE> [options].
15 Example:
16 
17 %prog reco -s RAW2DIGI,RECO --conditions STARTUP_V4::All --eventcontent RECOSIM
18 """
19 parser = optparse.OptionParser(usage)
20 
21 expertSettings = optparse.OptionGroup(parser, '===============\n Expert Options', 'Caution: please use only if you know what you are doing.')
22 famosSettings = optparse.OptionGroup(parser, '===============\n FastSimulation options', '')
23 parser.add_option_group(expertSettings)
24 
25 parser.add_option("-s", "--step",
26  help="The desired step. The possible values are: "+\
27  "GEN,SIM,DIGI,L1,DIGI2RAW,HLT,RAW2DIGI,RECO,POSTRECO,DQM,ALCA,VALIDATION,HARVESTING, NONE or ALL.",
28  default="ALL",
29  dest="step")
30 
31 parser.add_option("--conditions",
32  help="What conditions to use. This has to be specified",
33  default=None,
34  dest="conditions")
35 
36 parser.add_option("--eventcontent",
37  help="What event content to write out. Default=FEVTDEBUG, or FEVT (for cosmics)",
38  default='RECOSIM',
39  dest="eventcontent")
40 
41 parser.add_option("--filein",
42  help="The infile name.",
43  default="",#to be changed in the default form later
44  dest="filein")
45 
46 parser.add_option("--fileout",
47  help="The outfile name. If absent a default value is assigned",
48  default="", #to be changed in the default form later
49  dest="fileout")
50 
51 parser.add_option("--filetype",
52  help="The type of the infile (EDM, LHE or MCDB).",
53  default="",#to be changed in the default form later
54  dest="filetype")
55 
56 parser.add_option("-n", "--number",
57  help="The number of events. The default is 1.",
58  default="1",
59  dest="number")
60 
61 parser.add_option("--mc",
62  help="Specify that simulation is to be processed (default = guess based on options",
63  action="store_true",
64  default=False,
65  dest="isMC")
66 
67 parser.add_option("--data",
68  help="Specify that data is to be processed (default = guess based on options",
69  action="store_true",
70  default=False,
71  dest="isData")
72 
73 
74 parser.add_option("--no_exec",
75  help="Do not exec cmsRun. Just prepare the python config file.",
76  action="store_true",
77  default=False,
78  dest="no_exec_flag")
79 
80 # expert settings
81 expertSettings.add_option("--beamspot",
82  help="What beam spot to use (from Configuration/StandardSequences). Default depends on scenario",
83  default=defaultOptions.beamspot,
84  dest="beamspot")
85 
86 expertSettings.add_option("--customise",
87  help="Specify the file where the code to modify the process object is stored.",
88  default="",
89  dest="customisation_file")
90 
91 expertSettings.add_option("--inline_custom",
92  help="inline the customisation file",
93  default=False,
94  dest="inline_custom")
95 
96 expertSettings.add_option("--datatier",
97  help="What data tier to use.",
98  default='',
99  dest="datatier")
100 
101 expertSettings.add_option( "--dirin",
102  help="The infile directory.",
103  default="",
104  dest="dirin")
105 
106 expertSettings.add_option( "--dirout",
107  help="The outfile directory.",
108  default="",
109  dest="dirout")
110 
111 expertSettings.add_option("--filtername",
112  help="What filter name to specify in output module",
113  default="",
114  dest="filtername")
115 
116 expertSettings.add_option("--geometry",
117  help="What geometry to use (from Configuration/StandardSequences). Default=Ideal",
118  default=defaultOptions.geometry,
119  dest="geometry")
120 
121 expertSettings.add_option("--magField",
122  help="What magnetic field to use (from Configuration/StandardSequences).",
123  default=defaultOptions.magField,
124  dest="magField")
125 
126 expertSettings.add_option("--no_output",
127  help="Do not write anything to disk. This is for "+\
128  "benchmarking purposes.",
129  action="store_true",
130  default=False,
131  dest="no_output_flag")
132 
133 expertSettings.add_option("--oneoutput",
134  help="use only one output module",
135  action="store_true",
136  default="False",
137  dest="oneoutput")
138 
139 expertSettings.add_option("--prefix",
140  help="Specify a prefix to the cmsRun command.",
141  default="",
142  dest="prefix")
143 
144 expertSettings.add_option("--relval",
145  help="Set total number of events and events per job.", #this does not get used but get parsed in the command by DatOps
146  default="",
147  dest="relval")
148 
149 expertSettings.add_option("--dump_python",
150  help="Dump the config file in python "+\
151  "and do a full expansion of imports.",
152  action="store_true",
153  default=False,
154  dest="dump_python")
155 
156 expertSettings.add_option("--dump_DSetName",
157  help="Dump the primary datasetname.",
158  action="store_true",
159  default=False,
160  dest="dump_dsetname_flag")
161 
162 expertSettings.add_option("--pileup",
163  help="What pileup config to use. Default=NoPileUp.",
164  default=defaultOptions.pileup,
165  dest="pileup")
166 
167 expertSettings.add_option("--pileup_input",
168  help="define the pile up files to mix with",
169  default=None,
170  dest="pileup_input")
171 
172 expertSettings.add_option("--datamix",
173  help="What datamix config to use. Default=DataOnSim.",
174  default=defaultOptions.datamix,
175  dest="datamix")
176 
177 expertSettings.add_option("--gflash",
178  help="Run the FULL SIM using the GFlash parameterization.",
179  action="store_true",
180  default=defaultOptions.gflash,
181  dest="gflash")
182 
183 expertSettings.add_option("--himix",
184  help="Run the Heavy Ions signal mixing.",
185  action="store_true",
186  default=defaultOptions.himix,
187  dest="himix")
188 
189 expertSettings.add_option("--python_filename",
190  help="Change the name of the created config file ",
191  default='',
192  dest="python_filename")
193 
194 expertSettings.add_option("--secondfilein",
195  help="The secondary infile name."+\
196  "for the two-file solution. Default is no file",
197  default="",#to be changed in the default form later
198  dest="secondfilein")
199 
200 expertSettings.add_option("--writeraw",
201  help="In addition to the nominal output, write a file with just raw",
202  action="store_true",
203  default=False,
204  dest="writeraw")
205 
206 expertSettings.add_option("--processName",
207  help="set process name explicitly",
208  default = None,
209  dest="name"
210  )
211 
212 expertSettings.add_option("--triggerResultsProcess",
213  help="for splitting jobs specify from which process to take edm::TriggerResults",
214  default = None,
215  dest="triggerResultsProcess"
216  )
217 
218 expertSettings.add_option("--hltProcess",
219  help="modify the DQM sequence to look for HLT trigger results with the specified process name",
220  default = None,
221  dest="hltProcess"
222  )
223 
224 expertSettings.add_option("--scenario",
225  help="Select scenario overriding standard settings (available:"+str(defaultOptions.scenarioOptions)+")",
226  default='pp',
227  dest="scenario")
228 
229 expertSettings.add_option("--harvesting",
230  help="What harvesting to use (from Configuration/StandardSequences). Default=AtRunEnd",
231  default=defaultOptions.harvesting,
232  dest="harvesting")
233 
234 expertSettings.add_option("--particle_table",
235  help="Which particle properties table is loaded. Default=pythia",
236  default=defaultOptions.particleTable,
237  dest="particleTable")
238 
239 expertSettings.add_option("--dasquery",
240  help="Allow to define the source.fileNames from the das search command",
241  default='',
242  dest="dbsquery")
243 expertSettings.add_option("--dbsquery",
244  help="Deprecated. Please use dasquery option. Functions for backward compatibility",
245  default='',
246  dest="dasquery")
247 
248 expertSettings.add_option("--lazy_download",
249  help="Enable lazy downloading of input files",
250  action="store_true",
251  default=False,
252  dest="lazy_download")
253 
254 expertSettings.add_option("--repacked",
255  help="When the input file is a file with repacked raw data with label rawDataRepacker",
256  action="store_true",
257  default=False,
258  dest="isRepacked"
259  )
260 
261 expertSettings.add_option("--custom_conditions",
262  help="Allow to give a few overriding tags for the GT",
263  default='',
264  dest='custom_conditions')
265 
266 expertSettings.add_option("--inline_eventcontent",
267  help="expand event content definitions",
268  action="store_true",
269  default=False,
270  dest="inlineEventContent")
271 
272 
273 expertSettings.add_option("--inline_object",
274  help="expand explicitely the definition of a list of objects",
275  default='',
276  dest="inlineObjets")
277 
278 expertSettings.add_option("--hideGen",
279  help="do not inline the generator information, just load it",
280  default=False,
281  action="store_true")
282 expertSettings.add_option("--output",
283  help="specify the list of output modules using dict",
284  default='',
285  dest="outputDefinition")
286 
287 expertSettings.add_option("--inputCommands",
288  help="specify the input commands; i.e dropping products",
289  default=None,
290  dest="inputCommands")
291 
292 expertSettings.add_option("--inputEventContent",
293  help="specify the input event content",
294  default=None,
295  dest="inputEventContent")
296 expertSettings.add_option("--slhc",
297  help="Specify the SLHC scenario version",
298  default=None,
299  dest="slhc")
300 
301 (options,args) = parser.parse_args() # by default the arg is sys.argv[1:]
302 
303 
304 #################################
305 # Check parameters for validity #
306 #################################
307 # A simple check on the consistency of the arguments
308 if len(sys.argv)==1:
309  raise "Event Type: ", "No event type specified!"
310 
311 # check in case of ALCAOUTPUT case for alca splitting
312 if options.triggerResultsProcess == None and "ALCAOUTPUT" in options.step:
313  print "ERROR: If ALCA splitting is requested, the name of the process in which the alca producers ran needs to be specified. E.g. via --triggerResultsProcess RECO"
314  sys.exit(1)
315 
316 
317 options.evt_type=sys.argv[1]
318 
319 # memorize the command line arguments
320 options.arguments = reduce(lambda x, y: x+' '+y, sys.argv[1:])
321 
322 # now adjust the given parameters before passing it to the ConfigBuilder
323 
324 
325 
326 # Build the IO files if necessary.
327 # The default form of the files is:
328 # <type>_<energy>_<step>.root
329 prec_step = {"NONE":"",
330  "ALL":"",
331  "GEN":"",
332  "SIM":"GEN",
333  "DIGI":"SIM",
334  "HLT":"RAW",
335  "RECO":"DIGI",
336  "ALCA":"RECO",
337  "ANA":"RECO",
338  "SKIM":"RECO",
339  "DIGI2RAW":"DIGI",
340  "RAW2DIGI":"DIGI2RAW",
341  "RAW2RECO":"DIGI2RAW",
342  "DATAMIX":"DIGI",
343  "DIGI2RAW":"DATAMIX",
344  "HARVESTING":"RECO",
345  "ALCAHARVEST":"RECO"}
346 
347 trimmedEvtType=options.evt_type.split('/')[-1]
348 
349 trimmedStep=''
350 isFirst=0
351 step_list=options.step.split(',')
352 for s in step_list:
353  stepSP=s.split(':')
354  step=stepSP[0]
355  if ( isFirst==0 ):
356  trimmedStep=step
357  isFirst=1
358  else:
359  trimmedStep=trimmedStep+','+step
360 
361 
362 if options.filetype=="":
363  if options.filein.lower().endswith(".lhe") or options.filein.lower().endswith(".lhef"):
364  options.filetype="LHE"
365  elif options.filein.startswith("mcdb:"):
366  options.filetype="MCDB"
367  else:
368  options.filetype="EDM"
369 if options.filetype=="MCDB" and options.filein.startswith("mcdb:"):
370  options.filein = options.filein[5:]
371 
372 filesuffix = {"LHE": "lhe", "EDM": "root", "MCDB": ""}[options.filetype]
373 
374 first_step=trimmedStep.split(',')[0]
375 if options.filein=="" and not (first_step in ("ALL","GEN","SIM_CHAIN") and options.dirin == ""):
376  if options.dirin=="":
377  options.dirin="file:"
378  options.filein=trimmedEvtType+"_"+prec_step[first_step]+"."+filesuffix
379 
380 
381 # Prepare the canonical file name for output / config file etc
382 # (EventType_STEP1_STEP2_..._PU)
383 standardFileName = ""
384 standardFileName = trimmedEvtType+"_"+trimmedStep
385 standardFileName = standardFileName.replace(",","_").replace(".","_")
386 if options.pileup != "NoPileUp":
387  standardFileName += "_PU"
388 
389 
390 # if no output file name given, set it to default
391 if options.fileout=="" and not first_step in ("HARVESTING", "ALCAHARVEST"):
392  options.fileout = standardFileName+".root"
393 
394 # Prepare the name of the config file
395 # (in addition list conditions in name)
396 python_config_filename = standardFileName
397 
398 # now treat the conditions...
399 conditionsSP = options.conditions.split(',')
400 if len(conditionsSP) > 1:
401  # for conditions like STARTUP_V1, IDEAL_V1 we want only the STARTUP or IDEAL part
402  conditionsType = conditionsSP[1].split("_")[0]
403  python_config_filename += "_"+str(conditionsType)
404 
405 python_config_filename+=".py"
406 
407 
408 #if desired, just add _rawonly to the end of the output file name
409 fileraw=''
410 if options.writeraw:
411  fileraw=options.dirout
412  wrSP=options.fileout.split('.')
413  wrSPLen=len(wrSP)
414  counter=0
415  for w in wrSP:
416  counter=counter+1
417  if ( counter < wrSPLen ):
418  if ( counter == 1):
419  fileraw=fileraw+w
420  else:
421  fileraw=fileraw+'.'+w
422  else:
423  fileraw=fileraw+'_rawonly.'+w
424 
425 
426 
427 secondfilestr=''
428 if options.secondfilein!='':
429  secondfilestr=options.dirin+options.secondfilein
430 
431 
432 # replace step aliases by right list
433 if options.step=='NONE':
434  options.step=''
435 elif options.step=='ALL':
436  options.step='GEN,SIM,DIGI,L1,DIGI2RAW,RAW2DIGI,RECO,POSTRECO,VALIDATION,DQM'
437 elif options.step=='DATA_CHAIN':
438  options.step='RAW2DIGI,RECO,POSTRECO,DQM'
439 options.step = options.step.replace("SIM_CHAIN","GEN,SIM,DIGI,L1,DIGI2RAW")
440 
441 # add on the end of job sequence...
442 # if not fastsim or harvesting...
443 
444 addEndJob = True
445 if ("FASTSIM" in options.step and not "VALIDATION" in options.step) or "HARVESTING" in options.step or "ALCAHARVEST" in options.step or "ALCAOUTPUT" in options.step or options.step == "":
446  addEndJob = False
447 if ("SKIM" in options.step and not "RECO" in options.step):
448  addEndJob = False
449 if ("ENDJOB" in options.step):
450  addEndJob = False
451 if addEndJob:
452  options.step=options.step+',ENDJOB'
453 print options.step
454 
455 
456 # Setting name of process
457 # if not set explicitly it needs some thinking
458 if not options.name:
459  if 'HLT' in trimmedStep:
460  options.name = 'HLT'
461  elif 'RECO' in trimmedStep:
462  options.name = 'RECO'
463  elif trimmedStep == 'NONE' and options.filetype in ('LHE', 'MCDB'):
464  options.name = 'LHE'
465  else:
466  options.name = trimmedStep.split(',')[-1]
467 
468 # check to be sure that people run the harvesting as a separate step
469 isHarvesting = False
470 isOther = False
471 
472 s_list=options.step.split(',')
473 if "HARVESTING" in options.step and len(s_list) > 1:
474  print "The Harvesting step must be run alone"
475  sys.exit(1)
476 
477 # if not specified by user try to guess whether MC or DATA
478 if not options.isData and not options.isMC:
479  if 'SIM' in trimmedStep:
480  options.isMC=True
481  if 'CFWRITER' in trimmedStep:
482  options.isMC=True
483  if 'DIGI' in trimmedStep:
484  options.isMC=True
485  if (not (options.eventcontent == None)) and 'SIM' in options.eventcontent:
486  options.isMC=True
487  if 'SIM' in options.datatier:
488  options.isMC=True
489  if options.isMC:
490  print 'We have determined that this is simulation (if not, rerun cmsDriver.py with --data)'
491  else:
492  print 'We have determined that this is real data (if not, rerun cmsDriver.py with --mc)'
493 
494 
double split
Definition: MVATrainer.cc:139