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 applyPostfix
 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 cloneProcessingSnippet
 
def contains
 
def jetCollectionString
 
def listModules
 
def listSequences
 
def massSearchReplaceAnyInputTag
 
def massSearchReplaceParam
 
def removeIfInSequence
 

Function Documentation

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

Definition at line 27 of file helpers.py.

References listModules(), and listSequences().

Referenced by applyPostfix(), and removeIfInSequence().

27 
28 def __labelsInSequence(process, sequenceLabel, postfix=""):
29  result = [ m.label()[:-len(postfix)] for m in listModules( getattr(process,sequenceLabel+postfix))]
30  result.extend([ m.label()[:-len(postfix)] for m in listSequences( getattr(process,sequenceLabel+postfix))] )
31  if postfix == "":
32  result = [ m.label() for m in listModules( getattr(process,sequenceLabel+postfix))]
33  result.extend([ m.label() for m in listSequences( getattr(process,sequenceLabel+postfix))] )
34  return result
def listModules
Definition: helpers.py:208
def listSequences
Definition: helpers.py:213
def __labelsInSequence
Definition: helpers.py:27
def helpers.applyPostfix (   process,
  label,
  postfix 
)

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

If a module is in patDefaultSequence use the cloned module.
Will crash if patDefaultSequence has not been cloned with 'postfix' beforehand

Definition at line 6 of file helpers.py.

References __labelsInSequence().

Referenced by tauTools._switchToPFTau(), pfTools.adaptPFMuons(), pfTools.adaptPFTaus(), pfTools.addPFCandidates(), pfTools.reconfigurePF2PATTaus(), tauTools.redoPFTauDiscriminators(), tauTools.switchToCaloTau(), pfTools.switchToPFJets(), pfTools.switchToPFMET(), pfTools.tauTypeInPF2PAT(), HiCoreTools.RemoveMCMatching.toolCode(), HiCoreTools.RemoveSpecificPATObjects.toolCode(), coreTools.RemoveSpecificPATObjects.toolCode(), HiCoreTools.RemoveCleaning.toolCode(), coreTools.RemoveCleaning.toolCode(), jetTools.SwitchJetCollection.toolCode(), pfTools.useGsfElectrons(), pfTools.usePF2PAT(), pfTools.usePFIso(), and jetTools.SwitchJetCollection.vit().

6 
7 def applyPostfix(process, label, postfix):
8  ''' If a module is in patDefaultSequence use the cloned module.
9  Will crash if patDefaultSequence has not been cloned with 'postfix' beforehand'''
10  result = None
11  defaultLabels = __labelsInSequence(process, "patDefaultSequence", postfix)
12  if hasattr(process, "patPF2PATSequence"):
13  defaultLabels = __labelsInSequence(process, "patPF2PATSequence", postfix)
14  if label in defaultLabels and hasattr(process, label+postfix):
15  result = getattr(process, label+postfix)
16  elif hasattr(process, label):
17  print "WARNING: called applyPostfix for module/sequence %s which is not in patDefaultSequence%s!"%(label,postfix)
18  result = getattr(process, label)
19  return result
def applyPostfix
Helpers to perform some technically boring tasks like looking for all modules with a given parameter ...
Definition: helpers.py:6
def __labelsInSequence
Definition: helpers.py:27
def helpers.cloneProcessingSnippet (   process,
  sequence,
  postfix 
)
------------------------------------------------------------------
copy a sequence plus the modules and sequences therein
both are renamed by getting a postfix
input tags are automatically adjusted
------------------------------------------------------------------

Definition at line 262 of file helpers.py.

Referenced by pfTools.reconfigurePF2PATTaus(), tauTools.redoPFTauDiscriminators(), pfIsolation.setupPFIso(), pfIsolation.setupPFIsoPhoton(), pfTools.switchToPFMET(), and pfTools.usePF2PAT().

263 def cloneProcessingSnippet(process, sequence, postfix):
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)
274  sequence.visit(visitor)
275  result = visitor.clonedSequence()
276  return result
def cloneProcessingSnippet
Definition: helpers.py:262
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 246 of file helpers.py.

References spr.find().

Referenced by helpers.TestModuleCommand.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 
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:246
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 222 of file helpers.py.

References if().

Referenced by helpers.TestModuleCommand.testJetCollectionString(), heavyIonTools.ProductionDefaults.toolCode(), HiCoreTools.RemoveMCMatching.toolCode(), heavyIonTools.SelectionDefaults.toolCode(), coreTools.RemoveMCMatching.toolCode(), HiCoreTools.RemoveSpecificPATObjects.toolCode(), coreTools.RemoveSpecificPATObjects.toolCode(), and jetTools.AddJetCollection.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
def jetCollectionString
Definition: helpers.py:222
perl if(1 lt scalar(@::datatypes))
Definition: edlooper.cc:31
def helpers.listModules (   sequence)

Definition at line 208 of file helpers.py.

Referenced by __labelsInSequence(), trigTools._modulesInSequence(), jetTools.RunBTagging.apply(), helpers.TestModuleCommand.testListModules(), coreTools.RemoveSpecificPATObjects.toolCode(), HiCoreTools.RemoveCleaning.toolCode(), HiCoreTools.AddCleaning.toolCode(), coreTools.RemoveCleaning.toolCode(), and coreTools.AddCleaning.toolCode().

209 def listModules(sequence):
210  visitor = GatherAllModulesVisitor(gatheredInstance=cms._Module)
211  sequence.visit(visitor)
212  return visitor.modules()
def listModules
Definition: helpers.py:208
def helpers.listSequences (   sequence)

Definition at line 213 of file helpers.py.

Referenced by __labelsInSequence(), jetTools.RunBTagging.apply(), and coreTools.RemoveSpecificPATObjects.toolCode().

214 def listSequences(sequence):
215  visitor = GatherAllModulesVisitor(gatheredInstance=cms.Sequence)
216  sequence.visit(visitor)
217  return visitor.modules()
def listSequences
Definition: helpers.py:213
def helpers.massSearchReplaceAnyInputTag (   sequence,
  oldInputTag,
  newInputTag,
  verbose = False,
  moduleLabelOnly = False 
)
Replace InputTag oldInputTag with newInputTag, at any level of nesting within PSets, VPSets, VInputTags...

Definition at line 218 of file helpers.py.

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

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

Definition at line 205 of file helpers.py.

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

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

Definition at line 20 of file helpers.py.

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

Referenced by pfTools.adaptPFElectrons(), jetTools.RunBTagging.apply(), pfTools.removeMCMatchingPF2PAT(), HiCoreTools.RemoveSpecificPATObjects.toolCode(), coreTools.RemoveSpecificPATObjects.toolCode(), trigTools.SwitchOnTriggerMatching.toolCode(), trigTools.SwitchOnTriggerMatchEmbedding.toolCode(), pfTools.usePF2PAT(), and jetTools.SwitchJetCollection.vit().

20 
21 def removeIfInSequence(process, target, sequenceLabel, postfix=""):
22  labels = __labelsInSequence(process, sequenceLabel, postfix)
23  if target+postfix in labels:
24  getattr(process, sequenceLabel+postfix).remove(
25  getattr(process, target+postfix)
26  )
def removeIfInSequence
Definition: helpers.py:20
def __labelsInSequence
Definition: helpers.py:27