Storing arrays of classes in a tree

Hi All,
I have a problem in storing an array of classes into a tree using tree->Branch() method.
I declare and appropriately fill an array of Classes (created by me) of kind e.g. “Particle”

	Particle myPartcle[N_PART];

Is it possible and, if so, what is the correct syntax for creating a branch containing the myParticle array?
I tried with:

	tree->Branch("particle", myParticle, 32000, 99);

but this (obviously) stores into the tree only the first element of the array.


C-style array of objects are not support as a top level type in a branch. To store such an array you need to wrap it into another class (class MyClass { Particle myPartcle[N_PART]; }; ) or use a C++ collection (either a TClonesArray or an std::vector) instead of the C-style array.


Thanks a lot, Philippe,

Just another question. If I choose to use an std::vector, what would be the tree->Branch() syntax?
Declared an

std::vector<Particle> myParticle;

will the Branch method look like:

tree->Branch("particle", myParticle, 32000, 99);

or will it be a little more complicated?
If I instead use the TClonesArray solution I encounter a problem in filling it.
In and also in $ROOTSYS/tutorials a syntax like:

new(a[i]) TTrack(x,y,z,...);

is used. My classes are actually more elaborated and it is impossible for me filling them in such a way. Can I create an auxiliary class, fill it using an appriopriate method and the pass it to the TClonesArray?

Thanks for your kind help.

[quote]My classes are actually more elaborated and it is impossible for me filling them in such a way.[/quote]Why not? You can always doTTrack * track = new(a[i]) TTrack(...); track->Set....(...); track->Set....(...); etc.If you are able to use C style array for your classes, you will be able to use a TClonesArray.