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 
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.PyReleaseValidation.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  "reDIGI":"DIGI",
87  "L1REPACK":"RAW",
88  "HLT":"RAW",
89  "RECO":"DIGI",
90  "ALCA":"RECO",
91  "ANA":"RECO",
92  "SKIM":"RECO",
93  "DIGI2RAW":"DIGI",
94  "RAW2DIGI":"DIGI2RAW",
95  "RAW2RECO":"DIGI2RAW",
96  "DATAMIX":"DIGI",
97  "DIGI2RAW":"DATAMIX",
98  "HARVESTING":"RECO",
99  "ALCAHARVEST":"RECO"}
100 
101  trimmedEvtType=options.evt_type.split('/')[-1]
102 
103  #get the list of steps, without their options
104  options.trimmedStep=[]
105  for s in options.step.split(','):
106  step=s.split(':')[0]
107  options.trimmedStep.append(step)
108  first_step=options.trimmedStep[0]
109 
110  #replace step aliases
111  # this does not affect options.trimmedStep which still contains 'NONE'
112  stepsAliases={
113  'NONE':'',
114  'ALL':'GEN,SIM,DIGI,L1,DIGI2RAW,HLT:GRun,RAW2DIGI,RECO,POSTRECO,VALIDATION,DQM',
115  'DATA_CHAIN':'RAW2DIGI,RECO,POSTRECO,DQM'
116  }
117  if options.step in stepsAliases:
118  options.step=stepsAliases[options.step]
119 
120  options.step = options.step.replace("SIM_CHAIN","GEN,SIM,DIGI,L1,DIGI2RAW")
121 
122  # add on the end of job sequence...
123  addEndJob = True
124  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 == "":
125  addEndJob = False
126  if ("SKIM" in options.step and not "RECO" in options.step):
127  addEndJob = False
128  if ("ENDJOB" in options.step):
129  addEndJob = False
130  if ('DQMROOT' in options.datatier):
131  addEndJob = False
132  if addEndJob:
133  options.step=options.step+',ENDJOB'
134 
135 
136  #determine the type of file on input
137  if options.filetype==defaultOptions.filetype:
138  if options.filein.lower().endswith(".lhe") or options.filein.lower().endswith(".lhef") or options.filein.startswith("lhe:"):
139  options.filetype="LHE"
140  elif options.filein.startswith("mcdb:"):
141  print "This is a deprecated way of selecting lhe files from article number. Please use lhe:article argument to --filein"
142  options.filein=options.filein.replace('mcdb:','lhe:')
143  options.filetype="LHE"
144  else:
145  options.filetype="EDM"
146 
147  filesuffix = {"LHE": "lhe", "EDM": "root", "MCDB": "", "DQM":"root"}[options.filetype]
148 
149  if options.filein=="" and not (first_step in ("ALL","LHE","GEN","SIM_CHAIN")):
150  options.dirin="file:"+options.dirin.replace('file:','')
151  options.filein=trimmedEvtType+"_"+prec_step[first_step]+"."+filesuffix
152 
153 
154  # Prepare the canonical file name for output / config file etc
155  # (EventType_STEP1_STEP2_..._PU)
156  standardFileName = ""
157  standardFileName = trimmedEvtType+"_"+"_".join(options.trimmedStep)
158  standardFileName = standardFileName.replace(",","_").replace(".","_")
159  if options.pileup != "NoPileUp":
160  standardFileName += "_PU"
161 
162 
163  # if no output file name given, set it to default
164  if options.fileout=="" and not first_step in ("HARVESTING", "ALCAHARVEST"):
165  options.fileout = standardFileName+".root"
166 
167  # Prepare the name of the config file
168  if not options.python_filename:
169  options.python_filename = standardFileName+'.py'
170 
171  print options.step
172 
173 
174  # Setting name of process
175  # if not set explicitly it needs some thinking
176  if not options.name:
177  if 'reSIM' in options.trimmedStep:
178  options.name = 'RESIM'
179  elif 'reDIGI' in options.trimmedStep:
180  options.name = 'REDIGI'
181  elif 'HLT' in options.trimmedStep:
182  options.name = 'HLT'
183  elif 'RECO' in options.trimmedStep:
184  options.name = 'RECO'
185  elif options.trimmedStep == ['NONE'] and options.filetype in ('LHE', 'MCDB'):
186  options.name = 'LHE'
187  elif len(options.trimmedStep)==0:
188  options.name = 'PROCESS'
189  else:
190  options.name = options.trimmedStep[-1]
191 
192  # check to be sure that people run the harvesting as a separate step
193  isHarvesting = False
194  isOther = False
195 
196  if "HARVESTING" in options.trimmedStep and len(options.trimmedStep) > 1:
197  raise Exception("The Harvesting step must be run alone")
198 
199  # if not specified by user try to guess whether MC or DATA
200  if not options.isData and not options.isMC:
201  if 'SIM' in options.trimmedStep:
202  options.isMC=True
203  if 'CFWRITER' in options.trimmedStep:
204  options.isMC=True
205  if 'DIGI' in options.trimmedStep:
206  options.isMC=True
207  if (not (options.eventcontent == None)) and 'SIM' in options.eventcontent:
208  options.isMC=True
209  if 'SIM' in options.datatier:
210  options.isMC=True
211  if options.isMC:
212  print 'We have determined that this is simulation (if not, rerun cmsDriver.py with --data)'
213  else:
214  print 'We have determined that this is real data (if not, rerun cmsDriver.py with --mc)'
215 
216  if options.profile:
217  if options.profile and options.prefix:
218  raise Exception("--profile and --prefix are incompatible")
219  profilerType = 'pp'
220  profileOpts = options.profile.split(':')
221  if len(profileOpts):
222  profilerType = profileOpts[0].replace("=", " ")
223 
224  if profilerType == "pp":
225  options.profileTypeLabel = "performance"
226  elif profilerType == "mp":
227  options.profileTypeLabel = "memory"
228  elif profilerType.startswith("fp "):
229  options.profileTypeLabel = profilerType.replace("fp ", "")
230  else:
231  raise Exception("Not a valid profiler type %s. Alternatives are pp, mp, fp=<function>."%(profilerType))
232 
233  options.prefix = "igprof -t cmsRun -%s" % profilerType
234 
235  return options
236 
static std::string join(char **cmd)
Definition: RemoteFile.cc:18