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,
  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 244 of file helpers.py.

00245                                                                         :
00246    """
00247    ------------------------------------------------------------------
00248    copy a sequence plus the modules and sequences therein 
00249    both are renamed by getting a postfix
00250    input tags are automatically adjusted
00251    ------------------------------------------------------------------
00252    """
00253    result = sequence
00254    if not postfix == "":
00255        visitor = CloneSequenceVisitor(process, sequence.label(), postfix, removePostfix)
00256        sequence.visit(visitor)
00257        result = visitor.clonedSequence()    
00258    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 228 of file helpers.py.

00229                                   :
00230     """
00231     ------------------------------------------------------------------
00232     return True if a module with name 'module' is contained in the 
00233     sequence with name 'sequence' and False otherwise. This version
00234     is not so nice as it also returns True for any substr of the name
00235     of a contained module.
00236 
00237     sequence : sequence [e.g. process.patDefaultSequence]
00238     module   : module name as a string
00239     ------------------------------------------------------------------    
00240     """
00241     return not sequence.__str__().find(moduleName)==-1    
00242 
00243 

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 204 of file helpers.py.

00205                                                     :
00206     """
00207     ------------------------------------------------------------------
00208     return the string of the jet collection module depending on the
00209     input vaules. The default return value will be 'patAK5CaloJets'.
00210 
00211     algo   : indicating the algorithm type of the jet [expected are
00212              'AK5', 'IC5', 'SC7', ...]
00213     type   : indicating the type of constituents of the jet [expec-
00214              ted are 'Calo', 'PFlow', 'JPT', ...]
00215     prefix : prefix indicating the type of pat collection module (ex-
00216              pected are '', 'selected', 'clean').
00217     ------------------------------------------------------------------    
00218     """
00219     if(prefix==''):
00220         jetCollectionString ='pat'
00221     else:
00222         jetCollectionString =prefix
00223         jetCollectionString+='Pat'
00224     jetCollectionString+='Jets'        
00225     jetCollectionString+=algo
00226     jetCollectionString+=type
00227     return jetCollectionString

def helpers::listModules (   sequence)

Definition at line 190 of file helpers.py.

00191                          :
00192     visitor = GatherAllModulesVisitor(gatheredInstance=cms._Module)
00193     sequence.visit(visitor)
00194     return visitor.modules()

def helpers::listSequences (   sequence)

Definition at line 195 of file helpers.py.

00196                            :
00197     visitor = GatherAllModulesVisitor(gatheredInstance=cms.Sequence)
00198     sequence.visit(visitor)
00199     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 200 of file helpers.py.

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

Definition at line 187 of file helpers.py.

00188                                                                                      :
00189     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             )