1 import FWCore.ParameterSet.Config
as cms
8 from FWCore.ParameterSet.MassReplace
import massSearchReplaceAnyInputTag, MassSearchReplaceAnyInputTagVisitor
9 from FWCore.ParameterSet.MassReplace
import massSearchReplaceParam, MassSearchParamVisitor, MassSearchReplaceParamVisitor
12 ''' If a module is in patHeavyIonDefaultSequence use the cloned module. 13 Will crash if patHeavyIonDefaultSequence has not been cloned with 'postfix' beforehand''' 16 if hasattr(process,
"patPF2PATSequence"):
18 if label
in defaultLabels
and hasattr(process, label+postfix):
19 result = getattr(process, label+postfix)
20 elif hasattr(process, label):
21 print "WARNING: called applyPostfix for module/sequence %s which is not in patHeavyIonDefaultSequence%s!"%(label,postfix)
22 result = getattr(process, label)
27 if target+postfix
in labels:
28 getattr(process, sequenceLabel+postfix).
remove(
29 getattr(process, target+postfix)
33 result = [ m.label()[:-len(postfix)]
for m
in listModules( getattr(process,sequenceLabel+postfix))]
34 result.extend([ m.label()[:-len(postfix)]
for m
in listSequences( getattr(process,sequenceLabel+postfix))] )
36 result = [ m.label()
for m
in listModules( getattr(process,sequenceLabel+postfix))]
37 result.extend([ m.label()
for m
in listSequences( getattr(process,sequenceLabel+postfix))] )
42 """Visitor that travels within a cms.Sequence, and returns a list of objects of type gatheredInance(e.g. modules) that have it""" 43 def __init__(self, gatheredInstance=cms._Module):
48 self._modules.append(visitee)
55 """Visitor that travels within a cms.Sequence, and returns a cloned version of the Sequence. 56 All modules and sequences are cloned and a postfix is added""" 68 if isinstance(visitee,cms._Module):
69 label = visitee.label()
74 self._moduleLabels.append(label)
76 newModule = visitee.clone()
80 if isinstance(visitee,cms.Sequence):
83 self._sequenceStack.append( getattr(self.
_process, visitee.label()+self.
_postfix) )
85 self._sequenceStack.append(visitee.label())
88 if isinstance(visitee,cms.Sequence):
105 oldSequenceLabel = self._sequenceStack.pop()
106 newSequenceLabel = oldSequenceLabel + self.
_postfix 107 self._sequenceStack.append(cms.Sequence(visitee))
108 if hasattr(self.
_process, newSequenceLabel):
111 self._sequenceLabels.append(oldSequenceLabel)
117 sequence.visit(visitor)
118 return visitor.modules()
122 sequence.visit(visitor)
123 return visitor.modules()
127 ------------------------------------------------------------------ 128 return the string of the jet collection module depending on the 129 input vaules. The default return value will be 'patAK5CaloJets'. 131 algo : indicating the algorithm type of the jet [expected are 132 'AK5', 'IC5', 'SC7', ...] 133 type : indicating the type of constituents of the jet [expec- 134 ted are 'Calo', 'PFlow', 'JPT', ...] 135 prefix : prefix indicating the type of pat collection module (ex- 136 pected are '', 'selected', 'clean'). 137 ------------------------------------------------------------------ 140 jetCollectionString =
'pat' 142 jetCollectionString =prefix
143 jetCollectionString+=
'Pat' 144 jetCollectionString+=
'Jets' 145 jetCollectionString+=algo
146 jetCollectionString+=type
147 return jetCollectionString
151 ------------------------------------------------------------------ 152 return True if a module with name 'module' is contained in the 153 sequence with name 'sequence' and False otherwise. This version 154 is not so nice as it also returns True for any substr of the name 155 of a contained module. 157 sequence : sequence [e.g. process.patHeavyIonDefaultSequence] 158 module : module name as a string 159 ------------------------------------------------------------------ 161 return not sequence.__str__().
find(moduleName)==-1
167 ------------------------------------------------------------------ 168 copy a sequence plus the modules and sequences therein 169 both are renamed by getting a postfix 170 input tags are automatically adjusted 171 ------------------------------------------------------------------ 174 if not postfix ==
"":
176 sequence.visit(visitor)
177 result = visitor.clonedSequence()
180 if __name__==
"__main__":
187 p = cms.Process(
"test")
188 p.a = cms.EDProducer(
"a", src=cms.InputTag(
"gen"))
189 p.b = cms.EDProducer(
"b", src=cms.InputTag(
"a"))
190 p.c = cms.EDProducer(
"c", src=cms.InputTag(
"b",
"instance"))
191 p.s = cms.Sequence(p.a*p.b*p.c *p.a)
193 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')
195 p = cms.Process(
"test")
196 p.a = cms.EDProducer(
"a", src=cms.InputTag(
"gen"))
197 p.b = cms.EDProducer(
"ab", src=cms.InputTag(
"a"))
198 p.c = cms.EDProducer(
"ac", src=cms.InputTag(
"b"))
199 p.s1 = cms.Sequence(p.a*p.b*p.c)
200 p.s2 = cms.Sequence(p.b*p.c)
202 self.assert_(
not contains(p.s2,
"a") )
205 self.assertEqual(
jetCollectionString(prefix =
'prefix', algo =
'Foo', type =
'Bar'),
'prefixPatFooBarJets')
207 p = cms.Process(
"test")
208 p.a = cms.EDProducer(
"a", src=cms.InputTag(
"gen"))
209 p.b = cms.EDProducer(
"ab", src=cms.InputTag(
"a"))
210 p.c = cms.EDProducer(
"ac", src=cms.InputTag(
"b"))
211 p.s = cms.Sequence(p.a*p.b*p.c)
def massSearchReplaceAnyInputTag(sequence, oldInputTag, newInputTag, verbose=False, moduleLabelOnly=False, skipLabelTest=False)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
def remove(d, key, TELL=False)