Using GetEntryWithIndex with TChain

Hi,

I have a ROOT file that contains an index created using TTree::BuildIndex. If I access the file using a TTree, such as:
TFile f(“myfile.root”);
TTree t = (TTree)f.Get(“MyTree”);
t->GetEntryWithIndex(100, 10);

this works fine… If instead, I create a TChain containing only this file, it seems GetEntryWithIndex does not work:
TChain *c = new TChain(“MyTree”);
c->Add(“myfile.root”);
c->GetEntryWithIndex(100,10);
returns -1

is that expected behavior? Is there an acceptable why to use indices with TChains?..if I first call BuildIndex - it seems the index is created and I can use the GetEntryWIthIndex call just fine…

Is the index initially unavailable since there is no guarantee that all files in a TChain will have an index?

Thanks,
Heather

Hi Heather,

Currently calling BuildIndex on the chain is the only way to properly use this feature. We hope to enhance this part as soon as possible.

Cheers,
Philippe.

HI,

So I’m using ROOT 4.02.00 on Red Hat Linux…in case it makes a difference.

Ok, one more question… if I then add 2 files to the same TChain and then call BuildIndex…calling GetEntryNumberWithIndex consistently returns -1, even for entries I know should exist…while it works just fine if I just have the one file in the TChain.

I’m assuming that is not expected?

Take care,
Heather

Humm … not really … but then again we are not yet really support any sort of index on the chains … I was hoping callin BuildIndex was working … but it looks like it does not really :frowning:. Anyway if you send me your 2 files I will check whether there is an easy fix.

Cheers,
Philippe.

The CVS repository was updated so that you can now create the TTree index for a TChain object. Note that the creation of the TTree index currently requires all the indices to be fit in memory (aka the memory needed is proportional to the number of entries in the chain!).

Cheers,
Philippe.

Hi,
I’m not using ROOT 5.10/00 on Windows. I have a TChain that actually only contains one ROOT file for readng. While preparing to read, I check to see in a TTreeIndex exists and if not build one:

if (!m_mcTree->GetTreeIndex()) 
          m_mcTree->BuildIndex("m_runId", "m_eventId");

This is a standalone application and we link to a smaller subset of ROOT libraries:

Searching ROOT/lib\libCint.lib:
Searching ROOT/lib\libCore.lib:
Searching ROOT/lib\libTree.lib:
Searching ROOT/lib\libMatrix.lib:
Searching ROOT/lib\libPhysics.lib:
Searching ROOT/lib\libHist.lib:
Searching ROOT/lib\libGraf.lib:
Searching ROOT/lib\libGraf3d.lib:
Searching ROOT/lib\libTreePlayer.lib:
Searching ROOT/lib\libGpad.lib:
Searching ROOT/lib\libRint.lib:    
Searching ROOT/lib\libPostscript.lib

At run time, I receive the following error message:
Error in : dictionary of class TTreeIndex not found

and when it comes time to delete the TChain object, a segmentation fault occurs that points to TTreePlayer. If I remove the line concerning BuildIndex, my run completes just fine.

Clearly I’m doing some wrong when trying to create and use an index…incidentally, the file should in fact have an index - one was created and written to the file when it was initially created - yet it seems GetTreeIndex consistently returns no index exists.

Any help would be appreciated.

Thanks,
Heather

That first line should have said,
I am now using ROOT 5.10/00 on Windows …

Hi,

Did you run ‘gmake map’ or ‘gmake install’ on your ROOT installation?
If you did not, this will solve your problem.
If you did and it still fails, please send us a complete example reproducing the problem.

Thanks,
Philippe

Hi,

This is on windows and I’m using the binary distribution from the ROOT home page. I do not see this problem on Linux.

I did find a work-around… I explicitly load TreePlayer library if running on windows…and that seems to work just fine. I just don’t understand why TreePlayer is not automatically loaded.

Thanks,
Heather

Hi Heather,

Could you provide a standalone example reproducing the problem?

Thanks,
Philippe