Project

General

Profile

Feature #5582

tuple support in fhicl-cpp

Added by Andrei Gaponenko almost 6 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Infrastructure
Target version:
Start date:
03/04/2014
Due date:
% Done:

100%

Estimated time:
24.00 h
Spent time:
Scope:
Internal
Experiment:
Mu2e
SSI Package:
fhicl-cpp
Duration:

Description

Hello,

To configure a physics analysis one often needs to provide a list of
sets of values, e.g. particle type and energy cut for that particle,
or my latest use case: particle type (int) and G4 process name
(string). It would be natural to enter this configuration as
a sequence of tuples:

codes: [ [11, "DIO"], [22, "NuclearCapture" ] ]

The fhicl language allows this, but the C++ binding currently lacks
the ability to use such inputs in a straightforward manner:

const auto codes = pset.get<std::vector<std::tuple<int,std::string> > >("codes");

leads to a run-time exception:

---- Type mismatch BEGIN
codes
boost::bad_any_cast: failed conversion using boost::any_cast
---- Type mismatch END

This request is to implement support for the functionality above.

Andrei

History

#1 Updated by Christopher Green over 5 years ago

  • Project changed from fhicl-cpp to art
  • Category set to Infrastructure
  • Status changed from New to Accepted
  • Target version set to 521
  • Estimated time set to 24.00 h
  • Scope set to Internal
  • Experiment Mu2e added
  • SSI Package fhicl-cpp added

The time estimate assumes that the required form (heterogeneous sequence) is already accepted by the parser and the only change is to the conversion to requested type with ParameterSet::get<>().

#2 Updated by Kyle Knoepfel almost 5 years ago

  • Target version changed from 521 to 1.14.00

#3 Updated by Kyle Knoepfel almost 5 years ago

  • Status changed from Accepted to Resolved
  • Assignee set to Kyle Knoepfel
  • % Done changed from 0 to 100

We have implemented support for std::tuple<...>, std::pair<...>, and std::array<...>, and supported containers of the same types (std::vector, etc.). The following conversions (e.g.) are now supported:

pset.get< std::tuple<type1,type2,type3> >( "tuple" );
pset.get< std::pair <type1,type2>       >( "pair"  );
pset.get< std::array<type1,4u>          >( "array" );

This was provided via some overloads of the fhicl::detail::decode function (template).

Implemented with commits fhicl-cpp:cdab47871ebbd1032b708703bae3d09df3ae1c9b and fhicl-cpp:b8bcb527375b166b9021bfce4ebc99dad6693701.

#4 Updated by Kyle Knoepfel over 4 years ago

  • Status changed from Resolved to Closed


Also available in: Atom PDF