Building new indices in TChainIndex

Hi,

We’re using ROOT 5.18.00c.

Unfortunately we have a set of ROOT files with what I can best describe as truncated TTreeIndices. We had merged a number of files and neglected the existing indices, hence the index written to these merged files refers only to the first TTree in the original files.

We desire to build a TChainIndex on these files, where we have opened the files in read-only mode. My limited understanding of TChainIndex, is that during the constructor, a new index is constructed per tree, only if there is no pre-existing index. I had hoped to essentially eliminate the indices by doing something like:

  unsigned int iTree;
  for (iTree=0;iTree<dataset->chain->GetNtrees(); iTree++)
   {
    dataset->chain->LoadTree((dataset->chain->GetTreeOffset())[iTree]) ;
    dataset->chain->GetTree()->SetTreeIndex(0) ;
   }

and then creating a TChainIndex. This is not working, though, since the original indices still exist and are apparently used when the TChainIndex is constructed.

Is there any way to really delete those indices and force TChainIndex to build new ones, without having to open the files in update mode? Am I left to rewrite those files and fix up the indices?

Thanks,
Heather

Hi Heather,

The problem is that the SetTreeIndex does not ‘stick’ since you do not update the file. The TChain only holds one file open at a time and will close (and thus discard your changes) the file every time if loads a new TTree.

So your best solution is to go through each of the file an update the TTree by either doing SetTreeIndex or (probably better) by recreating the index.

Cheers,
Philippe.

A way to go : make a new class which inherit from TChain and redefine YourChain::LoadTree(). Each time LoadTree is called, you delete the new tree index and set it to 0.