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.
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?
[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:
tree->Branch("mystrucArray",myArrayStruct,"a/F:b/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.
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?
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”.