Deregister TTreeReadeValue in TTreeReader


I am using a TSelector that can work on two types of datasets that have not exactly the same branches. With the old TSelector, it was not a problem, but with the TTreeReader, declaring TTreeReaderValues that are not in the Tree makes the Selector crash.

Is there a way to handle this ? Like removing in the Begin() method some TTreeReaderValues ?

Thanks in advance

Please read tips for efficient and successful posting and posting code

ROOT Version: 6-18-04
Platform: linux
Compiler: gcc 5-4

Hi everyone,

I didn’t received any hints. Is it because my problem is not clearly explained ?

@Axel @pcanal what do you think?

For the moment the only solution I found is to make a second selector, inheriting from the first one and containing the branches that are not always present, and to apply a test on the TChain before starting the selector to know which one I launch.


First of all, you can still use the old selector style.

Then - you could create members of type std::vector<std::unique_ptr<TTreeReaderValueBase>> and std::vector<std::unique_ptr<TTreeReaderValueArray>> and create only those readers that you actually need. Would that work?



Thanks for your answer. Yes I can still use the old style, but I would like to be able to use the new tools…

I can try your solution, but how can I create the reader ?

In my header, I declare : std::vector<std::unique_ptr<TTreeReaderValueBase>> myValue;

Then, in my Begin() method, something like:

if(dospecialbranches) {
myValue ... => Here I don't see how to do.


For example (using just unique_ptr rather than vector of):

std::unique_ptr<TTreeReaderValue<Float_t>> px;
// in Begin/where-ever you know you need them
px  = std::make_unique<TTreeReaderValue<Float_t>>(fReader, "px");

Hi, Sorry for the delay of the answer.

Thanks for your solution, it works, by to get the value, I need to do : *px.get()->Get()

Is there an easier way to do it ?

Thanks in advance

Two shorter alternatives:

  f = *px->Get(); // same as: *(px->Get())
  f = **px; // same as: *(*px);

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