CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Functions
helpers Namespace Reference

Classes

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

Functions

def __labelsInSequence
 
def _lineDiff
 
def addESProducers
 
def addKeepStatement
 
def addToProcessAndTask
 
def addToTask
 
def applyPostfix
 
def associatePatAlgosToolsTask
 
def cloneProcessingSnippet
 
def cloneProcessingSnippetTask
 
def contains
 
def extendWithPrePostfix
 
def get_path
 
def get_vars
 
def getPatAlgosToolsTask
 
def jetCollectionString
 
def listDependencyChain
 
def listModules
 
def listSequences
 
def loadWithPostfix
 
def loadWithPrefix
 
def loadWithPrePostfix
 
def removeIfInSequence
 
def testContains
 
def testJetCollectionString
 
def testListModules
 

Function Documentation

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

Definition at line 129 of file helpers.py.

References listModules(), and listSequences().

Referenced by removeIfInSequence().

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 
#FIXME name is not generic enough now
def listModules
Definition: helpers.py:207
def listSequences
Definition: helpers.py:212
def __labelsInSequence
Definition: helpers.py:129
def helpers._lineDiff (   newString,
  oldString 
)
private

Definition at line 367 of file helpers.py.

References join().

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 )
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def _lineDiff
Definition: helpers.py:367
def helpers.addESProducers (   process,
  config 
)

Definition at line 32 of file helpers.py.

References DeadROC_duringRun.dir.

32 
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)
def addESProducers
Definition: helpers.py:32
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.

References print().

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

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 process.outputModules.items():
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 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def addKeepStatement
Definition: helpers.py:354
def helpers.addToProcessAndTask (   label,
  module,
  process,
  task 
)

Definition at line 28 of file helpers.py.

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().

28 
29 def addToProcessAndTask(label, module, process, task):
30  setattr(process, label, module)
31  task.add(getattr(process, label))
def addToProcessAndTask
Definition: helpers.py:28
def helpers.addToTask (   loadedProducersAndFilters,
  module 
)

Definition at line 55 of file helpers.py.

Referenced by extendWithPrePostfix().

55 
56 def addToTask(loadedProducersAndFilters, module):
57  if loadedProducersAndFilters:
58  if isinstance(module, cms.EDProducer) or isinstance(module, cms.EDFilter):
59  loadedProducersAndFilters.add(module)
def addToTask
Definition: helpers.py:55
def helpers.applyPostfix (   process,
  label,
  postfix 
)

Definition at line 114 of file helpers.py.

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

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
def applyPostfix
Definition: helpers.py:114
def helpers.associatePatAlgosToolsTask (   process)

Definition at line 24 of file helpers.py.

References getPatAlgosToolsTask().

Referenced by ConfigBuilder.ConfigBuilder.prepare().

24 
25 def associatePatAlgosToolsTask(process):
26  task = getPatAlgosToolsTask(process)
27  process.schedule.associate(task)
def getPatAlgosToolsTask
Definition: helpers.py:13
def associatePatAlgosToolsTask
Definition: helpers.py:24
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.

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

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
def cloneProcessingSnippet
Definition: helpers.py:257
def helpers.cloneProcessingSnippetTask (   process,
  task,
  postfix,
  removePostfix = "",
  noClones = [],
  verbose = False 
)
------------------------------------------------------------------
copy a task plus the modules therein (including modules in subtasks)
both are renamed by getting a postfix
input tags are automatically adjusted
------------------------------------------------------------------

Definition at line 484 of file helpers.py.

485 def cloneProcessingSnippetTask(process, task, postfix, removePostfix="", noClones = [], verbose = False):
486  """
487  ------------------------------------------------------------------
488  copy a task plus the modules therein (including modules in subtasks)
489  both are renamed by getting a postfix
490  input tags are automatically adjusted
491  ------------------------------------------------------------------
492  """
493  result = task
494  if not postfix == "":
495  visitor = CloneTaskVisitor(process, task.label(), postfix, removePostfix, noClones, verbose)
496  task.visit(visitor)
497  result = visitor.clonedTask()
498  return result
def cloneProcessingSnippetTask
Definition: helpers.py:484
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.

References spr.find().

Referenced by testContains().

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 
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
def contains
Definition: helpers.py:241
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.

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

Referenced by loadWithPrePostfix().

60 
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)
def extendWithPrePostfix
Definition: helpers.py:60
def addToTask
Definition: helpers.py:55
def massSearchReplaceAnyInputTag
Definition: MassReplace.py:79
def helpers.get_path (   file_in_path)

Definition at line 6 of file helpers.py.

Referenced by get_vars().

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

Definition at line 18 of file helpers.py.

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

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

Definition at line 13 of file helpers.py.

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().

13 
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
def getPatAlgosToolsTask
Definition: helpers.py:13
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.

References if().

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

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
def jetCollectionString
Definition: helpers.py:217
if(conf_.getParameter< bool >("UseStripCablingDB"))
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.

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

Referenced by extraJets_MuEGFixMoriond2017.backupJetsFirstStep().

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 moduleOrPSet.parameters_().items():
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)
def listDependencyChain
Definition: helpers.py:272
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def helpers.listModules (   sequence)

Definition at line 207 of file helpers.py.

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

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

Definition at line 212 of file helpers.py.

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

213 def listSequences(sequence):
214  visitor = GatherAllModulesVisitor(gatheredInstance=cms.Sequence)
215  sequence.visit(visitor)
216  return visitor.modules()
def listSequences
Definition: helpers.py:212
def helpers.loadWithPostfix (   process,
  moduleName,
  postfix = '',
  loadedProducersAndFilters = None 
)

Definition at line 46 of file helpers.py.

References loadWithPrePostfix().

Referenced by pfTools.usePF2PAT().

46 
47 def loadWithPostfix(process,moduleName,postfix='',loadedProducersAndFilters=None):
48  loadWithPrePostfix(process,moduleName,'',postfix,loadedProducersAndFilters)
def loadWithPostfix
Definition: helpers.py:46
def loadWithPrePostfix
Definition: helpers.py:49
def helpers.loadWithPrefix (   process,
  moduleName,
  prefix = '',
  loadedProducersAndFilters = None 
)

Definition at line 43 of file helpers.py.

References loadWithPrePostfix().

Referenced by jetTools.setupBTagging().

43 
44 def loadWithPrefix(process,moduleName,prefix='',loadedProducersAndFilters=None):
45  loadWithPrePostfix(process,moduleName,prefix,'',loadedProducersAndFilters)
def loadWithPrePostfix
Definition: helpers.py:49
def loadWithPrefix
Definition: helpers.py:43
def helpers.loadWithPrePostfix (   process,
  moduleName,
  prefix = '',
  postfix = '',
  loadedProducersAndFilters = None 
)

Definition at line 49 of file helpers.py.

References extendWithPrePostfix().

Referenced by loadWithPostfix(), and loadWithPrefix().

49 
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)
def extendWithPrePostfix
Definition: helpers.py:60
def loadWithPrePostfix
Definition: helpers.py:49
def helpers.removeIfInSequence (   process,
  target,
  sequenceLabel,
  postfix = "" 
)

Definition at line 122 of file helpers.py.

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

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  )
def removeIfInSequence
Definition: helpers.py:122
def __labelsInSequence
Definition: helpers.py:129
def helpers.testContains (   self)

Definition at line 415 of file helpers.py.

References contains().

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.assertTrue( contains(p.s1, "a") )
self.assertTrue( not contains(p.s2, "a") )
def testContains
Definition: helpers.py:415
def contains
Definition: helpers.py:241
def helpers.testJetCollectionString (   self)

Definition at line 424 of file helpers.py.

References jetCollectionString().

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

Definition at line 427 of file helpers.py.

References listModules().

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))
def listModules
Definition: helpers.py:207
def testListModules
Definition: helpers.py:427