13 if ROOT.gSystem.FindDynamicLibrary (
"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())
42 ROOT.xAOD.TEvent.record_impl = ROOT.xAOD.TEvent.record
43 def record (event, obj, key, basketSize=32000, splitLevel = 1):
44 return event.record_impl (obj,
45 _typename (obj.__class__),
47 basketSize, splitLevel)
48 ROOT.xAOD.TEvent.record = record
53 cvec_cls=ROOT.DataVector(ROOT.DMTest.C_v1)
54 cel_cls=ROOT.ElementLink(cvec_cls)
61 def format_el(x):
return '%s[%s]' % (x.dataID(), (
'inv' if x.isDefaultIndex()
else x.index()))
65 return '[' +
','.
join(l) +
']'
68 return '[' +
','.
join(l) +
']'
71 return '[' +
','.
join(l) +
']'
72 CVec_type = ROOT.DataVector(ROOT.DMTest.C_v1)
74 'int' : (ROOT.SG.ConstAccessor(int), format_int),
75 'unsigned int' : (getattr (ROOT,
'SG::ConstAccessor<unsigned int>'), format_int),
76 'float' : (ROOT.SG.ConstAccessor(float), format_float),
77 'std::vector<float>' : (getattr (ROOT,
'SG::ConstAccessor<std::vector<float> >'), format_float_vec),
78 'std::vector<int>' : (getattr (ROOT,
'SG::ConstAccessor<std::vector<int> >'), format_int_vec),
79 'ElementLink<DataVector<DMTest::C_v1> >' :
80 (ROOT.SG.ConstAccessor(cel_cls), format_el),
81 'SG::JaggedVecElt<int>' :
82 (ROOT.SG.ConstAccessor(ROOT.SG.JaggedVecElt(ROOT.int)),
84 'SG::JaggedVecElt<float>' :
85 (ROOT.SG.ConstAccessor(ROOT.SG.JaggedVecElt(ROOT.float)),
87 'SG::JaggedVecElt<double>' :
88 (ROOT.SG.ConstAccessor(ROOT.SG.JaggedVecElt(ROOT.double)),
90 'SG::JaggedVecElt<std::string>' :
91 (ROOT.SG.ConstAccessor(ROOT.SG.JaggedVecElt(ROOT.std.string)),
93 'SG::JaggedVecElt<ElementLink<DataVector<DMTest::C_v1> > >' :
94 (ROOT.SG.ConstAccessor(ROOT.SG.JaggedVecElt(ROOT.ElementLink(CVec_type))),
96 'SG::PackedLink<DataVector<DMTest::C_v1> >' :
97 (ROOT.SG.ConstAccessor(ROOT.SG.PackedLink(ROOT.DataVector(ROOT.DMTest.C_v1))),
99 'std::vector<SG::PackedLink<DataVector<DMTest::C_v1> > >' :
100 (ROOT.SG.ConstAccessor(ROOT.std.vector(ROOT.SG.PackedLink(ROOT.DataVector(ROOT.DMTest.C_v1)))),
105 tname = reg.getTypeName (auxid)
106 ac_p = accessors.get (tname)
108 print (
'<unknown %s>'%tname, end=
'', file=f)
110 (ac_cl, formatter) = ac_p
111 val = ac_cl(reg.getName(auxid))(x)
112 print (
formatter(val) +
'; ', end=
'', file=f)
117 auxids =
list(x.getAuxIDs())
118 auxids = [(reg.getName(id), id)
for id
in auxids]
120 for name, auxid
in auxids:
121 if name
in exclude:
continue
122 if reg.isLinked (auxid):
continue
123 print (name +
': ', file=f, end=
'')
124 dump_auxitem (x, auxid, f)
129 if hasattr(c,
'__deref__'):
131 print (
' anInt1: %d; aFloat: %.1f; ' % (c.anInt(), c.aFloat()), end=
'')
132 dump_auxdata (c, exclude = [
'anInt1',
'aFloat'])
138 if hasattr(h,
'__deref__'):
146 if hasattr(p,
'__deref__'):
154 copy = obj.__class__()
155 copy_aux = obj.getConstStore().__class__()
156 copy.setNonConstStore (copy_aux)
157 copy.__assign__ (obj)
158 CHECK (event.record (copy, key))
159 CHECK (event.record (copy_aux, key +
'Aux.'))
160 ROOT.SetOwnership (copy,
False)
161 ROOT.SetOwnership (copy_aux,
False)
166 copy = obj.__class__()
167 copy_aux = obj.getConstStore().__class__()
168 copy.setNonConstStore (copy_aux)
169 for i
in range(obj.size()):
171 if _typename (elt_orig.__class__).startswith (
'DataModel_detail::ElementProxy<'):
172 elt_orig = elt_orig.__follow__()
173 elt = elt_orig.__class__()
175 ROOT.SetOwnership (elt,
False)
176 elt.__assign__ (elt_orig)
177 CHECK (event.record (copy, key))
178 CHECK (event.record (copy_aux, key +
'Aux.'))
179 ROOT.SetOwnership (copy,
False)
180 ROOT.SetOwnership (copy_aux,
False)
185 copy = obj.__class__(obj)
187 CHECK (event.record (copy, key))
188 ROOT.SetOwnership (copy,
False)
200 vec = getattr (tree, self.
readPrefix +
'cvec')
205 cinfo = getattr (tree, self.
readPrefix +
'cinfo')
209 ctrig = getattr (tree, self.
readPrefix +
'ctrig')
213 vec = getattr (tree, self.
readPrefix +
'cvecWD')
214 print (self.
readPrefix +
'cvecWD' +
' ', vec.meta1)
218 vec = getattr (tree, self.
readPrefix +
'cview')
224 vec = getattr (tree, self.
readPrefix +
'pvec')
229 vec = getattr (tree, self.
readPrefix +
'hvec')
234 vec = getattr (tree, self.
readPrefix +
'jvecContainer')
239 jvecInfo = getattr (tree, self.
readPrefix +
'jvecInfo')
240 dump_xaodobj (jvecInfo)
243 vec = getattr (tree, self.
readPrefix +
'plinksContainer')
248 plinksInfo = getattr (tree, self.
readPrefix +
'plinksInfo')
249 dump_plinks (plinksInfo)
260 def __init__ (self, readPrefix = '', writePrefix = None):
267 CHECK (event.copy (self.
readPrefix +
'cinfo'))
268 CHECK (event.copy (self.
readPrefix +
'ctrig'))
269 CHECK (event.copy (self.
readPrefix +
'cvecWD'))
270 CHECK (event.copy (self.
readPrefix +
'cview'))
273 CHECK (event.copy (self.
readPrefix +
'jvecContainer'))
274 CHECK (event.copy (self.
readPrefix +
'jvecInfo'))
275 CHECK (event.copy (self.
readPrefix +
'plinksContainer'))
276 CHECK (event.copy (self.
readPrefix +
'plinksInfo'))
280 cinfo = getattr (tree, self.
readPrefix +
'cinfo')
281 copy_obj (event, cinfo, self.
writePrefix +
'cinfo')
283 cvec = getattr (tree, self.
readPrefix +
'cvec')
286 ctrig = getattr (tree, self.
readPrefix +
'ctrig')
287 copy_vec (event, ctrig, self.
writePrefix +
'ctrig')
289 cvecwd = getattr (tree, self.
readPrefix +
'cvecWD')
290 copy_vec (event, cvecwd, self.
writePrefix +
'cvecWD')
292 cview = getattr (tree, self.
readPrefix +
'cview')
293 copy_view (event, cview, self.
writePrefix +
'cview')
295 pvec = getattr (tree, self.
readPrefix +
'pvec')
298 hvec = getattr (tree, self.
readPrefix +
'hvec')
301 jvec = getattr (tree, self.
readPrefix +
'jvecContainer')
302 copy_vec (event, jvec, self.
writePrefix +
'jvecContainer')
304 jvecinfo = getattr (tree, self.
readPrefix +
'jvecInfo')
305 copy_obj (event, jvecinfo, self.
writePrefix +
'jvecInfo')
307 plinks = getattr (tree, self.
readPrefix +
'plinksContainer')
308 copy_vec (event, plinks, self.
writePrefix +
'plinksContainer')
310 plinksinfo = getattr (tree, self.
readPrefix +
'plinksInfo')
311 copy_obj (event, plinksinfo, self.
writePrefix +
'plinksInfo')
320 def __init__ (self, decorName, offset=0, readPrefix = ''):
323 self.
decor = ROOT.SG.Decorator(int)(decorName)
328 cvec = getattr (tree, self.
readPrefix +
'cvec')
332 ctrig = getattr (tree, self.
readPrefix +
'ctrig')
336 cinfo = getattr (tree, self.
readPrefix +
'cinfo')
342 def __init__ (self, decorName, offset=0, readPrefix = ''):
345 self.
decor = ROOT.SG.Decorator(int)(decorName)
350 cvec = getattr (tree, self.
readPrefix +
'cvec')
351 assert cvec.setOption (self.
decor.auxid(), ROOT.SG.AuxDataOption (
'nbins', 23))
364 cvec = getattr (tree, self.
readPrefix +
'cvec')
365 cvec.clearDecorations()
367 ctrig = getattr (tree, self.
readPrefix +
'ctrig')
368 ctrig.clearDecorations()
370 cinfo = getattr (tree, self.
readPrefix +
'cinfo')
371 cinfo.clearDecorations()
378 cont = tree.AllocTest
379 print (
'AllocTest: ', end=
'')
381 print (a.atInt1(), a.atInt2(), end=
' ')
390 self.
f = ROOT.TFile (ifname)
391 self.
event = ROOT.xAOD.TEvent (ROOT.xAOD.TEvent.kAthenaAccess)
392 CHECK (self.
event.readFrom (self.
f,
True,
'CollectionTree'))
393 self.
tree = ROOT.xAOD.MakeTransientTree(self.
event,
'CollectionTree')
396 self.
fout = ROOT.TFile.Open (ofname,
'recreate')
401 self.
algs.append (alg)
408 for i
in range(nent):
409 self.
tree.GetEntry(i)
410 print (
'---> Event', i)
413 if self.
fout !=
None:
419 CHECK (self.
event.finishWritingTo (self.
fout))