LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
fhicl::Sequence< T,-1ull > Class Template Referencefinal

#include "Sequence.h"

Inheritance diagram for fhicl::Sequence< T,-1ull >:
fhicl::detail::SequenceBase fhicl::detail::RegisterIfTableMember fhicl::detail::ParameterBase

Public Types

using default_type = std::vector< typename tt::fhicl_type< T >::default_type >
 
using ftype = std::vector< std::shared_ptr< tt::fhicl_type< T >>>
 
using value_type = std::vector< tt::return_type< T >>
 

Public Member Functions

 Sequence (Name &&name)
 
 Sequence (Name &&name, Comment &&comment)
 
 Sequence (Name &&name, Comment &&comment, std::function< bool()> maybeUse)
 
 Sequence (Name &&name, default_type const &defaults)
 
 Sequence (Name &&name, Comment &&comment, default_type const &defaults)
 
 Sequence (Name &&name, Comment &&comment, std::function< bool()> maybeUse, default_type const &defaults)
 
auto operator() () const
 
auto operator() (std::size_t const i) const
 
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

void do_prepare_elements_for_validation (std::size_t const n) override
 
std::size_t get_size () const noexcept 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 &ps) override
 
void do_set_value (fhicl::ParameterSet const &) override
 

Private Attributes

std::variant< ftype, value_typevalue_
 

Detailed Description

template<typename T>
class fhicl::Sequence< T,-1ull >

Definition at line 181 of file Sequence.h.

Member Typedef Documentation

template<typename T >
using fhicl::Sequence< T,-1ull >::default_type = std::vector<typename tt::fhicl_type<T>::default_type>

Definition at line 188 of file Sequence.h.

template<typename T >
using fhicl::Sequence< T,-1ull >::ftype = std::vector<std::shared_ptr<tt::fhicl_type<T>>>

Definition at line 189 of file Sequence.h.

template<typename T >
using fhicl::Sequence< T,-1ull >::value_type = std::vector<tt::return_type<T>>

Definition at line 190 of file Sequence.h.

Constructor & Destructor Documentation

template<typename T >
fhicl::Sequence< T,-1ull >::Sequence ( Name &&  name)
explicit

Definition at line 422 of file Sequence.h.

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

423  : Sequence{std::move(name), Comment{""}}
424  {}
std::string const & name() const
template<typename T >
fhicl::Sequence< T,-1ull >::Sequence ( Name &&  name,
Comment &&  comment 
)
explicit

Definition at line 427 of file Sequence.h.

References fhicl::detail::AlwaysUse(), fhicl::detail::ParameterBase::comment(), fhicl::NameStackRegistry::end_of_ctor(), fhicl::detail::ParameterBase::name(), fhicl::detail::RegisterIfTableMember::RegisterIfTableMember(), fhicl::REQUIRED, fhicl::SEQ_VECTOR, fhicl::Name::sequence_element(), and fhicl::Sequence< T, N >::value_.

428  : SequenceBase{std::move(name),
429  std::move(comment),
433  , RegisterIfTableMember{this}
434  , value_{
435  ftype{std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(0ul))}}
436  {
438  }
std::variant< ftype, value_type > value_
Definition: Sequence.h:231
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::vector< std::shared_ptr< tt::fhicl_type< T >>> ftype
Definition: Sequence.h:189
std::string const & name() const
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
std::string const & comment() const
template<typename T >
fhicl::Sequence< T,-1ull >::Sequence ( Name &&  name,
Comment &&  comment,
std::function< bool()>  maybeUse 
)
explicit

Definition at line 441 of file Sequence.h.

References fhicl::detail::ParameterBase::comment(), fhicl::NameStackRegistry::end_of_ctor(), fhicl::detail::ParameterBase::name(), fhicl::detail::RegisterIfTableMember::RegisterIfTableMember(), fhicl::REQUIRED_CONDITIONAL, fhicl::SEQ_VECTOR, fhicl::Name::sequence_element(), and fhicl::Sequence< T, N >::value_.

444  : SequenceBase{std::move(name),
445  std::move(comment),
448  maybeUse}
449  , RegisterIfTableMember{this}
450  , value_{
451  ftype{std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(0ul))}}
452  {
454  }
std::variant< ftype, value_type > value_
Definition: Sequence.h:231
SequenceBase(Name &&name, Comment &&comment, par_style const vt, par_type const type, std::function< bool()> maybeUse)
Definition: SequenceBase.h:19
std::vector< std::shared_ptr< tt::fhicl_type< T >>> ftype
Definition: Sequence.h:189
std::string const & name() const
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
std::string const & comment() const
template<typename T >
fhicl::Sequence< T,-1ull >::Sequence ( Name &&  name,
default_type const &  defaults 
)
explicit

Definition at line 458 of file Sequence.h.

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

459  : Sequence{std::move(name), Comment{""}, defaults}
460  {}
std::string const & name() const
template<typename T >
fhicl::Sequence< T,-1ull >::Sequence ( Name &&  name,
Comment &&  comment,
default_type const &  defaults 
)
explicit

Definition at line 463 of file Sequence.h.

References fhicl::detail::AlwaysUse(), fhicl::detail::ParameterBase::comment(), fhicl::DEFAULT, fhicl::NameStackRegistry::end_of_ctor(), fhicl::detail::ParameterBase::name(), NO_DEFAULTS_FOR_TABLE, fhicl::detail::RegisterIfTableMember::RegisterIfTableMember(), fhicl::SEQ_VECTOR, fhicl::Name::sequence_element(), value, and fhicl::Sequence< T, N >::value_.

466  : SequenceBase{std::move(name),
467  std::move(comment),
471  , RegisterIfTableMember{this}
472  {
473  static_assert(!tt::is_table_v<T>, NO_DEFAULTS_FOR_TABLE);
474  std::size_t i{};
475  auto& value = std::get<ftype>(value_);
476  for (auto const& t : defaults) {
477  value.push_back(
478  std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(i), t));
479  ++i;
480  }
482  }
std::variant< ftype, value_type > value_
Definition: Sequence.h:231
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
typename fhicl_type_impl< T >::type fhicl_type
Definition: type_traits.h:315
std::string const & name() const
double value
Definition: spectrum.C:18
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
#define NO_DEFAULTS_FOR_TABLE
std::string const & comment() const
template<typename T >
fhicl::Sequence< T,-1ull >::Sequence ( Name &&  name,
Comment &&  comment,
std::function< bool()>  maybeUse,
default_type const &  defaults 
)
explicit

Definition at line 485 of file Sequence.h.

References fhicl::detail::ParameterBase::comment(), fhicl::DEFAULT_CONDITIONAL, fhicl::NameStackRegistry::end_of_ctor(), fhicl::detail::ParameterBase::name(), NO_DEFAULTS_FOR_TABLE, fhicl::detail::RegisterIfTableMember::RegisterIfTableMember(), fhicl::SEQ_VECTOR, fhicl::Name::sequence_element(), value, and fhicl::Sequence< T, N >::value_.

489  : SequenceBase{std::move(name),
490  std::move(comment),
493  maybeUse}
494  , RegisterIfTableMember{this}
495  {
496  static_assert(!tt::is_table_v<T>, NO_DEFAULTS_FOR_TABLE);
497  std::size_t i{};
498  auto& value = std::get<ftype>(value_);
499  for (auto const& t : defaults) {
500  value.emplace_back(
501  std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(i), t));
502  ++i;
503  }
505  }
std::variant< ftype, value_type > value_
Definition: Sequence.h:231
SequenceBase(Name &&name, Comment &&comment, par_style const vt, par_type const type, std::function< bool()> maybeUse)
Definition: SequenceBase.h:19
typename fhicl_type_impl< T >::type fhicl_type
Definition: type_traits.h:315
std::string const & name() const
double value
Definition: spectrum.C:18
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
#define NO_DEFAULTS_FOR_TABLE
std::string const & comment() const

Member Function Documentation

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

Implements fhicl::detail::SequenceBase.

Definition at line 234 of file Sequence.h.

References fhicl::NameStackRegistry::current(), fhicl::NameStackRegistry::empty(), n, fhicl::Name::sequence_element(), and value.

235  {
236  // We only enter here if we do not have a preset value.
237  auto& value = std::get<ftype>(value_);
238 
239  // For an unbounded sequence, we need to resize it so that any
240  // nested parameters of the elements can be checked.
241  if (n < value.size()) {
242  value.resize(n);
243  } else if (n > value.size()) {
244  std::string key_fragment{key()};
245  // When emplacing a new element, do not include in the key
246  // argument the current name-stack stem--it will automatically
247  // be prepended.
248  if (!NameStackRegistry::empty()) {
249  std::string const& current_stem = NameStackRegistry::current();
250  std::size_t const pos =
251  key_fragment.find(current_stem) != std::string::npos ?
252  current_stem.size() + 1ul : // + 1ul to account for the '.'
253  0ul;
254  key_fragment.replace(0ul, pos, "");
255  }
256 
257  for (auto i = value.size(); i != n; ++i) {
258  value.push_back(std::make_shared<tt::fhicl_type<T>>(
259  Name::sequence_element(key_fragment, i)));
260  }
261  }
262  }
std::variant< ftype, value_type > value_
Definition: Sequence.h:231
static std::string current()
typename fhicl_type_impl< T >::type fhicl_type
Definition: type_traits.h:315
std::string const & key() const
Definition: ParameterBase.cc:6
double value
Definition: spectrum.C:18
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
Char_t n[5]
template<typename T >
bool fhicl::Sequence< T,-1ull >::do_preset_value ( fhicl::ParameterSet const &  ps)
inlineoverrideprivatevirtual

Reimplemented from fhicl::detail::ParameterBase.

Definition at line 292 of file Sequence.h.

References fhicl::ParameterSet::get(), and fhicl::detail::strip_first_containing_name().

293  {
294  if constexpr (std::is_same_v<tt::fhicl_type<T>, Atom<T>>) {
295  auto const trimmed_key = detail::strip_first_containing_name(key());
296  value_ = ps.get<value_type>(trimmed_key);
297  return true;
298  }
299  return false;
300  }
std::variant< ftype, value_type > value_
Definition: Sequence.h:231
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
std::vector< tt::return_type< T >> value_type
Definition: Sequence.h:190
template<typename T >
void fhicl::Sequence< T,-1ull >::do_set_value ( fhicl::ParameterSet const &  )
inlineoverrideprivatevirtual

Implements fhicl::detail::ParameterBase.

Definition at line 303 of file Sequence.h.

304  {}
template<typename T >
void fhicl::Sequence< T,-1ull >::do_walk_elements ( detail::ParameterWalker< tt::const_flavor::require_non_const > &  pw)
inlineoverrideprivatevirtual

Implements fhicl::detail::SequenceBase.

Definition at line 274 of file Sequence.h.

References e, and fhicl::detail::ParameterWalker< C >::walk_over().

276  {
277  // We only enter here if we do not have a preset value.
278  cet::for_all(std::get<ftype>(value_),
279  [&pw](auto& e) { pw.walk_over(*e); });
280  }
std::variant< ftype, value_type > value_
Definition: Sequence.h:231
Float_t e
Definition: plot.C:35
template<typename T >
void fhicl::Sequence< T,-1ull >::do_walk_elements ( detail::ParameterWalker< tt::const_flavor::require_const > &  pw) const
inlineoverrideprivatevirtual

Implements fhicl::detail::SequenceBase.

Definition at line 283 of file Sequence.h.

References e, and fhicl::detail::ParameterWalker< C >::walk_over().

285  {
286  // We only enter here if we do not have a preset value.
287  cet::for_all(std::get<ftype>(value_),
288  [&pw](auto const& e) { pw.walk_over(*e); });
289  }
std::variant< ftype, value_type > value_
Definition: Sequence.h:231
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 fhicl::Sequence< T,-1ull >::get_size ( ) const
inlineoverrideprivatevirtualnoexcept

Implements fhicl::detail::SequenceBase.

Definition at line 265 of file Sequence.h.

References util::size(), and value.

266  {
267  if (auto value = std::get_if<value_type>(&value_)) {
268  return value->size();
269  }
270  return std::get<ftype>(value_).size();
271  }
std::size_t size() const noexcept
Definition: SequenceBase.h:33
std::variant< ftype, value_type > value_
Definition: Sequence.h:231
double value
Definition: spectrum.C:18
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 >
auto fhicl::Sequence< T,-1ull >::operator() ( ) const
inline

Definition at line 209 of file Sequence.h.

References e, and value.

210  {
211  if (auto value = std::get_if<value_type>(&value_)) {
212  return *value;
213  }
214  value_type result;
215  cet::transform_all(std::get<ftype>(value_),
216  std::back_inserter(result),
217  [](auto const& e) { return (*e)(); });
218  return result;
219  }
std::variant< ftype, value_type > value_
Definition: Sequence.h:231
std::vector< tt::return_type< T >> value_type
Definition: Sequence.h:190
double value
Definition: spectrum.C:18
Float_t e
Definition: plot.C:35
template<typename T >
auto fhicl::Sequence< T,-1ull >::operator() ( std::size_t const  i) const
inline

Definition at line 222 of file Sequence.h.

References value.

223  {
224  if (auto value = std::get_if<value_type>(&value_)) {
225  return value->at(i);
226  }
227  return (*std::get<ftype>(value_).at(i))();
228  }
std::variant< ftype, value_type > value_
Definition: Sequence.h:231
double value
Definition: spectrum.C:18
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

template<typename T >
std::variant<ftype, value_type> fhicl::Sequence< T,-1ull >::value_
private

Definition at line 231 of file Sequence.h.


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