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.Applications
10 from Configuration.Applications.ConfigBuilder import ConfigBuilder, defaultOptions
11 import traceback
12 
13 
15  return
16 
18  return
19 
20 def OptionsFromCommand(command):
21  items=command.split()
22  if items[0] != 'cmsDriver.py':
23  return None
24  items.append('--evt_type')
25  items.append(items[1])
26  options=OptionsFromItems(items[2:])
27  options.arguments = command
28  return options
29 
31  import sys
32  options=OptionsFromItems(sys.argv[1:])
33  # memorize the command line arguments
34  options.arguments = reduce(lambda x, y: x+' '+y, sys.argv[1:])
35  return options
36 
37 def OptionsFromItems(items):
38  import sys
39  from Configuration.Applications.Options import parser,threeValued
40  #three valued options
41  for (index,item) in enumerate(items):
42  for (opt,value) in threeValued:
43  if (str(item) in opt) and (index==len(items)-1 or items[index+1].startswith('-')):
44  items.insert(index+1,value)
45 
46  (options,args) = parser.parse_args(items)
47 
48  if not options.conditions or options.conditions=="help":
49  from Configuration.AlCa import autoCond
50  possible=""
51  for k in autoCond.autoCond:
52  possible+="\nauto:"+k+" -> "+autoCond.autoCond[k]
53  raise Exception("the --conditions option is mandatory. Possibilities are: "+possible)
54 
55 
56  #################################
57  # Check parameters for validity #
58  #################################
59 
60  # check in case of ALCAOUTPUT case for alca splitting
61  if options.triggerResultsProcess == None and "ALCAOUTPUT" in options.step:
62  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"
63  sys.exit(1)
64 
65  if not options.evt_type:
66  options.evt_type=sys.argv[1]
67 
68  #now adjust the given parameters before passing it to the ConfigBuilder
69 
70  #trail a "/" to dirin and dirout
71  if options.dirin!='' and (not options.dirin.endswith('/')): options.dirin+='/'
72  if options.dirout!='' and (not options.dirout.endswith('/')): options.dirout+='/'
73 
74  # Build the IO files if necessary.
75  # The default form of the files is:
76  # <type>_<energy>_<step>.root
77  prec_step = {"NONE":"",
78  "FILTER":"",
79  "ALL":"",
80  "LHE":"",
81  "GEN":"",
82  "reGEN":"",
83  "SIM":"GEN",
84  "reSIM":"SIM",
85  "DIGI":"SIM",
86  "DIGIPREMIX":"SIM",
87  "DIGIPREMIX_S2":"SIM",
88  "reDIGI":"DIGI",
89  "L1REPACK":"RAW",
90  "HLT":"RAW",
91  "RECO":"DIGI",
92  "ALCA":"RECO",
93  "ANA":"RECO",
94  "SKIM":"RECO",
95  "DIGI2RAW":"DIGI",
96  "RAW2DIGI":"DIGI2RAW",
97  "RAW2RECO":"DIGI2RAW",
98  "DATAMIX":"DIGI",
99  "DIGI2RAW":"DATAMIX",
100  "HARVESTING":"RECO",
101  "ALCAHARVEST":"RECO",
102  "PAT":"RECO"}
103 
104  trimmedEvtType=options.evt_type.split('/')[-1]
105 
106  #get the list of steps, without their options
107  options.trimmedStep=[]
108  for s in options.step.split(','):
109  step=s.split(':')[0]
110  options.trimmedStep.append(step)
111  first_step=options.trimmedStep[0]
112 
113  #replace step aliases
114  # this does not affect options.trimmedStep which still contains 'NONE'
115  stepsAliases={
116  'NONE':'',
117  'ALL':'GEN,SIM,DIGI,L1,DIGI2RAW,HLT:GRun,RAW2DIGI,RECO,POSTRECO,VALIDATION,DQM',
118  'DATA_CHAIN':'RAW2DIGI,RECO,POSTRECO,DQM'
119  }
120  if options.step in stepsAliases:
121  options.step=stepsAliases[options.step]
122 
123  options.step = options.step.replace("SIM_CHAIN","GEN,SIM,DIGI,L1,DIGI2RAW")
124 
125  # add on the end of job sequence...
126  addEndJob = True
127  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 == "":
128  addEndJob = False
129  if ("SKIM" in options.step and not "RECO" in options.step):
130  addEndJob = False
131  if ("ENDJOB" in options.step):
132  addEndJob = False
133  if ('DQMIO' in options.datatier):
134  addEndJob = False
135  if addEndJob:
136  options.step=options.step+',ENDJOB'
137 
138 
139  #determine the type of file on input
140  if options.filetype==defaultOptions.filetype:
141  if options.filein.lower().endswith(".lhe") or options.filein.lower().endswith(".lhef") or options.filein.startswith("lhe:"):
142  options.filetype="LHE"
143  elif options.filein.startswith("mcdb:"):
144  print "This is a deprecated way of selecting lhe files from article number. Please use lhe:article argument to --filein"
145  options.filein=options.filein.replace('mcdb:','lhe:')
146  options.filetype="LHE"
147  else:
148  options.filetype="EDM"
149 
150  filesuffix = {"LHE": "lhe", "EDM": "root", "MCDB": "", "DQM":"root"}[options.filetype]
151 
152  if options.filein=="" and not (first_step in ("ALL","GEN","LHE","SIM_CHAIN")):
153  options.dirin="file:"+options.dirin.replace('file:','')
154  options.filein=trimmedEvtType+"_"+prec_step[first_step]+"."+filesuffix
155 
156 
157  # Prepare the canonical file name for output / config file etc
158  # (EventType_STEP1_STEP2_..._PU)
159  standardFileName = ""
160  standardFileName = trimmedEvtType+"_"+"_".join(options.trimmedStep)
161  standardFileName = standardFileName.replace(",","_").replace(".","_")
162  if options.pileup != "NoPileUp":
163  standardFileName += "_PU"
164 
165 
166  # if no output file name given, set it to default
167  if options.fileout=="" and not first_step in ("HARVESTING", "ALCAHARVEST"):
168  options.fileout = standardFileName+".root"
169 
170  # Prepare the name of the config file
171  if not options.python_filename:
172  options.python_filename = standardFileName+'.py'
173 
174  print options.step
175 
176 
177  # Setting name of process
178  # if not set explicitly it needs some thinking
179  if not options.name:
180  if 'reSIM' in options.trimmedStep:
181  options.name = 'RESIM'
182  elif 'reDIGI' in options.trimmedStep:
183  options.name = 'REDIGI'
184  elif 'HLT' in options.trimmedStep:
185  options.name = 'HLT'
186  elif 'RECO' in options.trimmedStep:
187  options.name = 'RECO'
188  elif options.trimmedStep == ['NONE'] and options.filetype in ('LHE', 'MCDB'):
189  options.name = 'LHE'
190  elif len(options.trimmedStep)==0:
191  options.name = 'PROCESS'
192  else:
193  options.name = options.trimmedStep[-1]
194 
195  # check to be sure that people run the harvesting as a separate step
196  isHarvesting = False
197  isOther = False
198 
199  if "HARVESTING" in options.trimmedStep and len(options.trimmedStep) > 1:
200  raise Exception("The Harvesting step must be run alone")
201 
202  # if not specified by user try to guess whether MC or DATA
203  if not options.isData and not options.isMC:
204  if 'SIM' in options.trimmedStep:
205  options.isMC=True
206  if 'CFWRITER' in options.trimmedStep:
207  options.isMC=True
208  if 'DIGI' in options.trimmedStep:
209  options.isMC=True
210  if 'DIGI2RAW' in options.trimmedStep:
211  options.isMC=True
212  if (not (options.eventcontent == None)) and 'SIM' in options.eventcontent:
213  options.isMC=True
214  if 'SIM' in options.datatier:
215  options.isMC=True
216  if options.isMC:
217  print 'We have determined that this is simulation (if not, rerun cmsDriver.py with --data)'
218  else:
219  print 'We have determined that this is real data (if not, rerun cmsDriver.py with --mc)'
220 
221  if options.profile:
222  if options.profile and options.prefix:
223  raise Exception("--profile and --prefix are incompatible")
224  profilerType = 'pp'
225  profileOpts = options.profile.split(':')
226  if len(profileOpts):
227  profilerType = profileOpts[0].replace("=", " ")
228 
229  if profilerType == "pp":
230  options.profileTypeLabel = "performance"
231  elif profilerType == "mp":
232  options.profileTypeLabel = "memory"
233  elif profilerType.startswith("fp "):
234  options.profileTypeLabel = profilerType.replace("fp ", "")
235  else:
236  raise Exception("Not a valid profiler type %s. Alternatives are pp, mp, fp=<function>."%(profilerType))
237 
238  options.prefix = "igprof -t cmsRun -%s" % profilerType
239 
240  # If an "era" argument was supplied make sure it is one of the valid possibilities
241  if options.era :
242  from Configuration.StandardSequences.Eras import eras
243  from FWCore.ParameterSet.Config import Modifier, ModifierChain
244  # Split the string by commas to check individual eras
245  requestedEras = options.era.split(",")
246  # Check that the entry is a valid era
247  for eraName in requestedEras :
248  if not hasattr( eras, eraName ) : # Not valid, so print a helpful message
249  validOptions="" # Create a stringified list of valid options to print to the user
250  for key in eras.__dict__ :
251  if eras.internalUseEras.count(getattr(eras,key)) > 0 : continue # Don't tell the user about things they should leave alone
252  if isinstance( eras.__dict__[key], Modifier ) or isinstance( eras.__dict__[key], ModifierChain ) :
253  if validOptions!="" : validOptions+=", "
254  validOptions+="'"+key+"'"
255  raise Exception( "'%s' is not a valid option for '--era'. Valid options are %s." % (eraName, validOptions) )
256  # Warn the user if they are explicitly setting an era that should be
257  # set automatically by the ConfigBuilder.
258  for eraName in requestedEras : # Same loop, but had to make sure all the names existed first
259  if eras.internalUseEras.count(getattr(eras,eraName)) > 0 :
260  print "WARNING: You have explicitly set '"+eraName+"' with the '--era' command. That is usually reserved for internal use only."
261  # If the "--fast" option was supplied automatically enable the fastSim era
262  if options.fast :
263  if options.era:
264  options.era+=",fastSim"
265  else :
266  options.era="fastSim"
267 
268 
269  return options
270 
static std::string join(char **cmd)
Definition: RemoteFile.cc:18