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 _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 from __future__ import print_function
0010 
0011 import sys
0012 import getopt
0013 import traceback
0014 import pickle
0015 
0016 from Configuration.DataProcessing.GetScenario import getScenario
0017 
0018 
0019 
0020 class RunExpressProcessing:
0021 
0022     def __init__(self):
0023         self.scenario = None
0024         self.writeRAW = False
0025         self.writeRECO = False
0026         self.writeFEVT = False
0027         self.writeDQM = False
0028         self.writeDQMIO = False
0029         self.noOutput = False
0030         self.globalTag = None
0031         self.inputLFN = None
0032         self.alcaRecos = None
0033         self.nThreads = None
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 
0094             if self.nThreads:
0095                 kwds['nThreads'] = self.nThreads
0096 
0097             process = scenario.expressProcessing(self.globalTag, **kwds)
0098 
0099         except NotImplementedError as ex:
0100             print("This scenario does not support Express Processing:\n")
0101             return
0102         except Exception as ex:
0103             msg = "Error creating Express Processing config:\n"
0104             msg += traceback.format_exc()
0105             raise RuntimeError(msg)
0106 
0107         process.source.fileNames = [self.inputLFN]
0108 
0109         import FWCore.ParameterSet.Config as cms
0110 
0111         process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(10) )
0112 
0113         pklFile = open("RunExpressProcessingCfg.pkl", "wb")
0114         psetFile = open("RunExpressProcessingCfg.py", "w")
0115         try:
0116             pickle.dump(process, pklFile, protocol=0)
0117             psetFile.write("import FWCore.ParameterSet.Config as cms\n")
0118             psetFile.write("import pickle\n")
0119             psetFile.write("handle = open('RunExpressProcessingCfg.pkl','rb')\n")
0120             psetFile.write("process = pickle.load(handle)\n")
0121             psetFile.write("handle.close()\n")
0122             psetFile.close()
0123         except Exception as ex:
0124             print("Error writing out PSet:")
0125             print(traceback.format_exc())
0126             raise ex
0127         finally:
0128             psetFile.close()
0129             pklFile.close()
0130 
0131         cmsRun = "cmsRun -e RunExpressProcessingCfg.py"
0132         print("Now do:\n%s" % cmsRun)
0133 
0134 
0135 
0136 if __name__ == '__main__':
0137     valid = ["scenario=", "raw", "reco", "fevt", "dqm", "dqmio", "no-output",
0138              "global-tag=", "lfn=", 'alcarecos=', "nThreads="]
0139     usage = \
0140 """
0141 RunExpressProcessing.py <options>
0142 
0143 Where options are:
0144  --scenario=ScenarioName
0145  --raw (to enable RAW output)
0146  --reco (to enable RECO output)
0147  --fevt (to enable FEVT output)
0148  --dqm (to enable DQM output)
0149  --no-output (create config with no output, overrides other settings)
0150  --global-tag=GlobalTag
0151  --lfn=/store/input/lfn
0152  --alcarecos=plus_seprated_list
0153  --nThreads=Number_of_cores_or_Threads_used
0154 
0155 Examples:
0156 
0157 python RunExpressProcessing.py --scenario cosmics --global-tag GLOBALTAG --lfn /store/whatever --fevt --dqmio --alcarecos=TkAlCosmics0T+SiStripCalZeroBias
0158 
0159 python RunExpressProcessing.py --scenario pp --global-tag GLOBALTAG --lfn /store/whatever --fevt --dqmio --alcarecos=TkAlMinBias+SiStripCalZeroBias
0160 
0161 """
0162     try:
0163         opts, args = getopt.getopt(sys.argv[1:], "", valid)
0164     except getopt.GetoptError as ex:
0165         print(usage)
0166         print(str(ex))
0167         sys.exit(1)
0168 
0169 
0170     expressinator = RunExpressProcessing()
0171 
0172     for opt, arg in opts:
0173         if opt == "--scenario":
0174             expressinator.scenario = arg
0175         if opt == "--raw":
0176             expressinator.writeRAW = True
0177         if opt == "--reco":
0178             expressinator.writeRECO = True
0179         if opt == "--fevt":
0180             expressinator.writeFEVT = True
0181         if opt == "--dqm":
0182             expressinator.writeDQM = True
0183         if opt == "--dqmio":
0184             expressinator.writeDQMIO = True
0185         if opt == "--no-output":
0186             expressinator.noOutput = True
0187         if opt == "--global-tag":
0188             expressinator.globalTag = arg
0189         if opt == "--lfn" :
0190             expressinator.inputLFN = arg
0191         if opt == "--alcarecos":
0192             expressinator.alcaRecos = [ x for x in arg.split('+') if len(x) > 0 ]
0193         if opt == "--nThreads":
0194             expressinator.nThreads = arg
0195 
0196     expressinator()