1 from __future__
import print_function
2 import FWCore.ParameterSet.Config
as cms
9 from FWCore.ParameterSet.MassReplace
import massSearchReplaceAnyInputTag, MassSearchReplaceAnyInputTagVisitor
10 from FWCore.ParameterSet.MassReplace
import massSearchReplaceParam, MassSearchParamVisitor, MassSearchReplaceParamVisitor
13 ''' If a module is in patHeavyIonDefaultSequence use the cloned module. 14 Will crash if patHeavyIonDefaultSequence has not been cloned with 'postfix' beforehand''' 17 if hasattr(process,
"patPF2PATSequence"):
19 if label
in defaultLabels
and hasattr(process, label+postfix):
20 result = getattr(process, label+postfix)
21 elif hasattr(process, label):
22 print(
"WARNING: called applyPostfix for module/sequence %s which is not in patHeavyIonDefaultSequence%s!"%(label,postfix))
23 result = getattr(process, label)
28 if target+postfix
in labels:
29 getattr(process, sequenceLabel+postfix).
remove(
30 getattr(process, target+postfix)
34 result = [ m.label()[:-len(postfix)]
for m
in listModules( getattr(process,sequenceLabel+postfix))]
35 result.extend([ m.label()[:-len(postfix)]
for m
in listSequences( getattr(process,sequenceLabel+postfix))] )
37 result = [ m.label()
for m
in listModules( getattr(process,sequenceLabel+postfix))]
38 result.extend([ m.label()
for m
in listSequences( getattr(process,sequenceLabel+postfix))] )
43 """Visitor that travels within a cms.Sequence, and returns a list of objects of type gatheredInance(e.g. modules) that have it""" 44 def __init__(self, gatheredInstance=cms._Module):
49 self._modules.append(visitee)
56 """Visitor that travels within a cms.Sequence, and returns a cloned version of the Sequence. 57 All modules and sequences are cloned and a postfix is added""" 69 if isinstance(visitee,cms._Module):
70 label = visitee.label()
75 self._moduleLabels.append(label)
77 newModule = visitee.clone()
81 if isinstance(visitee,cms.Sequence):
84 self._sequenceStack.append( getattr(self.
_process, visitee.label()+self.
_postfix) )
86 self._sequenceStack.append(visitee.label())
89 if isinstance(visitee,cms.Sequence):
106 oldSequenceLabel = self._sequenceStack.pop()
107 newSequenceLabel = oldSequenceLabel + self.
_postfix 108 self._sequenceStack.append(cms.Sequence(visitee))
109 if hasattr(self.
_process, newSequenceLabel):
112 self._sequenceLabels.append(oldSequenceLabel)
118 sequence.visit(visitor)
119 return visitor.modules()
123 sequence.visit(visitor)
124 return visitor.modules()
128 ------------------------------------------------------------------ 129 return the string of the jet collection module depending on the 130 input vaules. The default return value will be 'patAK5CaloJets'. 132 algo : indicating the algorithm type of the jet [expected are 133 'AK5', 'IC5', 'SC7', ...] 134 type : indicating the type of constituents of the jet [expec- 135 ted are 'Calo', 'PFlow', 'JPT', ...] 136 prefix : prefix indicating the type of pat collection module (ex- 137 pected are '', 'selected', 'clean'). 138 ------------------------------------------------------------------ 141 jetCollectionString =
'pat' 143 jetCollectionString =prefix
144 jetCollectionString+=
'Pat' 145 jetCollectionString+=
'Jets' 146 jetCollectionString+=algo
147 jetCollectionString+=type
148 return jetCollectionString
152 ------------------------------------------------------------------ 153 return True if a module with name 'module' is contained in the 154 sequence with name 'sequence' and False otherwise. This version 155 is not so nice as it also returns True for any substr of the name 156 of a contained module. 158 sequence : sequence [e.g. process.patHeavyIonDefaultSequence] 159 module : module name as a string 160 ------------------------------------------------------------------ 162 return not sequence.__str__().
find(moduleName)==-1
168 ------------------------------------------------------------------ 169 copy a sequence plus the modules and sequences therein 170 both are renamed by getting a postfix 171 input tags are automatically adjusted 172 ------------------------------------------------------------------ 175 if not postfix ==
"":
177 sequence.visit(visitor)
178 result = visitor.clonedSequence()
181 if __name__==
"__main__":
188 p = cms.Process(
"test")
189 p.a = cms.EDProducer(
"a", src=cms.InputTag(
"gen"))
190 p.b = cms.EDProducer(
"b", src=cms.InputTag(
"a"))
191 p.c = cms.EDProducer(
"c", src=cms.InputTag(
"b",
"instance"))
192 p.s = cms.Sequence(p.a*p.b*p.c *p.a)
194 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')
196 p = cms.Process(
"test")
197 p.a = cms.EDProducer(
"a", src=cms.InputTag(
"gen"))
198 p.b = cms.EDProducer(
"ab", src=cms.InputTag(
"a"))
199 p.c = cms.EDProducer(
"ac", src=cms.InputTag(
"b"))
200 p.s1 = cms.Sequence(p.a*p.b*p.c)
201 p.s2 = cms.Sequence(p.b*p.c)
203 self.assert_(
not contains(p.s2,
"a") )
206 self.assertEqual(
jetCollectionString(prefix =
'prefix', algo =
'Foo', type =
'Bar'),
'prefixPatFooBarJets')
208 p = cms.Process(
"test")
209 p.a = cms.EDProducer(
"a", src=cms.InputTag(
"gen"))
210 p.b = cms.EDProducer(
"ab", src=cms.InputTag(
"a"))
211 p.c = cms.EDProducer(
"ac", src=cms.InputTag(
"b"))
212 p.s = cms.Sequence(p.a*p.b*p.c)
def massSearchReplaceAnyInputTag(sequence, oldInputTag, newInputTag, verbose=False, moduleLabelOnly=False, skipLabelTest=False)
S & print(S &os, JobReport::InputFile const &f)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
def remove(d, key, TELL=False)