Reading a leaf from a TTree - a feature request?

Dear ROOTers,

I am creating and distributing TTrees that are supposed to be accessible and usable just with ROOT, without any additional code needed. However, I am using those TTrees mainly through PyROOT or with simple Scan/Print() functions. So I was really surprised to learn, that one cannot read a single leaf of a branch, that the only way to read leaves is to do SetBranchAddress() with a structure that can be filled by all the leaves.

It would be much easier to be able to access a single leaf. I understand that this work is almost done - in PyROOT one can do that. Print() and Scan() functions of the TTree also do that. So, would it be possible to introduce such feature to (C++) ROOT?

Hi,

Did you take a look at the TTreeReader interface?

Cheers, Bertrand.

Hi,

[quote]So I was really surprised to learn, that one cannot read a single leaf of a branch, that the only way to read leaves is to do SetBranchAddress() with a structure that can be filled by all the leaves.[/quote]There is of course other ways (as demonstrated by PyROOT and TTree::Scan :slight_smile:). For example you can use TTreeFormula directly or request the address from the leaf (and let the TTree manage the memory) or set the TTree in MakeClass code (see the result of MakeSelector).

However, as Bertrand pointed out, the simplest way in ROOT v6 is to use the TTreeReader interface.

Cheers,
Philippe.

It is still ROOT 5.34, but TLeaf::GetValuePointer() does the trick. Thanks!