CMS 3D CMS Logo

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 (process, sequenceLabel, postfix="", keepPostFix=False)
 
def _lineDiff (newString, oldString)
 
def addESProducers (process, config)
 
def addKeepStatement (process, oldKeep, newKeeps, verbose=False)
 
def addTaskToProcess (process, label, task)
 
def addToProcessAndTask (label, module, process, task)
 
def addToTask (loadedProducersAndFilters, module)
 
def applyPostfix (process, label, postfix)
 
def associatePatAlgosToolsTask (process)
 
def cloneProcessingSnippet (process, sequence, postfix, removePostfix="", noClones=[], addToTask=False, verbose=False)
 
def cloneProcessingSnippetTask (process, task, postfix, removePostfix="", noClones=[], verbose=False)
 
def contains (sequence, moduleName)
 
def extendWithPrePostfix (process, other, prefix, postfix, loadedProducersAndFilters=None)
 
def get_path (file_in_path)
 
def get_vars (xml_path, useFileInPath=True)
 
def getPatAlgosToolsTask (process)
 
def jetCollectionString (prefix='', algo='', type='')
 
def listDependencyChain (process, module, sources, verbose=False)
 
def listModules (sequence)
 
def listSequences (sequence)
 
def loadWithPostfix (process, moduleName, postfix='', loadedProducersAndFilters=None)
 
def loadWithPrefix (process, moduleName, prefix='', loadedProducersAndFilters=None)
 
def loadWithPrePostfix (process, moduleName, prefix='', postfix='', loadedProducersAndFilters=None)
 
def removeIfInSequence (process, target, sequenceLabel, postfix="")
 
def testContains (self)
 
def testJetCollectionString (self)
 
def testListModules (self)
 

Function Documentation

◆ __labelsInSequence()

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

Definition at line 135 of file helpers.py.

References listModules(), and listSequences().

Referenced by removeIfInSequence().

135 def __labelsInSequence(process, sequenceLabel, postfix="", keepPostFix=False):
136  position = -len(postfix)
137  if keepPostFix:
138  position = None
139 
140  result = [ m.label()[:position] for m in listModules( getattr(process,sequenceLabel+postfix))]
141  result.extend([ m.label()[:position] for m in listSequences( getattr(process,sequenceLabel+postfix))] )
142  if postfix == "":
143  result = [ m.label() for m in listModules( getattr(process,sequenceLabel+postfix))]
144  result.extend([ m.label() for m in listSequences( getattr(process,sequenceLabel+postfix))] )
145  return result
146 
147 #FIXME name is not generic enough now
def listModules(sequence)
Definition: helpers.py:213
def listSequences(sequence)
Definition: helpers.py:218
def __labelsInSequence(process, sequenceLabel, postfix="", keepPostFix=False)
Definition: helpers.py:135

◆ _lineDiff()

def helpers._lineDiff (   newString,
  oldString 
)
private

Definition at line 373 of file helpers.py.

References join().

373  def _lineDiff(newString, oldString):
374  newString = ( x for x in newString.split('\n') if len(x) > 0)
375  oldString = [ x for x in oldString.split('\n') if len(x) > 0]
376  diff = []
377  oldStringLine = 0
378  for l in newString:
379  if oldStringLine >= len(oldString):
380  diff.append(l)
381  continue
382  if l == oldString[oldStringLine]:
383  oldStringLine +=1
384  continue
385  diff.append(l)
386  return "\n".join( diff )
387 
def _lineDiff(newString, oldString)
Definition: helpers.py:373
static std::string join(char **cmd)
Definition: RemoteFile.cc:19

◆ addESProducers()

def helpers.addESProducers (   process,
  config 
)

Definition at line 38 of file helpers.py.

References DeadROC_duringRun.dir.

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

◆ addKeepStatement()

def helpers.addKeepStatement (   process,
  oldKeep,
  newKeeps,
  verbose = False 
)
Add new keep statements to any PoolOutputModule of the process that has the old keep statements

Definition at line 360 of file helpers.py.

References print().

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

360 def addKeepStatement(process, oldKeep, newKeeps, verbose=False):
361  """Add new keep statements to any PoolOutputModule of the process that has the old keep statements"""
362  for name,out in process.outputModules.items():
363  if out.type_() == 'PoolOutputModule' and hasattr(out, "outputCommands"):
364  if oldKeep in out.outputCommands:
365  out.outputCommands += newKeeps
366  if verbose:
367  print("Adding the following keep statements to output module %s: " % name)
368  for k in newKeeps: print("\t'%s'," % k)
369 
370 
def addKeepStatement(process, oldKeep, newKeeps, verbose=False)
Definition: helpers.py:360
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

◆ addTaskToProcess()

def helpers.addTaskToProcess (   process,
  label,
  task 
)

Definition at line 32 of file helpers.py.

References PVValHelper.add().

Referenced by runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.ak4JetReclustering(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.createShiftedModules(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.extractMET(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.getCorrectedMET(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.getJetCollectionForCorsAndUncs(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.getMETUncertainties(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.jetCleaning(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.miniAODConfiguration(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.miniAODConfigurationPre(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.produceMET(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.recomputeRawMetFromPfcs(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.runFixEE2017(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.toolCode(), and runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.updateJECs().

32 def addTaskToProcess(process, label, task):
33  if not hasattr(process, label):
34  setattr(process, label, task)
35  else:
36  getattr(process, label).add(task)
37 
def addTaskToProcess(process, label, task)
Definition: helpers.py:32
void add(std::map< std::string, TH1 *> &h, TH1 *hist)

◆ addToProcessAndTask()

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(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.miniAODConfigurationPre(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.produceMET(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.recomputeRawMetFromPfcs(), pfTools.reconfigurePF2PATTaus(), extraJets_MuEGFixMoriond2017.reduceFinalJetCollection(), extraJets_MuEGFixMoriond2017.reduceInputJetCollection(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.runFixEE2017(), jetTools.setupBTagging(), jetTools.setupJetCorrections(), jetTools.setupPuppiForPackedPF(), 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

◆ addToTask()

def helpers.addToTask (   loadedProducersAndFilters,
  module 
)

Definition at line 61 of file helpers.py.

Referenced by extendWithPrePostfix().

61 def addToTask(loadedProducersAndFilters, module):
62  if loadedProducersAndFilters:
63  if isinstance(module, cms.EDProducer) or isinstance(module, cms.EDFilter):
64  loadedProducersAndFilters.add(module)
65 
def addToTask(loadedProducersAndFilters, module)
Definition: helpers.py:61

◆ applyPostfix()

def helpers.applyPostfix (   process,
  label,
  postfix 
)

Definition at line 120 of file helpers.py.

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

120 def applyPostfix(process, label, postfix):
121  result = None
122  if hasattr(process, label+postfix):
123  result = getattr(process, label + postfix)
124  else:
125  raise ValueError("Error in <applyPostfix>: No module of name = %s attached to process !!" % (label + postfix))
126  return result
127 
def applyPostfix(process, label, postfix)
Definition: helpers.py:120

◆ associatePatAlgosToolsTask()

def helpers.associatePatAlgosToolsTask (   process)

Definition at line 24 of file helpers.py.

References getPatAlgosToolsTask().

Referenced by ConfigBuilder.ConfigBuilder.prepare().

24 def associatePatAlgosToolsTask(process):
25  task = getPatAlgosToolsTask(process)
26  process.schedule.associate(task)
27 
def associatePatAlgosToolsTask(process)
Definition: helpers.py:24
def getPatAlgosToolsTask(process)
Definition: helpers.py:13

◆ cloneProcessingSnippet()

def helpers.cloneProcessingSnippet (   process,
  sequence,
  postfix,
  removePostfix = "",
  noClones = [],
  addToTask = False,
  verbose = False 
)
------------------------------------------------------------------
copy a sequence plus the modules and sequences therein
both are renamed by getting a postfix
input tags are automatically adjusted
------------------------------------------------------------------

Definition at line 263 of file helpers.py.

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

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

◆ cloneProcessingSnippetTask()

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

490 def cloneProcessingSnippetTask(process, task, postfix, removePostfix="", noClones = [], verbose = False):
491  """
492  ------------------------------------------------------------------
493  copy a task plus the modules therein (including modules in subtasks)
494  both are renamed by getting a postfix
495  input tags are automatically adjusted
496  ------------------------------------------------------------------
497  """
498  result = task
499  if not postfix == "":
500  visitor = CloneTaskVisitor(process, task.label(), postfix, removePostfix, noClones, verbose)
501  task.visit(visitor)
502  result = visitor.clonedTask()
503  return result
504 
def cloneProcessingSnippetTask(process, task, postfix, removePostfix="", noClones=[], verbose=False)
Definition: helpers.py:490

◆ contains()

def helpers.contains (   sequence,
  moduleName 
)
------------------------------------------------------------------
return True if a module with name 'module' is contained in the
sequence with name 'sequence' and False otherwise. This version
is not so nice as it also returns True for any substr of the name
of a contained module.

sequence : sequence [e.g. process.patDefaultSequence]
module   : module name as a string
------------------------------------------------------------------

Definition at line 247 of file helpers.py.

References spr.find().

Referenced by testContains().

247 def contains(sequence, moduleName):
248  """
249  ------------------------------------------------------------------
250  return True if a module with name 'module' is contained in the
251  sequence with name 'sequence' and False otherwise. This version
252  is not so nice as it also returns True for any substr of the name
253  of a contained module.
254 
255  sequence : sequence [e.g. process.patDefaultSequence]
256  module : module name as a string
257  ------------------------------------------------------------------
258  """
259  return not sequence.__str__().find(moduleName)==-1
260 
261 
262 
def contains(sequence, moduleName)
Definition: helpers.py:247
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19

◆ extendWithPrePostfix()

def helpers.extendWithPrePostfix (   process,
  other,
  prefix,
  postfix,
  loadedProducersAndFilters = None 
)
Look in other and find types which we can use

Definition at line 66 of file helpers.py.

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

Referenced by loadWithPrePostfix().

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

◆ get_path()

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

◆ get_vars()

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

◆ getPatAlgosToolsTask()

def helpers.getPatAlgosToolsTask (   process)

Definition at line 13 of file helpers.py.

Referenced by customizeMiniAOD_MuEGFixMoriond2017.addBadMuonFilters(), customizeMiniAOD_MuEGFixMoriond2017.addDiscardedPFCandidates(), customizeMiniAOD_HcalFixLegacy2016.addDiscardedPFCandidates(), pfTools.addPFCandidates(), jetCollectionTools.GenJetAdder.addProcessAndTask(), jetCollectionTools.RecoJetAdder.addProcessAndTask(), applyDeepBtagging_cff.applyDeepBtagging(), applySubstructure_cff.applySubstructure(), associatePatAlgosToolsTask(), extraJets_MuEGFixMoriond2017.backupJetsFirstStep(), extraJets_MuEGFixMoriond2017.backupJetsSecondStep(), customizeMiniAOD_MuEGFixMoriond2017.cleanPFCandidates(), customizeMiniAOD_HcalFixLegacy2016.cleanPfCandidates(), eGammaCorrection.eGammaCorrection(), 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(), pfTools.reconfigurePF2PATTaus(), extraJets_MuEGFixMoriond2017.reduceFinalJetCollection(), extraJets_MuEGFixMoriond2017.reduceInputJetCollection(), jetTools.setupBTagging(), jetTools.setupJetCorrections(), jetTools.setupPuppiForPackedPF(), 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(), 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

◆ jetCollectionString()

def helpers.jetCollectionString (   prefix = '',
  algo = '',
  type = '' 
)
------------------------------------------------------------------
return the string of the jet collection module depending on the
input vaules. The default return value will be 'patAK5CaloJets'.

algo   : indicating the algorithm type of the jet [expected are
         'AK5', 'IC5', 'SC7', ...]
type   : indicating the type of constituents of the jet [expec-
         ted are 'Calo', 'PFlow', 'JPT', ...]
prefix : prefix indicating the type of pat collection module (ex-
         pected are '', 'selected', 'clean').
------------------------------------------------------------------

Definition at line 223 of file helpers.py.

References ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets.if().

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

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

◆ listDependencyChain()

def helpers.listDependencyChain (   process,
  module,
  sources,
  verbose = False 
)
Walk up the dependencies of a module to find any that depend on any of the listed sources

Definition at line 278 of file helpers.py.

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

Referenced by extraJets_MuEGFixMoriond2017.backupJetsFirstStep().

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

◆ listModules()

def helpers.listModules (   sequence)

Definition at line 213 of file helpers.py.

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

213 def listModules(sequence):
214  visitor = GatherAllModulesVisitor(gatheredInstance=cms._Module)
215  sequence.visit(visitor)
216  return visitor.modules()
217 
def listModules(sequence)
Definition: helpers.py:213

◆ listSequences()

def helpers.listSequences (   sequence)

Definition at line 218 of file helpers.py.

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

218 def listSequences(sequence):
219  visitor = GatherAllModulesVisitor(gatheredInstance=cms.Sequence)
220  sequence.visit(visitor)
221  return visitor.modules()
222 
def listSequences(sequence)
Definition: helpers.py:218

◆ loadWithPostfix()

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

Definition at line 52 of file helpers.py.

References loadWithPrePostfix().

Referenced by pfTools.usePF2PAT().

52 def loadWithPostfix(process,moduleName,postfix='',loadedProducersAndFilters=None):
53  loadWithPrePostfix(process,moduleName,'',postfix,loadedProducersAndFilters)
54 
def loadWithPrePostfix(process, moduleName, prefix='', postfix='', loadedProducersAndFilters=None)
Definition: helpers.py:55
def loadWithPostfix(process, moduleName, postfix='', loadedProducersAndFilters=None)
Definition: helpers.py:52

◆ loadWithPrefix()

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

Definition at line 49 of file helpers.py.

References loadWithPrePostfix().

Referenced by jetTools.setupBTagging().

49 def loadWithPrefix(process,moduleName,prefix='',loadedProducersAndFilters=None):
50  loadWithPrePostfix(process,moduleName,prefix,'',loadedProducersAndFilters)
51 
def loadWithPrePostfix(process, moduleName, prefix='', postfix='', loadedProducersAndFilters=None)
Definition: helpers.py:55
def loadWithPrefix(process, moduleName, prefix='', loadedProducersAndFilters=None)
Definition: helpers.py:49

◆ loadWithPrePostfix()

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

Definition at line 55 of file helpers.py.

References extendWithPrePostfix().

Referenced by loadWithPostfix(), and loadWithPrefix().

55 def loadWithPrePostfix(process,moduleName,prefix='',postfix='',loadedProducersAndFilters=None):
56  moduleName = moduleName.replace("/",".")
57  module = __import__(moduleName)
58  #print module.PatAlgos.patSequences_cff.patDefaultSequence
59  extendWithPrePostfix(process,sys.modules[moduleName],prefix,postfix,loadedProducersAndFilters)
60 
def extendWithPrePostfix(process, other, prefix, postfix, loadedProducersAndFilters=None)
Definition: helpers.py:66
def loadWithPrePostfix(process, moduleName, prefix='', postfix='', loadedProducersAndFilters=None)
Definition: helpers.py:55

◆ removeIfInSequence()

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

Definition at line 128 of file helpers.py.

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

128 def removeIfInSequence(process, target, sequenceLabel, postfix=""):
129  labels = __labelsInSequence(process, sequenceLabel, postfix, True)
130  if target+postfix in labels:
131  getattr(process, sequenceLabel+postfix).remove(
132  getattr(process, target+postfix)
133  )
134 
def removeIfInSequence(process, target, sequenceLabel, postfix="")
Definition: helpers.py:128
def __labelsInSequence(process, sequenceLabel, postfix="", keepPostFix=False)
Definition: helpers.py:135
def remove(d, key, TELL=False)
Definition: MatrixUtil.py:223

◆ testContains()

def helpers.testContains (   self)

Definition at line 421 of file helpers.py.

References contains().

421  def testContains(self):
422  p = cms.Process("test")
423  p.a = cms.EDProducer("a", src=cms.InputTag("gen"))
424  p.b = cms.EDProducer("ab", src=cms.InputTag("a"))
425  p.c = cms.EDProducer("ac", src=cms.InputTag("b"))
426  p.s1 = cms.Sequence(p.a*p.b*p.c)
427  p.s2 = cms.Sequence(p.b*p.c)
428  self.assertTrue( contains(p.s1, "a") )
429  self.assertTrue( not contains(p.s2, "a") )
def contains(sequence, moduleName)
Definition: helpers.py:247
def testContains(self)
Definition: helpers.py:421

◆ testJetCollectionString()

def helpers.testJetCollectionString (   self)

Definition at line 430 of file helpers.py.

References jetCollectionString().

430  def testJetCollectionString(self):
431  self.assertEqual(jetCollectionString(algo = 'Foo', type = 'Bar'), 'patJetsFooBar')
432  self.assertEqual(jetCollectionString(prefix = 'prefix', algo = 'Foo', type = 'Bar'), 'prefixPatJetsFooBar')
def testJetCollectionString(self)
Definition: helpers.py:430
def jetCollectionString(prefix='', algo='', type='')
Definition: helpers.py:223

◆ testListModules()

def helpers.testListModules (   self)

Definition at line 433 of file helpers.py.

References listModules().

433  def testListModules(self):
434  p = cms.Process("test")
435  p.a = cms.EDProducer("a", src=cms.InputTag("gen"))
436  p.b = cms.EDProducer("ab", src=cms.InputTag("a"))
437  p.c = cms.EDProducer("ac", src=cms.InputTag("b"))
438  p.s = cms.Sequence(p.a*p.b*p.c)
439  self.assertEqual([p.a,p.b,p.c], listModules(p.s))
440 
def testListModules(self)
Definition: helpers.py:433
def listModules(sequence)
Definition: helpers.py:213