CMS 3D CMS Logo

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.
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.

00028                                                           :
00029     result = [ m.label()[:-len(postfix)] for m in listModules( getattr(process,sequenceLabel+postfix))]
00030     result.extend([ m.label()[:-len(postfix)] for m in listSequences( getattr(process,sequenceLabel+postfix))]  )
00031     if postfix == "":  
00032         result = [ m.label() for m in listModules( getattr(process,sequenceLabel+postfix))]
00033         result.extend([ m.label() for m in listSequences( getattr(process,sequenceLabel+postfix))]  )
00034     return result
    
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.

00007                                          :
00008     ''' If a module is in patDefaultSequence use the cloned module.
00009     Will crash if patDefaultSequence has not been cloned with 'postfix' beforehand'''
00010     result = None 
00011     defaultLabels = __labelsInSequence(process, "patDefaultSequence", postfix)
00012     if hasattr(process, "patPF2PATSequence"):
00013         defaultLabels = __labelsInSequence(process, "patPF2PATSequence", postfix)
00014     if label in defaultLabels and hasattr(process, label+postfix):
00015         result = getattr(process, label+postfix)
00016     elif hasattr(process, label):
00017         print "WARNING: called applyPostfix for module/sequence %s which is not in patDefaultSequence%s!"%(label,postfix)
00018         result = getattr(process, label)    
00019     return result

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.

00263                                                       :
00264    """
00265    ------------------------------------------------------------------
00266    copy a sequence plus the modules and sequences therein 
00267    both are renamed by getting a postfix
00268    input tags are automatically adjusted
00269    ------------------------------------------------------------------
00270    """
00271    result = sequence
00272    if not postfix == "":
00273        visitor = CloneSequenceVisitor(process,sequence.label(),postfix)
00274        sequence.visit(visitor)
00275        result = visitor.clonedSequence()    
00276    return result

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.

00247                                   :
00248     """
00249     ------------------------------------------------------------------
00250     return True if a module with name 'module' is contained in the 
00251     sequence with name 'sequence' and False otherwise. This version
00252     is not so nice as it also returns True for any substr of the name
00253     of a contained module.
00254 
00255     sequence : sequence [e.g. process.patDefaultSequence]
00256     module   : module name as a string
00257     ------------------------------------------------------------------    
00258     """
00259     return not sequence.__str__().find(moduleName)==-1    
00260 
00261 

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.

00223                                                     :
00224     """
00225     ------------------------------------------------------------------
00226     return the string of the jet collection module depending on the
00227     input vaules. The default return value will be 'patAK5CaloJets'.
00228 
00229     algo   : indicating the algorithm type of the jet [expected are
00230              'AK5', 'IC5', 'SC7', ...]
00231     type   : indicating the type of constituents of the jet [expec-
00232              ted are 'Calo', 'PFlow', 'JPT', ...]
00233     prefix : prefix indicating the type of pat collection module (ex-
00234              pected are '', 'selected', 'clean').
00235     ------------------------------------------------------------------    
00236     """
00237     if(prefix==''):
00238         jetCollectionString ='pat'
00239     else:
00240         jetCollectionString =prefix
00241         jetCollectionString+='Pat'
00242     jetCollectionString+='Jets'        
00243     jetCollectionString+=algo
00244     jetCollectionString+=type
00245     return jetCollectionString

def helpers::listModules (   sequence)

Definition at line 208 of file helpers.py.

00209                          :
00210     visitor = GatherAllModulesVisitor(gatheredInstance=cms._Module)
00211     sequence.visit(visitor)
00212     return visitor.modules()

def helpers::listSequences (   sequence)

Definition at line 213 of file helpers.py.

00214                            :
00215     visitor = GatherAllModulesVisitor(gatheredInstance=cms.Sequence)
00216     sequence.visit(visitor)
00217     return visitor.modules()

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.

00218                                                                                                          : 
00219     """Replace InputTag oldInputTag with newInputTag, at any level of nesting within PSets, VPSets, VInputTags..."""
00220     sequence.visit(MassSearchReplaceAnyInputTagVisitor(oldInputTag,newInputTag,verbose=verbose,moduleLabelOnly=moduleLabelOnly))
00221     
def helpers::massSearchReplaceParam (   sequence,
  paramName,
  paramOldValue,
  paramValue,
  verbose = False 
)

Definition at line 205 of file helpers.py.

00206                                                                                      :
00207     sequence.visit(MassSearchReplaceParamVisitor(paramName,paramOldValue,paramValue,verbose))

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

Definition at line 20 of file helpers.py.

00021                                                                    :
00022     labels = __labelsInSequence(process, sequenceLabel, postfix)
00023     if target+postfix in labels: 
00024         getattr(process, sequenceLabel+postfix).remove(
00025             getattr(process, target+postfix)
00026             )