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:203
def listSequences
Definition: helpers.py:208
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(), coreTools.RemoveMCMatching.toolCode(), HiCoreTools.RemoveSpecificPATObjects.toolCode(), coreTools.RemoveSpecificPATObjects.toolCode(), HiCoreTools.RemoveCleaning.toolCode(), coreTools.RemoveCleaning.toolCode(), jetTools.SwitchJetCollection.toolCode(), cmsswVersionTools.SwitchJetCollection35X.toolCode(), pfTools.usePF2PAT(), jetTools.SwitchJetCollection.vit(), and cmsswVersionTools.SwitchJetCollection35X.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 257 of file helpers.py.

Referenced by pfTools.reconfigurePF2PATTaus(), tauTools.redoPFTauDiscriminators(), and pfTools.usePF2PAT().

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

References spr.find().

Referenced by helpers.TestModuleCommand.testContains().

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

References if().

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

218 def jetCollectionString(prefix='', algo='', type=''):
219  """
220  ------------------------------------------------------------------
221  return the string of the jet collection module depending on the
222  input vaules. The default return value will be 'patAK5CaloJets'.
223 
224  algo : indicating the algorithm type of the jet [expected are
225  'AK5', 'IC5', 'SC7', ...]
226  type : indicating the type of constituents of the jet [expec-
227  ted are 'Calo', 'PFlow', 'JPT', ...]
228  prefix : prefix indicating the type of pat collection module (ex-
229  pected are '', 'selected', 'clean').
230  ------------------------------------------------------------------
231  """
232  if(prefix==''):
233  jetCollectionString ='pat'
234  else:
235  jetCollectionString =prefix
236  jetCollectionString+='Pat'
237  jetCollectionString+='Jets'
238  jetCollectionString+=algo
239  jetCollectionString+=type
240  return jetCollectionString
def jetCollectionString
Definition: helpers.py:217
perl if(1 lt scalar(@::datatypes))
Definition: edlooper.cc:31
def helpers.listModules (   sequence)

Definition at line 203 of file helpers.py.

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

204 def listModules(sequence):
205  visitor = GatherAllModulesVisitor(gatheredInstance=cms._Module)
206  sequence.visit(visitor)
207  return visitor.modules()
def listModules
Definition: helpers.py:203
def helpers.listSequences (   sequence)

Definition at line 208 of file helpers.py.

Referenced by __labelsInSequence(), and coreTools.RemoveSpecificPATObjects.toolCode().

209 def listSequences(sequence):
210  visitor = GatherAllModulesVisitor(gatheredInstance=cms.Sequence)
211  sequence.visit(visitor)
212  return visitor.modules()
def listSequences
Definition: helpers.py:208
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 213 of file helpers.py.

Referenced by helpers.CloneSequenceVisitor.clonedSequence().

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

Definition at line 200 of file helpers.py.

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

201 def massSearchReplaceParam(sequence,paramName,paramOldValue,paramValue,verbose=False):
202  sequence.visit(MassSearchReplaceParamVisitor(paramName,paramOldValue,paramValue,verbose))
def massSearchReplaceParam
Definition: helpers.py:200
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(), pfTools.removeMCMatchingPF2PAT(), HiCoreTools.RemoveSpecificPATObjects.toolCode(), coreTools.RemoveSpecificPATObjects.toolCode(), trigTools.SwitchOnTriggerMatching.toolCode(), trigTools.SwitchOnTriggerMatchEmbedding.toolCode(), pfTools.usePF2PAT(), jetTools.SwitchJetCollection.vit(), and cmsswVersionTools.SwitchJetCollection35X.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