Duplication of pointer objects after RIO?

Hi,

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() .

Is it an expected behaviour?
How to avoid it?

Thanks
Valeri Tioukov

Hi,

To avoid the problem use a TRefArray instead of a TObjArray.

This is the expected behavior when saving object in a TClonesArray that is either split or store memberwise (your case).

Cheers,
Philippe.

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.

VT

[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.

Cheers,
Philippe.

I see… If I’m not mistaken it were not like that in versions of Root earlier then 3?

It should have been. Do you have a concrete example where the behavior is different?

Actually I refered to some thread concerning pointers in roottalk 3 years ago:
root.cern.ch/root/roottalk/roottalk01/4667.html

VT[/quote]

Hi,

The comment is still valid. However it was (and is) not covering the exception for the specialized case you are in.

Cheers,
Philippe.