File indexing completed on 2024-11-28 23:10:44
0001
0002 """
0003 _RunPromptReco_
0004 Test wrapper to generate a reco config and actually push it into cmsRun for
0005 testing with a few input files etc from the command line
0006 """
0007
0008 import sys
0009 import getopt
0010 import traceback
0011 import pickle
0012
0013 from Configuration.DataProcessing.GetScenario import getScenario
0014
0015
0016 class RunPromptReco:
0017
0018 def __init__(self):
0019 self.scenario = None
0020 self.writeRECO = False
0021 self.writeAOD = False
0022 self.writeMINIAOD = False
0023 self.writeNANOAOD = False
0024 self.writeDQM = False
0025 self.writeDQMIO = False
0026 self.noOutput = False
0027 self.globalTag = None
0028 self.inputLFN = None
0029 self.nanoFlavours = None
0030 self.alcaRecos = None
0031 self.PhysicsSkims = None
0032 self.dqmSeq = None
0033 self.setRepacked = False
0034 self.isRepacked = False
0035 self.nThreads = None
0036
0037 def __call__(self):
0038 if self.scenario == None:
0039 msg = "No --scenario specified"
0040 raise RuntimeError(msg)
0041 if self.globalTag == None:
0042 msg = "No --global-tag specified"
0043 raise RuntimeError(msg)
0044 if self.inputLFN == None:
0045 msg = "No --lfn specified"
0046 raise RuntimeError(msg)
0047
0048 try:
0049 scenario = getScenario(self.scenario)
0050 except Exception as ex:
0051 msg = "Error getting Scenario implementation for %s\n" % (
0052 self.scenario,)
0053 msg += str(ex)
0054 raise RuntimeError(msg)
0055
0056 print("Retrieved Scenario: %s" % self.scenario)
0057 print("Using Global Tag: %s" % self.globalTag)
0058
0059 dataTiers = []
0060 if self.writeRECO:
0061 dataTiers.append("RECO")
0062 print("Configuring to Write out RECO")
0063 if self.writeAOD:
0064 dataTiers.append("AOD")
0065 print("Configuring to Write out AOD")
0066 if self.writeMINIAOD:
0067 dataTiers.append("MINIAOD")
0068 print("Configuring to Write out MiniAOD")
0069 if self.writeNANOAOD:
0070 dataTiers.append("NANOAOD")
0071 print("Configuring to Write out NanoAOD")
0072 if self.writeDQM:
0073 dataTiers.append("DQM")
0074 print("Configuring to Write out DQM")
0075 if self.writeDQMIO:
0076 dataTiers.append("DQMIO")
0077 print("Configuring to Write out DQMIO")
0078 if self.alcaRecos:
0079 dataTiers.append("ALCARECO")
0080 print("Configuring to Write out ALCARECO")
0081
0082 try:
0083 kwds = {}
0084
0085 if self.noOutput:
0086 kwds['outputs'] = []
0087 else:
0088 outputs = []
0089 for dataTier in dataTiers:
0090 outputs.append({ 'dataTier' : dataTier,
0091 'eventContent' : dataTier,
0092 'moduleLabel' : "write_%s" % dataTier })
0093 kwds['outputs'] = outputs
0094
0095 if self.nanoFlavours:
0096 kwds['nanoFlavours'] = self.nanoFlavours
0097
0098 if self.alcaRecos:
0099 kwds['skims'] = self.alcaRecos
0100
0101 if self.PhysicsSkims:
0102 kwds['PhysicsSkims'] = self.PhysicsSkims
0103
0104 if self.dqmSeq:
0105 kwds['dqmSeq'] = self.dqmSeq
0106
0107 if self.setRepacked:
0108 kwds['repacked'] = self.isRepacked
0109
0110 if self.nThreads:
0111 kwds['nThreads'] = int(self.nThreads)
0112
0113 process = scenario.promptReco(self.globalTag, **kwds)
0114
0115 except NotImplementedError as ex:
0116 print("This scenario does not support Prompt Reco:\n")
0117 return
0118 except Exception as ex:
0119 msg = "Error creating Prompt Reco config:\n"
0120 msg += traceback.format_exc()
0121 raise RuntimeError(msg)
0122
0123 process.source.fileNames.append(self.inputLFN)
0124
0125 import FWCore.ParameterSet.Config as cms
0126
0127 process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(10) )
0128
0129 pklFile = open("RunPromptRecoCfg.pkl", "wb")
0130 psetFile = open("RunPromptRecoCfg.py", "w")
0131 try:
0132 pickle.dump(process, pklFile, protocol=0)
0133 psetFile.write("import FWCore.ParameterSet.Config as cms\n")
0134 psetFile.write("import pickle\n")
0135 psetFile.write("handle = open('RunPromptRecoCfg.pkl','rb')\n")
0136 psetFile.write("process = pickle.load(handle)\n")
0137 psetFile.write("handle.close()\n")
0138 psetFile.close()
0139 except Exception as ex:
0140 print("Error writing out PSet:")
0141 print(traceback.format_exc())
0142 raise ex
0143 finally:
0144 psetFile.close()
0145 pklFile.close()
0146
0147 cmsRun = "cmsRun -e RunPromptRecoCfg.py"
0148 print("Now do:\n%s" % cmsRun)
0149
0150
0151
0152 if __name__ == '__main__':
0153 valid = ["scenario=", "reco", "aod", "miniaod", "nanoaod", "dqm", "dqmio", "no-output", "nThreads=",
0154 "global-tag=", "lfn=", "nanoFlavours=", "alcarecos=", "PhysicsSkims=", "dqmSeq=", "isRepacked", "isNotRepacked" ]
0155 usage = \
0156 """
0157 RunPromptReco.py <options>
0158 Where options are:
0159 --scenario=ScenarioName
0160 --reco (to enable RECO output)
0161 --aod (to enable AOD output)
0162 --miniaod (to enable MiniAOD output)
0163 --nanoaod (to enable NanoAOD output)
0164 --nanoFlavours=flavour_plus_separated_list
0165 --dqm (to enable DQM output)
0166 --dqmio (to enable DQMIO output)
0167 --isRepacked --isNotRepacked (to override default repacked flags)
0168 --no-output (create config with no output, overrides other settings)
0169 --global-tag=GlobalTag
0170 --lfn=/store/input/lfn
0171 --alcarecos=alcareco_plus_separated_list
0172 --PhysicsSkims=skim_plus_separated_list
0173 --dqmSeq=dqmSeq_plus_separated_list
0174 --nThreads=Number_of_cores_or_Threads_used
0175 Example:
0176 python RunPromptReco.py --scenario=cosmics --reco --aod --dqmio --global-tag GLOBALTAG --lfn=/store/whatever --alcarecos=TkAlCosmics0T+MuAlGlobalCosmics
0177 python RunPromptReco.py --scenario=pp --reco --aod --dqmio --global-tag GLOBALTAG --lfn=/store/whatever --alcarecos=TkAlMinBias+SiStripCalMinBias
0178 python RunPromptReco.py --scenario=ppEra_Run2_2016 --reco --aod --miniaod --nanoaod --dqmio --global-tag GLOBALTAG --lfn=/store/whatever --nanoFlavours=@MUPOG --alcarecos=TkAlMinBias+SiStripCalMinBias --PhysicsSkims=@SingleMuon
0179 """
0180 try:
0181 opts, args = getopt.getopt(sys.argv[1:], "", valid)
0182 except getopt.GetoptError as ex:
0183 print(usage)
0184 print(str(ex))
0185 sys.exit(1)
0186
0187
0188 recoinator = RunPromptReco()
0189
0190 for opt, arg in opts:
0191 if opt == "--scenario":
0192 recoinator.scenario = arg
0193 if opt == "--reco":
0194 recoinator.writeRECO = True
0195 if opt == "--aod":
0196 recoinator.writeAOD = True
0197 if opt == "--miniaod":
0198 recoinator.writeMINIAOD = True
0199 if opt == "--nanoaod":
0200 recoinator.writeNANOAOD = True
0201 if opt == "--dqm":
0202 recoinator.writeDQM = True
0203 if opt == "--dqmio":
0204 recoinator.writeDQMIO = True
0205 if opt == "--no-output":
0206 recoinator.noOutput = True
0207 if opt == "--nThreads":
0208 recoinator.nThreads = arg
0209 if opt == "--global-tag":
0210 recoinator.globalTag = arg
0211 if opt == "--lfn" :
0212 recoinator.inputLFN = arg
0213 if opt == "--nanoFlavours":
0214 recoinator.nanoFlavours = [ x for x in arg.split('+') if len(x) > 0 ]
0215 if opt == "--alcarecos":
0216 recoinator.alcaRecos = [ x for x in arg.split('+') if len(x) > 0 ]
0217 if opt == "--PhysicsSkims":
0218 recoinator.PhysicsSkims = [ x for x in arg.split('+') if len(x) > 0 ]
0219 if opt == "--dqmSeq":
0220 recoinator.dqmSeq = [ x for x in arg.split('+') if len(x) > 0 ]
0221 if opt == "--isRepacked":
0222 recoinator.setRepacked = True
0223 recoinator.isRepacked = True
0224 if opt == "--isNotRepacked":
0225 recoinator.setRepacked = True
0226 recoinator.isRepacked = False
0227
0228 recoinator()