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