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