How to read the size of a 2D array in a TTree?

The question is quite simple, but the answer may be not…
I’ll explain it with a simple example:
I have a TTree stored in a TFile (attached) and called ‘tree’, which contains a 2D array, called ‘x’.
‘x’ is an array of Float_t of fix sizes in both dimensions, 10 and 10.
If I print ‘tree’ it, I get:

[code]root [1] tree->Print()

*Tree :tree : tree *
*Entries : 1 : Total = 1268 bytes File Size = 623 *

  •    :          : Tree compression factor =   1.67                       *

*Br 0 :x : x[10][10]/F *
*Entries : 1 : Total Size= 942 bytes File Size = 280 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 1.67 *

Print() tells me that the array is 10 x 10, but I would like to extract this information automatically from a C program, without looking to the stdout.
How do I do this?
It seems quite easy, but I don’t know how to do it and i would be really useful from me.
Thanks in advance.

array.root (5.25 KB)

It’s me again. So does anybody have a clue on this?
I am aware that it can seem trivial and out of interest, but what I posted above is just a simple example to explain the problem.
I need this for an analysis software, to make it much more general without defining every time by hand the lengths of the arrays to be analyzed.
If this is achievable in ROOT, that would make my work much easier. If not, I’ll have to re-write something new.
I’d appreciate any help or advice on this.
Again, thank you.


Getting this information in the general case is non trivial (many use cases, see the implementation of TTreeFormula for details). In the specific case you have (branch created using a leaf list), you can get the total length:TLeaf *l = tree->GetBranch("x")->GetLeaf("x"); ULong_t fulllength = l->GetLenStatic(); // This returns 100 for the file file array.root To get the details you will need to parse the string of TString nameWithDimenions = l->GetTitle(); /* this returns "x[10][10]" */


Hi Philippe,
And thanks! That should work for my purposes. I’ll try it!