Skip to content

Commit

Permalink
Merge pull request #43042 from kpedro88/CoreArgParse
Browse files Browse the repository at this point in the history
argparse migration for cmsDriver and FWCore
  • Loading branch information
cmsbuild authored Oct 25, 2023
2 parents c85a467 + d27742b commit ba0d01e
Show file tree
Hide file tree
Showing 20 changed files with 753 additions and 790 deletions.
57 changes: 28 additions & 29 deletions Configuration/Applications/python/ConfigBuilder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#! /usr/bin/env python3

from __future__ import print_function
__version__ = "$Revision: 1.19 $"
__source__ = "$Source: /local/reps/CMSSW/CMSSW/Configuration/Applications/python/ConfigBuilder.py,v $"

Expand Down Expand Up @@ -62,7 +61,7 @@ class Options:
defaultOptions.eventcontent = None
defaultOptions.datatier = None
defaultOptions.inlineEventContent = True
defaultOptions.inlineObjets =''
defaultOptions.inlineObjects =''
defaultOptions.hideGen=False
from Configuration.StandardSequences.VtxSmeared import VtxSmearedDefaultKey,VtxSmearedHIDefaultKey
defaultOptions.beamspot=None
Expand All @@ -87,10 +86,10 @@ class Options:
defaultOptions.runsScenarioForMCIntegerWeights = None
defaultOptions.runUnscheduled = False
defaultOptions.timeoutOutput = False
defaultOptions.nThreads = '1'
defaultOptions.nStreams = '0'
defaultOptions.nConcurrentLumis = '0'
defaultOptions.nConcurrentIOVs = '0'
defaultOptions.nThreads = 1
defaultOptions.nStreams = 0
defaultOptions.nConcurrentLumis = 0
defaultOptions.nConcurrentIOVs = 0
defaultOptions.accelerators = None

# some helper routines
Expand Down Expand Up @@ -425,9 +424,9 @@ def addCommon(self):

def addMaxEvents(self):
"""Here we decide how many evts will be processed"""
self.process.maxEvents.input = int(self._options.number)
self.process.maxEvents.input = self._options.number
if self._options.number_out:
self.process.maxEvents.output = int(self._options.number_out)
self.process.maxEvents.output = self._options.number_out
self.addedObjects.append(("","maxEvents"))

def addSource(self):
Expand Down Expand Up @@ -794,7 +793,7 @@ def addStandardSequences(self):
#the file is local
self.process.load(mixingDict['file'])
print("inlining mixing module configuration")
self._options.inlineObjets+=',mix'
self._options.inlineObjects+=',mix'
else:
self.loadAndRemember(mixingDict['file'])

Expand Down Expand Up @@ -1352,8 +1351,8 @@ def prepare_ALCA(self, stepSpec = None, workflow = 'full'):
if shortName in alcaList and isinstance(alcastream,cms.FilteredStream):
if shortName in AlCaNoConcurrentLumis:
print("Setting numberOfConcurrentLuminosityBlocks=1 because of AlCa sequence {}".format(shortName))
self._options.nConcurrentLumis = "1"
self._options.nConcurrentIOVs = "1"
self._options.nConcurrentLumis = 1
self._options.nConcurrentIOVs = 1
output = self.addExtraStream(name,alcastream, workflow = workflow)
self.executeAndRemember('process.ALCARECOEventContent.outputCommands.extend(process.OutALCARECO'+shortName+'_noDrop.outputCommands)')
self.AlCaPaths.append(shortName)
Expand Down Expand Up @@ -1404,9 +1403,9 @@ def prepare_LHE(self, stepSpec = None):
__import__(loadFragment)
self.process.load(loadFragment)
##inline the modules
self._options.inlineObjets+=','+stepSpec
self._options.inlineObjects+=','+stepSpec

getattr(self.process,stepSpec).nEvents = int(self._options.number)
getattr(self.process,stepSpec).nEvents = self._options.number

#schedule it
self.process.lhe_step = cms.Path( getattr( self.process,stepSpec) )
Expand Down Expand Up @@ -1453,13 +1452,13 @@ def prepare_GEN(self, stepSpec = None):
for name in genModules:
theObject = getattr(generatorModule,name)
if isinstance(theObject, cmstypes._Module):
self._options.inlineObjets=name+','+self._options.inlineObjets
self._options.inlineObjects=name+','+self._options.inlineObjects
if theObject.type_() in noConcurrentLumiGenerators:
print("Setting numberOfConcurrentLuminosityBlocks=1 because of generator {}".format(theObject.type_()))
self._options.nConcurrentLumis = "1"
self._options.nConcurrentIOVs = "1"
self._options.nConcurrentLumis = 1
self._options.nConcurrentIOVs = 1
elif isinstance(theObject, cms.Sequence) or isinstance(theObject, cmstypes.ESProducer):
self._options.inlineObjets+=','+name
self._options.inlineObjects+=','+name

if stepSpec == self.GENDefaultSeq or stepSpec == 'pgen_genonly' or stepSpec == 'pgen_smear':
if 'ProductionFilterSequence' in genModules and ('generator' in genModules):
Expand Down Expand Up @@ -1709,8 +1708,8 @@ def leave(self,v): pass

expander=PrintAllModules()
getattr(self.process,filterSeq).visit( expander )
self._options.inlineObjets+=','+expander.inliner
self._options.inlineObjets+=','+filterSeq
self._options.inlineObjects+=','+expander.inliner
self._options.inlineObjects+=','+filterSeq

## put the filtering path in the schedule
self.scheduleSequence(filterSeq,'filtering_step')
Expand Down Expand Up @@ -2286,7 +2285,7 @@ def prepare(self, doChecking = False):
self.pythonCfgCode += command + "\n"

#comma separated list of objects that deserve to be inlined in the configuration (typically from a modified config deep down)
for object in self._options.inlineObjets.split(','):
for object in self._options.inlineObjects.split(','):
if not object:
continue
if not hasattr(self.process,object):
Expand Down Expand Up @@ -2345,24 +2344,24 @@ def prepare(self, doChecking = False):
self.pythonCfgCode+="from PhysicsTools.PatAlgos.tools.helpers import associatePatAlgosToolsTask\n"
self.pythonCfgCode+="associatePatAlgosToolsTask(process)\n"

overrideThreads = (self._options.nThreads != "1")
overrideThreads = (self._options.nThreads != 1)
overrideConcurrentLumis = (self._options.nConcurrentLumis != defaultOptions.nConcurrentLumis)
overrideConcurrentIOVs = (self._options.nConcurrentIOVs != defaultOptions.nConcurrentIOVs)

if overrideThreads or overrideConcurrentLumis or overrideConcurrentIOVs:
self.pythonCfgCode +="\n"
self.pythonCfgCode +="#Setup FWK for multithreaded\n"
if overrideThreads:
self.pythonCfgCode +="process.options.numberOfThreads = "+self._options.nThreads+"\n"
self.pythonCfgCode +="process.options.numberOfStreams = "+self._options.nStreams+"\n"
self.process.options.numberOfThreads = int(self._options.nThreads)
self.process.options.numberOfStreams = int(self._options.nStreams)
self.pythonCfgCode +="process.options.numberOfThreads = {}\n".format(self._options.nThreads)
self.pythonCfgCode +="process.options.numberOfStreams = {}\n".format(self._options.nStreams)
self.process.options.numberOfThreads = self._options.nThreads
self.process.options.numberOfStreams = self._options.nStreams
if overrideConcurrentLumis:
self.pythonCfgCode +="process.options.numberOfConcurrentLuminosityBlocks = "+self._options.nConcurrentLumis+"\n"
self.process.options.numberOfConcurrentLuminosityBlocks = int(self._options.nConcurrentLumis)
self.pythonCfgCode +="process.options.numberOfConcurrentLuminosityBlocks = {}\n".format(self._options.nConcurrentLumis)
self.process.options.numberOfConcurrentLuminosityBlocks = self._options.nConcurrentLumis
if overrideConcurrentIOVs:
self.pythonCfgCode +="process.options.eventSetup.numberOfConcurrentIOVs = "+self._options.nConcurrentIOVs+"\n"
self.process.options.eventSetup.numberOfConcurrentIOVs = int(self._options.nConcurrentIOVs)
self.pythonCfgCode +="process.options.eventSetup.numberOfConcurrentIOVs = {}\n".format(self._options.nConcurrentIOVs)
self.process.options.eventSetup.numberOfConcurrentIOVs = self._options.nConcurrentIOVs

if self._options.accelerators is not None:
accelerators = self._options.accelerators.split(',')
Expand Down
Loading

0 comments on commit ba0d01e

Please sign in to comment.