Multiple TTreeReader on the same TTree conflict

ROOT Version: 6.20/08
Built for linuxx8664gcc on Mar 15 2021, 18:52:00
From tags/v6-20-08-alice1@v6-20-08-1-g700d618

I need to have two iterators on the same TTree to combine founded values so I have defined two TTreeReader which advance separately. When I read the value of the entry with GetCurrentyEntry the two readers show different values and they are correct but when I access the values stored for the 2 TTreaderValue I get same values.

I have done a test in the console (I use a custom class AliEvent but the problem should be independent):

root [1] #include "AliEvent.h"
root [2] #include "AliParticle.h"
root [3] TFile fEvents("output-WC/AnalysisResults_WC.root", "READ")
(TFile &) Name: output-WC/AnalysisResults_WC.root Title:
root [4] TList *outputList = (TList *) fEvents.Get("RsnOut_MyRareTest");
root [5] TTree *events = (TTree*) (*outputList)("Events");
root [6] TTreeReader tREv(events);
root [7] TTreeReaderValue<INFNCatania::AliEvent> event(tREv, "EventCollection");
root [8] TTreeReader tREvComb(events);
root [9] TTreeReaderValue<INFNCatania::AliEvent> eventComb(tREvComb, "EventCollection");
root [10] eventComb->CountK0()
E-TTreeReaderValue::Get(): Value reader not properly initialized, did you remember to call TTreeReader.Set(Next)Entry()?


n
E-HandleInterpreterException: Trying to dereference null pointer or trying to call routine taking non-null arguments.
Execution of your code was aborted.
ROOT_prompt_10:1:1: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
eventComb->CountK0()
^~~~~~~~~
root [11] tREv->N
"tREv" is not of pointer type. Use this operator: .

variable "tREv->N" not defined.
root [11] tREv.Next()
(bool) true
root [12] eventComb->CountK0()
E-TTreeReaderValue::Get(): Value reader not properly initialized, did you remember to call TTreeReader.Set(Next)Entry()?




E-HandleInterpreterException: Trying to dereference null pointer or trying to call routine taking non-null arguments.
Execution of your code was aborted.
ROOT_prompt_12:1:1: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
eventComb->CountK0()
^~~~~~~~~
root [13]
root [13]
root [13]
root [13]
root [13]
root [13] tREvComb.N
Next
Notify
root [13] tREvComb.Next()
(bool) true
root [14] eventComb->CountK0()
(int) 15
root [15] tREv.Next()
(bool) true
root [16] eventComb->CountK0()
(int) 15
root [17] tREv.Next()
(bool) true
root [18] eventComb->CountK0()
(int) 15
root [19] event->CountK0()
(int) 18
root [20] tREv.Next()
(bool) true
root [21] event->CountK0()
(int) 5
root [22] eventComb->CountK0()
(int) 5
root [23] event->CountK0()

As you can see after a Next operation both TTreeReaderValue provide the same results although only one should change.

I think @pcanal can have an opinion on this issue

Hi @fmarco76 ,
I don’t think this usage of TTreeReader is supported, TTreeReader is designed around the assumption that it has exclusive access to the underlying TTree. A simple workaround is opening the file 2 times, extracting 2 separate TTrees and iterating over them with 2 TTreeReaders.

Cheers,
Enrico

2 Likes

Hi @eguiraud ,
I was thinking it could be not supported although there is no hint of this possible problem in the documentation. Therefore, I have started to modify the code using the more traditional way to iterate over the entries (with GetEntry()).

Thanks to confirm the problem was not in my code.

Cheers,
Marco

It can actually be much less performant to use GetEntry() on the same tree: if you jump back and forth in the entries then opening the file separately (with two TTrees) is much more performant.

Hi @Axel,
thanks for the suggestion! I’ll definitely try this approach of opening the file twice to improve the execution speed.

Cheers,
Marco

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