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

00258                                                       :
00259    """
00260    ------------------------------------------------------------------
00261    copy a sequence plus the modules and sequences therein 
00262    both are renamed by getting a postfix
00263    input tags are automatically adjusted
00264    ------------------------------------------------------------------
00265    """
00266    result = sequence
00267    if not postfix == "":
00268        visitor = CloneSequenceVisitor(process,sequence.label(),postfix)
00269        sequence.visit(visitor)
00270        result = visitor.clonedSequence()    
00271    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 241 of file helpers.py.

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

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.

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

def helpers::listModules (   sequence)

Definition at line 203 of file helpers.py.

00204                          :
00205     visitor = GatherAllModulesVisitor(gatheredInstance=cms._Module)
00206     sequence.visit(visitor)
00207     return visitor.modules()

def helpers::listSequences (   sequence)

Definition at line 208 of file helpers.py.

00209                            :
00210     visitor = GatherAllModulesVisitor(gatheredInstance=cms.Sequence)
00211     sequence.visit(visitor)
00212     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 213 of file helpers.py.

00213                                                                                                          : 
00214     """Replace InputTag oldInputTag with newInputTag, at any level of nesting within PSets, VPSets, VInputTags..."""
00215     sequence.visit(MassSearchReplaceAnyInputTagVisitor(oldInputTag,newInputTag,verbose=verbose,moduleLabelOnly=moduleLabelOnly))
00216     
def helpers::massSearchReplaceParam (   sequence,
  paramName,
  paramOldValue,
  paramValue 
)

Definition at line 200 of file helpers.py.

00201                                                                        :
00202     sequence.visit(MassSearchReplaceParamVisitor(paramName,paramOldValue,paramValue))

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             )