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 addESProducers
 Helpers to perform some technically boring tasks like looking for all modules with a given parameter and replacing that to a given value.
def applyPostfix
def cloneProcessingSnippet
def contains
def extendWithPostfix
def jetCollectionString
def listModules
def listSequences
def loadWithPostfix
def massSearchReplaceAnyInputTag
def massSearchReplaceParam
def removeIfInSequence

Function Documentation

def helpers::__labelsInSequence (   process,
  sequenceLabel,
  postfix = "" 
) [private]

Definition at line 85 of file helpers.py.

00086                                                           :
00087     result = [ m.label()[:-len(postfix)] for m in listModules( getattr(process,sequenceLabel+postfix))]
00088     result.extend([ m.label()[:-len(postfix)] for m in listSequences( getattr(process,sequenceLabel+postfix))]  )
00089     if postfix == "":
00090         result = [ m.label() for m in listModules( getattr(process,sequenceLabel+postfix))]
00091         result.extend([ m.label() for m in listSequences( getattr(process,sequenceLabel+postfix))]  )
00092     return result

def helpers::addESProducers (   process,
  config 
)

Helpers to perform some technically boring tasks like looking for all modules with a given parameter and replacing that to a given value.

Definition at line 7 of file helpers.py.

00008                                   :
00009         config = config.replace("/",".")
00010         #import RecoBTag.Configuration.RecoBTag_cff as btag
00011         #print btag
00012         module = __import__(config)
00013         for name in dir(sys.modules[config]):
00014                 item = getattr(sys.modules[config],name)
00015                 if isinstance(item,_Labelable) and not isinstance(item,_ModuleSequenceType) and not name.startswith('_') and not (name == "source" or name == "looper" or name == "subProcess") and not type(item) is cms.PSet:
00016                         if 'ESProducer' in item.type_():
00017                                 setattr(process,name,item)

def helpers::applyPostfix (   process,
  label,
  postfix 
)

Definition at line 70 of file helpers.py.

00071                                          :
00072     result = None
00073     if hasattr(process, label+postfix):
00074         result = getattr(process, label + postfix)
00075     else:
00076         raise ValueError("Error in <applyPostfix>: No module of name = %s attached to process !!" % (label + postfix))
00077     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 302 of file helpers.py.

00303                                                                         :
00304    """
00305    ------------------------------------------------------------------
00306    copy a sequence plus the modules and sequences therein
00307    both are renamed by getting a postfix
00308    input tags are automatically adjusted
00309    ------------------------------------------------------------------
00310    """
00311    result = sequence
00312    if not postfix == "":
00313        visitor = CloneSequenceVisitor(process, sequence.label(), postfix, removePostfix)
00314        sequence.visit(visitor)
00315        result = visitor.clonedSequence()
00316    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 286 of file helpers.py.

00287                                   :
00288     """
00289     ------------------------------------------------------------------
00290     return True if a module with name 'module' is contained in the
00291     sequence with name 'sequence' and False otherwise. This version
00292     is not so nice as it also returns True for any substr of the name
00293     of a contained module.
00294 
00295     sequence : sequence [e.g. process.patDefaultSequence]
00296     module   : module name as a string
00297     ------------------------------------------------------------------
00298     """
00299     return not sequence.__str__().find(moduleName)==-1
00300 
00301 

def helpers::extendWithPostfix (   process,
  other,
  postfix,
  items = () 
)
Look in other and find types which we can use

Definition at line 24 of file helpers.py.

00025                                                      :
00026         """Look in other and find types which we can use"""
00027         # enable explicit check to avoid overwriting of existing objects
00028         #__dict__['_Process__InExtendCall'] = True
00029 
00030         seqs = dict()
00031         sequence = cms.Sequence()
00032         sequence._moduleLabels = []
00033         sequence.setLabel('tempSequence')
00034         for name in dir(other):
00035             #'from XX import *' ignores these, and so should we.
00036                 if name.startswith('_'):
00037                         continue
00038                 item = getattr(other,name)
00039                 if name == "source" or name == "looper" or name == "subProcess":
00040                         continue
00041                 elif isinstance(item,cms._ModuleSequenceType):
00042                         continue
00043                 elif isinstance(item,cms.Schedule):
00044                         continue
00045                 elif isinstance(item,cms.VPSet) or isinstance(item,cms.PSet):
00046                         continue
00047                 elif isinstance(item,cms._Labelable):
00048                         if not item.hasLabel_():
00049                                 item.setLabel(name)
00050                         if postfix != '':
00051                                 newModule = item.clone()
00052                                 if isinstance(item,cms.ESProducer):
00053                                         newLabel = item.label()
00054                                         newName =name
00055                                 else:
00056                                         if 'TauDiscrimination' in name:
00057                                                        process.__setattr__(name,item)
00058                                         newLabel = item.label()+postfix
00059                                         newName = name+postfix
00060                                 process.__setattr__(newName,newModule)
00061                                 if isinstance(newModule, cms._Sequenceable) and not newName == name:
00062                                         sequence +=getattr(process,newName)
00063                                         sequence._moduleLabels.append(item.label())
00064                         else:
00065                                 process.__setattr__(name,item)
00066 
00067         if postfix != '':
00068                 for label in sequence._moduleLabels:
00069                         massSearchReplaceAnyInputTag(sequence, label, label+postfix,verbose=False,moduleLabelOnly=True)

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

00263                                                     :
00264     """
00265     ------------------------------------------------------------------
00266     return the string of the jet collection module depending on the
00267     input vaules. The default return value will be 'patAK5CaloJets'.
00268 
00269     algo   : indicating the algorithm type of the jet [expected are
00270              'AK5', 'IC5', 'SC7', ...]
00271     type   : indicating the type of constituents of the jet [expec-
00272              ted are 'Calo', 'PFlow', 'JPT', ...]
00273     prefix : prefix indicating the type of pat collection module (ex-
00274              pected are '', 'selected', 'clean').
00275     ------------------------------------------------------------------
00276     """
00277     if(prefix==''):
00278         jetCollectionString ='pat'
00279     else:
00280         jetCollectionString =prefix
00281         jetCollectionString+='Pat'
00282     jetCollectionString+='Jets'
00283     jetCollectionString+=algo
00284     jetCollectionString+=type
00285     return jetCollectionString

def helpers::listModules (   sequence)

Definition at line 248 of file helpers.py.

00249                          :
00250     visitor = GatherAllModulesVisitor(gatheredInstance=cms._Module)
00251     sequence.visit(visitor)
00252     return visitor.modules()

def helpers::listSequences (   sequence)

Definition at line 253 of file helpers.py.

00254                            :
00255     visitor = GatherAllModulesVisitor(gatheredInstance=cms.Sequence)
00256     sequence.visit(visitor)
00257     return visitor.modules()

def helpers::loadWithPostfix (   process,
  moduleName,
  postfix = '' 
)

Definition at line 18 of file helpers.py.

00019                                                   :
00020         moduleName = moduleName.replace("/",".")
00021         module = __import__(moduleName)
00022         #print module.PatAlgos.patSequences_cff.patDefaultSequence
00023         extendWithPostfix(process,sys.modules[moduleName],postfix)

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

00259                                                                                                          :
00260     """Replace InputTag oldInputTag with newInputTag, at any level of nesting within PSets, VPSets, VInputTags..."""
00261     sequence.visit(MassSearchReplaceAnyInputTagVisitor(oldInputTag,newInputTag,verbose=verbose,moduleLabelOnly=moduleLabelOnly))

def helpers::massSearchReplaceParam (   sequence,
  paramName,
  paramOldValue,
  paramValue,
  verbose = False 
)

Definition at line 245 of file helpers.py.

00246                                                                                      :
00247     sequence.visit(MassSearchReplaceParamVisitor(paramName,paramOldValue,paramValue,verbose))

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

Definition at line 78 of file helpers.py.

00079                                                                    :
00080     labels = __labelsInSequence(process, sequenceLabel, postfix)
00081     if target+postfix in labels:
00082         getattr(process, sequenceLabel+postfix).remove(
00083             getattr(process, target+postfix)
00084             )