2-level TCloneArray

Hello ROOTers,

the problem of 2-level TCloneArrays was discussed here already, but unfortunately I did not find a solution for my problem.

I have a user defined class TC containing a TClonesArray of user defined class TB, which contains another TClonesArray of user defined class TA.
When filling TC by TBs and TBs by TAs and reading the data again, I see that TBs (and their simple scalar variables) contain originally stored values. But the lowest level is strange: all TAs within one TB are the same.

I attach a simple running example, tested with ROOT 5.24

run.cxx - starts the example
Test2Class.cxx - the example itself, filling one TC with TBs and TCs and reading the data out again. They do not agree (last column)
Ttcl.cxx, Ttcl.h - definition of classes TA, TB and TC

Later it should be possible to store these classes in a TFile and in a TTree.

What do I do wrong?

Thanks for any help!
TClonessArray2level.zip (1.78 KB)

Hi,

The problem is that you have:class TB : public TObject { private: static TClonesArray *fgAs; i.e you share a single TClonesArray for ALL TB objects … hence you result is ‘per se’ the expected result. You simple need to rewrite your cdeo without using this static TClonesArray.

Cheers,
Philippe.

Thank you, now it works!

I was wondering, why these static arrays are used in the example classes…

Cheers
OldA

[quote]I was wondering, why these static arrays are used in the example classes…[/quote]In the example, this allows to avoid deleting and recreating the TClonesArray object for each Event object and because in the example is such that there is only one Event object at a time (i.e. it is the top level object).

Cheers,
Philippe.