test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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. More...
 
def applyPostfix
 
def cloneProcessingSnippet
 
def contains
 
def extendWithPrePostfix
 
def get_path
 
def get_vars
 
def jetCollectionString
 
def listModules
 
def listSequences
 
def loadWithPostfix
 
def loadWithPrefix
 
def loadWithPrePostfix
 
def massSearchReplaceAnyInputTag
 
def massSearchReplaceParam
 
def removeIfInSequence
 

Function Documentation

def helpers.__labelsInSequence (   process,
  sequenceLabel,
  postfix = "" 
)
private

Definition at line 91 of file helpers.py.

References listModules(), and listSequences().

Referenced by removeIfInSequence().

91 
92 def __labelsInSequence(process, sequenceLabel, postfix=""):
93  result = [ m.label()[:-len(postfix)] for m in listModules( getattr(process,sequenceLabel+postfix))]
94  result.extend([ m.label()[:-len(postfix)] for m in listSequences( getattr(process,sequenceLabel+postfix))] )
95  if postfix == "":
96  result = [ m.label() for m in listModules( getattr(process,sequenceLabel+postfix))]
97  result.extend([ m.label() for m in listSequences( getattr(process,sequenceLabel+postfix))] )
98  return result
def listModules
Definition: helpers.py:261
def listSequences
Definition: helpers.py:266
def __labelsInSequence
Definition: helpers.py:91
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.

References dir.

7 
8 def addESProducers(process,config):
9  config = config.replace("/",".")
10  #import RecoBTag.Configuration.RecoBTag_cff as btag
11  #print btag
12  module = __import__(config)
13  for name in dir(sys.modules[config]):
14  item = getattr(sys.modules[config],name)
15  if isinstance(item,cms._Labelable) and not isinstance(item,cms._ModuleSequenceType) and not name.startswith('_') and not (name == "source" or name == "looper" or name == "subProcess") and not type(item) is cms.PSet:
16  if 'ESProducer' in item.type_():
17  setattr(process,name,item)
def addESProducers
Helpers to perform some technically boring tasks like looking for all modules with a given parameter ...
Definition: helpers.py:7
dbl *** dir
Definition: mlp_gen.cc:35
def helpers.applyPostfix (   process,
  label,
  postfix 
)

Definition at line 76 of file helpers.py.

Referenced by pfTools.adaptPFMuons(), pfTools.addPFCandidates(), pfTools.reconfigurePF2PATTaus(), pfTools.switchToPFJets(), pfTools.switchToPFMET(), pfTools.tauTypeInPF2PAT(), HiCoreTools.RemoveMCMatching.toolCode(), HiCoreTools.RemoveSpecificPATObjects.toolCode(), HiCoreTools.RemoveCleaning.toolCode(), and pfTools.usePF2PAT().

76 
77 def applyPostfix(process, label, postfix):
78  result = None
79  if hasattr(process, label+postfix):
80  result = getattr(process, label + postfix)
81  else:
82  raise ValueError("Error in <applyPostfix>: No module of name = %s attached to process !!" % (label + postfix))
83  return result
def applyPostfix
Definition: helpers.py:76
def helpers.cloneProcessingSnippet (   process,
  sequence,
  postfix,
  removePostfix = "",
  noClones = [] 
)
------------------------------------------------------------------
copy a sequence plus the modules and sequences therein
both are renamed by getting a postfix
input tags are automatically adjusted
------------------------------------------------------------------

Definition at line 315 of file helpers.py.

Referenced by boostedHPSPFTaus_cfi.addBoostedTaus(), pfIsolation.setupPFIso(), and pfIsolation.setupPFIsoPhoton().

316 def cloneProcessingSnippet(process, sequence, postfix, removePostfix="", noClones = []):
317  """
318  ------------------------------------------------------------------
319  copy a sequence plus the modules and sequences therein
320  both are renamed by getting a postfix
321  input tags are automatically adjusted
322  ------------------------------------------------------------------
323  """
324  result = sequence
325  if not postfix == "":
326  visitor = CloneSequenceVisitor(process, sequence.label(), postfix, removePostfix, noClones)
327  sequence.visit(visitor)
328  result = visitor.clonedSequence()
329  return result
def cloneProcessingSnippet
Definition: helpers.py:315
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 299 of file helpers.py.

References spr.find().

Referenced by helpers.TestModuleCommand.testContains().

300 def contains(sequence, moduleName):
301  """
302  ------------------------------------------------------------------
303  return True if a module with name 'module' is contained in the
304  sequence with name 'sequence' and False otherwise. This version
305  is not so nice as it also returns True for any substr of the name
306  of a contained module.
307 
308  sequence : sequence [e.g. process.patDefaultSequence]
309  module : module name as a string
310  ------------------------------------------------------------------
311  """
312  return not sequence.__str__().find(moduleName)==-1
313 
314 
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
def contains
Definition: helpers.py:299
def helpers.extendWithPrePostfix (   process,
  other,
  prefix,
  postfix,
  items = () 
)
Look in other and find types which we can use

Definition at line 30 of file helpers.py.

References cmsPerfStripChart.dict, dir, and massSearchReplaceAnyInputTag().

Referenced by loadWithPrePostfix().

30 
31 def extendWithPrePostfix(process,other,prefix,postfix,items=()):
32  """Look in other and find types which we can use"""
33  # enable explicit check to avoid overwriting of existing objects
34  #__dict__['_Process__InExtendCall'] = True
35 
36  seqs = dict()
37  sequence = cms.Sequence()
38  sequence._moduleLabels = []
39  sequence.setLabel('tempSequence')
40  for name in dir(other):
41  #'from XX import *' ignores these, and so should we.
42  if name.startswith('_'):
43  continue
44  item = getattr(other,name)
45  if name == "source" or name == "looper" or name == "subProcess":
46  continue
47  elif isinstance(item,cms._ModuleSequenceType):
48  continue
49  elif isinstance(item,cms.Schedule):
50  continue
51  elif isinstance(item,cms.VPSet) or isinstance(item,cms.PSet):
52  continue
53  elif isinstance(item,cms._Labelable):
54  if not item.hasLabel_():
55  item.setLabel(name)
56  if prefix != '' or postfix != '':
57  newModule = item.clone()
58  if isinstance(item,cms.ESProducer):
59  newLabel = item.label()
60  newName =name
61  else:
62  if 'TauDiscrimination' in name:
63  process.__setattr__(name,item)
64  newLabel = prefix+item.label()+postfix
65  newName = prefix+name+postfix
66  process.__setattr__(newName,newModule)
67  if isinstance(newModule, cms._Sequenceable) and not newName == name:
68  sequence +=getattr(process,newName)
69  sequence._moduleLabels.append(item.label())
70  else:
71  process.__setattr__(name,item)
72 
73  if prefix != '' or postfix != '':
74  for label in sequence._moduleLabels:
75  massSearchReplaceAnyInputTag(sequence, label, prefix+label+postfix,verbose=False,moduleLabelOnly=True)
def extendWithPrePostfix
Definition: helpers.py:30
def massSearchReplaceAnyInputTag
Definition: helpers.py:271
dbl *** dir
Definition: mlp_gen.cc:35
def helpers.get_path (   file_in_path)

Definition at line 6 of file helpers.py.

Referenced by get_vars().

6 
7 def get_path(file_in_path):
8  'mimics edm.FileInPath behavior'
9  search_env = os.environ.get('CMSSW_SEARCH_PATH', '')
10  if not search_env:
11  raise RuntimeError('The environmental variable CMSSW_SEARCH_PATH must be set')
12  search_paths = search_env.split(':')
13  for spath in search_paths:
14  full_path = os.path.join(spath, file_in_path)
15  if os.path.isfile(full_path):
16  return full_path
17  raise RuntimeError('No suitable path found for %s' % file_in_path)
def get_path
Definition: helpers.py:6
def helpers.get_vars (   xml_path,
  useFileInPath = True 
)

Definition at line 18 of file helpers.py.

References get_path(), and trainingvars.get_var_pset().

18 
19 def get_vars(xml_path, useFileInPath=True):
20  full_path = get_path(xml_path) if useFileInPath else xml_path
21  xml_tree = ET.parse(full_path)
22  root = xml_tree.getroot()
23  variables = None
24  for i in root:
25  if i.tag == 'Variables':
26  variables = i
27 
28  if i is None:
29  raise RuntimeError('Could not find Variables inside the xml weights')
30 
31  var_names = [i.attrib['Title'] for i in variables]
32  return [get_var_pset(i) for i in var_names]
33 
def get_path
Definition: helpers.py:6
def get_vars
Definition: helpers.py:18
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 275 of file helpers.py.

References reco.if().

Referenced by helpers.TestModuleCommand.testJetCollectionString(), heavyIonTools.ProductionDefaults.toolCode(), HiCoreTools.RemoveMCMatching.toolCode(), coreTools.RemoveMCMatching.toolCode(), heavyIonTools.SelectionDefaults.toolCode(), and HiCoreTools.RemoveSpecificPATObjects.toolCode().

276 def jetCollectionString(prefix='', algo='', type=''):
277  """
278  ------------------------------------------------------------------
279  return the string of the jet collection module depending on the
280  input vaules. The default return value will be 'patAK5CaloJets'.
281 
282  algo : indicating the algorithm type of the jet [expected are
283  'AK5', 'IC5', 'SC7', ...]
284  type : indicating the type of constituents of the jet [expec-
285  ted are 'Calo', 'PFlow', 'JPT', ...]
286  prefix : prefix indicating the type of pat collection module (ex-
287  pected are '', 'selected', 'clean').
288  ------------------------------------------------------------------
289  """
290  if(prefix==''):
291  jetCollectionString ='pat'
292  else:
293  jetCollectionString =prefix
294  jetCollectionString+='Pat'
295  jetCollectionString+='Jets'
296  jetCollectionString+=algo
297  jetCollectionString+=type
298  return jetCollectionString
def jetCollectionString
Definition: helpers.py:275
if(dp >Float(M_PI)) dp-
def helpers.listModules (   sequence)

Definition at line 261 of file helpers.py.

Referenced by __labelsInSequence(), trigTools._modulesInPath(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.labelsInSequence(), helpers.TestModuleCommand.testListModules(), HiCoreTools.RemoveCleaning.toolCode(), and HiCoreTools.AddCleaning.toolCode().

262 def listModules(sequence):
263  visitor = GatherAllModulesVisitor(gatheredInstance=cms._Module)
264  sequence.visit(visitor)
265  return visitor.modules()
def listModules
Definition: helpers.py:261
def helpers.listSequences (   sequence)

Definition at line 266 of file helpers.py.

Referenced by __labelsInSequence(), and runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties.labelsInSequence().

267 def listSequences(sequence):
268  visitor = GatherAllModulesVisitor(gatheredInstance=cms.Sequence)
269  sequence.visit(visitor)
270  return visitor.modules()
def listSequences
Definition: helpers.py:266
def helpers.loadWithPostfix (   process,
  moduleName,
  postfix = '' 
)

Definition at line 21 of file helpers.py.

References loadWithPrePostfix().

Referenced by pfTools.usePF2PAT().

21 
22 def loadWithPostfix(process,moduleName,postfix=''):
23  loadWithPrePostfix(process,moduleName,'',postfix)
def loadWithPostfix
Definition: helpers.py:21
def loadWithPrePostfix
Definition: helpers.py:24
def helpers.loadWithPrefix (   process,
  moduleName,
  prefix = '' 
)

Definition at line 18 of file helpers.py.

References loadWithPrePostfix().

Referenced by jetTools.setupBTagging().

18 
19 def loadWithPrefix(process,moduleName,prefix=''):
20  loadWithPrePostfix(process,moduleName,prefix,'')
def loadWithPrePostfix
Definition: helpers.py:24
def loadWithPrefix
Definition: helpers.py:18
def helpers.loadWithPrePostfix (   process,
  moduleName,
  prefix = '',
  postfix = '' 
)

Definition at line 24 of file helpers.py.

References extendWithPrePostfix().

Referenced by loadWithPostfix(), and loadWithPrefix().

24 
25 def loadWithPrePostfix(process,moduleName,prefix='',postfix=''):
26  moduleName = moduleName.replace("/",".")
27  module = __import__(moduleName)
28  #print module.PatAlgos.patSequences_cff.patDefaultSequence
29  extendWithPrePostfix(process,sys.modules[moduleName],prefix,postfix)
def extendWithPrePostfix
Definition: helpers.py:30
def loadWithPrePostfix
Definition: helpers.py:24
def helpers.massSearchReplaceAnyInputTag (   sequence,
  oldInputTag,
  newInputTag,
  verbose = False,
  moduleLabelOnly = False,
  skipLabelTest = False 
)
Replace InputTag oldInputTag with newInputTag, at any level of nesting within PSets, VPSets, VInputTags...

Definition at line 271 of file helpers.py.

Referenced by boostedHPSPFTaus_cfi.addBoostedTaus(), patMuonsWithTrigger_cff.changeRecoMuonInput(), customiseForPremixingInput.customiseForPreMixingInput(), extendWithPrePostfix(), CustomConfigs.MassReplaceInputTag(), ConfigBuilder.MassReplaceInputTag(), ConfigBuilder.ConfigBuilder.renameInputTagsInSequence(), helpers.TestModuleCommand.testMassSearchReplaceAnyInputTag(), and patMuonsWithTrigger_cff.useExistingPATMuons().

272 def massSearchReplaceAnyInputTag(sequence, oldInputTag, newInputTag,verbose=False,moduleLabelOnly=False,skipLabelTest=False) :
273  """Replace InputTag oldInputTag with newInputTag, at any level of nesting within PSets, VPSets, VInputTags..."""
274  sequence.visit(MassSearchReplaceAnyInputTagVisitor(oldInputTag,newInputTag,verbose=verbose,moduleLabelOnly=moduleLabelOnly,skipLabelTest=skipLabelTest))
def massSearchReplaceAnyInputTag
Definition: helpers.py:271
def helpers.massSearchReplaceParam (   sequence,
  paramName,
  paramOldValue,
  paramValue,
  verbose = False 
)

Definition at line 258 of file helpers.py.

Referenced by CustomConfigs.MassReplaceParameter(), pfTools.reconfigurePF2PATTaus(), switchMVAtoDB_cfi.switchMVAtoDB(), and helpers.TestModuleCommand.testMassSearchReplaceParam().

259 def massSearchReplaceParam(sequence,paramName,paramOldValue,paramValue,verbose=False):
260  sequence.visit(MassSearchReplaceParamVisitor(paramName,paramOldValue,paramValue,verbose))
def massSearchReplaceParam
Definition: helpers.py:258
def helpers.removeIfInSequence (   process,
  target,
  sequenceLabel,
  postfix = "" 
)

Definition at line 84 of file helpers.py.

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

Referenced by HiCoreTools.RemoveSpecificPATObjects.toolCode().

84 
85 def removeIfInSequence(process, target, sequenceLabel, postfix=""):
86  labels = __labelsInSequence(process, sequenceLabel, postfix)
87  if target+postfix in labels:
88  getattr(process, sequenceLabel+postfix).remove(
89  getattr(process, target+postfix)
90  )
def removeIfInSequence
Definition: helpers.py:84
def __labelsInSequence
Definition: helpers.py:91