Is BuildIndex() still necessary on TChain when included trees already have indices?

Hello,

I found that in the past, a BuildIndex() call was always necessary on TChain to use GetEntryWithIndex(). However, in one post, I see a mention that if member TTrees already have indices stored in the file, this should be enough. Mine do, and the TChain that I built does not have an index - GetTreeIndex() returns a null pointer. Is this the expected behaviour for ROOT 6.30.06?

Hello @LeWhoo,

which post are you referring to? Anyway, let me add in the loop @pcanal

Cheers,
Monica

Quite an old one :slight_smile:

Dear @LeWhoo ,

Thanks for reaching out to the forum! And thanks for adding the reference to the previous post. It would also of course be beneficial to have a code reproducer of your situation.

Keep in mind that there might be a slight misunderstanding, if I understand your description properly. It is true that a TTreeIndex can be stored to file together with its TTree, but this does not mean that a TChain will get this automatically. A TChain is simply a virtual concatenation of TTrees, so it does not automatically know whether you want to build an index for it, even if its TTrees might have their indices stored on disk. So if you’re working with a TChain, please make sure to call BuildIndex on it before befriending it to another TChain/TTree.

Cheers,
Vincenzo

Thank you for quick answer. I just need it to call GetEntryWithIndex(), but I understand now that BuildIndex on TChain is necessary for it.

Perhaps an automatic joining of member TTree indices could be considered in future for TChain, to save some computation power.