TChain/TTree Polymorphishm & BuildIndex / GetEntryWithIndex

Can anyone advise me how to properly use TTree::BuildIndex and TTree::GetEntryWithIndex / TChain::GetEntryWithIndex in an instance where my code will accept a TChain or a TTree? My code (too simple to even bother giving a snippet: it really just calls BuildIndex before a loop, and then GetEntryWithIndex inside a loop) works fine when run on a TTree and a TChain containing only one TTree. But I get the following error when run on a TChain containing two or more trees:

Warning in TChainIndex::GetSubTreeIndex: The index value is less than the smallest index values in subtrees
Error in TChainIndex::GetEntryNumberWithIndex: no index found

I apologize if this has already been covered elsewhere in the forum, but I did not find any pertinent entry (nor any newer than 2009) by searching TChain and index.



If you build an index for the whole chain it should work fine. Alternatively, you can build the index for each individual TTree but then you need to also make sure it is stored in the file.



thanks for the reply. I should have posted earlier to say I’ve solved the problem. It turned out not all to be related to the polymorphism. Instead my problem arose from that, though the ROOT reference explicitly states you can, you cannot in fact add files to a TChain using wildcards. I imagine this bug has already been reported.