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