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)
60 def format_el(x):
return '%s[%d]' % (x.dataID(), x.index())
63 return '[' +
','.
join(l) +
']'
66 return '[' +
','.
join(l) +
']'
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),
78 tname = reg.getTypeName (auxid)
79 ac_p = accessors.get (tname)
81 print (
'<unknown %s>'%tname, end=
'', file=f)
83 (ac_cl, formatter) = ac_p
84 val = ac_cl(reg.getName(auxid))(x)
85 print (
formatter(val) +
'; ', end=
'', file=f)
90 auxids =
list(x.getAuxIDs())
91 auxids = [(reg.getName(id), id)
for id
in auxids]
93 for name, auxid
in auxids:
94 if name
in exclude:
continue
95 print (name +
': ', file=f, end=
'')
96 dump_auxitem (x, auxid, f)
101 if hasattr(c,
'__deref__'):
103 print (
' anInt1: %d; aFloat: %.1f; ' % (c.anInt(), c.aFloat()), end=
'')
104 dump_auxdata (c, exclude = [
'anInt1',
'aFloat'])
110 if hasattr(h,
'__deref__'):
118 copy = obj.__class__()
119 copy_aux = obj.getConstStore().__class__()
120 copy.setNonConstStore (copy_aux)
121 copy.__assign__ (obj)
122 CHECK (event.record (copy, key))
123 CHECK (event.record (copy_aux, key +
'Aux.'))
124 ROOT.SetOwnership (copy,
False)
125 ROOT.SetOwnership (copy_aux,
False)
130 copy = obj.__class__()
131 copy_aux = obj.getConstStore().__class__()
132 copy.setNonConstStore (copy_aux)
133 for i
in range(obj.size()):
135 if _typename (elt_orig.__class__).startswith (
'DataModel_detail::ElementProxy<'):
136 elt_orig = elt_orig.__follow__()
137 elt = elt_orig.__class__()
139 ROOT.SetOwnership (elt,
False)
140 elt.__assign__ (elt_orig)
141 CHECK (event.record (copy, key))
142 CHECK (event.record (copy_aux, key +
'Aux.'))
143 ROOT.SetOwnership (copy,
False)
144 ROOT.SetOwnership (copy_aux,
False)
149 copy = obj.__class__(obj)
151 CHECK (event.record (copy, key))
152 ROOT.SetOwnership (copy,
False)
164 vec = getattr (tree, self.
readPrefix +
'cvec')
169 cinfo = getattr (tree, self.
readPrefix +
'cinfo')
173 ctrig = getattr (tree, self.
readPrefix +
'ctrig')
177 vec = getattr (tree, self.
readPrefix +
'cvecWD')
178 print (self.
readPrefix +
'cvecWD' +
' ', vec.meta1)
182 vec = getattr (tree, self.
readPrefix +
'cview')
188 vec = getattr (tree, self.
readPrefix +
'hvec')
201 def __init__ (self, readPrefix = '', writePrefix = None):
208 CHECK (event.copy (self.
readPrefix +
'cinfo'))
209 CHECK (event.copy (self.
readPrefix +
'ctrig'))
210 CHECK (event.copy (self.
readPrefix +
'cvecWD'))
211 CHECK (event.copy (self.
readPrefix +
'cview'))
216 cinfo = getattr (tree, self.
readPrefix +
'cinfo')
217 copy_obj (event, cinfo, self.
writePrefix +
'cinfo')
219 cvec = getattr (tree, self.
readPrefix +
'cvec')
222 ctrig = getattr (tree, self.
readPrefix +
'ctrig')
223 copy_vec (event, ctrig, self.
writePrefix +
'ctrig')
225 cvecwd = getattr (tree, self.
readPrefix +
'cvecWD')
226 copy_vec (event, cvecwd, self.
writePrefix +
'cvecWD')
228 cview = getattr (tree, self.
readPrefix +
'cview')
229 copy_view (event, cview, self.
writePrefix +
'cview')
231 hvec = getattr (tree, self.
readPrefix +
'hvec')
241 def __init__ (self, decorName, offset=0, readPrefix = ''):
244 self.
decor = ROOT.SG.Decorator(int)(decorName)
249 cvec = getattr (tree, self.
readPrefix +
'cvec')
253 ctrig = getattr (tree, self.
readPrefix +
'ctrig')
257 cinfo = getattr (tree, self.
readPrefix +
'cinfo')
263 def __init__ (self, decorName, offset=0, readPrefix = ''):
266 self.
decor = ROOT.SG.Decorator(int)(decorName)
271 cvec = getattr (tree, self.
readPrefix +
'cvec')
272 assert cvec.setOption (self.
decor.auxid(), ROOT.SG.AuxDataOption (
'nbins', 23))
285 cvec = getattr (tree, self.
readPrefix +
'cvec')
286 cvec.clearDecorations()
288 ctrig = getattr (tree, self.
readPrefix +
'ctrig')
289 ctrig.clearDecorations()
291 cinfo = getattr (tree, self.
readPrefix +
'cinfo')
292 cinfo.clearDecorations()
299 cont = tree.AllocTest
300 print (
'AllocTest: ', end=
'')
302 print (a.atInt1(), a.atInt2(), end=
' ')
311 self.
f = ROOT.TFile (ifname)
312 self.
event = ROOT.xAOD.TEvent (ROOT.xAOD.TEvent.kAthenaAccess)
313 CHECK (self.
event.readFrom (self.
f,
True,
'CollectionTree'))
314 self.
tree = ROOT.xAOD.MakeTransientTree(self.
event,
'CollectionTree')
317 self.
fout = ROOT.TFile.Open (ofname,
'recreate')
322 self.
algs.append (alg)
329 for i
in range(nent):
330 self.
tree.GetEntry(i)
331 print (
'---> Event', i)
334 if self.
fout !=
None:
340 CHECK (self.
event.finishWritingTo (self.
fout))