A new overload of getByLabel
My standard mantra for getting a data product is:
string moduleLable(pset.get<string>("moduleLabel"); art::Handle<StatusG4> g4StatusHandle; event.getByLabel( moduleLabel, g4StatusHandle); StatusG4 const& g4Status = *g4StatusHandle;
It occurred to Adam and I that maybe the following might work:
auto const& g4Status = event.getByLabel<StatusG4>(moduleLabel);
Even better would be if we can get rid of the const & and still have the variable g4Status be const&.
auto g4Status = event.getByLabel<StatusG4>(_g4ModulleLabel);
We propose to extend the API to include this new method. We recognize that this method has no way to indicate failure except to throw and exception - that is the behaviour we want. People who need to deal with the possibility of a product being absent or with multiple valid answers to the get can still use the old version. We believe that the new version can be implemented by calling through to the old version.
If it is necessary to change the function name that's fine too.
#1 Updated by Adam Lyon almost 7 years ago
If we can believe http://stackoverflow.com/questions/7138588/c11-auto-what-if-it-gets-a-constant-reference , then it looks like we'll need the
auto const & myData = ...
Which is fine. I think boiling down the three lines to one goes a long way to make things easier.