TRef IO test

Dear Rooters,

With the attached exampel I tried to test TRef behaviour when save/read to/from tree.
From the output (below) it’s clear that only the last track object was saved correctly.
What is wrong with my example?

Thank you,
Valeri

Script output:
root [0] .x testref_tree.C++
Info in TUnixSystem::ACLiC: creating shared library ./testref_tree_C.so
------- write ------------
trk id = 0 TObjString = ev = 0 track = 0
trk id = 1 TObjString = ev = 0 track = 1
event=0 ntr = 2

trk id = 1000 TObjString = ev = 1 track = 0
trk id = 1001 TObjString = ev = 1 track = 1
event=1 ntr = 2

trk id = 2000 TObjString = ev = 2 track = 0
trk id = 2001 TObjString = ev = 2 track = 1
event=2 ntr = 2

------- read ------------
tree with 3 entries
vertex 0 ntr = 2
iv = 0 it=0 trk id = 2001 TObjString = ev = 2 track = 1
iv = 0 it=1 trk id = 2001 TObjString = ev = 2 track = 1
vertex 1 ntr = 2
iv = 1 it=0 trk id = 2001 TObjString = ev = 2 track = 1
iv = 1 it=1 trk id = 2001 TObjString = ev = 2 track = 1
vertex 2 ntr = 2
iv = 2 it=0 trk id = 2001 TObjString = ev = 2 track = 1
iv = 2 it=1 trk id = 2001 TObjString = ev = 2 track = 1
testref_tree.C (1.93 KB)

I note that there was a misprint in the uploaded script. Attach the correct version.

Valeri
testref_tree.C (2.04 KB)

Hi,

The objects you are referring to (the TObjString and the Track) are never stored in the file. The TRef and TRefArray only store referenced to the objects and assumes that they are stored and/or managed somewhere else.

So simply add a regular collection of Tracks to the TTree in a separate branch.

Cheers,
Philippe.