test
CMS 3D CMS Logo

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

Classes

class  CloneSequenceVisitor
 
class  GatherAllModulesVisitor
 
class  MassSearchParamVisitor
 
class  MassSearchReplaceAnyInputTagVisitor
 
class  MassSearchReplaceParamVisitor
 
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 HiHelperTools.__labelsInSequence (   process,
  sequenceLabel,
  postfix = "" 
)
private

Definition at line 27 of file HiHelperTools.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 __labelsInSequence
def HiHelperTools.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 patHeavyIonDefaultSequence use the cloned module.
Will crash if patHeavyIonDefaultSequence has not been cloned with 'postfix' beforehand

Definition at line 6 of file HiHelperTools.py.

References __labelsInSequence().

6 
7 def applyPostfix(process, label, postfix):
8  ''' If a module is in patHeavyIonDefaultSequence use the cloned module.
9  Will crash if patHeavyIonDefaultSequence has not been cloned with 'postfix' beforehand'''
10  result = None
11  defaultLabels = __labelsInSequence(process, "patHeavyIonDefaultSequence", 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 patHeavyIonDefaultSequence%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: HiHelperTools.py:6
def __labelsInSequence
def HiHelperTools.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 HiHelperTools.py.

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
def HiHelperTools.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.patHeavyIonDefaultSequence]
module   : module name as a string
------------------------------------------------------------------    

Definition at line 241 of file HiHelperTools.py.

References spr.find().

Referenced by HiHelperTools.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.patHeavyIonDefaultSequence]
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 HiHelperTools.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 HiHelperTools.py.

References reco.if().

Referenced by HiHelperTools.TestModuleCommand.testJetCollectionString().

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
if(dp >Float(M_PI)) dp-
def HiHelperTools.listModules (   sequence)

Definition at line 203 of file HiHelperTools.py.

Referenced by __labelsInSequence(), and HiHelperTools.TestModuleCommand.testListModules().

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

Definition at line 208 of file HiHelperTools.py.

Referenced by __labelsInSequence().

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

Referenced by HiHelperTools.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
def HiHelperTools.massSearchReplaceParam (   sequence,
  paramName,
  paramOldValue,
  paramValue 
)

Definition at line 200 of file HiHelperTools.py.

Referenced by HiHelperTools.TestModuleCommand.testMassSearchReplaceParam().

201 def massSearchReplaceParam(sequence,paramName,paramOldValue,paramValue):
202  sequence.visit(MassSearchReplaceParamVisitor(paramName,paramOldValue,paramValue))
def massSearchReplaceParam
def HiHelperTools.removeIfInSequence (   process,
  target,
  sequenceLabel,
  postfix = "" 
)

Definition at line 20 of file HiHelperTools.py.

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

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
def __labelsInSequence