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 ?
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?
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");