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())
41 if len(sys.argv) >= 2
and sys.argv[1] ==
'--rntuple':
47 cvec_cls=ROOT.DataVector(ROOT.DMTest.C_v1)
48 cel_cls=ROOT.ElementLink(cvec_cls)
55 def format_el(x):
return '%s[%s]' % (x.dataID(), (
'inv' if x.isDefaultIndex()
else x.index()))
59 return '[' +
','.
join(l) +
']'
62 return '[' +
','.
join(l) +
']'
65 return '[' +
','.
join(l) +
']'
66 CVec_type = ROOT.DataVector(ROOT.DMTest.C_v1)
68 'int' : (ROOT.SG.ConstAccessor(int), format_int),
69 'unsigned int' : (getattr (ROOT,
'SG::ConstAccessor<unsigned int>'), format_int),
70 'float' : (ROOT.SG.ConstAccessor(float), format_float),
71 'std::vector<float>' : (getattr (ROOT,
'SG::ConstAccessor<std::vector<float> >'), format_float_vec),
72 'std::vector<int>' : (getattr (ROOT,
'SG::ConstAccessor<std::vector<int> >'), format_int_vec),
73 'ElementLink<DataVector<DMTest::C_v1> >' :
74 (ROOT.SG.ConstAccessor(cel_cls), format_el),
75 'SG::JaggedVecElt<int>' :
76 (ROOT.SG.ConstAccessor(ROOT.SG.JaggedVecElt(ROOT.int)),
78 'SG::JaggedVecElt<float>' :
79 (ROOT.SG.ConstAccessor(ROOT.SG.JaggedVecElt(ROOT.float)),
81 'SG::JaggedVecElt<double>' :
82 (ROOT.SG.ConstAccessor(ROOT.SG.JaggedVecElt(ROOT.double)),
84 'SG::JaggedVecElt<std::string>' :
85 (ROOT.SG.ConstAccessor(ROOT.SG.JaggedVecElt(ROOT.std.string)),
87 'SG::JaggedVecElt<ElementLink<DataVector<DMTest::C_v1> > >' :
88 (ROOT.SG.ConstAccessor(ROOT.SG.JaggedVecElt(ROOT.ElementLink(CVec_type))),
90 'SG::PackedLink<DataVector<DMTest::C_v1> >' :
91 (ROOT.SG.ConstAccessor(ROOT.SG.PackedLink(ROOT.DataVector(ROOT.DMTest.C_v1))),
93 'std::vector<SG::PackedLink<DataVector<DMTest::C_v1> > >' :
94 (ROOT.SG.ConstAccessor(ROOT.std.vector(ROOT.SG.PackedLink(ROOT.DataVector(ROOT.DMTest.C_v1)))),
99 tname = reg.getTypeName (auxid)
100 ac_p = accessors.get (tname)
102 print (
'<unknown %s>'%tname, end=
'', file=f)
104 (ac_cl, formatter) = ac_p
105 val = ac_cl(reg.getName(auxid))(x)
106 print (
formatter(val) +
'; ', end=
'', file=f)
111 auxids =
list(x.getAuxIDs())
112 auxids = [(reg.getName(id), id)
for id
in auxids]
114 for name, auxid
in auxids:
115 if name
in exclude:
continue
116 if reg.isLinked (auxid):
continue
117 print (name +
': ', file=f, end=
'')
118 dump_auxitem (x, auxid, f)
123 if hasattr(c,
'__deref__'):
125 print (
' anInt1: %d; aFloat: %.1f; ' % (c.anInt(), c.aFloat()), end=
'')
126 dump_auxdata (c, exclude = [
'anInt1',
'aFloat'])
132 if hasattr(h,
'__deref__'):
140 if hasattr(p,
'__deref__'):
148 copy = obj.__class__()
149 copy_aux = obj.getConstStore().__class__()
150 copy.setNonConstStore (copy_aux)
151 copy.__assign__ (obj)
152 CHECK (event.record (copy, key))
153 CHECK (event.record (copy_aux, key +
'Aux.'))
154 ROOT.SetOwnership (copy,
False)
155 ROOT.SetOwnership (copy_aux,
False)
160 copy = obj.__class__()
161 copy_aux = obj.getConstStore().__class__()
162 copy.setNonConstStore (copy_aux)
163 for i
in range(obj.size()):
165 if _typename (elt_orig.__class__).startswith (
'DataModel_detail::ElementProxy<'):
166 elt_orig = elt_orig.__follow__()
167 elt = elt_orig.__class__()
169 ROOT.SetOwnership (elt,
False)
170 elt.__assign__ (elt_orig)
171 CHECK (event.record (copy, key))
172 CHECK (event.record (copy_aux, key +
'Aux.'))
173 ROOT.SetOwnership (copy,
False)
174 ROOT.SetOwnership (copy_aux,
False)
179 copy = obj.__class__(obj)
181 CHECK (event.record (copy, key))
182 ROOT.SetOwnership (copy,
False)
209 print (self.
readPrefix +
'cvecWD' +
' ', vec.meta1)
230 vec = event[self.
readPrefix +
'jvecContainer']
235 jvecInfo = event[self.
readPrefix +
'jvecInfo']
236 dump_xaodobj (jvecInfo)
239 vec = event[self.
readPrefix +
'plinksContainer']
244 plinksInfo = event[self.
readPrefix +
'plinksInfo']
245 dump_plinks (plinksInfo)
256 def __init__ (self, readPrefix = '', writePrefix = None):
263 CHECK (event.copy (self.
readPrefix +
'cinfo'))
264 CHECK (event.copy (self.
readPrefix +
'ctrig'))
265 CHECK (event.copy (self.
readPrefix +
'cvecWD'))
266 CHECK (event.copy (self.
readPrefix +
'cview'))
269 CHECK (event.copy (self.
readPrefix +
'jvecContainer'))
270 CHECK (event.copy (self.
readPrefix +
'jvecInfo'))
271 CHECK (event.copy (self.
readPrefix +
'plinksContainer'))
272 CHECK (event.copy (self.
readPrefix +
'plinksInfo'))
277 copy_obj (event, cinfo, self.
writePrefix +
'cinfo')
283 copy_vec (event, ctrig, self.
writePrefix +
'ctrig')
286 copy_vec (event, cvecwd, self.
writePrefix +
'cvecWD')
289 copy_view (event, cview, self.
writePrefix +
'cview')
297 jvec = event[self.
readPrefix +
'jvecContainer']
298 copy_vec (event, jvec, self.
writePrefix +
'jvecContainer')
300 jvecinfo = event[self.
readPrefix +
'jvecInfo']
301 copy_obj (event, jvecinfo, self.
writePrefix +
'jvecInfo')
303 plinks = event[self.
readPrefix +
'plinksContainer']
304 copy_vec (event, plinks, self.
writePrefix +
'plinksContainer')
306 plinksinfo = event[self.
readPrefix +
'plinksInfo']
307 copy_obj (event, plinksinfo, self.
writePrefix +
'plinksInfo')
316 def __init__ (self, decorName, offset=0, readPrefix = ''):
319 self.
decor = ROOT.SG.Decorator(int)(decorName)
338 def __init__ (self, decorName, offset=0, readPrefix = ''):
341 self.
decor = ROOT.SG.Decorator(int)(decorName)
347 assert cvec.setOption (self.
decor.auxid(), ROOT.SG.AuxDataOption (
'nbins', 23))
361 cvec.clearDecorations()
364 ctrig.clearDecorations()
367 cinfo.clearDecorations()
374 cont = event[
'AllocTest']
375 print (
'AllocTest: ', end=
'')
377 print (a.atInt1(), a.atInt2(), end=
' ')
384 def __init__ (self, ifname, ofname = None, is_rntuple = False):
387 from xAODRootAccess.RPyEvent
import RPyEvent
389 CHECK (self.
event.readFrom (ifname))
391 from xAODRootAccess.TPyEvent
import TPyEvent
392 self.
f = ROOT.TFile (ifname)
393 self.
event = TPyEvent (TPyEvent.kAthenaAccess)
394 CHECK (self.
event.readFrom (self.
f,
True,
'CollectionTree'))
397 self.
fout = ROOT.TFile.Open (ofname,
'recreate')
402 self.
algs.append (alg)
406 nent = self.
event.getEntries()
409 for i
in range(nent):
410 self.
event.getEntry(i)
411 print (
'---> Event', i)
413 a.execute (self.
event)
414 if self.
fout !=
None:
420 CHECK (self.
event.finishWritingTo (self.
fout))