CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
customizeHLTforNewJetCorrectors Namespace Reference

Functions

def _buildSequenceOfCorrectors
 
def _correctorNameChanger
 
def _findCorrectorsRecursive
 
def _findCorrectorsUsedByProducer
 
def _findModulesToChange
 
def _makeNewCorrectorFromOld
 
def _makeNewProducerFroOld
 
def _translateParameters
 
def customizeHLTforNewJetCorrectors
 

Variables

dictionary _oldToNewProds = {'CaloJetCorrectionProducer':'CorrectedCaloJetProducer','PFJetCorrectionProducer':'CorrectedPFJetProducer'}
 

Function Documentation

def customizeHLTforNewJetCorrectors._buildSequenceOfCorrectors (   process,
  correctorNames 
)
private
Using the dependencies between correctors, construct the appropriate cms.Sequence.

Definition at line 74 of file customizeHLTforNewJetCorrectors.py.

References _correctorNameChanger(), and _makeNewCorrectorFromOld().

Referenced by customizeHLTforNewJetCorrectors().

74 
75 def _buildSequenceOfCorrectors(process, correctorNames):
76  """Using the dependencies between correctors, construct the appropriate cms.Sequence.
77  """
78  modSequence = None
79  for n in correctorNames:
80  mod = getattr(process,n)
81  newLabel = _correctorNameChanger(n)
82  newMod = _makeNewCorrectorFromOld(mod)
83  setattr(process,newLabel,newMod)
84  if not modSequence:
85  modSequence = newMod
86  else:
87  modSequence += newMod
88  return cms.Sequence(modSequence)
def customizeHLTforNewJetCorrectors._correctorNameChanger (   oldName)
private
Based on the label from the old correct, determine what label to use for the new corrector

Definition at line 33 of file customizeHLTforNewJetCorrectors.py.

Referenced by _buildSequenceOfCorrectors(), _translateParameters(), and customizeHLTforNewJetCorrectors().

33 
34 def _correctorNameChanger(oldName):
35  """Based on the label from the old correct, determine what label to use for the new corrector
36  """
37  post1 = "CorrectionESProducer"
38  if oldName[-1*len(post1):] == post1:
39  return oldName[:-1*len(post1)]+"Corrector"
40  post2 = "Correction"
41  if oldName[-1*len(post2):] == post2:
42  return oldName[:-1*len(post2)]+"Corrector"
43  return None
def customizeHLTforNewJetCorrectors._findCorrectorsRecursive (   process,
  name,
  correctors 
)
private
Find all Correctors used by the corrector 'name'

Definition at line 23 of file customizeHLTforNewJetCorrectors.py.

Referenced by _findCorrectorsUsedByProducer().

23 
24 def _findCorrectorsRecursive(process, name, correctors):
25  """Find all Correctors used by the corrector 'name'
26  """
27  m=getattr(process,name)
28  if m.type_() == 'JetCorrectionESChain':
29  for n in m.correctors:
30  _findCorrectorsRecursive(process,n,correctors)
31  #we want all the dependent modules first
32  correctors.append(name)
def customizeHLTforNewJetCorrectors._findCorrectorsUsedByProducer (   process,
  producer 
)
private
Starting from a EDProducer, find which old jet correctors are used

Definition at line 15 of file customizeHLTforNewJetCorrectors.py.

References _findCorrectorsRecursive().

Referenced by customizeHLTforNewJetCorrectors().

15 
16 def _findCorrectorsUsedByProducer(process,producer):
17  """Starting from a EDProducer, find which old jet correctors are used
18  """
19  correctors =[]
20  for x in producer.correctors:
21  _findCorrectorsRecursive(process,x,correctors)
22  return correctors
def customizeHLTforNewJetCorrectors._findModulesToChange (   producers,
  prodsToFind 
)
private
Based on the type, find the labels for modules we need to change

Definition at line 6 of file customizeHLTforNewJetCorrectors.py.

Referenced by customizeHLTforNewJetCorrectors().

6 
7 def _findModulesToChange(producers, prodsToFind):
8  """Based on the type, find the labels for modules we need to change
9  """
10  modulesToChange = []
11  for label,mod in producers.iteritems():
12  if mod.type_() in prodsToFind:
13  modulesToChange.append(label)
14  return modulesToChange
def customizeHLTforNewJetCorrectors._makeNewCorrectorFromOld (   oldCorrector)
private
Based on the old ESProducer corrector, create the equivalent EDProducer

Definition at line 59 of file customizeHLTforNewJetCorrectors.py.

References _translateParameters().

Referenced by _buildSequenceOfCorrectors().

59 
60 def _makeNewCorrectorFromOld(oldCorrector):
61  """Based on the old ESProducer corrector, create the equivalent EDProducer
62  """
63  oldToNewCorrectors_ = {'JetCorrectionESChain':'ChainedJetCorrectorProducer', 'LXXXCorrectionESProducer':'LXXXCorrectorProducer', 'L1FastjetCorrectionESProducer':'L1FastjetCorrectorProducer'}
64  type = oldToNewCorrectors_[oldCorrector.type_()]
65  corrector = cms.EDProducer(type)
66  return _translateParameters(oldCorrector,corrector)
def customizeHLTforNewJetCorrectors._makeNewProducerFroOld (   oldProducer)
private
Based on the old EDProducer which used a corrector from the EventSetup, create the appropriate EDProducer which gets the corrector from the Event.

Definition at line 67 of file customizeHLTforNewJetCorrectors.py.

References _translateParameters().

Referenced by customizeHLTforNewJetCorrectors().

67 
68 def _makeNewProducerFroOld(oldProducer):
69  """Based on the old EDProducer which used a corrector from the EventSetup, create the appropriate EDProducer which gets the corrector from the Event.
70  """
71  type = _oldToNewProds[oldProducer.type_()]
72  newProd = cms.EDProducer(type)
73  return _translateParameters(oldProducer,newProd)
def customizeHLTforNewJetCorrectors._translateParameters (   oldModule,
  newModule 
)
private
Appropriately transform the parameters from the old module to the new module.
This includes changing 'correctors' from a vstring to a VInputTag

Definition at line 44 of file customizeHLTforNewJetCorrectors.py.

References _correctorNameChanger(), and dir.

Referenced by _makeNewCorrectorFromOld(), and _makeNewProducerFroOld().

44 
45 def _translateParameters(oldModule, newModule):
46  """Appropriately transform the parameters from the old module to the new module.
47  This includes changing 'correctors' from a vstring to a VInputTag
48  """
49  for n in dir(oldModule):
50  p = getattr(oldModule,n)
51  if isinstance(p,cms._ParameterTypeBase):
52  if n == 'appendToDataLabel':
53  continue
54  if n == "correctors" and isinstance(p,cms.vstring):
55  p = cms.VInputTag( (cms.InputTag( _correctorNameChanger(tag) ) for tag in p))
56  setattr(newModule,n,p)
57  return newModule
58 
dbl *** dir
Definition: mlp_gen.cc:35
def customizeHLTforNewJetCorrectors.customizeHLTforNewJetCorrectors (   process)

Definition at line 89 of file customizeHLTforNewJetCorrectors.py.

References _buildSequenceOfCorrectors(), _correctorNameChanger(), _findCorrectorsUsedByProducer(), _findModulesToChange(), _makeNewProducerFroOld(), and join().

89 
91  modulesToChange = _findModulesToChange(process.producers, [x for x in _oldToNewProds.iterkeys()])
92 
93 
94  oldCorrectorsSequence = set()
95  oldCorrectors = set()
96  oldCorrectorsToNewSequence = {}
97  for m in modulesToChange:
98  correctors = _findCorrectorsUsedByProducer(process, getattr(process,m))
99  oldCorrectors.update( correctors )
100  stringOfOldCorrectorNames = ",".join(correctors)
101  if stringOfOldCorrectorNames not in oldCorrectorsSequence:
102  seq = _buildSequenceOfCorrectors(process,correctors)
103  #need to attach to process since some code looks for labels for all items in a path
104  setattr(process,"correctorSeqFor"+_correctorNameChanger(correctors[-1]), seq)
105  oldCorrectorsSequence.add(stringOfOldCorrectorNames)
106  oldCorrectorsToNewSequence[stringOfOldCorrectorNames] = seq
107 
108  #replace the old module
109  oldModule = getattr(process,m)
110  newModule = _makeNewProducerFroOld(oldModule)
111  setattr(process,m,newModule)
112 
113  #need to insert the new sequence
114  seq = oldCorrectorsToNewSequence[stringOfOldCorrectorNames]
115  for p in process.paths.itervalues():
116  if m in p.moduleNames():
117  if not p.replace(newModule,seq+newModule):
118  print "failed to replace ",m, "in path ", p.label_(), p
119 
120  #now remove the old correctors
121  for m in oldCorrectors:
122  delattr(process,m)
123 
124  return process
static std::string join(char **cmd)
Definition: RemoteFile.cc:18

Variable Documentation

dictionary customizeHLTforNewJetCorrectors._oldToNewProds = {'CaloJetCorrectionProducer':'CorrectedCaloJetProducer','PFJetCorrectionProducer':'CorrectedPFJetProducer'}

Definition at line 4 of file customizeHLTforNewJetCorrectors.py.