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 _RunAlcaHarvesting_
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 RunAlcaHarvesting:
0020 
0021     def __init__(self):
0022         self.scenario = None
0023         self.dataset = None
0024 #         self.run = None
0025         self.globalTag = None
0026         self.inputLFN = None
0027         self.workflows = None
0028         self.alcapromptdataset = None
0029 
0030     def __call__(self):
0031         if self.scenario == None:
0032             msg = "No --scenario specified"
0033             raise RuntimeError(msg)
0034         if self.inputLFN == None:
0035             msg = "No --lfn specified"
0036             raise RuntimeError(msg)
0037         
0038 #         if self.run == None:
0039 #             msg = "No --run specified"
0040 #             raise RuntimeError, msg
0041         
0042         if self.dataset == None:
0043             msg = "No --dataset specified"
0044             raise RuntimeError(msg)
0045         
0046         if self.globalTag == None:
0047             msg = "No --global-tag specified"
0048             raise RuntimeError(msg)
0049 
0050         
0051         try:
0052             scenario = getScenario(self.scenario)
0053         except Exception as ex:
0054             msg = "Error getting Scenario implementation for %s\n" % (
0055                 self.scenario,)
0056             msg += str(ex)
0057             raise RuntimeError(msg)
0058 
0059         print("Retrieved Scenario: %s" % self.scenario)
0060         print("Using Global Tag: %s" % self.globalTag)
0061         print("Dataset: %s" % self.dataset)
0062 #         print "Run: %s" % self.run
0063         
0064         
0065         try:
0066             kwds = {}
0067             if not self.workflows is None:
0068                 kwds['skims'] = self.workflows
0069             if not self.alcapromptdataset is None:
0070                 kwds['alcapromptdataset'] = self.alcapromptdataset
0071             process = scenario.alcaHarvesting(self.globalTag, self.dataset, **kwds)
0072             
0073         except Exception as ex:
0074             msg = "Error creating AlcaHarvesting config:\n"
0075             msg += str(ex)
0076             raise RuntimeError(msg)
0077 
0078         process.source.fileNames.append(self.inputLFN)
0079 
0080 
0081         pklFile = open("RunAlcaHarvestingCfg.pkl", "wb")
0082         psetFile = open("RunAlcaHarvestingCfg.py", "w")
0083         try:
0084             pickle.dump(process, pklFile, protocol=0)
0085             psetFile.write("import FWCore.ParameterSet.Config as cms\n")
0086             psetFile.write("import pickle\n")
0087             psetFile.write("handle = open('RunAlcaHarvestingCfg.pkl','rb')\n")
0088             psetFile.write("process = pickle.load(handle)\n")
0089             psetFile.write("handle.close()\n")
0090             psetFile.close()
0091         except Exception as ex:
0092             print("Error writing out PSet:")
0093             print(traceback.format_exc())
0094             raise ex
0095         finally:
0096             psetFile.close()
0097             pklFile.close()
0098 
0099         cmsRun = "cmsRun -j FrameworkJobReport.xml RunAlcaHarvestingCfg.py"
0100         print("Now do:\n%s" % cmsRun)
0101         
0102 
0103 
0104 
0105 if __name__ == '__main__':
0106     valid = ["scenario=", "global-tag=", "lfn=", "dataset=","workflows=","alcapromptdataset="]
0107     usage = \
0108     usage = """
0109     RunAlcaHarvesting.py <options>
0110 
0111 
0112     Where options are:
0113     --scenario=ScenarioName
0114     --global-tag=GlobalTag
0115     --lfn=/store/input/lfn
0116     --dataset=/A/B/C
0117     --workflows=theWFs
0118     --alcapromptdataset=theAPdataset
0119 
0120     """
0121 
0122 
0123     try:
0124         opts, args = getopt.getopt(sys.argv[1:], "", valid)
0125     except getopt.GetoptError as ex:
0126         print(usage)
0127         print(str(ex))
0128         sys.exit(1)
0129 
0130 
0131     harvester = RunAlcaHarvesting()
0132 
0133     for opt, arg in opts:
0134         if opt == "--scenario":
0135             harvester.scenario = arg
0136         if opt == "--global-tag":
0137             harvester.globalTag = arg
0138         if opt == "--lfn" :
0139             harvester.inputLFN = arg
0140         if opt == "--dataset" :
0141             harvester.dataset = arg
0142         if opt == "--workflows":
0143             harvester.workflows = [ x for x in arg.split(',') if len(x) > 0 ]
0144         if opt == "--alcapromptdataset":
0145             harvester.alcapromptdataset = arg
0146 
0147 
0148     harvester()