TTreeReader reads friend of TChain incorrectly


ROOT Version: 6.13/02
Platform: Not Provided
Compiler: Not Provided


I have 4 files file0.root, file1.root ,file2.root and friendfile.root. They all have a single TTree inside. file0, file1 and file2 has identical tree structure and each of them have 200 entries. The tree in friendfile.root has different branches and is supposed to be added as friend, which has 400 entries. I found that TTreeReader won’t read pass entry 200 of friendfile.root. Here’s a demonstration:

TChain chain("maintree");
chain.Add("file*.root");
TChain friend_chain("maintree");
friend_chain.Add("friendfile.root");
chain.AddFriend(&friend_chain);

TTreeReader reader(&chain);
// The branch "EventID" comes from the tree in friendfile.root
// It contains the index of each event and should be identical to what you supplied with SetEntry(i)
TTreeReaderValue<int> idx(reader, "EventID");

reader.GetEntry(10);
cout << *idx << endl; // this show 10 correctly

reader.GetEntry(201);
cout << *idx << endl; // but this shows 1 instead of 201??

This seems to be a problem unique to TTreeReader. I tried SetBranchAddress and it reads my friendfile correctly.

Please see if anything is wrong with my code and possible ways to solve it. Thanks for all your help.

Maybe using RDataFrame can help…

Hi,

is it really wise to use GetEntry() for TTreeReader? I don’t see such method in https://root.cern.ch/doc/v614/classTTreeReader.html

Can you confirm that you meant reader.SetEntry(201);?

I will test with a reproducer. If this bug exists it really needs to get fixed!

Ouch, I can reproduce this even with the current master! I’m on it… Thanks a lot for reporting this, Tommy!

Yes it’s supposed to be SetEntry(201); Thanks for looking into it. Meanwhile if there’s any workaround that allows me to keep using TTreeReader please let me know. I can rewrite my script to use SetBranchAddress instead but it will not be as simple.

Thanks again for your help.

This is now https://sft.its.cern.ch/jira/browse/ROOT-9886

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

Sorry - I cannot reproduce this (my initial test was broken). Would you have a reproducer for me? E.g. by sending the input files to me?

Maybe you could check the attached non-reproducing reproducer at https://sft.its.cern.ch/jira/browse/ROOT-9886 to see how it differs from your case, i.e. if I misunderstood something?

I modified your script. It only happens if the number of entries of individual friend trees differ from that of the main trees.

Please see if you reproduce my error with the attached script. Now friend tree has 30 entries while each main tree has 10 entries. I am getting

"Reader: Unexpected value in friend tree: expected 13, read 3"TTreeReaderFriend.C (2.6 KB)

Awesome, thanks for tracking that down! I’ll be back…

We’re going to delay the release of v6.16/00 because of your bug report. Which means: thank you for reporting this evil bug!

We expect that this should be fixed by next Wednesday.

Fixed in master; you can verify with tomorrow’s nightlies: https://root.cern/download/nightly/

Will also be part of v6.16/00; I hope to be able to tag tomorrow.