Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-07 22:32:56

0001 #!/usr/bin/env python3
0002 """
0003 _RunVisualizationProcessing_
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 pickle
0014 
0015 from Configuration.DataProcessing.GetScenario import getScenario
0016 
0017 
0018 
0019 class RunVisualizationProcessing:
0020 
0021     def __init__(self):
0022         self.scenario = None
0023         self.writeRaw = False
0024         self.writeReco = False
0025         self.writeFevt = False
0026         self.writeAlca = False
0027         self.writeDqm = False
0028         self.noOutput = False
0029         self.globalTag = None
0030         self.inputLFN = None
0031         self.preFilter = None
0032 
0033         
0034  #FIXME: should add an option to specify an EDM input source?
0035  
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 
0045 
0046         
0047         try:
0048             scenario = getScenario(self.scenario)
0049         except Exception as ex:
0050             msg = "Error getting Scenario implementation for %s\n" % (
0051                 self.scenario,)
0052             msg += str(ex)
0053             raise RuntimeError(msg)
0054 
0055         print("Retrieved Scenario: %s" % self.scenario)
0056         print("Using Global Tag: %s" % self.globalTag)
0057 
0058         dataTiers = []
0059         if self.writeRaw:
0060             dataTiers.append("RAW")
0061             print("Configuring to Write out Raw...")
0062         if self.writeReco:
0063             dataTiers.append("RECO")
0064             print("Configuring to Write out Reco...")
0065         if self.writeFevt:
0066             dataTiers.append("FEVT")
0067             print("Configuring to Write out Fevt...")
0068         if self.writeAlca:
0069             dataTiers.append("ALCARECO")
0070             print("Configuring to Write out Alca...")
0071         if self.writeDqm:
0072             dataTiers.append("DQM")
0073             print("Configuring to Write out Dqm...")
0074 
0075 
0076 
0077         try:
0078             kwds = {}
0079             if self.inputLFN != None:
0080                 kwds['inputSource'] = 'EDM'
0081                 
0082             if self.noOutput:
0083                 # get config without any output
0084                 kwds['writeTiers'] = []
0085 
0086             elif len(dataTiers) > 0:
0087                 # get config with specified output
0088                 kwds['writeTiers'] = dataTiers
0089 
0090             if self.preFilter:
0091                 kwds['preFilter'] = self.preFilter
0092 
0093 
0094             # if none of the above use default output data tiers
0095 
0096             process = scenario.visualizationProcessing(self.globalTag, **kwds)
0097 
0098         except NotImplementedError as ex:
0099             print("This scenario does not support Visualization Processing:\n")
0100             return
0101         except Exception as ex:
0102             msg = "Error creating Visualization Processing config:\n"
0103             msg += str(ex)
0104             raise RuntimeError(msg)
0105 
0106         if self.inputLFN != None:
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("RunVisualizationProcessingCfg.pkl", "wb")
0114         psetFile = open("RunVisualizationProcessingCfg.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('RunVisualizationProcessingCfg.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 RunVisualizationProcessingCfg.py"
0132         print("Now do:\n%s" % cmsRun)
0133 
0134 
0135 
0136 if __name__ == '__main__':
0137     valid = ["scenario=", "reco", "fevt", "no-output",
0138              "global-tag=", "lfn=",'preFilter=']
0139     usage = \
0140 """
0141 RunVisualizationProcessing.py <options>
0142 
0143 Where options are:
0144  --scenario=ScenarioName
0145  --reco (to enable RECO output)
0146  --fevt (to enable FEVT output)
0147  --no-output (create config with no output, overrides other settings)
0148  --global-tag=GlobalTag
0149  --lfn=/store/input/lfn
0150  --preFilter=/sybsystem/package/filtername.sequence
0151  
0152 Example:
0153 python RunVisualizationProcessing.py --scenario cosmics --global-tag GLOBALTAG::ALL --lfn /store/whatever --reco
0154 
0155 """
0156     try:
0157         opts, args = getopt.getopt(sys.argv[1:], "", valid)
0158     except getopt.GetoptError as ex:
0159         print(usage)
0160         print(str(ex))
0161         sys.exit(1)
0162 
0163 
0164     visualizator = RunVisualizationProcessing()
0165 
0166     for opt, arg in opts:
0167         if opt == "--scenario":
0168             visualizator.scenario = arg
0169         if opt == "--reco":
0170             visualizator.writeReco = True
0171         if opt == "--fevt":
0172             visualizator.writeFevt = True
0173         if opt == "--no-output":
0174             visualizator.noOutput = True
0175         if opt == "--global-tag":
0176             visualizator.globalTag = arg
0177         if opt == "--lfn" :
0178             visualizator.inputLFN = arg
0179         if opt == "--preFilter":
0180             visualizator.preFilter = arg
0181 
0182     visualizator()