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 130 of file helpers.py.

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

References listModules(), and listSequences().

Referenced by removeIfInSequence().

◆ _lineDiff()

def helpers._lineDiff (   newString,
  oldString 
)
private

Definition at line 368 of file helpers.py.

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

References join().

◆ addESProducers()

def helpers.addESProducers (   process,
  config 
)

Definition at line 33 of file helpers.py.

33 def addESProducers(process,config):
34  config = config.replace("/",".")
35  #import RecoBTag.Configuration.RecoBTag_cff as btag
36  #print btag
37  module = __import__(config)
38  for name in dir(sys.modules[config]):
39  item = getattr(sys.modules[config],name)
40  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):
41  if 'ESProducer' in item.type_():
42  setattr(process,name,item)
43 

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 355 of file helpers.py.

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

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 29 of file helpers.py.

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

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 56 of file helpers.py.

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

Referenced by extendWithPrePostfix().

◆ applyPostfix()

def helpers.applyPostfix (   process,
  label,
  postfix 
)

Definition at line 115 of file helpers.py.

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

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 25 of file helpers.py.

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

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 258 of file helpers.py.

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

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 242 of file helpers.py.

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

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 61 of file helpers.py.

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

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 14 of file helpers.py.

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

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(), CompactSkim_cff.CompactSkim(), 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 218 of file helpers.py.

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

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 273 of file helpers.py.

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

References mps_setup.append, and print().

Referenced by extraJets_MuEGFixMoriond2017.backupJetsFirstStep().

◆ listModules()

def helpers.listModules (   sequence)

Definition at line 208 of file helpers.py.

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

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

◆ listSequences()

def helpers.listSequences (   sequence)

Definition at line 213 of file helpers.py.

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

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

◆ loadWithPostfix()

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

Definition at line 47 of file helpers.py.

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

References loadWithPrePostfix().

Referenced by pfTools.usePF2PAT().

◆ loadWithPrefix()

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

Definition at line 44 of file helpers.py.

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

References loadWithPrePostfix().

Referenced by jetTools.setupBTagging().

◆ loadWithPrePostfix()

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

Definition at line 50 of file helpers.py.

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

References extendWithPrePostfix().

Referenced by loadWithPostfix(), and loadWithPrefix().

◆ removeIfInSequence()

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

Definition at line 123 of file helpers.py.

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

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

◆ testContains()

def helpers.testContains (   self)

Definition at line 416 of file helpers.py.

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

References contains().

◆ testJetCollectionString()

def helpers.testJetCollectionString (   self)

Definition at line 425 of file helpers.py.

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

References jetCollectionString().

◆ testListModules()

def helpers.testListModules (   self)

Definition at line 428 of file helpers.py.

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

References listModules().

helpers.associatePatAlgosToolsTask
def associatePatAlgosToolsTask(process)
Definition: helpers.py:25
helpers.removeIfInSequence
def removeIfInSequence(process, target, sequenceLabel, postfix="")
Definition: helpers.py:123
helpers.addKeepStatement
def addKeepStatement(process, oldKeep, newKeeps, verbose=False)
Definition: helpers.py:355
helpers.loadWithPostfix
def loadWithPostfix(process, moduleName, postfix='', loadedProducersAndFilters=None)
Definition: helpers.py:47
helpers.getPatAlgosToolsTask
def getPatAlgosToolsTask(process)
Definition: helpers.py:14
helpers.testJetCollectionString
def testJetCollectionString(self)
Definition: helpers.py:425
helpers.testContains
def testContains(self)
Definition: helpers.py:416
helpers.addESProducers
def addESProducers(process, config)
Definition: helpers.py:33
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
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:61
helpers._lineDiff
def _lineDiff(newString, oldString)
Definition: helpers.py:368
helpers.contains
def contains(sequence, moduleName)
Definition: helpers.py:242
helpers.addToTask
def addToTask(loadedProducersAndFilters, module)
Definition: helpers.py:56
helpers.listSequences
def listSequences(sequence)
Definition: helpers.py:213
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:208
helpers.testListModules
def testListModules(self)
Definition: helpers.py:428
helpers.applyPostfix
def applyPostfix(process, label, postfix)
Definition: helpers.py:115
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:44
helpers.listDependencyChain
def listDependencyChain(process, module, sources, verbose=False)
Definition: helpers.py:273
helpers.__labelsInSequence
def __labelsInSequence(process, sequenceLabel, postfix="", keepPostFix=False)
Definition: helpers.py:130
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:218
helpers.loadWithPrePostfix
def loadWithPrePostfix(process, moduleName, prefix='', postfix='', loadedProducersAndFilters=None)
Definition: helpers.py:50
helpers.addToProcessAndTask
def addToProcessAndTask(label, module, process, task)
Definition: helpers.py:29
helpers.cloneProcessingSnippet
def cloneProcessingSnippet(process, sequence, postfix, removePostfix="", noClones=[], addToTask=False, verbose=False)
Definition: helpers.py:258
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23