I have been having problems with a little test program using the TTreeIndex. The attached files show how i generate 2 identical trees with identical leaves (ntuple.C). I then make a class using one of these trees (called markanal). I use a little macro to create 2 markanal* objects out of the 2 trees(run_markanal.C) and then include one of the trees as an argument for the Loop function in the class(markanal.C). The function tries to GetEntryWithIndex(x,y) of the passed-in object based on the x,y leaf values of the object that called the loop function.
I am trying to compare an event in one tree with the corresponding event in the other tree and use the index feature to choose the correct event in the second tree. The Loop(markanal*) function includes cout’s that should show the values returned by the GetEntryWithIndex function. The output shows that the GetEntryWithIndex(.,.) function is returning -1, i can’t see why this program is not working…
Can anybody see what is wrong?
Thanks for your time.
(p.s. - sorry, just noticed, the 2 BuildIndex lines in markanal.C should not be commented out.)
ntuple.C (965 Bytes)
markanal.C (2.02 KB)
run_markanal.C (172 Bytes)
You did not send the file markanal.h so we can not reproduce the problem.
Also please send the output you see and clearly mark what you see as a problem.
Sorry about that, here is the header file. The output looks as follows;
root  .x run_markanal.C
serial: -1 // fails to find entry in passed in object’s tree (send_ma->fChain) indexed by (1,2)
serial: -1 // fails to find entry in passed in object’s tree indexed by (3,6)
serial: -1 // fails to find entry in passed in objects tree indexed by (5,10)
The problem seems to be that the GetEntryWithIndex(.,.) is not working as should. These trees are very small and have very simple indices so i do not see why it fails sometimes.
markanal.h (3.54 KB)
In your example, you are confusing GetEntryWithIndex and GetEntryNumberWithIndex.
Also, you should not build twice the index in your Loop function.
See the correct files in attachement
markanal.C (2.02 KB)
run_markanal.C (344 Bytes)
Thanks for your help, it works fine now!
Note that in ROOT version 4.03/01 and older you need to call BuildIndex immediately after retrieving the TTree object (namely it requires tree->GetReadEntry() to return -1).
The problem is fixed in ROOT 4.03/02 and above.
I was working with Mark on this problem. It seems that the solution offered by Rene was not the thing that solved the problem, but it only appeared to work because the solution was tested on a different machine than the problem appeared on. The actual problem seems to be related to the compiler (and c++ standard libraries) used to build the root version. I have v4.01.04 and v4.02.00 both built with gcc3.2 and both showing the indexing error. I’ve rebuit v4.02.00 from the same source on the same machine with the same configuration settings but with gcc 3.2.2 and find that the problem disappears.
You might want to post an advisory against gcc3.2, particularly if the behaviour is seen on another system.
(Rene: I submitted a “bug report” earlier today regarding the fact that one of the binary versions on the site was listed as built with gcc3.2 but alas it turned out to be 3.2.2. At the time, I was trying to find another version built with gcc3.2 upon which to test my claim!)