Project

General

Profile

Feature #3349

A new overload of getByLabel

Added by Rob Kutschke about 7 years ago. Updated almost 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Navigation
Target version:
Start date:
01/24/2013
Due date:
% Done:

100%

Estimated time:
Scope:
Internal
Experiment:
-
SSI Package:
Duration:

Description

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.

Rob

History

#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.

#2 Updated by Christopher Green almost 7 years ago

  • Description updated (diff)

#3 Updated by Christopher Green almost 7 years ago

  • Category set to Navigation
  • Status changed from New to Resolved
  • Assignee set to Marc Paterno
  • Target version set to 1.06.00
  • % Done changed from 0 to 100

This was implemented with commits ea83f1d and 2884d40. See Release notes for 1.06.00.

#4 Updated by Christopher Green almost 7 years ago

  • Status changed from Resolved to Closed


Also available in: Atom PDF