Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:32

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