File indexing completed on 2023-03-17 10:48:52
0001
0002
0003
0004
0005 from __future__ import print_function
0006 import optparse
0007 import sys
0008 import os
0009 import re
0010 import Configuration.Applications
0011 from Configuration.Applications.ConfigBuilder import ConfigBuilder, defaultOptions
0012 import traceback
0013 from functools import reduce
0014
0015 def checkModifier(era):
0016 from FWCore.ParameterSet.Config import Modifier, ModifierChain
0017 return isinstance( era, Modifier ) or isinstance( era, ModifierChain )
0018
0019 def checkOptions():
0020 return
0021
0022 def adaptOptions():
0023 return
0024
0025 def OptionsFromCommand(command):
0026 items=command.split()
0027 if items[0] != 'cmsDriver.py':
0028 return None
0029 items.append('--evt_type')
0030 items.append(items[1])
0031 options=OptionsFromItems(items[2:])
0032 options.arguments = command
0033 return options
0034
0035 def OptionsFromCommandLine():
0036 import sys
0037 options=OptionsFromItems(sys.argv[1:])
0038
0039 options.arguments = reduce(lambda x, y: x+' '+y, sys.argv[1:])
0040 return options
0041
0042 def OptionsFromItems(items):
0043 import sys
0044 from Configuration.Applications.Options import parser,threeValued
0045
0046 for (index,item) in enumerate(items):
0047 for (opt,value) in threeValued:
0048 if (str(item) in opt) and (index==len(items)-1 or items[index+1].startswith('-')):
0049 items.insert(index+1,value)
0050
0051 (options,args) = parser.parse_args(items)
0052
0053 if not options.conditions or options.conditions=="help":
0054 from Configuration.AlCa import autoCond
0055 possible=""
0056 for k in autoCond.autoCond:
0057 possible+="\nauto:"+k+" -> "+str(autoCond.autoCond[k])
0058 raise Exception("the --conditions option is mandatory. Possibilities are: "+possible)
0059
0060
0061
0062
0063
0064
0065
0066 if options.triggerResultsProcess == None and "ALCAOUTPUT" in options.step:
0067 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")
0068 sys.exit(1)
0069
0070 if not options.evt_type:
0071 options.evt_type=sys.argv[1]
0072
0073
0074
0075
0076 if options.dirin!='' and (not options.dirin.endswith('/')): options.dirin+='/'
0077 if options.dirout!='' and (not options.dirout.endswith('/')): options.dirout+='/'
0078
0079
0080
0081
0082 prec_step = {"NONE":"",
0083 "FILTER":"",
0084 "ALL":"",
0085 "LHE":"",
0086 "GEN":"",
0087 "reGEN":"",
0088 "SIM":"GEN",
0089 "reSIM":"SIM",
0090 "DIGI":"SIM",
0091 "reDIGI":"DIGI",
0092 "L1REPACK":"RAW",
0093 "HLT":"RAW",
0094 "RECO":"DIGI",
0095 "ALCA":"RECO",
0096 "ANA":"RECO",
0097 "SKIM":"RECO",
0098 "DIGI2RAW":"DIGI",
0099 "RAW2DIGI":"DIGI2RAW",
0100 "RAW2RECO":"DIGI2RAW",
0101 "DATAMIX":"DIGI",
0102 "DIGI2RAW":"DATAMIX",
0103 "HARVESTING":"RECO",
0104 "ALCAHARVEST":"RECO",
0105 "PAT":"RECO",
0106 "NANO":"PAT",
0107 "PATGEN":"GEN"}
0108
0109 trimmedEvtType=options.evt_type.split('/')[-1]
0110
0111
0112 options.trimmedStep=[]
0113 for s in options.step.split(','):
0114 step=s.split(':')[0]
0115 options.trimmedStep.append(step)
0116 first_step=options.trimmedStep[0]
0117
0118
0119
0120 stepsAliases={
0121 'NONE':'',
0122 'ALL':'GEN,SIM,DIGI,L1,DIGI2RAW,HLT:GRun,RAW2DIGI,RECO,POSTRECO,VALIDATION,DQM',
0123 'DATA_CHAIN':'RAW2DIGI,RECO,POSTRECO,DQM'
0124 }
0125 if options.step in stepsAliases:
0126 options.step=stepsAliases[options.step]
0127
0128 options.step = options.step.replace("SIM_CHAIN","GEN,SIM,DIGI,L1,DIGI2RAW")
0129
0130
0131 addEndJob = True
0132 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 == "":
0133 addEndJob = False
0134 if ("SKIM" in options.step and not "RECO" in options.step):
0135 addEndJob = False
0136 if ("ENDJOB" in options.step):
0137 addEndJob = False
0138 if ('DQMIO' in options.datatier):
0139 addEndJob = False
0140 if addEndJob:
0141 options.step=options.step+',ENDJOB'
0142
0143
0144
0145 if options.filetype==defaultOptions.filetype:
0146 if options.filein.lower().endswith(".lhe") or options.filein.lower().endswith(".lhef") or options.filein.startswith("lhe:"):
0147 options.filetype="LHE"
0148 elif options.filein.startswith("mcdb:"):
0149 print("This is a deprecated way of selecting lhe files from article number. Please use lhe:article argument to --filein")
0150 options.filein=options.filein.replace('mcdb:','lhe:')
0151 options.filetype="LHE"
0152 else:
0153 options.filetype="EDM"
0154
0155 filesuffix = {"LHE": "lhe", "EDM": "root", "MCDB": "", "DQM":"root"}[options.filetype]
0156
0157 if options.filein=="" and not (first_step in ("ALL","GEN","LHE","SIM_CHAIN")):
0158 options.dirin="file:"+options.dirin.replace('file:','')
0159 options.filein=trimmedEvtType+"_"+prec_step[first_step]+"."+filesuffix
0160
0161
0162
0163
0164 standardFileName = ""
0165 standardFileName = trimmedEvtType+"_"+"_".join(options.trimmedStep)
0166 standardFileName = standardFileName.replace(",","_").replace(".","_")
0167 if options.pileup != "NoPileUp":
0168 standardFileName += "_PU"
0169
0170
0171
0172 if options.fileout=="" and not first_step in ("HARVESTING", "ALCAHARVEST"):
0173 options.fileout = standardFileName+".root"
0174
0175
0176 if not options.python_filename:
0177 options.python_filename = standardFileName+'.py'
0178
0179 print(options.step)
0180
0181
0182
0183
0184 if not options.name:
0185 if 'reSIM' in options.trimmedStep:
0186 options.name = 'RESIM'
0187 elif 'reDIGI' in options.trimmedStep:
0188 options.name = 'REDIGI'
0189 elif 'HLT' in options.trimmedStep:
0190 options.name = 'HLT'
0191 elif 'RECO' in options.trimmedStep:
0192 options.name = 'RECO'
0193 elif options.trimmedStep == ['NONE'] and options.filetype in ('LHE', 'MCDB'):
0194 options.name = 'LHE'
0195 elif len(options.trimmedStep)==0:
0196 options.name = 'PROCESS'
0197 else:
0198 options.name = options.trimmedStep[-1]
0199
0200
0201 isHarvesting = False
0202 isOther = False
0203
0204 if "HARVESTING" in options.trimmedStep and len(options.trimmedStep) > 1:
0205 raise Exception("The Harvesting step must be run alone")
0206
0207
0208 if not options.isData and not options.isMC:
0209 if 'LHE' in options.trimmedStep or 'LHE' in options.datatier:
0210 options.isMC=True
0211 if 'GEN' in options.trimmedStep or 'GEN' in options.datatier:
0212 options.isMC=True
0213 if 'SIM' in options.trimmedStep:
0214 options.isMC=True
0215 if 'CFWRITER' in options.trimmedStep:
0216 options.isMC=True
0217 if 'DIGI' in options.trimmedStep:
0218 options.isMC=True
0219 if 'DIGI2RAW' in options.trimmedStep:
0220 options.isMC=True
0221 if (not (options.eventcontent == None)) and 'SIM' in options.eventcontent:
0222 options.isMC=True
0223 if 'SIM' in options.datatier:
0224 options.isMC=True
0225 if 'VALIDATION' in options.trimmedStep:
0226 options.isMC=True
0227 if options.era and 'Phase2' in options.era:
0228 options.isMC=True
0229 if options.isMC:
0230 print('We have determined that this is simulation (if not, rerun cmsDriver.py with --data)')
0231 else:
0232 print('We have determined that this is real data (if not, rerun cmsDriver.py with --mc)')
0233 options.isData=True
0234
0235 if options.profile:
0236 if options.profile and options.prefix:
0237 raise Exception("--profile and --prefix are incompatible")
0238 profilerType = 'pp'
0239 profileOpts = options.profile.split(':')
0240 if len(profileOpts):
0241 profilerType = profileOpts[0].replace("=", " ")
0242
0243 if profilerType == "pp":
0244 options.profileTypeLabel = "performance"
0245 elif profilerType == "mp":
0246 options.profileTypeLabel = "memory"
0247 elif profilerType.startswith("fp "):
0248 options.profileTypeLabel = profilerType.replace("fp ", "")
0249 else:
0250 raise Exception("Not a valid profiler type %s. Alternatives are pp, mp, fp=<function>."%(profilerType))
0251
0252 options.prefix = "igprof -t cmsRun -%s" % profilerType
0253
0254 if options.heap_profile:
0255 if options.profile and options.prefix:
0256 raise Exception("--heap_profile and --prefix are incompatible")
0257 profilerType = 'pp'
0258 options.prefix = "MALLOC_CONF=prof:true,prof_accum:true,prof_prefix:jeprof.out cmsRunJE "
0259
0260
0261 if options.era :
0262 from Configuration.StandardSequences.Eras import eras
0263
0264 requestedEras = options.era.split(",")
0265
0266 for eraName in requestedEras :
0267 if not hasattr( eras, eraName ) or not checkModifier(getattr(eras,eraName)):
0268 validOptions=""
0269 for key in eras.__dict__ :
0270 if checkModifier(eras.__dict__[key]):
0271 if validOptions!="" : validOptions+=", "
0272 validOptions+="'"+key+"'"
0273 raise Exception( "'%s' is not a valid option for '--era'. Valid options are %s." % (eraName, validOptions) )
0274
0275 if options.fast :
0276 if options.era:
0277 options.era+=",fastSim"
0278 else :
0279 options.era="fastSim"
0280
0281
0282 if options.fast and not options.scenario == "pp":
0283 raise Exception("ERROR: the --option fast is only compatible with the default scenario (--scenario=pp)")
0284 if options.fast and 'HLT' in options.trimmedStep:
0285 raise Exception("ERROR: the --option fast is incompatible with HLT (HLT is no longer available in FastSim)")
0286
0287 return options
0288