1 from Mixins
import _ConfigureComponent, saveOrigin
2 from Mixins
import _Unlabelable, _Labelable
3 from Mixins
import _TypedParameterizable, _Parameterizable, PrintOptions
4 from SequenceTypes
import _SequenceLeaf
5 from Types
import vstring
7 from ExceptionHandling
import *
10 super(Service,self).
__init__(type_,*arg,**kargs)
12 proc._placeService(self.
type_(),self)
14 newpset = processDesc.newPSet()
15 newpset.addString(
True,
"@service_type", self.
type_())
17 processDesc.addService(newpset)
22 super(ESSource,self).
__init__(type_,*arg,**kargs)
27 proc._placeESSource(name,self)
30 if self.
type_() == myname:
40 super(ESProducer,self).
__init__(type_,*arg,**kargs)
44 proc._placeESProducer(name,self)
47 if self.
type_() == myname:
56 """Used to set which EventSetup provider should provide a particular data item
57 in the case where multiple providers are capable of delivering the data.
58 The first argument specifies the C++ class type of the prodiver.
59 If the provider has been given a label, you must specify that label as the second argument.
60 Additional 'vstring' arguments maybe used to specify exactly which EventSetup Records
61 are being preferred and optionally which data items within that Record.
63 #prefer all data in record 'OrangeRecord' from 'juicer'
64 ESPrefer("ESJuicerProd", OrangeRecord=cms.vstring())
66 #prefer only "Orange" data in "OrangeRecord" from "juicer"
67 ESPrefer("ESJuicerProd", OrangeRecord=cms.vstring("ExtraPulp"))
69 #prefer only "Orange" data with label "ExtraPulp" in "OrangeRecord" from "juicer"
70 ESPrefer("ESJuicerProd", OrangeRecord=cms.vstring("Orange/ExtraPulp"))
72 def __init__(self,type_,targetLabel='',*arg,**kargs):
73 super(ESPrefer,self).
__init__(type_,*arg,**kargs)
75 if targetLabel
is None:
78 for k,v
in kargs.iteritems():
79 if not isinstance(v,vstring):
80 raise RuntimeError(
'ESPrefer only allows vstring attributes. "'+k+
'" is a '+str(type(v)))
82 proc._placeESPrefer(name,self)
87 returnValue = ESPrefer.__new__(type(self))
95 result = options.indentation()
98 basename = self.
type_()
101 result +=
'process.prefer("'+basename+
'"'
103 result +=
",\n"+_Parameterizable.dumpPython(self,options)+options.indentation()
107 result +=
'es_prefer_'+basename+
' = cms.ESPrefer("'+self.
type_()+
'"'
111 result +=
",\n"+_Parameterizable.dumpPython(self,options)+options.indentation()
116 """base class for classes which denote framework event based 'modules'"""
119 super(_Module,self).
__init__(type_,*arg,**kargs)
120 if _Module.__isStrict__:
125 return lookuptable[id(self)]
131 return "%s('%s', ...)" %(typename, self.type_())
134 self.__dict__[
"libraries_"] = libs
137 if "libraries_" in self.__dict__:
138 from ctypes
import LibraryLoader, CDLL
140 loader = LibraryLoader(CDLL)
141 ext = platform.uname()[0] ==
"Darwin" and "dylib" or "so"
142 [loader.LoadLibrary(
"lib%s.%s" % (l, ext))
for l
in self.libraries_]
143 super(_Module,self).
insertInto(parameterSet,myname)
147 super(EDProducer,self).
__init__(type_,*arg,**kargs)
149 proc._placeProducer(name,self)
154 super(EDFilter,self).
__init__(type_,*arg,**kargs)
156 proc._placeFilter(name,self)
161 super(EDAnalyzer,self).
__init__(type_,*arg,**kargs)
163 proc._placeAnalyzer(name,self)
168 super(OutputModule,self).
__init__(type_,*arg,**kargs)
170 proc._placeOutputModule(name,self)
175 super(Source,self).
__init__(type_,*arg,**kargs)
177 proc._placeSource(name,self)
186 super(Looper,self).
__init__(type_,*arg,**kargs)
188 proc._placeLooper(name,self)
190 return "@main_looper"
192 return "@main_looper"
196 if __name__ ==
"__main__":
199 from SequenceTypes
import *
204 self.assertEqual(withParam.foo.value(), 1)
205 self.assertEqual(withParam.bar.value(),
"it")
206 aCopy = withParam.copy()
207 self.assertEqual(aCopy.foo.value(), 1)
208 self.assertEqual(aCopy.bar.value(),
"it")
210 self.assertEqual(withType.type.value(),1)
213 self.assertEqual(9, m.i.value())
214 self.assertEqual(10, m.j.value())
219 self.assertEqual(juicer.dumpPythonAs(
"juicer", options),
"process.prefer(\"JuiceProducer\")\n")
220 options.isCfg =
False
221 self.assertEqual(juicer.dumpPythonAs(
"juicer", options),
"es_prefer_JuiceProducer = cms.ESPrefer(\"JuiceProducer\")\n")
223 juicer =
ESPrefer(
"JuiceProducer",
"juicer")
226 self.assertEqual(juicer.dumpPythonAs(
"juicer", options),
'process.prefer("juicer")\n')
227 options.isCfg =
False
228 self.assertEqual(juicer.dumpPythonAs(
"juicer", options),
'es_prefer_juicer = cms.ESPrefer("JuiceProducer","juicer")\n')
230 self.assertEqual(juicer.dumpConfig(options),
239 self.assertEqual(juicer.dumpPythonAs(
"juicer"),
240 """process.prefer("JuiceProducer",
241 fooRcd = cms.vstring()
244 options.isCfg =
False
245 self.assertEqual(juicer.dumpPythonAs(
"juicer", options),
246 """es_prefer_JuiceProducer = cms.ESPrefer("JuiceProducer",
247 fooRcd = cms.vstring()
254 self.assertEqual(withParam.foo.value(), 1)
255 self.assertEqual(withParam.bar.value(),
"it")
256 self.assertEqual(empty.dumpPython(),
"cms.Service(\"Empty\")\n")
257 self.assertEqual(withParam.dumpPython(),
"cms.Service(\"Parameterized\",\n bar = cms.untracked.string(\'it\'),\n foo = cms.untracked.int32(1)\n)\n")