13 if ROOT.gSystem.FindDynamicLibrary (cppyy.gbl.TString (
"libGaudiKernel"),
True):
14 ROOT.gSystem.Load(
"libGaudiKernel")
19 cppyy.load_library(
"libDataModelTestDataCommonDict")
20 if 'LOAD_WRITE_DIR' in globals():
21 cppyy.load_library(
"libDataModelTestDataWriteDict")
23 cppyy.load_library(
"libDataModelTestDataReadDict")
26 if not sc.isSuccess():
27 raise Exception (
'bad StatusCode')
32 reg=ROOT.SG.AuxTypeRegistry.instance()
35 return getattr (t,
'__cpp_name__', t.__name__)
39 CHECK(ROOT.xAOD.Init())
44 cvec_cls=ROOT.DataVector(ROOT.DMTest.C_v1)
45 cel_cls=ROOT.ElementLink(cvec_cls)
52 def format_el(x):
return '%s[%s]' % (x.dataID(), (
'inv' if x.isDefaultIndex()
else x.index()))
56 return '[' +
','.
join(l) +
']'
59 return '[' +
','.
join(l) +
']'
62 return '[' +
','.
join(l) +
']'
63 CVec_type = ROOT.DataVector(ROOT.DMTest.C_v1)
65 'int' : (ROOT.SG.ConstAccessor(int), format_int),
66 'unsigned int' : (getattr (ROOT,
'SG::ConstAccessor<unsigned int>'), format_int),
67 'float' : (ROOT.SG.ConstAccessor(float), format_float),
68 'std::vector<float>' : (getattr (ROOT,
'SG::ConstAccessor<std::vector<float> >'), format_float_vec),
69 'std::vector<int>' : (getattr (ROOT,
'SG::ConstAccessor<std::vector<int> >'), format_int_vec),
70 'ElementLink<DataVector<DMTest::C_v1> >' :
71 (ROOT.SG.ConstAccessor(cel_cls), format_el),
72 'SG::JaggedVecElt<int>' :
73 (ROOT.SG.ConstAccessor(ROOT.SG.JaggedVecElt(ROOT.int)),
75 'SG::JaggedVecElt<float>' :
76 (ROOT.SG.ConstAccessor(ROOT.SG.JaggedVecElt(ROOT.float)),
78 'SG::JaggedVecElt<double>' :
79 (ROOT.SG.ConstAccessor(ROOT.SG.JaggedVecElt(ROOT.double)),
81 'SG::JaggedVecElt<std::string>' :
82 (ROOT.SG.ConstAccessor(ROOT.SG.JaggedVecElt(ROOT.std.string)),
84 'SG::JaggedVecElt<ElementLink<DataVector<DMTest::C_v1> > >' :
85 (ROOT.SG.ConstAccessor(ROOT.SG.JaggedVecElt(ROOT.ElementLink(CVec_type))),
87 'SG::PackedLink<DataVector<DMTest::C_v1> >' :
88 (ROOT.SG.ConstAccessor(ROOT.SG.PackedLink(ROOT.DataVector(ROOT.DMTest.C_v1))),
90 'std::vector<SG::PackedLink<DataVector<DMTest::C_v1> > >' :
91 (ROOT.SG.ConstAccessor(ROOT.std.vector(ROOT.SG.PackedLink(ROOT.DataVector(ROOT.DMTest.C_v1)))),
96 tname = reg.getTypeName (auxid)
97 ac_p = accessors.get (tname)
99 print (
'<unknown %s>'%tname, end=
'', file=f)
101 (ac_cl, formatter) = ac_p
102 val = ac_cl(reg.getName(auxid))(x)
103 print (
formatter(val) +
'; ', end=
'', file=f)
108 auxids =
list(x.getAuxIDs())
109 auxids = [(reg.getName(id), id)
for id
in auxids]
111 for name, auxid
in auxids:
112 if name
in exclude:
continue
113 if reg.isLinked (auxid):
continue
114 print (name +
': ', file=f, end=
'')
115 dump_auxitem (x, auxid, f)
120 if hasattr(c,
'__deref__'):
122 print (
' anInt1: %d; aFloat: %.1f; ' % (c.anInt(), c.aFloat()), end=
'')
123 dump_auxdata (c, exclude = [
'anInt1',
'aFloat'])
129 if hasattr(h,
'__deref__'):
137 if hasattr(p,
'__deref__'):
145 copy = obj.__class__()
146 copy_aux = obj.getConstStore().__class__()
147 copy.setNonConstStore (copy_aux)
148 copy.__assign__ (obj)
149 CHECK (event.record (copy, key))
150 CHECK (event.record (copy_aux, key +
'Aux.'))
151 ROOT.SetOwnership (copy,
False)
152 ROOT.SetOwnership (copy_aux,
False)
157 copy = obj.__class__()
158 copy_aux = obj.getConstStore().__class__()
159 copy.setNonConstStore (copy_aux)
160 for i
in range(obj.size()):
162 if _typename (elt_orig.__class__).startswith (
'DataModel_detail::ElementProxy<'):
163 elt_orig = elt_orig.__follow__()
164 elt = elt_orig.__class__()
166 ROOT.SetOwnership (elt,
False)
167 elt.__assign__ (elt_orig)
168 CHECK (event.record (copy, key))
169 CHECK (event.record (copy_aux, key +
'Aux.'))
170 ROOT.SetOwnership (copy,
False)
171 ROOT.SetOwnership (copy_aux,
False)
176 copy = obj.__class__(obj)
178 CHECK (event.record (copy, key))
179 ROOT.SetOwnership (copy,
False)
205 print (self.
readPrefix +
'cvecWD' +
' ', vec.meta1)
225 vec = event[self.
readPrefix +
'jvecContainer']
230 jvecInfo = event[self.
readPrefix +
'jvecInfo']
231 dump_xaodobj (jvecInfo)
234 vec = event[self.
readPrefix +
'plinksContainer']
239 plinksInfo = event[self.
readPrefix +
'plinksInfo']
240 dump_plinks (plinksInfo)
251 def __init__ (self, readPrefix = '', writePrefix = None):
258 CHECK (event.copy (self.
readPrefix +
'cinfo'))
259 CHECK (event.copy (self.
readPrefix +
'ctrig'))
260 CHECK (event.copy (self.
readPrefix +
'cvecWD'))
261 CHECK (event.copy (self.
readPrefix +
'cview'))
264 CHECK (event.copy (self.
readPrefix +
'jvecContainer'))
265 CHECK (event.copy (self.
readPrefix +
'jvecInfo'))
266 CHECK (event.copy (self.
readPrefix +
'plinksContainer'))
267 CHECK (event.copy (self.
readPrefix +
'plinksInfo'))
272 copy_obj (event, cinfo, self.
writePrefix +
'cinfo')
278 copy_vec (event, ctrig, self.
writePrefix +
'ctrig')
281 copy_vec (event, cvecwd, self.
writePrefix +
'cvecWD')
284 copy_view (event, cview, self.
writePrefix +
'cview')
292 jvec = event[self.
readPrefix +
'jvecContainer']
293 copy_vec (event, jvec, self.
writePrefix +
'jvecContainer')
295 jvecinfo = event[self.
readPrefix +
'jvecInfo']
296 copy_obj (event, jvecinfo, self.
writePrefix +
'jvecInfo')
298 plinks = event[self.
readPrefix +
'plinksContainer']
299 copy_vec (event, plinks, self.
writePrefix +
'plinksContainer')
301 plinksinfo = event[self.
readPrefix +
'plinksInfo']
302 copy_obj (event, plinksinfo, self.
writePrefix +
'plinksInfo')
311 def __init__ (self, decorName, offset=0, readPrefix = ''):
314 self.
decor = ROOT.SG.Decorator(int)(decorName)
333 def __init__ (self, decorName, offset=0, readPrefix = ''):
336 self.
decor = ROOT.SG.Decorator(int)(decorName)
342 assert cvec.setOption (self.
decor.auxid(), ROOT.SG.AuxDataOption (
'nbins', 23))
356 cvec.clearDecorations()
359 ctrig.clearDecorations()
362 cinfo.clearDecorations()
369 cont = event[
'AllocTest']
370 print (
'AllocTest: ', end=
'')
372 print (a.atInt1(), a.atInt2(), end=
' ')
381 self.
f = ROOT.TFile (ifname)
382 from xAODRootAccess.TPyEvent
import TPyEvent
383 self.
event = TPyEvent (ROOT.xAOD.TEvent.kAthenaAccess)
384 CHECK (self.
event.readFrom (self.
f,
True,
'CollectionTree'))
387 self.
fout = ROOT.TFile.Open (ofname,
'recreate')
392 self.
algs.append (alg)
396 nent = self.
event.getEntries()
399 for i
in range(nent):
400 self.
event.getEntry(i)
401 print (
'---> Event', i)
403 a.execute (self.
event)
404 if self.
fout !=
None:
410 CHECK (self.
event.finishWritingTo (self.
fout))