7 ''' If a module is in patHeavyIonDefaultSequence use the cloned module.
8 Will crash if patHeavyIonDefaultSequence has not been cloned with 'postfix' beforehand'''
11 if hasattr(process,
"patPF2PATSequence"):
13 if label
in defaultLabels
and hasattr(process, label+postfix):
14 result = getattr(process, label+postfix)
15 elif hasattr(process, label):
16 print "WARNING: called applyPostfix for module/sequence %s which is not in patHeavyIonDefaultSequence%s!"%(label,postfix)
17 result = getattr(process, label)
22 if target+postfix
in labels:
23 getattr(process, sequenceLabel+postfix).
remove(
24 getattr(process, target+postfix)
28 result = [ m.label()[:-len(postfix)]
for m
in listModules( getattr(process,sequenceLabel+postfix))]
29 result.extend([ m.label()[:-len(postfix)]
for m
in listSequences( getattr(process,sequenceLabel+postfix))] )
31 result = [ m.label()
for m
in listModules( getattr(process,sequenceLabel+postfix))]
32 result.extend([ m.label()
for m
in listSequences( getattr(process,sequenceLabel+postfix))] )
36 """Visitor that travels within a cms.Sequence, looks for a parameter and replaces its value"""
37 def __init__(self,paramName,paramSearch,paramValue,verbose=False):
50 class MassSearchReplaceAnyInputTagVisitor(
object):
51 """Visitor that travels within a cms.Sequence, looks for a parameter and replace its value
52 It will climb down within PSets, VPSets and VInputTags to find its target"""
53 def __init__(self,paramSearch,paramReplace,verbose=False,moduleLabelOnly=False):
60 if isinstance(pset, cms._Parameterizable):
61 for name
in pset.parameters_().
keys():
64 value = getattr(pset,name)
65 type = value.pythonTypeName()
66 if type ==
'cms.PSet':
67 self.
doIt(value,base+
"."+name)
68 elif type ==
'cms.VPSet':
69 for (i,ps)
in enumerate(value): self.
doIt(ps,
"%s.%s[%d]"%(base,name,i) )
70 elif type ==
'cms.VInputTag':
71 for (i,n)
in enumerate(value):
77 elif self.
_moduleLabelOnly and n.moduleLabel == self._paramSearch.moduleLabel:
78 nrep = n; nrep.moduleLabel = self._paramReplace.moduleLabel
79 if self.
_verbose:
print "Replace %s.%s[%d] %s ==> %s " % (base, name, i, n, nrep)
81 elif type ==
'cms.InputTag':
84 from copy
import deepcopy
86 elif self.
_moduleLabelOnly and value.moduleLabel == self._paramSearch.moduleLabel:
87 from copy
import deepcopy
88 repl = deepcopy(getattr(pset, name))
89 repl.moduleLabel = self._paramReplace.moduleLabel
90 setattr(pset, name, repl)
91 if self.
_verbose:
print "Replace %s.%s %s ==> %s " % (base, name, value, repl)
96 ''' helper function to ensure that the InputTag is defined as cms.InputTag(str) and not as a plain str '''
97 if not isinstance(inputTag, cms.InputTag):
98 return cms.InputTag(inputTag)
103 try: label = visitee.label()
104 except AttributeError: label =
'<Module not in a Process>'
105 self.
doIt(visitee, label)
111 """Visitor that travels within a cms.Sequence, and returns a list of objects of type gatheredInance(e.g. modules) that have it"""
117 self._modules.append(visitee)
124 """Visitor that travels within a cms.Sequence, and returns a cloned version of the Sequence.
125 All modules and sequences are cloned and a postfix is added"""
137 if isinstance(visitee,cms._Module):
138 label = visitee.label()
143 self._moduleLabels.append(label)
145 newModule = visitee.clone()
149 if isinstance(visitee,cms.Sequence):
152 self._sequenceStack.append( getattr(self.
_process, visitee.label()+self.
_postfix) )
154 self._sequenceStack.append(visitee.label())
157 if isinstance(visitee,cms.Sequence):
161 raise StandardError,
"empty Sequence encountered during cloneing. sequnece stack: %s"%self.
_sequenceStack
166 raise StandardError,
"someting went wrong, the sequence stack looks like: %s"%self.
_sequenceStack
174 oldSequenceLabel = self._sequenceStack.pop()
175 newSequenceLabel = oldSequenceLabel + self.
_postfix
176 self._sequenceStack.append(cms.Sequence(visitee))
177 if hasattr(self.
_process, newSequenceLabel):
178 raise StandardError(
"Cloning the sequence "+self.
_sequenceStack[-1].
label()+
" would overwrite existing object." )
180 self._sequenceLabels.append(oldSequenceLabel)
185 """Visitor that travels within a cms.Sequence, looks for a parameter and returns a list of modules that have it"""
193 self._modules.append(visitee)
205 sequence.visit(visitor)
206 return visitor.modules()
210 sequence.visit(visitor)
211 return visitor.modules()
214 """Replace InputTag oldInputTag with newInputTag, at any level of nesting within PSets, VPSets, VInputTags..."""
219 ------------------------------------------------------------------
220 return the string of the jet collection module depending on the
221 input vaules. The default return value will be 'patAK5CaloJets'.
223 algo : indicating the algorithm type of the jet [expected are
224 'AK5', 'IC5', 'SC7', ...]
225 type : indicating the type of constituents of the jet [expec-
226 ted are 'Calo', 'PFlow', 'JPT', ...]
227 prefix : prefix indicating the type of pat collection module (ex-
228 pected are '', 'selected', 'clean').
229 ------------------------------------------------------------------
232 jetCollectionString =
'pat'
234 jetCollectionString =prefix
235 jetCollectionString+=
'Pat'
236 jetCollectionString+=
'Jets'
237 jetCollectionString+=algo
238 jetCollectionString+=type
239 return jetCollectionString
243 ------------------------------------------------------------------
244 return True if a module with name 'module' is contained in the
245 sequence with name 'sequence' and False otherwise. This version
246 is not so nice as it also returns True for any substr of the name
247 of a contained module.
249 sequence : sequence [e.g. process.patHeavyIonDefaultSequence]
250 module : module name as a string
251 ------------------------------------------------------------------
253 return not sequence.__str__().
find(moduleName)==-1
259 ------------------------------------------------------------------
260 copy a sequence plus the modules and sequences therein
261 both are renamed by getting a postfix
262 input tags are automatically adjusted
263 ------------------------------------------------------------------
266 if not postfix ==
"":
268 sequence.visit(visitor)
269 result = visitor.clonedSequence()
272 if __name__==
"__main__":
279 p = cms.Process(
"test")
280 p.a = cms.EDProducer(
"a", src=cms.InputTag(
"gen"))
281 p.b = cms.EDProducer(
"b", src=cms.InputTag(
"a"))
282 p.c = cms.EDProducer(
"c", src=cms.InputTag(
"b",
"instance"))
283 p.s = cms.Sequence(p.a*p.b*p.c *p.a)
285 self.assertEqual(p.dumpPython(),
'import FWCore.ParameterSet.Config as cms\n\nprocess = cms.Process("test")\n\nprocess.a = cms.EDProducer("a",\n src = cms.InputTag("gen")\n)\n\n\nprocess.c = cms.EDProducer("c",\n src = cms.InputTag("b","instance")\n)\n\n\nprocess.cNew = cms.EDProducer("c",\n src = cms.InputTag("bNew","instance")\n)\n\n\nprocess.bNew = cms.EDProducer("b",\n src = cms.InputTag("aNew")\n)\n\n\nprocess.aNew = cms.EDProducer("a",\n src = cms.InputTag("gen")\n)\n\n\nprocess.b = cms.EDProducer("b",\n src = cms.InputTag("a")\n)\n\n\nprocess.s = cms.Sequence(process.a*process.b*process.c*process.a)\n\n\nprocess.sNew = cms.Sequence(process.aNew+process.bNew+process.cNew)\n\n\n')
287 p = cms.Process(
"test")
288 p.a = cms.EDProducer(
"a", src=cms.InputTag(
"gen"))
289 p.b = cms.EDProducer(
"ab", src=cms.InputTag(
"a"))
290 p.c = cms.EDProducer(
"ac", src=cms.InputTag(
"b"))
291 p.s1 = cms.Sequence(p.a*p.b*p.c)
292 p.s2 = cms.Sequence(p.b*p.c)
294 self.assert_(
not contains(p.s2,
"a") )
297 self.assertEqual(
jetCollectionString(prefix =
'prefix', algo =
'Foo', type =
'Bar'),
'prefixPatFooBarJets')
299 p = cms.Process(
"test")
300 p.a = cms.EDProducer(
"a", src=cms.InputTag(
"gen"))
301 p.b = cms.EDProducer(
"ab", src=cms.InputTag(
"a"))
302 p.c = cms.EDProducer(
"ac", src=cms.InputTag(
"b"))
303 p.s = cms.Sequence(p.a*p.b*p.c)
306 p = cms.Process(
"test")
307 p.a = cms.EDProducer(
"a", src=cms.InputTag(
"gen"))
308 p.b = cms.EDProducer(
"ab", src=cms.InputTag(
"a"))
309 p.c = cms.EDProducer(
"ac", src=cms.InputTag(
"b"),
310 nested = cms.PSet(src = cms.InputTag(
"c"))
312 p.s = cms.Sequence(p.a*p.b*p.c)
314 self.assertEqual(cms.InputTag(
"a"),p.c.src)
315 self.assertNotEqual(cms.InputTag(
"a"),p.c.nested.src)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
if(conf.exists("allCellsPositionCalc"))