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

References listModules(), and listSequences().

Referenced by removeIfInSequence().

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

Definition at line 32 of file helpers.py.

References dir.

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

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

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

Definition at line 28 of file helpers.py.

Referenced by pfTools.addPFCandidates(), 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(), 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(), 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 def addToProcessAndTask(label, module, process, task):
29  setattr(process, label, module)
30  task.add(getattr(process, label))
31 
def addToProcessAndTask(label, module, process, task)
Definition: helpers.py:28
def helpers.addToTask (   loadedProducersAndFilters,
  module 
)

Definition at line 55 of file helpers.py.

Referenced by extendWithPrePostfix().

55 def addToTask(loadedProducersAndFilters, module):
56  if loadedProducersAndFilters:
57  if isinstance(module, cms.EDProducer) or isinstance(module, cms.EDFilter):
58  loadedProducersAndFilters.add(module)
59 
def addToTask(loadedProducersAndFilters, module)
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(), HiCoreTools.RemoveMCMatching.toolCode(), HiCoreTools.RemoveSpecificPATObjects.toolCode(), HiCoreTools.RemoveCleaning.toolCode(), and pfTools.usePF2PAT().

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

Definition at line 24 of file helpers.py.

References getPatAlgosToolsTask().

Referenced by ConfigBuilder.ConfigBuilder.prepare().

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

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

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

References spr.find().

Referenced by helpers.TestModuleCommand.testContains().

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

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

Referenced by loadWithPrePostfix().

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

Referenced by customizeMiniAOD_MuEGFixMoriond2017.addBadMuonFilters(), customizeMiniAOD_MuEGFixMoriond2017.addDiscardedPFCandidates(), customizeMiniAOD_HcalFixLegacy2016.addDiscardedPFCandidates(), extraSlimmedMETs_MuEGFixMoriond2017.addExtraMETCollections(), extraSlimmedMETs_MuEGFixMoriond2017.addExtraPuppiMETCorrections(), pfTools.addPFCandidates(), 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(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.miniAODConfigurationPre(), muonRecoMitigation.muonRecoMitigation(), 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 def getPatAlgosToolsTask(process):
14  taskName = "patAlgosToolsTask"
15  if hasattr(process, taskName):
16  task = getattr(process, taskName)
17  if not isinstance(task, cms.Task):
18  raise Exception("patAlgosToolsTask does not have type Task")
19  else:
20  setattr(process, taskName, cms.Task())
21  task = getattr(process, taskName)
22  return task
23 
def getPatAlgosToolsTask(process)
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 216 of file helpers.py.

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

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

References mps_setup.append.

Referenced by extraJets_MuEGFixMoriond2017.backupJetsFirstStep().

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

Definition at line 211 of file helpers.py.

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

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

Definition at line 46 of file helpers.py.

References loadWithPrePostfix().

Referenced by pfTools.usePF2PAT().

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

Definition at line 43 of file helpers.py.

References loadWithPrePostfix().

Referenced by jetTools.setupBTagging().

43 def loadWithPrefix(process,moduleName,prefix='',loadedProducersAndFilters=None):
44  loadWithPrePostfix(process,moduleName,prefix,'',loadedProducersAndFilters)
45 
def loadWithPrePostfix(process, moduleName, prefix='', postfix='', loadedProducersAndFilters=None)
Definition: helpers.py:49
def loadWithPrefix(process, moduleName, prefix='', loadedProducersAndFilters=None)
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 def loadWithPrePostfix(process,moduleName,prefix='',postfix='',loadedProducersAndFilters=None):
50  moduleName = moduleName.replace("/",".")
51  module = __import__(moduleName)
52  #print module.PatAlgos.patSequences_cff.patDefaultSequence
53  extendWithPrePostfix(process,sys.modules[moduleName],prefix,postfix,loadedProducersAndFilters)
54 
def extendWithPrePostfix(process, other, prefix, postfix, loadedProducersAndFilters=None)
Definition: helpers.py:60
def loadWithPrePostfix(process, moduleName, prefix='', postfix='', loadedProducersAndFilters=None)
Definition: helpers.py:49
def helpers.removeIfInSequence (   process,
  target,
  sequenceLabel,
  postfix = "" 
)

Definition at line 122 of file helpers.py.

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

Referenced by HiCoreTools.RemoveSpecificPATObjects.toolCode().

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