CMS 3D CMS Logo

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

Classes

class  CloneSequenceVisitor
 
struct  CompositeCandidateMaker
 
struct  CompositePtrCandidateMaker
 
class  GatherAllModulesVisitor
 
class  MassSearchParamVisitor
 
class  MassSearchReplaceAnyInputTagVisitor
 
class  MassSearchReplaceParamVisitor
 
struct  MCTruthPairSelector
 
struct  NamedCompositeCandidateMaker
 
class  TestModuleCommand
 

Functions

def __labelsInSequence
 
def addESProducers
 Helpers to perform some technically boring tasks like looking for all modules with a given parameter and replacing that to a given value. More...
 
def applyPostfix
 
def cloneProcessingSnippet
 
def contains
 
def extendWithPostfix
 
def jetCollectionString
 
def listModules
 
def listSequences
 
def loadWithPostfix
 
def massSearchReplaceAnyInputTag
 
def massSearchReplaceParam
 
def removeIfInSequence
 

Function Documentation

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

Definition at line 85 of file helpers.py.

References listModules(), and listSequences().

Referenced by removeIfInSequence().

85 
86 def __labelsInSequence(process, sequenceLabel, postfix=""):
87  result = [ m.label()[:-len(postfix)] for m in listModules( getattr(process,sequenceLabel+postfix))]
88  result.extend([ m.label()[:-len(postfix)] for m in listSequences( getattr(process,sequenceLabel+postfix))] )
89  if postfix == "":
90  result = [ m.label() for m in listModules( getattr(process,sequenceLabel+postfix))]
91  result.extend([ m.label() for m in listSequences( getattr(process,sequenceLabel+postfix))] )
92  return result
def listModules
Definition: helpers.py:252
def listSequences
Definition: helpers.py:257
def __labelsInSequence
Definition: helpers.py:85
def helpers.addESProducers (   process,
  config 
)

Helpers to perform some technically boring tasks like looking for all modules with a given parameter and replacing that to a given value.

Definition at line 7 of file helpers.py.

References dir.

7 
8 def addESProducers(process,config):
9  config = config.replace("/",".")
10  #import RecoBTag.Configuration.RecoBTag_cff as btag
11  #print btag
12  module = __import__(config)
13  for name in dir(sys.modules[config]):
14  item = getattr(sys.modules[config],name)
15  if isinstance(item,_Labelable) and not isinstance(item,_ModuleSequenceType) and not name.startswith('_') and not (name == "source" or name == "looper" or name == "subProcess") and not type(item) is cms.PSet:
16  if 'ESProducer' in item.type_():
17  setattr(process,name,item)
def addESProducers
Helpers to perform some technically boring tasks like looking for all modules with a given parameter ...
Definition: helpers.py:7
dbl *** dir
Definition: mlp_gen.cc:35
def helpers.applyPostfix (   process,
  label,
  postfix 
)

Definition at line 70 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().

70 
71 def applyPostfix(process, label, postfix):
72  result = None
73  if hasattr(process, label+postfix):
74  result = getattr(process, label + postfix)
75  else:
76  raise ValueError("Error in <applyPostfix>: No module of name = %s attached to process !!" % (label + postfix))
77  return result
def applyPostfix
Definition: helpers.py:70
def helpers.cloneProcessingSnippet (   process,
  sequence,
  postfix,
  removePostfix = "" 
)
------------------------------------------------------------------
copy a sequence plus the modules and sequences therein
both are renamed by getting a postfix
input tags are automatically adjusted
------------------------------------------------------------------

Definition at line 306 of file helpers.py.

Referenced by pfIsolation.setupPFIso(), and pfIsolation.setupPFIsoPhoton().

307 def cloneProcessingSnippet(process, sequence, postfix, removePostfix=""):
308  """
309  ------------------------------------------------------------------
310  copy a sequence plus the modules and sequences therein
311  both are renamed by getting a postfix
312  input tags are automatically adjusted
313  ------------------------------------------------------------------
314  """
315  result = sequence
316  if not postfix == "":
317  visitor = CloneSequenceVisitor(process, sequence.label(), postfix, removePostfix)
318  sequence.visit(visitor)
319  result = visitor.clonedSequence()
320  return result
def cloneProcessingSnippet
Definition: helpers.py:306
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 290 of file helpers.py.

References spr.find().

Referenced by helpers.TestModuleCommand.testContains().

291 def contains(sequence, moduleName):
292  """
293  ------------------------------------------------------------------
294  return True if a module with name 'module' is contained in the
295  sequence with name 'sequence' and False otherwise. This version
296  is not so nice as it also returns True for any substr of the name
297  of a contained module.
298 
299  sequence : sequence [e.g. process.patDefaultSequence]
300  module : module name as a string
301  ------------------------------------------------------------------
302  """
303  return not sequence.__str__().find(moduleName)==-1
304 
305 
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
def contains
Definition: helpers.py:290
def helpers.extendWithPostfix (   process,
  other,
  postfix,
  items = () 
)
Look in other and find types which we can use

Definition at line 24 of file helpers.py.

References python.multivaluedict.dict, dir, and massSearchReplaceAnyInputTag().

Referenced by loadWithPostfix().

24 
25 def extendWithPostfix(process,other,postfix,items=()):
26  """Look in other and find types which we can use"""
27  # enable explicit check to avoid overwriting of existing objects
28  #__dict__['_Process__InExtendCall'] = True
29 
30  seqs = dict()
31  sequence = cms.Sequence()
32  sequence._moduleLabels = []
33  sequence.setLabel('tempSequence')
34  for name in dir(other):
35  #'from XX import *' ignores these, and so should we.
36  if name.startswith('_'):
37  continue
38  item = getattr(other,name)
39  if name == "source" or name == "looper" or name == "subProcess":
40  continue
41  elif isinstance(item,cms._ModuleSequenceType):
42  continue
43  elif isinstance(item,cms.Schedule):
44  continue
45  elif isinstance(item,cms.VPSet) or isinstance(item,cms.PSet):
46  continue
47  elif isinstance(item,cms._Labelable):
48  if not item.hasLabel_():
49  item.setLabel(name)
50  if postfix != '':
51  newModule = item.clone()
52  if isinstance(item,cms.ESProducer):
53  newLabel = item.label()
54  newName =name
55  else:
56  if 'TauDiscrimination' in name:
57  process.__setattr__(name,item)
58  newLabel = item.label()+postfix
59  newName = name+postfix
60  process.__setattr__(newName,newModule)
61  if isinstance(newModule, cms._Sequenceable) and not newName == name:
62  sequence +=getattr(process,newName)
63  sequence._moduleLabels.append(item.label())
64  else:
65  process.__setattr__(name,item)
66 
67  if postfix != '':
68  for label in sequence._moduleLabels:
69  massSearchReplaceAnyInputTag(sequence, label, label+postfix,verbose=False,moduleLabelOnly=True)
def massSearchReplaceAnyInputTag
Definition: helpers.py:262
def extendWithPostfix
Definition: helpers.py:24
dbl *** dir
Definition: mlp_gen.cc:35
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 266 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().

267 def jetCollectionString(prefix='', algo='', type=''):
268  """
269  ------------------------------------------------------------------
270  return the string of the jet collection module depending on the
271  input vaules. The default return value will be 'patAK5CaloJets'.
272 
273  algo : indicating the algorithm type of the jet [expected are
274  'AK5', 'IC5', 'SC7', ...]
275  type : indicating the type of constituents of the jet [expec-
276  ted are 'Calo', 'PFlow', 'JPT', ...]
277  prefix : prefix indicating the type of pat collection module (ex-
278  pected are '', 'selected', 'clean').
279  ------------------------------------------------------------------
280  """
281  if(prefix==''):
282  jetCollectionString ='pat'
283  else:
284  jetCollectionString =prefix
285  jetCollectionString+='Pat'
286  jetCollectionString+='Jets'
287  jetCollectionString+=algo
288  jetCollectionString+=type
289  return jetCollectionString
def jetCollectionString
Definition: helpers.py:266
if(dp >Float(M_PI)) dp-
def helpers.listModules (   sequence)

Definition at line 252 of file helpers.py.

Referenced by __labelsInSequence(), trigTools._modulesInPath(), helpers.TestModuleCommand.testListModules(), HiCoreTools.RemoveCleaning.toolCode(), and HiCoreTools.AddCleaning.toolCode().

253 def listModules(sequence):
254  visitor = GatherAllModulesVisitor(gatheredInstance=cms._Module)
255  sequence.visit(visitor)
256  return visitor.modules()
def listModules
Definition: helpers.py:252
def helpers.listSequences (   sequence)

Definition at line 257 of file helpers.py.

Referenced by __labelsInSequence().

258 def listSequences(sequence):
259  visitor = GatherAllModulesVisitor(gatheredInstance=cms.Sequence)
260  sequence.visit(visitor)
261  return visitor.modules()
def listSequences
Definition: helpers.py:257
def helpers.loadWithPostfix (   process,
  moduleName,
  postfix = '' 
)

Definition at line 18 of file helpers.py.

References extendWithPostfix().

Referenced by pfTools.usePF2PAT().

18 
19 def loadWithPostfix(process,moduleName,postfix=''):
20  moduleName = moduleName.replace("/",".")
21  module = __import__(moduleName)
22  #print module.PatAlgos.patSequences_cff.patDefaultSequence
23  extendWithPostfix(process,sys.modules[moduleName],postfix)
def extendWithPostfix
Definition: helpers.py:24
def loadWithPostfix
Definition: helpers.py:18
def helpers.massSearchReplaceAnyInputTag (   sequence,
  oldInputTag,
  newInputTag,
  verbose = False,
  moduleLabelOnly = False,
  skipLabelTest = False 
)
Replace InputTag oldInputTag with newInputTag, at any level of nesting within PSets, VPSets, VInputTags...

Definition at line 262 of file helpers.py.

Referenced by patMuonsWithTrigger_cff.changeRecoMuonInput(), extendWithPostfix(), ConfigBuilder.MassReplaceInputTag(), ConfigBuilder.ConfigBuilder.renameInputTagsInSequence(), helpers.TestModuleCommand.testMassSearchReplaceAnyInputTag(), and patMuonsWithTrigger_cff.useExistingPATMuons().

263 def massSearchReplaceAnyInputTag(sequence, oldInputTag, newInputTag,verbose=False,moduleLabelOnly=False,skipLabelTest=False) :
264  """Replace InputTag oldInputTag with newInputTag, at any level of nesting within PSets, VPSets, VInputTags..."""
265  sequence.visit(MassSearchReplaceAnyInputTagVisitor(oldInputTag,newInputTag,verbose=verbose,moduleLabelOnly=moduleLabelOnly,skipLabelTest=skipLabelTest))
def massSearchReplaceAnyInputTag
Definition: helpers.py:262
def helpers.massSearchReplaceParam (   sequence,
  paramName,
  paramOldValue,
  paramValue,
  verbose = False 
)

Definition at line 249 of file helpers.py.

Referenced by pfTools.reconfigurePF2PATTaus(), and helpers.TestModuleCommand.testMassSearchReplaceParam().

250 def massSearchReplaceParam(sequence,paramName,paramOldValue,paramValue,verbose=False):
251  sequence.visit(MassSearchReplaceParamVisitor(paramName,paramOldValue,paramValue,verbose))
def massSearchReplaceParam
Definition: helpers.py:249
def helpers.removeIfInSequence (   process,
  target,
  sequenceLabel,
  postfix = "" 
)

Definition at line 78 of file helpers.py.

References __labelsInSequence(), and python.multivaluedict.remove().

Referenced by HiCoreTools.RemoveSpecificPATObjects.toolCode().

78 
79 def removeIfInSequence(process, target, sequenceLabel, postfix=""):
80  labels = __labelsInSequence(process, sequenceLabel, postfix)
81  if target+postfix in labels:
82  getattr(process, sequenceLabel+postfix).remove(
83  getattr(process, target+postfix)
84  )
def removeIfInSequence
Definition: helpers.py:78
def __labelsInSequence
Definition: helpers.py:85