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 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 = "",
  keepPostFix = False 
)
private

Definition at line 128 of file helpers.py.

References listModules(), and listSequences().

Referenced by removeIfInSequence().

128 def __labelsInSequence(process, sequenceLabel, postfix="", keepPostFix=False):
129  position = -len(postfix)
130  if keepPostFix:
131  position = None
132 
133  result = [ m.label()[:position] for m in listModules( getattr(process,sequenceLabel+postfix))]
134  result.extend([ m.label()[:position] for m in listSequences( getattr(process,sequenceLabel+postfix))] )
135  if postfix == "":
136  result = [ m.label() for m in listModules( getattr(process,sequenceLabel+postfix))]
137  result.extend([ m.label() for m in listSequences( getattr(process,sequenceLabel+postfix))] )
138  return result
139 
140 #FIXME name is not generic enough now
def listModules(sequence)
Definition: helpers.py:205
def listSequences(sequence)
Definition: helpers.py:210
def __labelsInSequence(process, sequenceLabel, postfix="", keepPostFix=False)
Definition: helpers.py:128
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 352 of file helpers.py.

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

352 def addKeepStatement(process, oldKeep, newKeeps, verbose=False):
353  """Add new keep statements to any PoolOutputModule of the process that has the old keep statements"""
354  for name,out in process.outputModules.iteritems():
355  if out.type_() == 'PoolOutputModule' and hasattr(out, "outputCommands"):
356  if oldKeep in out.outputCommands:
357  out.outputCommands += newKeeps
358  if verbose:
359  print "Adding the following keep statements to output module %s: " % name
360  for k in newKeeps: print "\t'%s'," % k
361 
362 
def addKeepStatement(process, oldKeep, newKeeps, verbose=False)
Definition: helpers.py:352
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(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.miniAODConfigurationPre(), 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 255 of file helpers.py.

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

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

References spr.find().

Referenced by helpers.TestModuleCommand.testContains().

239 def contains(sequence, moduleName):
240  """
241  ------------------------------------------------------------------
242  return True if a module with name 'module' is contained in the
243  sequence with name 'sequence' and False otherwise. This version
244  is not so nice as it also returns True for any substr of the name
245  of a contained module.
246 
247  sequence : sequence [e.g. process.patDefaultSequence]
248  module : module name as a string
249  ------------------------------------------------------------------
250  """
251  return not sequence.__str__().find(moduleName)==-1
252 
253 
254 
def contains(sequence, moduleName)
Definition: helpers.py:239
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:72
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(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.miniAODConfigurationPre(), 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 215 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().

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

References mps_setup.append.

Referenced by extraJets_MuEGFixMoriond2017.backupJetsFirstStep().

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

Definition at line 210 of file helpers.py.

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

210 def listSequences(sequence):
211  visitor = GatherAllModulesVisitor(gatheredInstance=cms.Sequence)
212  sequence.visit(visitor)
213  return visitor.modules()
214 
def listSequences(sequence)
Definition: helpers.py:210
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, True)
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="", keepPostFix=False)
Definition: helpers.py:128
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:211