LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
fhicl::OptionalSequence< T, N > Class Template Reference

#include "type_traits.h"

Inheritance diagram for fhicl::OptionalSequence< T, N >:
fhicl::detail::SequenceBase fhicl::detail::RegisterIfTableMember fhicl::detail::ParameterBase

Public Types

using ftype = std::array< std::shared_ptr< tt::fhicl_type< T >>, N >
 
using value_type = std::array< tt::return_type< T >, N >
 

Public Member Functions

 OptionalSequence (Name &&name)
 
 OptionalSequence (Name &&name, Comment &&comment)
 
 OptionalSequence (Name &&name, Comment &&comment, std::function< bool()> maybeUse)
 
std::optional< value_typeoperator() () const
 
bool operator() (value_type &t) const
 
bool hasValue () const noexcept
 
bool empty () const noexcept
 
std::size_t size () const noexcept
 
void prepare_elements_for_validation (std::size_t const n)
 
void walk_elements (ParameterWalker< tt::const_flavor::require_non_const > &pw)
 
void walk_elements (ParameterWalker< tt::const_flavor::require_const > &pw) const
 
std::string const & key () const
 
std::string const & name () const
 
std::string const & comment () const
 
bool has_default () const
 
bool is_optional () const
 
bool is_conditional () const
 
par_type parameter_type () const
 
bool should_use () const
 
void set_value (fhicl::ParameterSet const &ps)
 
bool preset_value (fhicl::ParameterSet const &ps)
 
void set_par_style (par_style const vt)
 

Private Member Functions

std::size_t get_size () const noexcept override
 
void do_prepare_elements_for_validation (std::size_t const n) override
 
void do_walk_elements (detail::ParameterWalker< tt::const_flavor::require_non_const > &pw) override
 
void do_walk_elements (detail::ParameterWalker< tt::const_flavor::require_const > &pw) const override
 
bool do_preset_value (fhicl::ParameterSet const &) override
 
void do_set_value (fhicl::ParameterSet const &) override
 

Private Attributes

std::variant< ftype, value_typevalue_
 
bool has_value_ {false}
 

Detailed Description

template<typename T, std::size_t N = -1ull>
class fhicl::OptionalSequence< T, N >

Definition at line 45 of file type_traits.h.

Member Typedef Documentation

template<typename T, std::size_t N = -1ull>
using fhicl::OptionalSequence< T, N >::ftype = std::array<std::shared_ptr<tt::fhicl_type<T>>, N>

Definition at line 36 of file OptionalSequence.h.

template<typename T, std::size_t N = -1ull>
using fhicl::OptionalSequence< T, N >::value_type = std::array<tt::return_type<T>, N>

Definition at line 37 of file OptionalSequence.h.

Constructor & Destructor Documentation

template<typename T , std::size_t N>
fhicl::OptionalSequence< T, N >::OptionalSequence ( Name &&  name)
explicit

Definition at line 249 of file OptionalSequence.h.

References fhicl::detail::ParameterBase::name().

250  : OptionalSequence{std::move(name), Comment("")}
251  {}
std::string const & name() const
template<typename T , std::size_t N>
fhicl::OptionalSequence< T, N >::OptionalSequence ( Name &&  name,
Comment &&  comment 
)
explicit

Definition at line 254 of file OptionalSequence.h.

References fhicl::detail::AlwaysUse(), fhicl::detail::ParameterBase::comment(), fhicl::NameStackRegistry::end_of_ctor(), fhicl::detail::ParameterBase::name(), fhicl::OPTIONAL, fhicl::detail::RegisterIfTableMember::RegisterIfTableMember(), fhicl::SEQ_ARRAY, fhicl::Name::sequence_element(), value, and fhicl::OptionalSequence< T, N >::value_.

255  : SequenceBase{std::move(name),
256  std::move(comment),
260  , RegisterIfTableMember{this}
261  , value_{ftype{nullptr}}
262  {
263  auto& value = std::get<ftype>(value_);
264  for (std::size_t i{}; i != N; ++i) {
265  value.at(i) =
266  std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(i));
267  }
269  }
std::function< bool()> AlwaysUse()
SequenceBase(Name &&name, Comment &&comment, par_style const vt, par_type const type, std::function< bool()> maybeUse)
Definition: SequenceBase.h:19
std::array< std::shared_ptr< tt::fhicl_type< T >>, N > ftype
std::variant< ftype, value_type > value_
std::string const & name() const
double value
Definition: spectrum.C:18
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
std::string const & comment() const
template<typename T , std::size_t N>
fhicl::OptionalSequence< T, N >::OptionalSequence ( Name &&  name,
Comment &&  comment,
std::function< bool()>  maybeUse 
)
explicit

Definition at line 272 of file OptionalSequence.h.

References fhicl::detail::ParameterBase::comment(), fhicl::NameStackRegistry::end_of_ctor(), fhicl::detail::ParameterBase::name(), fhicl::OPTIONAL_CONDITIONAL, fhicl::detail::RegisterIfTableMember::RegisterIfTableMember(), fhicl::SEQ_ARRAY, fhicl::Name::sequence_element(), value, and fhicl::OptionalSequence< T, N >::value_.

275  : SequenceBase{std::move(name),
276  std::move(comment),
279  maybeUse}
280  , RegisterIfTableMember{this}
281  , value_{ftype{nullptr}}
282  {
283  auto& value = std::get<ftype>(value_);
284  for (std::size_t i{}; i != N; ++i) {
285  value.at(i) =
286  std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(i));
287  }
289  }
SequenceBase(Name &&name, Comment &&comment, par_style const vt, par_type const type, std::function< bool()> maybeUse)
Definition: SequenceBase.h:19
std::array< std::shared_ptr< tt::fhicl_type< T >>, N > ftype
std::variant< ftype, value_type > value_
std::string const & name() const
double value
Definition: spectrum.C:18
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
std::string const & comment() const

Member Function Documentation

template<typename T, std::size_t N = -1ull>
void fhicl::OptionalSequence< T, N >::do_prepare_elements_for_validation ( std::size_t const  n)
inlineoverrideprivatevirtual

Implements fhicl::detail::SequenceBase.

Definition at line 93 of file OptionalSequence.h.

94  {
96  }
void check_nargs_for_bounded_sequences(std::string const &key, std::size_t expected, std::size_t provided)
std::size_t get_size() const noexcept override
std::string const & key() const
Definition: ParameterBase.cc:6
Char_t n[5]
template<typename T , std::size_t N>
bool fhicl::OptionalSequence< T, N >::do_preset_value ( fhicl::ParameterSet const &  ps)
overrideprivatevirtual

Reimplemented from fhicl::detail::ParameterBase.

Definition at line 293 of file OptionalSequence.h.

References fhicl::ParameterSet::get(), fhicl::OptionalSequence< T, N >::has_value_, fhicl::detail::ParameterBase::key(), fhicl::detail::strip_first_containing_name(), and fhicl::OptionalSequence< T, N >::value_.

Referenced by fhicl::OptionalSequence< art::InputTag >::do_walk_elements(), and fhicl::OptionalSequence< T,-1ull >::do_walk_elements().

294  {
295  if constexpr (std::is_same_v<tt::fhicl_type<T>, Atom<T>>) {
296  auto const trimmed_key = detail::strip_first_containing_name(key());
297  value_ = ps.get<value_type>(trimmed_key);
298  has_value_ = true;
299  return true;
300  }
301  return false;
302  }
std::array< tt::return_type< T >, N > value_type
std::variant< ftype, value_type > value_
std::string strip_first_containing_name(std::string const &key)
typename fhicl_type_impl< T >::type fhicl_type
Definition: type_traits.h:315
std::string const & key() const
Definition: ParameterBase.cc:6
template<typename T , std::size_t N>
void fhicl::OptionalSequence< T, N >::do_set_value ( fhicl::ParameterSet const &  )
overrideprivatevirtual

Implements fhicl::detail::ParameterBase.

Definition at line 306 of file OptionalSequence.h.

References fhicl::OptionalSequence< T, N >::has_value_.

Referenced by fhicl::OptionalSequence< art::InputTag >::do_walk_elements(), and fhicl::OptionalSequence< T,-1ull >::do_walk_elements().

307  {
308  // We do not explicitly set the sequence values here as the
309  // individual elements are set one at a time. However, this
310  // function is reached in the ValidateThenSet algorithm if the
311  // optional parameter is present. Otherwise, this override is
312  // skipped.
313  has_value_ = true;
314  }
template<typename T, std::size_t N = -1ull>
void fhicl::OptionalSequence< T, N >::do_walk_elements ( detail::ParameterWalker< tt::const_flavor::require_non_const > &  pw)
inlineoverrideprivatevirtual

Implements fhicl::detail::SequenceBase.

Definition at line 99 of file OptionalSequence.h.

101  {
102  // We only enter here if we do not have a preset value.
103  cet::for_all(std::get<ftype>(value_),
104  [&pw](auto& e) { pw.walk_over(*e); });
105  }
std::variant< ftype, value_type > value_
Float_t e
Definition: plot.C:35
template<typename T, std::size_t N = -1ull>
void fhicl::OptionalSequence< T, N >::do_walk_elements ( detail::ParameterWalker< tt::const_flavor::require_const > &  pw) const
inlineoverrideprivatevirtual

Implements fhicl::detail::SequenceBase.

Definition at line 108 of file OptionalSequence.h.

110  {
111  // We only enter here if we do not have a preset value.
112  cet::for_all(std::get<ftype>(value_),
113  [&pw](auto const& e) { pw.walk_over(*e); });
114  }
std::variant< ftype, value_type > value_
Float_t e
Definition: plot.C:35
bool fhicl::detail::SequenceBase::empty ( ) const
inlinenoexceptinherited

Definition at line 28 of file SequenceBase.h.

References fhicl::detail::SequenceBase::size().

Referenced by fhicl::detail::PrintAllowedConfiguration::enter_sequence().

29  {
30  return size() == 0;
31  }
std::size_t size() const noexcept
Definition: SequenceBase.h:33
template<typename T, std::size_t N = -1ull>
std::size_t fhicl::OptionalSequence< T, N >::get_size ( ) const
inlineoverrideprivatevirtualnoexcept

Implements fhicl::detail::SequenceBase.

Definition at line 84 of file OptionalSequence.h.

Referenced by fhicl::OptionalSequence< art::InputTag >::do_prepare_elements_for_validation().

85  {
86  if (auto value = std::get_if<value_type>(&value_)) {
87  return value->size();
88  }
89  return std::get<ftype>(value_).size();
90  }
std::size_t size() const noexcept
Definition: SequenceBase.h:33
std::variant< ftype, value_type > value_
double value
Definition: spectrum.C:18
template<typename T, std::size_t N = -1ull>
bool fhicl::OptionalSequence< T, N >::hasValue ( ) const
inlinenoexcept

Definition at line 74 of file OptionalSequence.h.

75  {
76  return has_value_;
77  }
bool fhicl::detail::ParameterBase::is_conditional ( ) const
inherited
std::string const & fhicl::detail::ParameterBase::key ( ) const
inherited

Definition at line 6 of file ParameterBase.cc.

References fhicl::detail::ParameterMetadata::key(), and fhicl::detail::ParameterBase::mdata_.

Referenced by fhicl::detail::PrintAllowedConfiguration::after_action(), fhicl::detail::ValidateThenSet::before_action(), fhicl::detail::PrintAllowedConfiguration::before_action(), fhicl::detail::SearchAllowedConfiguration::before_action(), fhicl::detail::PrintAllowedConfiguration::cacheTopLevelParameter(), detinfo::LArPropertiesStandard::Configure(), fhicl::OptionalTuple< ARGS... >::do_prepare_elements_for_validation(), fhicl::OptionalSequence< art::InputTag >::do_prepare_elements_for_validation(), fhicl::OptionalSequence< T,-1ull >::do_prepare_elements_for_validation(), fhicl::OptionalSequence< T, N >::do_preset_value(), fhicl::OptionalSequence< T,-1ull >::do_preset_value(), fhicl::Atom< T >::do_set_value(), fhicl::OptionalAtom< T >::do_set_value(), fhicl::detail::ValidateThenSet::enter_sequence(), fhicl::detail::PrintAllowedConfiguration::enter_sequence(), fhicl::detail::SearchAllowedConfiguration::form_absolute(), fhicl::DelegatedParameter::get(), fhicl::OptionalDelegatedParameter::get_if_present(), fhicl::OptionalDelegatedParameter::hasValue(), fhicl::detail::MaybeDisplayParent::is_sequence_element(), fhicl::detail::TableBase::maybe_select_pset(), fhicl::detail::PrintAllowedConfiguration::maybeReleaseTopLevelParameter(), fhicl::detail::RegisterIfTableMember::RegisterIfTableMember(), fhicl::detail::TableBase::select_pset(), and fhicl::detail::PrintAllowedConfiguration::suppressFormat().

7  {
8  return mdata_.key();
9  }
ParameterMetadata mdata_
Definition: ParameterBase.h:63
std::string const & key() const
template<typename T, std::size_t N = -1ull>
std::optional<value_type> fhicl::OptionalSequence< T, N >::operator() ( ) const
inline

Definition at line 46 of file OptionalSequence.h.

Referenced by fhicl::OptionalSequence< art::InputTag >::operator()().

47  {
48  if (!has_value_)
49  return std::nullopt;
50 
51  if (auto value = std::get_if<value_type>(&value_)) {
52  return std::make_optional(*value); // Do not move!
53  }
54 
55  value_type result = {{tt::return_type<T>()}};
56  cet::transform_all(std::get<ftype>(value_),
57  result.begin(),
58  [](auto const& elem) { return (*elem)(); });
59  return std::make_optional(std::move(result));
60  }
std::array< tt::return_type< T >, N > value_type
std::variant< ftype, value_type > value_
double value
Definition: spectrum.C:18
typename return_type_impl< ARGS... >::value_type return_type
Definition: type_traits.h:357
template<typename T, std::size_t N = -1ull>
bool fhicl::OptionalSequence< T, N >::operator() ( value_type t) const
inline

Definition at line 64 of file OptionalSequence.h.

65  {
66  auto const result = operator()();
67  if (result) {
68  t = *result;
69  }
70  return result.has_value();
71  }
std::optional< value_type > operator()() const
void fhicl::detail::SequenceBase::prepare_elements_for_validation ( std::size_t const  n)
inlineinherited

Definition at line 39 of file SequenceBase.h.

References fhicl::detail::SequenceBase::do_prepare_elements_for_validation().

Referenced by fhicl::detail::ValidateThenSet::enter_sequence().

40  {
42  }
virtual void do_prepare_elements_for_validation(std::size_t)=0
Char_t n[5]
bool fhicl::detail::ParameterBase::preset_value ( fhicl::ParameterSet const &  ps)
inherited

Definition at line 63 of file ParameterBase.cc.

References fhicl::detail::ParameterBase::do_preset_value().

Referenced by fhicl::detail::ValidateThenSet::before_action().

64  {
65  return do_preset_value(ps);
66  }
virtual bool do_preset_value(fhicl::ParameterSet const &)
void fhicl::detail::ParameterBase::set_par_style ( par_style const  vt)
inherited
void fhicl::detail::ParameterBase::set_value ( fhicl::ParameterSet const &  ps)
inherited

Definition at line 58 of file ParameterBase.cc.

References fhicl::detail::ParameterBase::do_set_value().

Referenced by fhicl::detail::ValidateThenSet::after_action().

59  {
60  do_set_value(ps);
61  }
virtual void do_set_value(fhicl::ParameterSet const &)=0
bool fhicl::detail::ParameterBase::should_use ( ) const
inherited

Definition at line 41 of file ParameterBase.cc.

References fhicl::detail::ParameterBase::maybeUse_.

Referenced by fhicl::detail::ValidateThenSet::before_action().

42  {
43  return maybeUse_();
44  }
std::function< bool()> maybeUse_
Definition: ParameterBase.h:64
std::size_t fhicl::detail::SequenceBase::size ( void  ) const
inlinenoexceptinherited
void fhicl::detail::SequenceBase::walk_elements ( ParameterWalker< tt::const_flavor::require_non_const > &  pw)
inlineinherited

Definition at line 44 of file SequenceBase.h.

References fhicl::detail::SequenceBase::do_walk_elements().

45  {
46  do_walk_elements(pw);
47  }
virtual void do_walk_elements(ParameterWalker< tt::const_flavor::require_non_const > &)=0
void fhicl::detail::SequenceBase::walk_elements ( ParameterWalker< tt::const_flavor::require_const > &  pw) const
inlineinherited

Definition at line 49 of file SequenceBase.h.

References fhicl::detail::SequenceBase::do_prepare_elements_for_validation(), fhicl::detail::SequenceBase::do_walk_elements(), and fhicl::detail::SequenceBase::get_size().

50  {
51  do_walk_elements(pw);
52  }
virtual void do_walk_elements(ParameterWalker< tt::const_flavor::require_non_const > &)=0

Member Data Documentation


The documentation for this class was generated from the following files: