Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-28 23:10:44

0001 #!/usr/bin/env python3
0002 """
0003 _RunDQMHarvesting_
0004 
0005 Test wrapper to generate a harvesting config and push it into cmsRun for
0006 testing with a few input files etc from the command line
0007 
0008 """
0009 
0010 import sys
0011 import getopt
0012 import pickle
0013 
0014 from Configuration.DataProcessing.GetScenario import getScenario
0015 
0016 
0017 
0018 class RunDQMHarvesting:
0019 
0020     def __init__(self):
0021         self.scenario = None
0022         self.dataset = None
0023         self.run = None
0024         self.globalTag = 'UNSPECIFIED::All'
0025         self.inputLFN = None
0026         self.dqmio = None
0027 
0028     def __call__(self):
0029         if self.scenario == None:
0030             msg = "No --scenario specified"
0031             raise RuntimeError(msg)
0032         if self.inputLFN == None:
0033             msg = "No --lfn specified"
0034             raise RuntimeError(msg)
0035         
0036         if self.run == None:
0037             msg = "No --run specified"
0038             raise RuntimeError(msg)
0039         
0040         if self.dataset == None:
0041             msg = "No --dataset specified"
0042             raise RuntimeError(msg)
0043         
0044 
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         print("Dataset: %s" % self.dataset)
0057         print("Run: %s" % self.run)
0058         
0059         
0060         try:
0061             kwds = {}
0062             if not self.dqmio is None:
0063                 kwds['newDQMIO'] = self.dqmio
0064 
0065             process = scenario.dqmHarvesting(self.dataset, self.run,
0066                                              self.globalTag, **kwds)
0067             
0068         except Exception as ex:
0069             msg = "Error creating Harvesting config:\n"
0070             msg += str(ex)
0071             raise RuntimeError(msg)
0072 
0073         process.source.fileNames.append(self.inputLFN)
0074 
0075 
0076         pklFile = open("RunDQMHarvestingCfg.pkl", "wb")
0077         psetFile = open("RunDQMHarvestingCfg.py", "w")
0078         try:
0079             pickle.dump(process, pklFile, protocol=0)
0080             psetFile.write("import FWCore.ParameterSet.Config as cms\n")
0081             psetFile.write("import pickle\n")
0082             psetFile.write("handle = open('RunDQMHarvestingCfg.pkl','rb')\n")
0083             psetFile.write("process = pickle.load(handle)\n")
0084             psetFile.write("handle.close()\n")
0085             psetFile.close()
0086         except Exception as ex:
0087             print("Error writing out PSet:")
0088             print(traceback.format_exc())
0089             raise ex
0090         finally:
0091             psetFile.close()
0092             pklFile.close()
0093 
0094         cmsRun = "cmsRun -j FrameworkJobReport.xml RunDQMHarvestingCfg.py"
0095         print("Now do:\n%s" % cmsRun)
0096         
0097 
0098 
0099 
0100 if __name__ == '__main__':
0101     valid = ["scenario=", "run=", "dataset=",
0102              "global-tag=", "lfn=", "dqmio"]
0103     usage = """RunDQMHarvesting.py <options>"""
0104     try:
0105         opts, args = getopt.getopt(sys.argv[1:], "", valid)
0106     except getopt.GetoptError as ex:
0107         print(usage)
0108         print(str(ex))
0109         sys.exit(1)
0110 
0111 
0112     harvester = RunDQMHarvesting()
0113 
0114     for opt, arg in opts:
0115         if opt == "--scenario":
0116             harvester.scenario = arg
0117         if opt == "--global-tag":
0118             harvester.globalTag = arg
0119         if opt == "--lfn" :
0120             harvester.inputLFN = arg
0121         if opt == "--run":
0122             harvester.run = arg
0123         if opt == "--dataset":
0124             harvester.dataset = arg
0125         if opt == "--dqmio":
0126             harvester.dqmio = True
0127 
0128     harvester()