CMS 3D CMS Logo

Classes | Functions
helpers Namespace Reference

Classes

class  CloneSequenceVisitor
 
struct  CompositeCandidateMaker
 
struct  CompositePtrCandidateMaker
 
class  GatherAllModulesVisitor
 
struct  MCTruthPairSelector
 
struct  NamedCompositeCandidateMaker
 
class  TestModuleCommand
 

Functions

def __labelsInSequence (process, sequenceLabel, postfix="", keepPostFix=False)
 
def _lineDiff (newString, oldString)
 
def addESProducers (process, config)
 
def addKeepStatement (process, oldKeep, newKeeps, verbose=False)
 
def addToProcessAndTask (label, module, process, task)
 
def addToTask (loadedProducersAndFilters, module)
 
def applyPostfix (process, label, postfix)
 
def associatePatAlgosToolsTask (process)
 
def cloneProcessingSnippet (process, sequence, postfix, removePostfix="", noClones=[], addToTask=False, verbose=False)
 
def contains (sequence, moduleName)
 
def extendWithPrePostfix (process, other, prefix, postfix, loadedProducersAndFilters=None)
 
def get_path (file_in_path)
 
def get_vars (xml_path, useFileInPath=True)
 
def getPatAlgosToolsTask (process)
 
def jetCollectionString (prefix='', algo='', type='')
 
def listDependencyChain (process, module, sources, verbose=False)
 
def listModules (sequence)
 
def listSequences (sequence)
 
def loadWithPostfix (process, moduleName, postfix='', loadedProducersAndFilters=None)
 
def loadWithPrefix (process, moduleName, prefix='', loadedProducersAndFilters=None)
 
def loadWithPrePostfix (process, moduleName, prefix='', postfix='', loadedProducersAndFilters=None)
 
def removeIfInSequence (process, target, sequenceLabel, postfix="")
 
def testContains (self)
 
def testJetCollectionString (self)
 
def testListModules (self)
 

Function Documentation

◆ __labelsInSequence()

def helpers.__labelsInSequence (   process,
  sequenceLabel,
  postfix = "",
  keepPostFix = False 
)
private

Definition at line 129 of file helpers.py.

129 def __labelsInSequence(process, sequenceLabel, postfix="", keepPostFix=False):
130  position = -len(postfix)
131  if keepPostFix:
132  position = None
133 
134  result = [ m.label()[:position] for m in listModules( getattr(process,sequenceLabel+postfix))]
135  result.extend([ m.label()[:position] for m in listSequences( getattr(process,sequenceLabel+postfix))] )
136  if postfix == "":
137  result = [ m.label() for m in listModules( getattr(process,sequenceLabel+postfix))]
138  result.extend([ m.label() for m in listSequences( getattr(process,sequenceLabel+postfix))] )
139  return result
140 
141 #FIXME name is not generic enough now

References listModules(), and listSequences().

Referenced by removeIfInSequence().

◆ _lineDiff()

def helpers._lineDiff (   newString,
  oldString 
)
private

Definition at line 367 of file helpers.py.

367  def _lineDiff(newString, oldString):
368  newString = ( x for x in newString.split('\n') if len(x) > 0)
369  oldString = [ x for x in oldString.split('\n') if len(x) > 0]
370  diff = []
371  oldStringLine = 0
372  for l in newString:
373  if oldStringLine >= len(oldString):
374  diff.append(l)
375  continue
376  if l == oldString[oldStringLine]:
377  oldStringLine +=1
378  continue
379  diff.append(l)
380  return "\n".join( diff )
381 

References join().

◆ addESProducers()

def helpers.addESProducers (   process,
  config 
)

Definition at line 32 of file helpers.py.

32 def addESProducers(process,config):
33  config = config.replace("/",".")
34  #import RecoBTag.Configuration.RecoBTag_cff as btag
35  #print btag
36  module = __import__(config)
37  for name in dir(sys.modules[config]):
38  item = getattr(sys.modules[config],name)
39  if isinstance(item,cms._Labelable) and not isinstance(item,cms._ModuleSequenceType) and not name.startswith('_') and not (name == "source" or name == "looper" or name == "subProcess") and not isinstance(item, cms.PSet):
40  if 'ESProducer' in item.type_():
41  setattr(process,name,item)
42 

References DeadROC_duringRun.dir.

◆ addKeepStatement()

def helpers.addKeepStatement (   process,
  oldKeep,
  newKeeps,
  verbose = False 
)
Add new keep statements to any PoolOutputModule of the process that has the old keep statements

Definition at line 354 of file helpers.py.

354 def addKeepStatement(process, oldKeep, newKeeps, verbose=False):
355  """Add new keep statements to any PoolOutputModule of the process that has the old keep statements"""
356  for name,out in process.outputModules.items():
357  if out.type_() == 'PoolOutputModule' and hasattr(out, "outputCommands"):
358  if oldKeep in out.outputCommands:
359  out.outputCommands += newKeeps
360  if verbose:
361  print("Adding the following keep statements to output module %s: " % name)
362  for k in newKeeps: print("\t'%s'," % k)
363 
364 

References print().

Referenced by customizeMiniAOD_MuEGFixMoriond2017.addDiscardedPFCandidates(), customizeMiniAOD_HcalFixLegacy2016.addDiscardedPFCandidates(), extraSlimmedMETs_MuEGFixMoriond2017.addExtraMETCollections(), extraSlimmedMETs_MuEGFixMoriond2017.addExtraPuppiMETCorrections(), extraJets_MuEGFixMoriond2017.backupJetsSecondStep(), and customizeMiniAOD_MuEGFixMoriond2017.customizeAll().

◆ addToProcessAndTask()

def helpers.addToProcessAndTask (   label,
  module,
  process,
  task 
)

Definition at line 28 of file helpers.py.

28 def addToProcessAndTask(label, module, process, task):
29  setattr(process, label, module)
30  task.add(getattr(process, label))
31 

Referenced by pfTools.addPFCandidates(), jetCollectionTools.GenJetAdder.addProcessAndTask(), jetCollectionTools.RecoJetAdder.addProcessAndTask(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.ak4JetReclustering(), applyDeepBtagging_cff.applyDeepBtagging(), applySubstructure_cff.applySubstructure(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.createShiftedModules(), eGammaCorrection.eGammaCorrection(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.extractMET(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.getCorrectedMET(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.getJetCollectionForCorsAndUncs(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.getMETUncertainties(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.jetCleaning(), egmIsolationsPUPPI_cfi.makeInputForPUPPIIsolationEgm(), muonIsolationsPUPPI_cfi.makeInputForPUPPIIsolationMuon(), extraJets_MuEGFixMoriond2017.makeRecoJetCollection(), miniAOD_tools.miniAOD_customizeCommon(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.miniAODConfiguration(), muonRecoMitigation.muonRecoMitigation(), nano_cff.nanoAOD_recalibrateMETs(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.produceMET(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.recomputeRawMetFromPfcs(), pfTools.reconfigurePF2PATTaus(), extraJets_MuEGFixMoriond2017.reduceFinalJetCollection(), extraJets_MuEGFixMoriond2017.reduceInputJetCollection(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.runFixEE2017(), jetTools.setupBTagging(), jetTools.setupJetCorrections(), pfTools.switchToPFJets(), trackTools.MakeAODTrackCandidates.toolCode(), metTools.AddMETCollection.toolCode(), trigTools.SwitchOnTrigger.toolCode(), trackTools.MakePATTrackCandidates.toolCode(), trigTools.SwitchOnTriggerStandAlone.toolCode(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.toolCode(), trigTools.SwitchOnTriggerMatchEmbedding.toolCode(), jetTools.AddJetCollection.toolCode(), jetTools.UpdateJetCollection.toolCode(), jetTools.AddJetID.toolCode(), and runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.updateJECs().

◆ addToTask()

def helpers.addToTask (   loadedProducersAndFilters,
  module 
)

Definition at line 55 of file helpers.py.

55 def addToTask(loadedProducersAndFilters, module):
56  if loadedProducersAndFilters:
57  if isinstance(module, cms.EDProducer) or isinstance(module, cms.EDFilter):
58  loadedProducersAndFilters.add(module)
59 

Referenced by extendWithPrePostfix().

◆ applyPostfix()

def helpers.applyPostfix (   process,
  label,
  postfix 
)

Definition at line 114 of file helpers.py.

114 def applyPostfix(process, label, postfix):
115  result = None
116  if hasattr(process, label+postfix):
117  result = getattr(process, label + postfix)
118  else:
119  raise ValueError("Error in <applyPostfix>: No module of name = %s attached to process !!" % (label + postfix))
120  return result
121 

Referenced by pfTools.adaptPFMuons(), pfTools.addPFCandidates(), pfTools.reconfigurePF2PATTaus(), pfTools.switchToPFJets(), pfTools.switchToPFMET(), pfTools.tauTypeInPF2PAT(), and pfTools.usePF2PAT().

◆ associatePatAlgosToolsTask()

def helpers.associatePatAlgosToolsTask (   process)

Definition at line 24 of file helpers.py.

24 def associatePatAlgosToolsTask(process):
25  task = getPatAlgosToolsTask(process)
26  process.schedule.associate(task)
27 

References getPatAlgosToolsTask().

Referenced by ConfigBuilder.ConfigBuilder.prepare().

◆ cloneProcessingSnippet()

def helpers.cloneProcessingSnippet (   process,
  sequence,
  postfix,
  removePostfix = "",
  noClones = [],
  addToTask = False,
  verbose = False 
)
------------------------------------------------------------------
copy a sequence plus the modules and sequences therein
both are renamed by getting a postfix
input tags are automatically adjusted
------------------------------------------------------------------

Definition at line 257 of file helpers.py.

257 def cloneProcessingSnippet(process, sequence, postfix, removePostfix="", noClones = [], addToTask = False, verbose = False):
258  """
259  ------------------------------------------------------------------
260  copy a sequence plus the modules and sequences therein
261  both are renamed by getting a postfix
262  input tags are automatically adjusted
263  ------------------------------------------------------------------
264  """
265  result = sequence
266  if not postfix == "":
267  visitor = CloneSequenceVisitor(process, sequence.label(), postfix, removePostfix, noClones, addToTask, verbose)
268  sequence.visit(visitor)
269  result = visitor.clonedSequence()
270  return result
271 

Referenced by boostedHPSPFTaus_cfi.addBoostedTaus(), extraSlimmedMETs_MuEGFixMoriond2017.addExtraMETCollections(), extraJets_MuEGFixMoriond2017.backupJetsFirstStep(), extraJets_MuEGFixMoriond2017.makeRecoJetCollection(), pfIsolation.setupPFIso(), and pfIsolation.setupPFIsoPhoton().

◆ contains()

def helpers.contains (   sequence,
  moduleName 
)
------------------------------------------------------------------
return True if a module with name 'module' is contained in the
sequence with name 'sequence' and False otherwise. This version
is not so nice as it also returns True for any substr of the name
of a contained module.

sequence : sequence [e.g. process.patDefaultSequence]
module   : module name as a string
------------------------------------------------------------------

Definition at line 241 of file helpers.py.

241 def contains(sequence, moduleName):
242  """
243  ------------------------------------------------------------------
244  return True if a module with name 'module' is contained in the
245  sequence with name 'sequence' and False otherwise. This version
246  is not so nice as it also returns True for any substr of the name
247  of a contained module.
248 
249  sequence : sequence [e.g. process.patDefaultSequence]
250  module : module name as a string
251  ------------------------------------------------------------------
252  """
253  return not sequence.__str__().find(moduleName)==-1
254 
255 
256 

References spr.find().

Referenced by testContains().

◆ extendWithPrePostfix()

def helpers.extendWithPrePostfix (   process,
  other,
  prefix,
  postfix,
  loadedProducersAndFilters = None 
)
Look in other and find types which we can use

Definition at line 60 of file helpers.py.

60 def extendWithPrePostfix(process,other,prefix,postfix,loadedProducersAndFilters=None):
61  """Look in other and find types which we can use"""
62  # enable explicit check to avoid overwriting of existing objects
63  #__dict__['_Process__InExtendCall'] = True
64 
65  if loadedProducersAndFilters:
66  task = getattr(process, loadedProducersAndFilters)
67  if not isinstance(task, cms.Task):
68  raise Exception("extendWithPrePostfix argument must be name of Task type object attached to the process or None")
69  else:
70  task = None
71 
72  sequence = cms.Sequence()
73  sequence._moduleLabels = []
74  for name in dir(other):
75  #'from XX import *' ignores these, and so should we.
76  if name.startswith('_'):
77  continue
78  item = getattr(other,name)
79  if name == "source" or name == "looper" or name == "subProcess":
80  continue
81  elif isinstance(item,cms._ModuleSequenceType):
82  continue
83  elif isinstance(item,cms.Task):
84  continue
85  elif isinstance(item,cms.Schedule):
86  continue
87  elif isinstance(item,cms.VPSet) or isinstance(item,cms.PSet):
88  continue
89  elif isinstance(item,cms._Labelable):
90  if not item.hasLabel_():
91  item.setLabel(name)
92  if prefix != '' or postfix != '':
93  newModule = item.clone()
94  if isinstance(item,cms.ESProducer):
95  newName =name
96  else:
97  if 'TauDiscrimination' in name:
98  process.__setattr__(name,item)
99  addToTask(task, item)
100  newName = prefix+name+postfix
101  process.__setattr__(newName,newModule)
102  addToTask(task, newModule)
103  if isinstance(newModule, cms._Sequenceable) and not newName == name:
104  sequence +=getattr(process,newName)
105  sequence._moduleLabels.append(item.label())
106  else:
107  process.__setattr__(name,item)
108  addToTask(task, item)
109 
110  if prefix != '' or postfix != '':
111  for label in sequence._moduleLabels:
112  massSearchReplaceAnyInputTag(sequence, label, prefix+label+postfix,verbose=False,moduleLabelOnly=True)
113 

References addToTask(), DeadROC_duringRun.dir, and MassReplace.massSearchReplaceAnyInputTag().

Referenced by loadWithPrePostfix().

◆ get_path()

def helpers.get_path (   file_in_path)

Definition at line 6 of file helpers.py.

6 def get_path(file_in_path):
7  'mimics edm.FileInPath behavior'
8  search_env = os.environ.get('CMSSW_SEARCH_PATH', '')
9  if not search_env:
10  raise RuntimeError('The environmental variable CMSSW_SEARCH_PATH must be set')
11  search_paths = search_env.split(':')
12  for spath in search_paths:
13  full_path = os.path.join(spath, file_in_path)
14  if os.path.isfile(full_path):
15  return full_path
16  raise RuntimeError('No suitable path found for %s' % file_in_path)
17 

Referenced by get_vars().

◆ get_vars()

def helpers.get_vars (   xml_path,
  useFileInPath = True 
)

Definition at line 18 of file helpers.py.

18 def get_vars(xml_path, useFileInPath=True):
19  full_path = get_path(xml_path) if useFileInPath else xml_path
20  xml_tree = ET.parse(full_path)
21  root = xml_tree.getroot()
22  variables = None
23  for i in root:
24  if i.tag == 'Variables':
25  variables = i
26 
27  if i is None:
28  raise RuntimeError('Could not find Variables inside the xml weights')
29 
30  var_names = [i.attrib['Title'] for i in variables]
31  return [get_var_pset(i) for i in var_names]
32 

References get_path(), and trainingvars.get_var_pset().

◆ getPatAlgosToolsTask()

def helpers.getPatAlgosToolsTask (   process)

Definition at line 13 of file helpers.py.

13 def getPatAlgosToolsTask(process):
14  taskName = "patAlgosToolsTask"
15  if hasattr(process, taskName):
16  task = getattr(process, taskName)
17  if not isinstance(task, cms.Task):
18  raise Exception("patAlgosToolsTask does not have type Task")
19  else:
20  setattr(process, taskName, cms.Task())
21  task = getattr(process, taskName)
22  return task
23 

Referenced by customizeMiniAOD_MuEGFixMoriond2017.addBadMuonFilters(), customizeMiniAOD_MuEGFixMoriond2017.addDiscardedPFCandidates(), customizeMiniAOD_HcalFixLegacy2016.addDiscardedPFCandidates(), extraSlimmedMETs_MuEGFixMoriond2017.addExtraMETCollections(), extraSlimmedMETs_MuEGFixMoriond2017.addExtraPuppiMETCorrections(), pfTools.addPFCandidates(), jetCollectionTools.GenJetAdder.addProcessAndTask(), jetCollectionTools.RecoJetAdder.addProcessAndTask(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.ak4JetReclustering(), applyDeepBtagging_cff.applyDeepBtagging(), applySubstructure_cff.applySubstructure(), associatePatAlgosToolsTask(), extraJets_MuEGFixMoriond2017.backupJetsFirstStep(), extraJets_MuEGFixMoriond2017.backupJetsSecondStep(), customizeMiniAOD_MuEGFixMoriond2017.cleanPFCandidates(), customizeMiniAOD_HcalFixLegacy2016.cleanPfCandidates(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.createMVAMETModule(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.createShiftedModules(), eGammaCorrection.eGammaCorrection(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.extractMET(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.getCorrectedMET(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.getJetCollectionForCorsAndUncs(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.getMETUncertainties(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.jetCleaning(), customizeMiniAOD_HcalFixLegacy2016.loadJetMETBTag(), customizeMiniAOD_MuEGFixMoriond2017.loadJetMETBTag(), egmIsolationsPUPPI_cfi.makeInputForPUPPIIsolationEgm(), muonIsolationsPUPPI_cfi.makeInputForPUPPIIsolationMuon(), puppiForMET_cff.makePuppies(), puppiForMET_cff.makePuppiesFromMiniAOD(), extraJets_MuEGFixMoriond2017.makeRecoJetCollection(), miniAOD_tools.miniAOD_customizeCommon(), miniAOD_tools.miniAOD_customizeData(), miniAOD_tools.miniAOD_customizeMC(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.miniAODConfiguration(), muonRecoMitigation.muonRecoMitigation(), nano_cff.nanoAOD_recalibrateMETs(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.produceMET(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.recomputeRawMetFromPfcs(), pfTools.reconfigurePF2PATTaus(), extraJets_MuEGFixMoriond2017.reduceFinalJetCollection(), extraJets_MuEGFixMoriond2017.reduceInputJetCollection(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.runFixEE2017(), jetTools.setupBTagging(), jetTools.setupJetCorrections(), pfTools.switchToPFJets(), trackTools.MakeAODTrackCandidates.toolCode(), metTools.AddMETCollection.toolCode(), trigTools.SwitchOnTrigger.toolCode(), trackTools.MakePATTrackCandidates.toolCode(), trigTools.SwitchOnTriggerStandAlone.toolCode(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.toolCode(), trigTools.SwitchOnTriggerMatching.toolCode(), trigTools.SwitchOnTriggerMatchingStandAlone.toolCode(), trigTools.SwitchOnTriggerMatchEmbedding.toolCode(), jetTools.AddJetCollection.toolCode(), jetTools.UpdateJetCollection.toolCode(), jetTools.AddJetID.toolCode(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.updateJECs(), and pfTools.usePF2PAT().

◆ jetCollectionString()

def helpers.jetCollectionString (   prefix = '',
  algo = '',
  type = '' 
)
------------------------------------------------------------------
return the string of the jet collection module depending on the
input vaules. The default return value will be 'patAK5CaloJets'.

algo   : indicating the algorithm type of the jet [expected are
         'AK5', 'IC5', 'SC7', ...]
type   : indicating the type of constituents of the jet [expec-
         ted are 'Calo', 'PFlow', 'JPT', ...]
prefix : prefix indicating the type of pat collection module (ex-
         pected are '', 'selected', 'clean').
------------------------------------------------------------------

Definition at line 217 of file helpers.py.

217 def jetCollectionString(prefix='', algo='', type=''):
218  """
219  ------------------------------------------------------------------
220  return the string of the jet collection module depending on the
221  input vaules. The default return value will be 'patAK5CaloJets'.
222 
223  algo : indicating the algorithm type of the jet [expected are
224  'AK5', 'IC5', 'SC7', ...]
225  type : indicating the type of constituents of the jet [expec-
226  ted are 'Calo', 'PFlow', 'JPT', ...]
227  prefix : prefix indicating the type of pat collection module (ex-
228  pected are '', 'selected', 'clean').
229  ------------------------------------------------------------------
230  """
231  if(prefix==''):
232  jetCollectionString ='pat'
233  else:
234  jetCollectionString =prefix
235  jetCollectionString+='Pat'
236  jetCollectionString+='Jets'
237  jetCollectionString+=algo
238  jetCollectionString+=type
239  return jetCollectionString
240 

References if().

Referenced by testJetCollectionString(), heavyIonTools.ProductionDefaults.toolCode(), coreTools.RemoveMCMatching.toolCode(), and heavyIonTools.SelectionDefaults.toolCode().

◆ listDependencyChain()

def helpers.listDependencyChain (   process,
  module,
  sources,
  verbose = False 
)
Walk up the dependencies of a module to find any that depend on any of the listed sources

Definition at line 272 of file helpers.py.

272 def listDependencyChain(process, module, sources, verbose=False):
273  """
274  Walk up the dependencies of a module to find any that depend on any of the listed sources
275  """
276  def allDirectInputModules(moduleOrPSet,moduleName,attrName):
277  ret = set()
278  for name,value in moduleOrPSet.parameters_().items():
279  type = value.pythonTypeName()
280  if type == 'cms.PSet':
281  ret.update(allDirectInputModules(value,moduleName,moduleName+"."+name))
282  elif type == 'cms.VPSet':
283  for (i,ps) in enumerate(value):
284  ret.update(allDirectInputModules(ps,moduleName,"%s.%s[%d]"%(moduleName,name,i)))
285  elif type == 'cms.VInputTag':
286  inputs = [ MassSearchReplaceAnyInputTagVisitor.standardizeInputTagFmt(it) for it in value ]
287  inputLabels = [ tag.moduleLabel for tag in inputs if tag.processName == '' or tag.processName == process.name_() ]
288  ret.update(inputLabels)
289  if verbose and inputLabels: print("%s depends on %s via %s" % (moduleName, inputLabels, attrName+"."+name))
290  elif type.endswith('.InputTag'):
291  if value.processName == '' or value.processName == process.name_():
292  ret.add(value.moduleLabel)
293  if verbose: print("%s depends on %s via %s" % (moduleName, value.moduleLabel, attrName+"."+name))
294  ret.discard("")
295  return ret
296  def fillDirectDepGraphs(root,fwdepgraph,revdepgraph):
297  if root.label_() in fwdepgraph: return
298  deps = allDirectInputModules(root,root.label_(),root.label_())
299  fwdepgraph[root.label_()] = []
300  for d in deps:
301  fwdepgraph[root.label_()].append(d)
302  if d not in revdepgraph: revdepgraph[d] = []
303  revdepgraph[d].append(root.label_())
304  depmodule = getattr(process,d,None)
305  if depmodule:
306  fillDirectDepGraphs(depmodule,fwdepgraph,revdepgraph)
307  return (fwdepgraph,revdepgraph)
308  fwdepgraph, revdepgraph = fillDirectDepGraphs(module, {}, {})
309  def flattenRevDeps(flatgraph, revdepgraph, tip):
310  """Make a graph that for each module lists all the ones that depend on it, directly or indirectly"""
311  # don't do it multiple times for the same module
312  if tip in flatgraph: return
313  # if nobody depends on this module, there's nothing to do
314  if tip not in revdepgraph: return
315  # assemble my dependencies, in a depth-first approach
316  mydeps = set()
317  # start taking the direct dependencies of this module
318  for d in revdepgraph[tip]:
319  # process them
320  flattenRevDeps(flatgraph, revdepgraph, d)
321  # then add them and their processed dependencies to our deps
322  mydeps.add(d)
323  if d in flatgraph:
324  mydeps.update(flatgraph[d])
325  flatgraph[tip] = mydeps
326  flatdeps = {}
327  allmodules = set()
328  for s in sources:
329  flattenRevDeps(flatdeps, revdepgraph, s)
330  if s in flatdeps: allmodules.update(f for f in flatdeps[s])
331  livemodules = [ a for a in allmodules if hasattr(process,a) ]
332  if not livemodules: return None
333  modulelist = [livemodules.pop()]
334  for module in livemodules:
335  for i,m in enumerate(modulelist):
336  if module in flatdeps and m in flatdeps[module]:
337  modulelist.insert(i, module)
338  break
339  if module not in modulelist:
340  modulelist.append(module)
341  # Validate
342  for i,m1 in enumerate(modulelist):
343  for j,m2 in enumerate(modulelist):
344  if j <= i: continue
345  if m2 in flatdeps and m1 in flatdeps[m2]:
346  raise RuntimeError("BAD ORDER %s BEFORE %s" % (m1,m2))
347  modules = [ getattr(process,p) for p in modulelist ]
348  #return cms.Sequence(sum(modules[1:],modules[0]))
349  task = cms.Task()
350  for mod in modules:
351  task.add(mod)
352  return task,cms.Sequence(task)
353 

References mps_setup.append, mps_monitormerge.items, and print().

Referenced by extraJets_MuEGFixMoriond2017.backupJetsFirstStep().

◆ listModules()

def helpers.listModules (   sequence)

Definition at line 207 of file helpers.py.

207 def listModules(sequence):
208  visitor = GatherAllModulesVisitor(gatheredInstance=cms._Module)
209  sequence.visit(visitor)
210  return visitor.modules()
211 

Referenced by __labelsInSequence(), trigTools._modulesInPath(), extraJets_MuEGFixMoriond2017.backupJetsSecondStep(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.labelsInSequence(), and testListModules().

◆ listSequences()

def helpers.listSequences (   sequence)

Definition at line 212 of file helpers.py.

212 def listSequences(sequence):
213  visitor = GatherAllModulesVisitor(gatheredInstance=cms.Sequence)
214  sequence.visit(visitor)
215  return visitor.modules()
216 

Referenced by __labelsInSequence(), and runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.labelsInSequence().

◆ loadWithPostfix()

def helpers.loadWithPostfix (   process,
  moduleName,
  postfix = '',
  loadedProducersAndFilters = None 
)

Definition at line 46 of file helpers.py.

46 def loadWithPostfix(process,moduleName,postfix='',loadedProducersAndFilters=None):
47  loadWithPrePostfix(process,moduleName,'',postfix,loadedProducersAndFilters)
48 

References loadWithPrePostfix().

Referenced by pfTools.usePF2PAT().

◆ loadWithPrefix()

def helpers.loadWithPrefix (   process,
  moduleName,
  prefix = '',
  loadedProducersAndFilters = None 
)

Definition at line 43 of file helpers.py.

43 def loadWithPrefix(process,moduleName,prefix='',loadedProducersAndFilters=None):
44  loadWithPrePostfix(process,moduleName,prefix,'',loadedProducersAndFilters)
45 

References loadWithPrePostfix().

Referenced by jetTools.setupBTagging().

◆ loadWithPrePostfix()

def helpers.loadWithPrePostfix (   process,
  moduleName,
  prefix = '',
  postfix = '',
  loadedProducersAndFilters = None 
)

Definition at line 49 of file helpers.py.

49 def loadWithPrePostfix(process,moduleName,prefix='',postfix='',loadedProducersAndFilters=None):
50  moduleName = moduleName.replace("/",".")
51  module = __import__(moduleName)
52  #print module.PatAlgos.patSequences_cff.patDefaultSequence
53  extendWithPrePostfix(process,sys.modules[moduleName],prefix,postfix,loadedProducersAndFilters)
54 

References extendWithPrePostfix().

Referenced by loadWithPostfix(), and loadWithPrefix().

◆ removeIfInSequence()

def helpers.removeIfInSequence (   process,
  target,
  sequenceLabel,
  postfix = "" 
)

Definition at line 122 of file helpers.py.

122 def removeIfInSequence(process, target, sequenceLabel, postfix=""):
123  labels = __labelsInSequence(process, sequenceLabel, postfix, True)
124  if target+postfix in labels:
125  getattr(process, sequenceLabel+postfix).remove(
126  getattr(process, target+postfix)
127  )
128 

References __labelsInSequence(), and MatrixUtil.remove().

◆ testContains()

def helpers.testContains (   self)

Definition at line 415 of file helpers.py.

415  def testContains(self):
416  p = cms.Process("test")
417  p.a = cms.EDProducer("a", src=cms.InputTag("gen"))
418  p.b = cms.EDProducer("ab", src=cms.InputTag("a"))
419  p.c = cms.EDProducer("ac", src=cms.InputTag("b"))
420  p.s1 = cms.Sequence(p.a*p.b*p.c)
421  p.s2 = cms.Sequence(p.b*p.c)
422  self.assertTrue( contains(p.s1, "a") )
423  self.assertTrue( not contains(p.s2, "a") )

References contains().

◆ testJetCollectionString()

def helpers.testJetCollectionString (   self)

Definition at line 424 of file helpers.py.

424  def testJetCollectionString(self):
425  self.assertEqual(jetCollectionString(algo = 'Foo', type = 'Bar'), 'patJetsFooBar')
426  self.assertEqual(jetCollectionString(prefix = 'prefix', algo = 'Foo', type = 'Bar'), 'prefixPatJetsFooBar')

References jetCollectionString().

◆ testListModules()

def helpers.testListModules (   self)

Definition at line 427 of file helpers.py.

427  def testListModules(self):
428  p = cms.Process("test")
429  p.a = cms.EDProducer("a", src=cms.InputTag("gen"))
430  p.b = cms.EDProducer("ab", src=cms.InputTag("a"))
431  p.c = cms.EDProducer("ac", src=cms.InputTag("b"))
432  p.s = cms.Sequence(p.a*p.b*p.c)
433  self.assertEqual([p.a,p.b,p.c], listModules(p.s))
434 

References listModules().

helpers.associatePatAlgosToolsTask
def associatePatAlgosToolsTask(process)
Definition: helpers.py:24
helpers.removeIfInSequence
def removeIfInSequence(process, target, sequenceLabel, postfix="")
Definition: helpers.py:122
helpers.addKeepStatement
def addKeepStatement(process, oldKeep, newKeeps, verbose=False)
Definition: helpers.py:354
helpers.loadWithPostfix
def loadWithPostfix(process, moduleName, postfix='', loadedProducersAndFilters=None)
Definition: helpers.py:46
helpers.getPatAlgosToolsTask
def getPatAlgosToolsTask(process)
Definition: helpers.py:13
helpers.testJetCollectionString
def testJetCollectionString(self)
Definition: helpers.py:424
helpers.testContains
def testContains(self)
Definition: helpers.py:415
helpers.addESProducers
def addESProducers(process, config)
Definition: helpers.py:32
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
if
if(0==first)
Definition: CAHitNtupletGeneratorKernelsImpl.h:58
helpers.get_path
def get_path(file_in_path)
Definition: helpers.py:6
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
helpers.extendWithPrePostfix
def extendWithPrePostfix(process, other, prefix, postfix, loadedProducersAndFilters=None)
Definition: helpers.py:60
mps_monitormerge.items
list items
Definition: mps_monitormerge.py:29
helpers._lineDiff
def _lineDiff(newString, oldString)
Definition: helpers.py:367
helpers.contains
def contains(sequence, moduleName)
Definition: helpers.py:241
helpers.addToTask
def addToTask(loadedProducersAndFilters, module)
Definition: helpers.py:55
helpers.listSequences
def listSequences(sequence)
Definition: helpers.py:212
helpers.get_vars
def get_vars(xml_path, useFileInPath=True)
Definition: helpers.py:18
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
Exception
mps_setup.append
append
Definition: mps_setup.py:85
helpers.listModules
def listModules(sequence)
Definition: helpers.py:207
helpers.testListModules
def testListModules(self)
Definition: helpers.py:427
helpers.applyPostfix
def applyPostfix(process, label, postfix)
Definition: helpers.py:114
trainingvars.get_var_pset
def get_var_pset(mvaname)
Definition: trainingvars.py:104
helpers.loadWithPrefix
def loadWithPrefix(process, moduleName, prefix='', loadedProducersAndFilters=None)
Definition: helpers.py:43
helpers.listDependencyChain
def listDependencyChain(process, module, sources, verbose=False)
Definition: helpers.py:272
helpers.__labelsInSequence
def __labelsInSequence(process, sequenceLabel, postfix="", keepPostFix=False)
Definition: helpers.py:129
MatrixUtil.remove
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:219
MassReplace.massSearchReplaceAnyInputTag
def massSearchReplaceAnyInputTag(sequence, oldInputTag, newInputTag, verbose=False, moduleLabelOnly=False, skipLabelTest=False)
Definition: MassReplace.py:79
helpers.jetCollectionString
def jetCollectionString(prefix='', algo='', type='')
Definition: helpers.py:217
helpers.loadWithPrePostfix
def loadWithPrePostfix(process, moduleName, prefix='', postfix='', loadedProducersAndFilters=None)
Definition: helpers.py:49
helpers.addToProcessAndTask
def addToProcessAndTask(label, module, process, task)
Definition: helpers.py:28
helpers.cloneProcessingSnippet
def cloneProcessingSnippet(process, sequence, postfix, removePostfix="", noClones=[], addToTask=False, verbose=False)
Definition: helpers.py:257
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23