I have complex class “A” consists of TClonesArray of objects and TObjArrays contained pointers to some selected objects objects of TClonesArrays.
All elements of A and class itself are inhereted from TObject so I can use the default streamers as:
A a;
a.Fill…
TFile f(…)
a.Write(“a”)
f.Close()
It works perfectly.
The problem is that after reading of “a”, TObjArrays containes the pointers on the objects different from ones contained in TClonesArrays. The pointed objects are dupliceted after a.Write(), a.Read() .
This is the expected behavior when saving object in a TClonesArray that is either split or store
memberwise (your case).
I see… If I’m not mistaken it were not like that in versions of Root earlier then 3?
This behaviour can lead to difficult to debug errors and should be stressed in documentation whenever it possible.
To avoid the problem use a TRefArray instead of a TObjArray.
Actually I in code I use TObjArray of TSortedLists of pointers to objects. I think the proposed solution is hard to implement here. Probably it’s easier to redo reconstruction and regenerate pointers.
[quote]I see… If I’m not mistaken it were not like that in versions of Root earlier then 3?
[/quote]
It should have been. Do you have a concrete example where the behavior is different?
[quote]I think the proposed solution is hard to implement here. Probably it’s easier to redo reconstruction and regenerate pointers.
[/quote]
Still not very simple … but you could derire a class from TRef (to implement Compare) and have TObjArray of TSortedList of (derived from) TRef pointed to the object in the TClonesArray.