Storing array of structure in a tree branch

Hi,

Is it possible to store an array of structures in a branch?
I can see in the examples that you can do that for array of objects
derived from e.g. the event class. but that would require building the library
and linking …
Is it possible if I have a simple sturcture to store it
without having to wrap it in a class, build a library and link it?
I have e.g.

struct mystruct{ float a; float b; }
and in source code:

and want to store this in a branch like:

does this stores both elements of the array, like in cases of arrays of simple types?

Thanks!

[quote]does this stores both elements of the array, like in cases of arrays of simple types? [/quote]No it does not. If you want to use the leaflist method of branch creation, you will need to use a struct with arrays:struct mystruct{ float a[2]; float b[2]; }; .... tree->Branch("mystrucArray",myArrayStruct,"a[2]/F:b[2]/F");Note that with the leaflist method of branch creation can not guess the size (nor the type) of the array and you have to specify each by hand.

If you want to use a collection of struct you will need to compile your code and generate a dictionary for the struct (this is easy with ACLiC) and either use a vector of struct, a TClonesArray of struct (if they inherit from TObject) or a wrapping struct containing a fixed length array of your struct.

Cheers,
Philippe.

Thanks for your reply, I see the need of switching to proper solution as you
suggest but one more quick and dirty try, would the following work reliably
for a fixed length array? i.e. defining one branch for each instance?

tree->Branch("mystrucArray_1",&myArrayStruct[0],"a/F:b/F");
tree->Branch("mystrucArray_2",&myArrayStruct[1],"a/F:b/F");

Hi,

Yes this will work.

Cheers,
Philippe.

How should I do to read the struct from the Tree in another code? I’m trying to declare the type of struct and set the branch address to the new variable associated to that struct, but the values returned are “0”.

Hi,

What did you try?

Philippe.