def insertOldSeeds(self, *seeds): """ _insertOldSeeds_ Backwards compatibility methods """ seedList = list(seeds) svc = self.data.services["RandomNumberGeneratorService"] # //=====Old methods, keep for backwards compat.======= # // #// srcSeedVec = getattr(svc, "sourceSeedVector", Utilities._CfgNoneType()).value() if srcSeedVec != None: numReq = len(srcSeedVec) seedsReq = seedList[0:numReq] seedList = seedList[numReq + 1:] svc.sourceSeedVector = CfgTypes.untracked( CfgTypes.vuint32(seedsReq)) else: svc.sourceSeed = CfgTypes.untracked( CfgTypes.uint32(seedList.pop(0))) modSeeds = getattr(svc, "moduleSeeds", Utilities._CfgNoneType()).value() if modSeeds != None: for param in modSeeds.parameterNames_(): setattr(modSeeds, param, CfgTypes.untracked(CfgTypes.uint32(seedList.pop(0)))) # // # // #//====End old stuff====================================== return
def insertOldSeeds(self, *seeds): """ _insertOldSeeds_ Backwards compatibility methods """ seedList = list(seeds) svc = self.data.services["RandomNumberGeneratorService"] # //=====Old methods, keep for backwards compat.======= # // #// srcSeedVec = getattr(svc, "sourceSeedVector", Utilities._CfgNoneType()).value() if srcSeedVec != None: numReq = len(srcSeedVec) seedsReq = seedList[0:numReq] seedList = seedList[numReq + 1:] svc.sourceSeedVector = CfgTypes.untracked( CfgTypes.vuint32(seedsReq)) else: svc.sourceSeed = CfgTypes.untracked( CfgTypes.uint32(seedList.pop(0))) modSeeds = getattr(svc, "moduleSeeds", Utilities._CfgNoneType()).value() if modSeeds != None: for param in modSeeds.parameterNames_(): setattr(modSeeds, param, CfgTypes.untracked(CfgTypes.uint32(seedList.pop(0)))) # // # // #//====End old stuff====================================== return
def setRunAndLumi(process, run, lumi): """ _setRunAndLumi_ Set the run and lumi number for the process provided via the EmptySource instance """ process.source.firstRun = CmsTypes.untracked(CmsTypes.uint32(run)) process.source.firstLuminosityBlock = CmsTypes.untracked( CmsTypes.uint32(lumi)) return
def insertSeeds(self, *seeds): """ _insertSeeds_ Given some list of specific seeds, insert them into the service. Length of seed list is required to be same as the seed count for the service. Usage: WM Tools. """ seeds = list(seeds) if len(seeds) < self.countSeeds(): msg = "Not enough seeds provided\n" msg += "Service requires %s seeds, only %s provided\n" msg += "to RandomeService.insertSeeds method\n" raise RuntimeError, msg for item in self.__psetsWithSeeds(): seedSet = getattr(item, "initialSeedSet", None) if seedSet != None: numSeeds = len(seedSet.value()) useSeeds = seeds[:numSeeds] seeds = seeds[numSeeds:] item.initialSeedSet = CfgTypes.untracked(CfgTypes.vuint32(*useSeeds)) continue useSeed = seeds[0] seeds = seeds[1:] item.initialSeed = CfgTypes.untracked(CfgTypes.uint32(useSeed)) continue return
def setFirstEvent(self, firstEv): """ set first event number """ self.data.firstEvent = CfgTypes.untracked( CfgTypes.uint32(int(firstEv)))
def insertSeeds(self, *seeds): """ _insertSeeds_ Given some list of specific seeds, insert them into the service. Length of seed list is required to be same as the seed count for the service. Usage: WM Tools. """ seeds = list(seeds) if len(seeds) < self.countSeeds(): msg = "Not enough seeds provided\n" msg += "Service requires %s seeds, only %s provided\n" msg += "to RandomeService.insertSeeds method\n" raise RuntimeError, msg for item in self.__psetsWithSeeds(): seedSet = getattr(item, "initialSeedSet", None) if seedSet != None: numSeeds = len(seedSet.value()) useSeeds = seeds[:numSeeds] seeds = seeds[numSeeds:] item.initialSeedSet = CfgTypes.untracked( CfgTypes.vuint32(*useSeeds)) continue useSeed = seeds[0] seeds = seeds[1:] item.initialSeed = CfgTypes.untracked(CfgTypes.uint32(useSeed)) continue return
def makeProcess(numEvents = 200): """ _makeProcess_ Create a new Process instance """ proc = Process("HLT") proc.include("FWCore/MessageLogger/data/MessageLogger.cfi") configName = "fake-streamer-config" configVersion = timestamp() configAnnot = "auto generated fake streamer config" proc.configurationMetadata = CmsTypes.untracked(CmsTypes.PSet()) proc.configurationMetadata.name = CmsTypes.untracked(CmsTypes.string( configName)) proc.configurationMetadata.version = CmsTypes.untracked(CmsTypes.string( configVersion)) proc.configurationMetadata.annotation = CmsTypes.untracked(CmsTypes.string( configAnnot)) proc.options = CmsTypes.untracked(CmsTypes.PSet()) proc.options.wantSummary = CmsTypes.untracked(CmsTypes.bool(True)) proc.source = Source("EmptySource") proc.maxEvents = CmsTypes.untracked(CmsTypes.PSet()) proc.maxEvents.input = CmsTypes.untracked(CmsTypes.int32(numEvents)) proc.prod = EDProducer("StreamThingProducer") proc.prod.array_size = CmsTypes.int32(2500) proc.prod.instance_count = CmsTypes.int32(150) proc.prod.apply_bit_mask = CmsTypes.untracked(CmsTypes.bool(True)) proc.prod.bit_mask = CmsTypes.untracked( CmsTypes.uint32( 16777215)) proc.add_(Service("RandomNumberGeneratorService")) svc = proc.services["RandomNumberGeneratorService"] svc.moduleSeeds = CmsTypes.PSet() proc.makeData = Path(proc.prod) return proc
def setNamedSeed(self, psetName, *seeds): """ _setNamedSeed_ If a specific set of seeds is needed for a PSet in this service, they can be set by name using this method. - *psetName* : Name of the pset containing the seeds - *seeds* : list of seeds to be added, should be a single seed for initialSeed values. """ pset = getattr(self._randService, psetName, None) if pset == None: msg = "No PSet named %s belongs to this instance of the" % ( psetName,) msg += "Random Seed Service" raise RuntimeError, msg seedVal = getattr(pset, "initialSeed", None) if seedVal != None: pset.initialSeed = CfgTypes.untracked( CfgTypes.uint32(seeds[0]) ) return seedSet = getattr(pset, "initialSeedSet", None) if seedSet != None: # // # // Do we want to check the number of seeds?? #// #if len(seeds) != len( seedSet.value()): pass pset.initialSeedSet = CfgTypes.untracked( CfgTypes.vuint32(*seeds)) return # // # // No seeds for that PSet #// Error throw? return
def setNamedSeed(self, psetName, *seeds): """ _setNamedSeed_ If a specific set of seeds is needed for a PSet in this service, they can be set by name using this method. - *psetName* : Name of the pset containing the seeds - *seeds* : list of seeds to be added, should be a single seed for initialSeed values. """ pset = getattr(self._randService, psetName, None) if pset == None: msg = "No PSet named %s belongs to this instance of the" % ( psetName,) msg += "Random Seed Service" raise RuntimeError, msg seedVal = getattr(pset, "initialSeed", None) if seedVal != None: pset.initialSeed = CfgTypes.untracked( CfgTypes.uint32(seeds[0]) ) return seedSet = getattr(pset, "initialSeedSet", None) if seedSet != None: # // # // Do we want to check the number of seeds?? #// #if len(seeds) != len( seedSet.value()): pass pset.initialSeedSet = CfgTypes.untracked( CfgTypes.vuint32(*seeds)) return # // # // No seeds for that PSet #// Error throw? return
def makeTriggerEntry(process, triggerPath, selectionEff): """ _makeTriggerEntry_ Add a single trigger entry to the configuration. This adds: - Random seed - """ modName = "mod%s" % triggerPath svc = process.services["RandomNumberGeneratorService"] setattr(svc.moduleSeeds, modName, CmsTypes.untracked( CmsTypes.uint32( seed() ))) filterMod = EDFilter("RandomFilter") filterMod.acceptRate = CmsTypes.untracked(CmsTypes.double(selectionEff)) setattr(process, modName, filterMod) setattr(process, triggerPath, Path(filterMod)) return
""" newSeeds = [ value for i in range(self.countSeeds())] self.insertSeeds(*newSeeds) return if __name__ == '__main__': # // # // Setup a test service and populate it #// randSvc = Service("RandomNumberGeneratorService") randHelper = RandomNumberServiceHelper(randSvc) randSvc.i1 = CfgTypes.untracked(CfgTypes.uint32(1)) randSvc.t1 = CfgTypes.PSet() randSvc.t2 = CfgTypes.PSet() randSvc.t3 = CfgTypes.PSet() randSvc.t1.initialSeed = CfgTypes.untracked( CfgTypes.uint32(123455678) ) randSvc.t2.initialSeedSet = CfgTypes.untracked( CfgTypes.vuint32(12345,234567,345677) ) randSvc.t3.initialSeed = CfgTypes.untracked( CfgTypes.uint32(987654321)
def main(argv) : """ writeCfg - Read in existing, user supplied pycfg or pickled pycfg file - Modify job specific parameters based on environment variables and arguments.xml - Write out pickled pycfg file required parameters: none optional parameters: --help : help --debug : debug statements """ # defaults inputFileNames = None parentFileNames = None debug = False _MAXINT = 900000000 try: opts, args = getopt.getopt(argv, "", ["debug", "help"]) except getopt.GetoptError: print main.__doc__ sys.exit(2) try: CMSSW = os.environ['CMSSW_VERSION'] parts = CMSSW.split('_') CMSSW_major = int(parts[1]) CMSSW_minor = int(parts[2]) except (KeyError, ValueError): msg = "Your environment doesn't specify the CMSSW version or specifies it incorrectly" raise ConfigException(msg) # Parse command line options for opt, arg in opts : if opt == "--help" : print main.__doc__ sys.exit() elif opt == "--debug" : debug = True # Parse remaining parameters try: fileName = args[0] outFileName = args[1] except IndexError: print main.__doc__ sys.exit() # Read in Environment, XML and get optional Parameters nJob = int(os.environ.get('NJob', '0')) preserveSeeds = os.environ.get('PreserveSeeds','') incrementSeeds = os.environ.get('IncrementSeeds','') # Defaults maxEvents = 0 skipEvents = 0 firstEvent = -1 compHEPFirstEvent = 0 firstRun = 0 # FUTURE: Remove firstRun firstLumi = 0 dom = xml.dom.minidom.parse(os.environ['RUNTIME_AREA']+'/arguments.xml') for elem in dom.getElementsByTagName("Job"): if nJob == int(elem.getAttribute("JobID")): if elem.getAttribute("MaxEvents"): maxEvents = int(elem.getAttribute("MaxEvents")) if elem.getAttribute("SkipEvents"): skipEvents = int(elem.getAttribute("SkipEvents")) if elem.getAttribute("FirstEvent"): firstEvent = int(elem.getAttribute("FirstEvent")) if elem.getAttribute("FirstRun"): firstRun = int(elem.getAttribute("FirstRun")) if elem.getAttribute("FirstLumi"): firstLumi = int(elem.getAttribute("FirstLumi")) generator = str(elem.getAttribute('Generator')) inputBlocks = str(elem.getAttribute('InputBlocks')) inputFiles = str(elem.getAttribute('InputFiles')) parentFiles = str(elem.getAttribute('ParentFiles')) lumis = str(elem.getAttribute('Lumis')) report(inputBlocks,inputFiles,parentFiles,lumis) # Read Input python config file handle = open(fileName, 'r') try: # Nested form for Python < 2.5 try: print "Importing .py file" cfo = imp.load_source("pycfg", fileName, handle) cmsProcess = cfo.process except Exception, ex: msg = "Your pycfg file is not valid python: %s" % str(ex) raise ConfigException(msg) finally: handle.close() cfg = CfgInterface(cmsProcess) # Set parameters for job print "Setting parameters" inModule = cfg.inputSource if maxEvents: cfg.maxEvents.setMaxEventsInput(maxEvents) if skipEvents and inModule.sourceType not in ['EmptySource']: inModule.setSkipEvents(skipEvents) # Set "skip events" for various generators if generator == 'comphep': cmsProcess.source.CompHEPFirstEvent = CfgTypes.int32(firstEvent) elif generator == 'lhe': cmsProcess.source.skipEvents = CfgTypes.untracked(CfgTypes.uint32(firstEvent)) cmsProcess.source.firstEvent = CfgTypes.untracked(CfgTypes.uint32(firstEvent+1)) elif firstEvent != -1: # (Old? Madgraph) cmsProcess.source.firstEvent = CfgTypes.untracked(CfgTypes.uint32(firstEvent)) if inputFiles: inputFileNames = inputFiles.split(',') inModule.setFileNames(*inputFileNames) # handle parent files if needed if parentFiles: parentFileNames = parentFiles.split(',') inModule.setSecondaryFileNames(*parentFileNames) if lumis: if CMSSW_major < 3: # FUTURE: Can remove this check print "Cannot skip lumis for CMSSW 2_x" else: lumiRanges = lumis.split(',') inModule.setLumisToProcess(*lumiRanges) # Pythia parameters if (firstRun): inModule.setFirstRun(firstRun) if (firstLumi): inModule.setFirstLumi(firstLumi) # Check if there are random #'s to deal with if cfg.data.services.has_key('RandomNumberGeneratorService'): print "RandomNumberGeneratorService found, will attempt to change seeds" from IOMC.RandomEngine.RandomServiceHelper import RandomNumberServiceHelper ranGenerator = cfg.data.services['RandomNumberGeneratorService'] ranModules = getattr(ranGenerator, "moduleSeeds", None) oldSource = getattr(ranGenerator, "sourceSeed", None) if ranModules != None or oldSource != None: msg = "Your random number seeds are set in an old,\n" msg += "deprecated style. Please change to new style:\n" msg += "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideEDMRandomNumberGeneratorService" raise ConfigException(msg) randSvc = RandomNumberServiceHelper(ranGenerator) incrementSeedList = [] preserveSeedList = [] if incrementSeeds: incrementSeedList = incrementSeeds.split(',') if preserveSeeds: preserveSeedList = preserveSeeds.split(',') # Increment requested seed sets for seedName in incrementSeedList: curSeeds = randSvc.getNamedSeed(seedName) newSeeds = [x+nJob for x in curSeeds] randSvc.setNamedSeed(seedName, *newSeeds) preserveSeedList.append(seedName) # Randomize remaining seeds randSvc.populate(*preserveSeedList) # Write out new config file pklFileName = outFileName + '.pkl' outFile = open(outFileName,"w") outFile.write("import FWCore.ParameterSet.Config as cms\n") outFile.write("import pickle\n") outFile.write("process = pickle.load(open('%s', 'rb'))\n" % pklFileName) outFile.close() pklFile = open(pklFileName,"wb") myPickle = pickle.Pickler(pklFile) myPickle.dump(cmsProcess) pklFile.close() if (debug): print "writeCfg output (May not be exact):" print "import FWCore.ParameterSet.Config as cms" print cmsProcess.dumpPython()
def main(argv) : """ writeCfg - Read in existing, user supplied pycfg or pickled pycfg file - Modify job specific parameters based on environment variables and arguments.xml - Write out pickled pycfg file required parameters: none optional parameters: --help : help --debug : debug statements """ # defaults inputFileNames = None parentFileNames = None debug = False _MAXINT = 900000000 try: opts, args = getopt.getopt(argv, "", ["debug", "help"]) except getopt.GetoptError: print main.__doc__ sys.exit(2) try: CMSSW = os.environ['CMSSW_VERSION'] parts = CMSSW.split('_') CMSSW_major = int(parts[1]) CMSSW_minor = int(parts[2]) CMSSW_patch = int(parts[3]) except (KeyError, ValueError): msg = "Your environment doesn't specify the CMSSW version or specifies it incorrectly" raise ConfigException(msg) # Parse command line options for opt, arg in opts : if opt == "--help" : print main.__doc__ sys.exit() elif opt == "--debug" : debug = True # Parse remaining parameters try: fileName = args[0] outFileName = args[1] except IndexError: print main.__doc__ sys.exit() # Read in Environment, XML and get optional Parameters nJob = int(os.environ.get('NJob', '0')) preserveSeeds = os.environ.get('PreserveSeeds','') incrementSeeds = os.environ.get('IncrementSeeds','') # Defaults maxEvents = 0 skipEvents = 0 firstEvent = -1 compHEPFirstEvent = 0 firstRun = 0 # FUTURE: Remove firstRun firstLumi = 0 dom = xml.dom.minidom.parse(os.environ['RUNTIME_AREA']+'/arguments.xml') for elem in dom.getElementsByTagName("Job"): if nJob == int(elem.getAttribute("JobID")): if elem.getAttribute("MaxEvents"): maxEvents = int(elem.getAttribute("MaxEvents")) if elem.getAttribute("SkipEvents"): skipEvents = int(elem.getAttribute("SkipEvents")) if elem.getAttribute("FirstEvent"): firstEvent = int(elem.getAttribute("FirstEvent")) if elem.getAttribute("FirstRun"): firstRun = int(elem.getAttribute("FirstRun")) if elem.getAttribute("FirstLumi"): firstLumi = int(elem.getAttribute("FirstLumi")) generator = str(elem.getAttribute('Generator')) inputFiles = str(elem.getAttribute('InputFiles')) parentFiles = str(elem.getAttribute('ParentFiles')) lumis = str(elem.getAttribute('Lumis')) # Read Input python config file handle = open(fileName, 'r') try: # Nested form for Python < 2.5 try: print "Importing .py file" cfo = imp.load_source("pycfg", fileName, handle) cmsProcess = cfo.process except Exception, ex: msg = "Your pycfg file is not valid python: %s" % str(ex) raise ConfigException(msg) finally: handle.close() cfg = CfgInterface(cmsProcess) # Set parameters for job print "Setting parameters" inModule = cfg.inputSource if maxEvents: cfg.maxEvents.setMaxEventsInput(maxEvents) if skipEvents: inModule.setSkipEvents(skipEvents) # Set "skip events" for various generators if generator == 'comphep': cmsProcess.source.CompHEPFirstEvent = CfgTypes.int32(firstEvent) elif generator == 'lhe': cmsProcess.source.skipEvents = CfgTypes.untracked(CfgTypes.uint32(firstEvent)) cmsProcess.source.firstEvent = CfgTypes.untracked(CfgTypes.uint32(firstEvent+1)) elif firstEvent != -1: # (Old? Madgraph) cmsProcess.source.firstEvent = CfgTypes.untracked(CfgTypes.uint32(firstEvent)) if inputFiles: inputFileNames = inputFiles.split(',') inModule.setFileNames(*inputFileNames) # handle parent files if needed if parentFiles: parentFileNames = parentFiles.split(',') inModule.setSecondaryFileNames(*parentFileNames) if lumis: if CMSSW_major < 3: # FUTURE: Can remove this check print "Cannot skip lumis for CMSSW 2_x" else: lumiRanges = lumis.split(',') inModule.setLumisToProcess(*lumiRanges) # Pythia parameters if (firstRun): inModule.setFirstRun(firstRun) if (firstLumi): inModule.setFirstLumi(firstLumi) # Check if there are random #'s to deal with if cfg.data.services.has_key('RandomNumberGeneratorService'): print "RandomNumberGeneratorService found, will attempt to change seeds" from IOMC.RandomEngine.RandomServiceHelper import RandomNumberServiceHelper ranGenerator = cfg.data.services['RandomNumberGeneratorService'] randSvc = RandomNumberServiceHelper(ranGenerator) incrementSeedList = [] preserveSeedList = [] if incrementSeeds: incrementSeedList = incrementSeeds.split(',') if preserveSeeds: preserveSeedList = preserveSeeds.split(',') # Increment requested seed sets for seedName in incrementSeedList: curSeeds = randSvc.getNamedSeed(seedName) newSeeds = [x+nJob for x in curSeeds] randSvc.setNamedSeed(seedName, *newSeeds) preserveSeedList.append(seedName) # Randomize remaining seeds randSvc.populate(*preserveSeedList) # Write out new config file outFile = open(outFileName,"w") outFile.write("import FWCore.ParameterSet.Config as cms\n") outFile.write("import pickle\n") outFile.write("pickledCfg=\"\"\"%s\"\"\"\n" % pickle.dumps(cmsProcess)) outFile.write("process = pickle.loads(pickledCfg)\n") outFile.close() if (debug): print "writeCfg output (May not be exact):" print "import FWCore.ParameterSet.Config as cms" print cmsProcess.dumpPython()
def setNumberEventsInRun(self, numEvents): """ set numberEventsInRun parameter """ self.data.numberEventsInRun = CfgTypes.untracked( CfgTypes.uint32(numEvents))
def setFirstLumi(self, lumiId): """ set lumi id for this job """ self.data.firstLuminosityBlock = CfgTypes.untracked( CfgTypes.uint32(int(lumiId)))
def setSkipEvents(self, skipEv): "set SkipEvents value""" self.data.skipEvents = CfgTypes.untracked(CfgTypes.uint32(int(skipEv)))
def setFirstRun(self, firstRun): """set first run number""" self.data.firstRun = CfgTypes.untracked(CfgTypes.uint32(int(firstRun)))
def setCacheSize(self, size): """Set source cacheSize""" self.data.cacheSize = CfgTypes.untracked(CfgTypes.uint32(int(size)))
reset all seeds to given value """ newSeeds = [value for i in range(self.countSeeds())] self.insertSeeds(*newSeeds) return if __name__ == "__main__": # // # // Setup a test service and populate it # // randSvc = Service("RandomNumberGeneratorService") randHelper = RandomNumberServiceHelper(randSvc) randSvc.i1 = CfgTypes.untracked(CfgTypes.uint32(1)) randSvc.t1 = CfgTypes.PSet() randSvc.t2 = CfgTypes.PSet() randSvc.t3 = CfgTypes.PSet() randSvc.t1.initialSeed = CfgTypes.untracked(CfgTypes.uint32(123455678)) randSvc.t2.initialSeedSet = CfgTypes.untracked(CfgTypes.vuint32(12345, 234567, 345677)) randSvc.t3.initialSeed = CfgTypes.untracked(CfgTypes.uint32(987654321)) print "Inital PSet" print randSvc # // # // Autofill seeds
""" newSeeds = [ value for i in range(self.countSeeds())] self.insertSeeds(*newSeeds) return if __name__ == '__main__': # // # // Setup a test service and populate it #// randSvc = Service("RandomNumberGeneratorService") randHelper = RandomNumberServiceHelper(randSvc) randSvc.i1 = CfgTypes.untracked(CfgTypes.uint32(1)) randSvc.t1 = CfgTypes.PSet() randSvc.t2 = CfgTypes.PSet() randSvc.t3 = CfgTypes.PSet() randSvc.t1.initialSeed = CfgTypes.untracked( CfgTypes.uint32(123455678) ) randSvc.t2.initialSeedSet = CfgTypes.untracked( CfgTypes.vuint32(12345,234567,345677) ) randSvc.t3.initialSeed = CfgTypes.untracked( CfgTypes.uint32(987654321)
def main(argv): """ writeCfg - Read in existing, user supplied pycfg or pickled pycfg file - Modify job specific parameters based on environment variables and arguments.xml - Write out pickled pycfg file required parameters: none optional parameters: --help : help --debug : debug statements """ # defaults inputFileNames = None parentFileNames = None debug = False _MAXINT = 900000000 try: opts, args = getopt.getopt(argv, "", ["debug", "help"]) except getopt.GetoptError: print main.__doc__ sys.exit(2) try: CMSSW = os.environ["CMSSW_VERSION"] parts = CMSSW.split("_") CMSSW_major = int(parts[1]) CMSSW_minor = int(parts[2]) CMSSW_patch = int(parts[3]) except (KeyError, ValueError): msg = "Your environment doesn't specify the CMSSW version or specifies it incorrectly" raise ConfigException(msg) # Parse command line options for opt, arg in opts: if opt == "--help": print main.__doc__ sys.exit() elif opt == "--debug": debug = True # Parse remaining parameters try: fileName = args[0] outFileName = args[1] except IndexError: print main.__doc__ sys.exit() # Read in Environment, XML and get optional Parameters nJob = int(os.environ.get("NJob", "0")) preserveSeeds = os.environ.get("PreserveSeeds", "") incrementSeeds = os.environ.get("IncrementSeeds", "") # Defaults maxEvents = 0 skipEvents = 0 firstEvent = -1 compHEPFirstEvent = 0 firstRun = 0 # FUTURE: Remove firstRun firstLumi = 0 dom = xml.dom.minidom.parse(os.environ["RUNTIME_AREA"] + "/arguments.xml") for elem in dom.getElementsByTagName("Job"): if nJob == int(elem.getAttribute("JobID")): if elem.getAttribute("MaxEvents"): maxEvents = int(elem.getAttribute("MaxEvents")) if elem.getAttribute("SkipEvents"): skipEvents = int(elem.getAttribute("SkipEvents")) if elem.getAttribute("FirstEvent"): firstEvent = int(elem.getAttribute("FirstEvent")) if elem.getAttribute("FirstRun"): firstRun = int(elem.getAttribute("FirstRun")) if elem.getAttribute("FirstLumi"): firstLumi = int(elem.getAttribute("FirstLumi")) generator = str(elem.getAttribute("Generator")) inputFiles = str(elem.getAttribute("InputFiles")) parentFiles = str(elem.getAttribute("ParentFiles")) lumis = str(elem.getAttribute("Lumis")) # Read Input python config file handle = open(fileName, "r") try: # Nested form for Python < 2.5 try: print "Importing .py file" cfo = imp.load_source("pycfg", fileName, handle) cmsProcess = cfo.process except Exception, ex: msg = "Your pycfg file is not valid python: %s" % str(ex) raise ConfigException(msg) finally: handle.close() cfg = CfgInterface(cmsProcess) # Set parameters for job print "Setting parameters" inModule = cfg.inputSource if maxEvents: cfg.maxEvents.setMaxEventsInput(maxEvents) if skipEvents: inModule.setSkipEvents(skipEvents) # Set "skip events" for various generators if generator == "comphep": cmsProcess.source.CompHEPFirstEvent = CfgTypes.int32(firstEvent) elif generator == "lhe": cmsProcess.source.skipEvents = CfgTypes.untracked(CfgTypes.uint32(firstEvent)) cmsProcess.source.firstEvent = CfgTypes.untracked(CfgTypes.uint32(firstEvent + 1)) elif firstEvent != -1: # (Old? Madgraph) cmsProcess.source.firstEvent = CfgTypes.untracked(CfgTypes.uint32(firstEvent)) if inputFiles: inputFileNames = inputFiles.split(",") inModule.setFileNames(*inputFileNames) # handle parent files if needed if parentFiles: parentFileNames = parentFiles.split(",") inModule.setSecondaryFileNames(*parentFileNames) if lumis: if CMSSW_major < 3: # FUTURE: Can remove this check print "Cannot skip lumis for CMSSW 2_x" else: lumiRanges = lumis.split(",") inModule.setLumisToProcess(*lumiRanges) # Pythia parameters if firstRun: inModule.setFirstRun(firstRun) if firstLumi: inModule.setFirstLumi(firstLumi) # Check if there are random #'s to deal with if cfg.data.services.has_key("RandomNumberGeneratorService"): print "RandomNumberGeneratorService found, will attempt to change seeds" from IOMC.RandomEngine.RandomServiceHelper import RandomNumberServiceHelper ranGenerator = cfg.data.services["RandomNumberGeneratorService"] randSvc = RandomNumberServiceHelper(ranGenerator) incrementSeedList = [] preserveSeedList = [] if incrementSeeds: incrementSeedList = incrementSeeds.split(",") if preserveSeeds: preserveSeedList = preserveSeeds.split(",") # Increment requested seed sets for seedName in incrementSeedList: curSeeds = randSvc.getNamedSeed(seedName) newSeeds = [x + nJob for x in curSeeds] randSvc.setNamedSeed(seedName, *newSeeds) preserveSeedList.append(seedName) # Randomize remaining seeds randSvc.populate(*preserveSeedList) # Write out new config file outFile = open(outFileName, "w") outFile.write("import FWCore.ParameterSet.Config as cms\n") outFile.write("import pickle\n") outFile.write('pickledCfg="""%s"""\n' % pickle.dumps(cmsProcess)) outFile.write("process = pickle.loads(pickledCfg)\n") outFile.close() if debug: print "writeCfg output (May not be exact):" print "import FWCore.ParameterSet.Config as cms" print cmsProcess.dumpPython()
reset all seeds to given value """ newSeeds = [value for i in range(self.countSeeds())] self.insertSeeds(*newSeeds) return if __name__ == '__main__': # // # // Setup a test service and populate it #// randSvc = Service("RandomNumberGeneratorService") randHelper = RandomNumberServiceHelper(randSvc) randSvc.i1 = CfgTypes.untracked(CfgTypes.uint32(1)) randSvc.t1 = CfgTypes.PSet() randSvc.t2 = CfgTypes.PSet() randSvc.t3 = CfgTypes.PSet() randSvc.t1.initialSeed = CfgTypes.untracked(CfgTypes.uint32(123455678)) randSvc.t2.initialSeedSet = CfgTypes.untracked( CfgTypes.vuint32(12345, 234567, 345677)) randSvc.t3.initialSeed = CfgTypes.untracked(CfgTypes.uint32(987654321)) print "Inital PSet" print randSvc # //