TTreeReaderValue in std::map

Relevant previous discussion here:

I would like to write a custom classs that would be supplied an arbitrary list of strings of branch names to be read. And I don’t see any other way to do this other than creating a std::map<std::string,TTreeReaderValue> object (ideally also further using std::variant).

I did consider RDataFrame as an alternative, but unfortunately I need lower-level control to the event loop than is allowed/easily-provided by this class.

While the code as written in the poster’s example as a work-around works correctly as expected, it does not work once the TTreeReaderValue object itself goes out of scope, which defeats the purpose of being able to store them in maps for me.

Is there really no way to have TTreeReaderValue objects in std containers?

Yes you can by using a container of (unique) pointer and allocation the Reader and ReaderValue with operator new.

Thank you very much for the simply & effective solution. I have gotten a working setup with std::unique_ptr and std::make_unique (not sure if the latter is necessary).

Just out of my own curiosity, is there any technical reason why having std::map<X,TTreeReaderValue> might not be feasible?

We have not completely sorted out the semantic of copying of TTreeReaderValue (there are some inter-related ownership issues) and/or implemented the necessary move constructors.

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