TTreeReader:: read/get a given entry

Hi! I would like to read/get a given entry for a TTreeReader… is there any other (shorter) option other then ?:

fReader.SetEntry(N);
fReader.Next();

moreover, having a vector with entries is there any possibility to use/ pass to SetEntriesRange? :

fRreader.SetEntriesRange(entries_list?);
while (fReader.Next()) {
// processing entries from list
}

Thanks a lot!

Hi @adrian_sev,

Not with TTreeReader, AFAIK; perhaps @pcanal knows better.

Is it single entries that you want to visit or entry ranges?

In the former case, you could have a std::vector<Long64_t> that you could manually iterate and call SetEntry() for each value.
For entry ranges, you can use a std::vector<std::pair<Long_t, Long_t>>, where each value in the vector holds the start and end values for a SetEntriesRange() call.

Also related to your issue, see this information in the manual: Trees - ROOT

Cheers,
J.

Note that you don’t need both SetEntry and Next, the first one is enough to read a given entry.

To process a list of entries from a vector you can call SetEntry in a loop as per Javi’s suggestion or you can construct a TEntryList, add it to the input tree/chain and then process the tree/chain as usual with TTreeReader::Next: only the entries in the entry list will be processed.

Cheers,
Enrico

Thanks a lot for information!! so far, i solved my problem with:

fReader.SetEntriesRange(ev[0], ev.back());
while (fReader.Next()) { // processing entries of collision

where ev is a vector of entries (long long) recorded by parsing the tree and applying a condition, and i have the guarantee that these entries are continuous.

Now, related to your link (for TEntryList construction): is is possible to use the TEntryList for TTreeReader? i see no signatur in class reference of TTreeReader for this …
also, if it’s possible (because i did not searched enough) what would be the pro/cons for having a vector<TEntryList> vs vector<vector<int>> ?
Thanks a lot!

L.E. oh, now i see it: first tree.SetEntryList(list) and then while (fReader.Next()) { process those entries }

@eguiraud it seems that i cannot use TTreeReader with TEntryLists as trying to do something like:

O2track o2track;  // selector created by MakeSelector
o2track.Init(my_tree);

o2track.fReader.GetTree()->SetEntryList(&MyEntryList);
while (o2track.fReader.Next()) { // processing entries of collision
}

i get:
Warning in <TTreeReader::SetEntryBase()>: The TTree / TChain has an associated TEntryList. TTreeReader ignores TEntryLists unless you construct the TTreeReader passing a TEntryList.

Is there any workaround or is just better to use the vector of ints?
Thanks a lot!

Hi @adrian_sev ,
sorry for the high latency, I was off last week.

As the error message says, you need to construct the TTreeReader passing the TEntryList, see the constructor docs: ROOT: TTreeReader Class Reference

Cheers,
Enrico

Hi! yes i understood this, but the MakeSelector does not offer me this option. I could modify by hand
the selector but i do not have a guarantee that the tree structure is not modified, so i was hoping to a solution that does not modify the generated selector.
Moreover from what you say it seems that TEntryList is bound to TTreeReader so is not like i can pass another TEntryList whenever i need to read another selection of entries and use the same TTreeReader. Did i understood this point correctly?
Thanks a lot for clarifications!

I don’t think MakeSelector has options to generate code that reads with a TEntryList, you’ll have to modify the generated code.

Yes, different TEntryList → different TTreeReader object.

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