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="")
 
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)
 
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="")
 

Function Documentation

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

Definition at line 128 of file helpers.py.

References listModules(), and listSequences().

Referenced by removeIfInSequence().

128 def __labelsInSequence(process, sequenceLabel, postfix=""):
129  result = [ m.label()[:-len(postfix)] for m in listModules( getattr(process,sequenceLabel+postfix))]
130  result.extend([ m.label()[:-len(postfix)] for m in listSequences( getattr(process,sequenceLabel+postfix))] )
131  if postfix == "":
132  result = [ m.label() for m in listModules( getattr(process,sequenceLabel+postfix))]
133  result.extend([ m.label() for m in listSequences( getattr(process,sequenceLabel+postfix))] )
134  return result
135 
136 #FIXME name is not generic enough now
def listModules(sequence)
Definition: helpers.py:201
def __labelsInSequence(process, sequenceLabel, postfix="")
Definition: helpers.py:128
def listSequences(sequence)
Definition: helpers.py:206
def helpers.addESProducers (   process,
  config 
)

Definition at line 31 of file helpers.py.

References dir.

31 def addESProducers(process,config):
32  config = config.replace("/",".")
33  #import RecoBTag.Configuration.RecoBTag_cff as btag
34  #print btag
35  module = __import__(config)
36  for name in dir(sys.modules[config]):
37  item = getattr(sys.modules[config],name)
38  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 type(item) is cms.PSet:
39  if 'ESProducer' in item.type_():
40  setattr(process,name,item)
41 
def addESProducers(process, config)
Definition: helpers.py:31
dbl *** dir
Definition: mlp_gen.cc:35
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 348 of file helpers.py.

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

348 def addKeepStatement(process, oldKeep, newKeeps, verbose=False):
349  """Add new keep statements to any PoolOutputModule of the process that has the old keep statements"""
350  for name,out in process.outputModules.iteritems():
351  if out.type_() == 'PoolOutputModule' and hasattr(out, "outputCommands"):
352  if oldKeep in out.outputCommands:
353  out.outputCommands += newKeeps
354  if verbose:
355  print "Adding the following keep statements to output module %s: " % name
356  for k in newKeeps: print "\t'%s'," % k
357 
358 
def addKeepStatement(process, oldKeep, newKeeps, verbose=False)
Definition: helpers.py:348
def helpers.addToProcessAndTask (   label,
  module,
  process,
  task 
)

Definition at line 27 of file helpers.py.

Referenced by pfTools.addPFCandidates(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.ak4JetReclustering(), 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(), puppiForMET_cff.makePuppies(), puppiForMET_cff.makePuppiesFromMiniAOD(), extraJets_MuEGFixMoriond2017.makeRecoJetCollection(), miniAOD_tools.miniAOD_customizeCommon(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.miniAODConfiguration(), muonRecoMitigation.muonRecoMitigation(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.produceMET(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.recomputeRawMetFromPfcs(), pfTools.reconfigurePF2PATTaus(), extraJets_MuEGFixMoriond2017.reduceFinalJetCollection(), extraJets_MuEGFixMoriond2017.reduceInputJetCollection(), jetTools.setupBTagging(), jetTools.setupJetCorrections(), pfTools.switchToPFJets(), trackTools.MakeAODTrackCandidates.toolCode(), metTools.AddMETCollection.toolCode(), trigTools.SwitchOnTrigger.toolCode(), trackTools.MakePATTrackCandidates.toolCode(), trigTools.SwitchOnTriggerStandAlone.toolCode(), trigTools.SwitchOnTriggerMatchEmbedding.toolCode(), jetTools.AddJetCollection.toolCode(), jetTools.UpdateJetCollection.toolCode(), jetTools.AddJetID.toolCode(), and runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.updateJECs().

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

Definition at line 54 of file helpers.py.

Referenced by extendWithPrePostfix().

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

Definition at line 113 of file helpers.py.

Referenced by pfTools.adaptPFMuons(), pfTools.addPFCandidates(), pfTools.reconfigurePF2PATTaus(), pfTools.switchToPFJets(), pfTools.switchToPFMET(), pfTools.tauTypeInPF2PAT(), HiCoreTools.RemoveMCMatching.toolCode(), HiCoreTools.RemoveSpecificPATObjects.toolCode(), HiCoreTools.RemoveCleaning.toolCode(), and pfTools.usePF2PAT().

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

Definition at line 23 of file helpers.py.

References getPatAlgosToolsTask().

Referenced by ConfigBuilder.ConfigBuilder.prepare().

24  task = getPatAlgosToolsTask(process)
25  process.schedule.associate(task)
26 
def associatePatAlgosToolsTask(process)
Definition: helpers.py:23
def getPatAlgosToolsTask(process)
Definition: helpers.py:12
def helpers.cloneProcessingSnippet (   process,
  sequence,
  postfix,
  removePostfix = "",
  noClones = [],
  addToTask = 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 251 of file helpers.py.

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

251 def cloneProcessingSnippet(process, sequence, postfix, removePostfix="", noClones = [], addToTask = False):
252  """
253  ------------------------------------------------------------------
254  copy a sequence plus the modules and sequences therein
255  both are renamed by getting a postfix
256  input tags are automatically adjusted
257  ------------------------------------------------------------------
258  """
259  result = sequence
260  if not postfix == "":
261  visitor = CloneSequenceVisitor(process, sequence.label(), postfix, removePostfix, noClones, addToTask)
262  sequence.visit(visitor)
263  result = visitor.clonedSequence()
264  return result
265 
def cloneProcessingSnippet(process, sequence, postfix, removePostfix="", noClones=[], addToTask=False)
Definition: helpers.py:251
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 235 of file helpers.py.

References spr.find().

Referenced by helpers.TestModuleCommand.testContains().

235 def contains(sequence, moduleName):
236  """
237  ------------------------------------------------------------------
238  return True if a module with name 'module' is contained in the
239  sequence with name 'sequence' and False otherwise. This version
240  is not so nice as it also returns True for any substr of the name
241  of a contained module.
242 
243  sequence : sequence [e.g. process.patDefaultSequence]
244  module : module name as a string
245  ------------------------------------------------------------------
246  """
247  return not sequence.__str__().find(moduleName)==-1
248 
249 
250 
def contains(sequence, moduleName)
Definition: helpers.py:235
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
def helpers.extendWithPrePostfix (   process,
  other,
  prefix,
  postfix,
  loadedProducersAndFilters = None 
)
Look in other and find types which we can use

Definition at line 59 of file helpers.py.

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

Referenced by loadWithPrePostfix().

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

Definition at line 6 of file helpers.py.

Referenced by get_vars().

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 
def get_path(file_in_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 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 
33 
def get_path(file_in_path)
Definition: helpers.py:6
def get_var_pset(mvaname)
def get_vars(xml_path, useFileInPath=True)
Definition: helpers.py:18
def helpers.getPatAlgosToolsTask (   process)

Definition at line 12 of file helpers.py.

Referenced by customizeMiniAOD_MuEGFixMoriond2017.addBadMuonFilters(), customizeMiniAOD_MuEGFixMoriond2017.addDiscardedPFCandidates(), extraSlimmedMETs_MuEGFixMoriond2017.addExtraMETCollections(), extraSlimmedMETs_MuEGFixMoriond2017.addExtraPuppiMETCorrections(), pfTools.addPFCandidates(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.ak4JetReclustering(), applySubstructure_cff.applySubstructure(), associatePatAlgosToolsTask(), extraJets_MuEGFixMoriond2017.backupJetsFirstStep(), extraJets_MuEGFixMoriond2017.backupJetsSecondStep(), customizeMiniAOD_MuEGFixMoriond2017.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_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(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.produceMET(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.recomputeRawMetFromPfcs(), pfTools.reconfigurePF2PATTaus(), extraJets_MuEGFixMoriond2017.reduceFinalJetCollection(), extraJets_MuEGFixMoriond2017.reduceInputJetCollection(), jetTools.setupBTagging(), jetTools.setupJetCorrections(), pfTools.switchToPFJets(), trackTools.MakeAODTrackCandidates.toolCode(), metTools.AddMETCollection.toolCode(), trigTools.SwitchOnTrigger.toolCode(), trackTools.MakePATTrackCandidates.toolCode(), trigTools.SwitchOnTriggerStandAlone.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().

12 def getPatAlgosToolsTask(process):
13  taskName = "patAlgosToolsTask"
14  if hasattr(process, taskName):
15  task = getattr(process, taskName)
16  if not isinstance(task, cms.Task):
17  raise Exception("patAlgosToolsTask does not have type Task")
18  else:
19  setattr(process, taskName, cms.Task())
20  task = getattr(process, taskName)
21  return task
22 
def getPatAlgosToolsTask(process)
Definition: helpers.py:12
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 211 of file helpers.py.

References reco.if().

Referenced by helpers.TestModuleCommand.testJetCollectionString(), heavyIonTools.ProductionDefaults.toolCode(), HiCoreTools.RemoveMCMatching.toolCode(), coreTools.RemoveMCMatching.toolCode(), heavyIonTools.SelectionDefaults.toolCode(), and HiCoreTools.RemoveSpecificPATObjects.toolCode().

211 def jetCollectionString(prefix='', algo='', type=''):
212  """
213  ------------------------------------------------------------------
214  return the string of the jet collection module depending on the
215  input vaules. The default return value will be 'patAK5CaloJets'.
216 
217  algo : indicating the algorithm type of the jet [expected are
218  'AK5', 'IC5', 'SC7', ...]
219  type : indicating the type of constituents of the jet [expec-
220  ted are 'Calo', 'PFlow', 'JPT', ...]
221  prefix : prefix indicating the type of pat collection module (ex-
222  pected are '', 'selected', 'clean').
223  ------------------------------------------------------------------
224  """
225  if(prefix==''):
226  jetCollectionString ='pat'
227  else:
228  jetCollectionString =prefix
229  jetCollectionString+='Pat'
230  jetCollectionString+='Jets'
231  jetCollectionString+=algo
232  jetCollectionString+=type
233  return jetCollectionString
234 
def jetCollectionString(prefix='', algo='', type='')
Definition: helpers.py:211
if(dp >Float(M_PI)) dp-
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 266 of file helpers.py.

References mps_alisetup.append.

Referenced by extraJets_MuEGFixMoriond2017.backupJetsFirstStep().

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

Definition at line 206 of file helpers.py.

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

206 def listSequences(sequence):
207  visitor = GatherAllModulesVisitor(gatheredInstance=cms.Sequence)
208  sequence.visit(visitor)
209  return visitor.modules()
210 
def listSequences(sequence)
Definition: helpers.py:206
def helpers.loadWithPostfix (   process,
  moduleName,
  postfix = '',
  loadedProducersAndFilters = None 
)

Definition at line 45 of file helpers.py.

References loadWithPrePostfix().

Referenced by pfTools.usePF2PAT().

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

Definition at line 42 of file helpers.py.

References loadWithPrePostfix().

Referenced by jetTools.setupBTagging().

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

Definition at line 48 of file helpers.py.

References extendWithPrePostfix().

Referenced by loadWithPostfix(), and loadWithPrefix().

48 def loadWithPrePostfix(process,moduleName,prefix='',postfix='',loadedProducersAndFilters=None):
49  moduleName = moduleName.replace("/",".")
50  module = __import__(moduleName)
51  #print module.PatAlgos.patSequences_cff.patDefaultSequence
52  extendWithPrePostfix(process,sys.modules[moduleName],prefix,postfix,loadedProducersAndFilters)
53 
def extendWithPrePostfix(process, other, prefix, postfix, loadedProducersAndFilters=None)
Definition: helpers.py:59
def loadWithPrePostfix(process, moduleName, prefix='', postfix='', loadedProducersAndFilters=None)
Definition: helpers.py:48
def helpers.removeIfInSequence (   process,
  target,
  sequenceLabel,
  postfix = "" 
)

Definition at line 121 of file helpers.py.

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

Referenced by HiCoreTools.RemoveSpecificPATObjects.toolCode().

121 def removeIfInSequence(process, target, sequenceLabel, postfix=""):
122  labels = __labelsInSequence(process, sequenceLabel, postfix)
123  if target+postfix in labels:
124  getattr(process, sequenceLabel+postfix).remove(
125  getattr(process, target+postfix)
126  )
127 
def removeIfInSequence(process, target, sequenceLabel, postfix="")
Definition: helpers.py:121
def __labelsInSequence(process, sequenceLabel, postfix="")
Definition: helpers.py:128
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:209