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 _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 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 RunDQMHarvesting:
0020 
0021     def __init__(self):
0022         self.scenario = None
0023         self.dataset = None
0024         self.run = None
0025         self.globalTag = 'UNSPECIFIED::All'
0026         self.inputLFN = None
0027         self.dqmio = None
0028 
0029     def __call__(self):
0030         if self.scenario == None:
0031             msg = "No --scenario specified"
0032             raise RuntimeError(msg)
0033         if self.inputLFN == None:
0034             msg = "No --lfn specified"
0035             raise RuntimeError(msg)
0036         
0037         if self.run == None:
0038             msg = "No --run specified"
0039             raise RuntimeError(msg)
0040         
0041         if self.dataset == None:
0042             msg = "No --dataset 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         print("Dataset: %s" % self.dataset)
0058         print("Run: %s" % self.run)
0059         
0060         
0061         try:
0062             kwds = {}
0063             if not self.dqmio is None:
0064                 kwds['newDQMIO'] = self.dqmio
0065 
0066             process = scenario.dqmHarvesting(self.dataset, self.run,
0067                                              self.globalTag, **kwds)
0068             
0069         except Exception as ex:
0070             msg = "Error creating Harvesting config:\n"
0071             msg += str(ex)
0072             raise RuntimeError(msg)
0073 
0074         process.source.fileNames.append(self.inputLFN)
0075 
0076 
0077         pklFile = open("RunDQMHarvestingCfg.pkl", "wb")
0078         psetFile = open("RunDQMHarvestingCfg.py", "w")
0079         try:
0080             pickle.dump(process, pklFile, protocol=0)
0081             psetFile.write("import FWCore.ParameterSet.Config as cms\n")
0082             psetFile.write("import pickle\n")
0083             psetFile.write("handle = open('RunDQMHarvestingCfg.pkl','rb')\n")
0084             psetFile.write("process = pickle.load(handle)\n")
0085             psetFile.write("handle.close()\n")
0086             psetFile.close()
0087         except Exception as ex:
0088             print("Error writing out PSet:")
0089             print(traceback.format_exc())
0090             raise ex
0091         finally:
0092             psetFile.close()
0093             pklFile.close()
0094 
0095         cmsRun = "cmsRun -j FrameworkJobReport.xml RunDQMHarvestingCfg.py"
0096         print("Now do:\n%s" % cmsRun)
0097         
0098 
0099 
0100 
0101 if __name__ == '__main__':
0102     valid = ["scenario=", "run=", "dataset=",
0103              "global-tag=", "lfn=", "dqmio"]
0104     usage = """RunDQMHarvesting.py <options>"""
0105     try:
0106         opts, args = getopt.getopt(sys.argv[1:], "", valid)
0107     except getopt.GetoptError as ex:
0108         print(usage)
0109         print(str(ex))
0110         sys.exit(1)
0111 
0112 
0113     harvester = RunDQMHarvesting()
0114 
0115     for opt, arg in opts:
0116         if opt == "--scenario":
0117             harvester.scenario = arg
0118         if opt == "--global-tag":
0119             harvester.globalTag = arg
0120         if opt == "--lfn" :
0121             harvester.inputLFN = arg
0122         if opt == "--run":
0123             harvester.run = arg
0124         if opt == "--dataset":
0125             harvester.dataset = arg
0126         if opt == "--dqmio":
0127             harvester.dqmio = True
0128 
0129     harvester()