Hi all,
does BuildIndex and GetEntryWithIndex work properly with TChains?
I have found that the BuildIndex command seems to return the number of files added to the chain (rather than the number of indices) and GetEntryWithIndex does not return -1 if the entry could not be found. Instead, GetEntryWithIndex will leave you pointing to the last element in the chain, and GetEntryNumberWithIndex will return the last index in the TChain.
I have verified this with 5.16/00 on a linux box and 5.18/00 on a mac.
I attach a very simple macro which reproduces the problem by writing a very simple TTree out to a file, loading it back into a TChain, and trying to use the functions above on a value that ought to fail.
kind regards
Peter Cogan
[code]void chainProblem(){
///////////////////////////////////////////////////
// Make a tree and a file and write them to disk //
///////////////////////////////////////////////////
TFile file(“newTestFile.root”, “recreate”);
TTree *tree = new TTree(“testTree”, “my test tree”);
Int_t variable=0;
tree->Branch(“variable”, &variable, “variable/I”);
for (int i=0; i<100; i++){
variable=i;
tree->Fill();
}
tree->Write();
file.Close();
////////////////////////////////////////////////////
// Try loading back in as a TChain //
////////////////////////////////////////////////////
TChain *chain = new TChain(“testTree”);
chain->Add(“newTestFile.root”);
cout<<"Entries in chain: "<GetEntries()<<endl;
cout<<"BuildIndex returns "<BuildIndex(“variable”)<<endl;
cout<<“Try to get value that is not in the chain, this should return a -1:”<<endl;
cout<GetEntryWithIndex(500)<<endl;
cout<GetEntryNumberWithIndex(500)<<endl;
}[/code]