Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-03 02:53: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.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.alcaRecos:
0096                     kwds['skims'] = self.alcaRecos
0097 
0098                 if self.PhysicsSkims:
0099                     kwds['PhysicsSkims'] = self.PhysicsSkims
0100 
0101                 if self.dqmSeq:
0102                     kwds['dqmSeq'] = self.dqmSeq
0103 
0104                 if self.setRepacked:
0105                     kwds['repacked'] = self.isRepacked
0106                 
0107                 if self.nThreads:
0108                     kwds['nThreads'] = self.nThreads
0109 
0110             process = scenario.promptReco(self.globalTag, **kwds)
0111 
0112         except NotImplementedError as ex:
0113             print("This scenario does not support Prompt Reco:\n")
0114             return
0115         except Exception as ex:
0116             msg = "Error creating Prompt Reco config:\n"
0117             msg += traceback.format_exc()
0118             raise RuntimeError(msg)
0119 
0120         process.source.fileNames.append(self.inputLFN)
0121 
0122         import FWCore.ParameterSet.Config as cms
0123 
0124         process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(10) )
0125 
0126         pklFile = open("RunPromptRecoCfg.pkl", "wb")
0127         psetFile = open("RunPromptRecoCfg.py", "w")
0128         try:
0129             pickle.dump(process, pklFile, protocol=0)
0130             psetFile.write("import FWCore.ParameterSet.Config as cms\n")
0131             psetFile.write("import pickle\n")
0132             psetFile.write("handle = open('RunPromptRecoCfg.pkl','rb')\n")
0133             psetFile.write("process = pickle.load(handle)\n")
0134             psetFile.write("handle.close()\n")
0135             psetFile.close()
0136         except Exception as ex:
0137             print("Error writing out PSet:")
0138             print(traceback.format_exc())
0139             raise ex
0140         finally:
0141             psetFile.close()
0142             pklFile.close()
0143 
0144         cmsRun = "cmsRun -e RunPromptRecoCfg.py"
0145         print("Now do:\n%s" % cmsRun)
0146 
0147 
0148 
0149 if __name__ == '__main__':
0150     valid = ["scenario=", "reco", "aod", "miniaod", "nanoaod", "dqm", "dqmio", "no-output", "nThreads=", 
0151              "global-tag=", "lfn=", "alcarecos=", "PhysicsSkims=", "dqmSeq=", "isRepacked", "isNotRepacked" ]
0152     usage = \
0153 """
0154 RunPromptReco.py <options>
0155 Where options are:
0156  --scenario=ScenarioName
0157  --reco (to enable RECO output)
0158  --aod (to enable AOD output)
0159  --miniaod (to enable MiniAOD output)
0160  --nanoaod (to enable NanoAOD output)
0161  --dqm (to enable DQM output)
0162  --dqmio (to enable DQMIO output)
0163  --isRepacked --isNotRepacked (to override default repacked flags)
0164  --no-output (create config with no output, overrides other settings)
0165  --global-tag=GlobalTag
0166  --lfn=/store/input/lfn
0167  --alcarecos=alcareco_plus_seprated_list
0168  --PhysicsSkims=skim_plus_seprated_list
0169  --dqmSeq=dqmSeq_plus_separated_list
0170  --nThreads=Number_of_cores_or_Threads_used
0171 Example:
0172 python RunPromptReco.py --scenario=cosmics --reco --aod --dqmio --global-tag GLOBALTAG --lfn=/store/whatever --alcarecos=TkAlCosmics0T+MuAlGlobalCosmics
0173 python RunPromptReco.py --scenario=pp --reco --aod --dqmio --global-tag GLOBALTAG --lfn=/store/whatever --alcarecos=TkAlMinBias+SiStripCalMinBias
0174 python RunPromptReco.py --scenario=ppEra_Run2_2016 --reco --aod --dqmio --global-tag GLOBALTAG --lfn=/store/whatever --alcarecos=TkAlMinBias+SiStripCalMinBias --PhysicsSkims=@SingleMuon
0175 """
0176     try:
0177         opts, args = getopt.getopt(sys.argv[1:], "", valid)
0178     except getopt.GetoptError as ex:
0179         print(usage)
0180         print(str(ex))
0181         sys.exit(1)
0182 
0183 
0184     recoinator = RunPromptReco()
0185 
0186     for opt, arg in opts:
0187         if opt == "--scenario":
0188             recoinator.scenario = arg
0189         if opt == "--reco":
0190             recoinator.writeRECO = True
0191         if opt == "--aod":
0192             recoinator.writeAOD = True
0193         if opt == "--miniaod":
0194             recoinator.writeMINIAOD = True
0195         if opt == "--nanoaod":
0196             recoinator.writeNANOAOD = True
0197         if opt == "--dqm":
0198             recoinator.writeDQM = True
0199         if opt == "--dqmio":
0200             recoinator.writeDQMIO = True
0201         if opt == "--no-output":
0202             recoinator.noOutput = True
0203         if opt == "--nThreads":
0204             recoinator.nThreads = arg
0205         if opt == "--global-tag":
0206             recoinator.globalTag = arg
0207         if opt == "--lfn" :
0208             recoinator.inputLFN = arg
0209         if opt == "--alcarecos":
0210             recoinator.alcaRecos = [ x for x in arg.split('+') if len(x) > 0 ]
0211         if opt == "--PhysicsSkims":
0212             recoinator.PhysicsSkims = [ x for x in arg.split('+') if len(x) > 0 ]
0213         if opt == "--dqmSeq":
0214             recoinator.dqmSeq = [ x for x in arg.split('+') if len(x) > 0 ]
0215         if opt == "--isRepacked":
0216             recoinator.setRepacked = True
0217             recoinator.isRepacked = True
0218         if opt == "--isNotRepacked":
0219             recoinator.setRepacked = True
0220             recoinator.isRepacked = False
0221 
0222     recoinator()