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

#include "OptionalSequence.h"

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

Public Types

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

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

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 &) 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>
class fhicl::OptionalSequence< T,-1ull >

Definition at line 124 of file OptionalSequence.h.

Member Typedef Documentation

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

Definition at line 132 of file OptionalSequence.h.

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

Definition at line 133 of file OptionalSequence.h.

Constructor & Destructor Documentation

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

Definition at line 321 of file OptionalSequence.h.

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

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

Definition at line 326 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_VECTOR, fhicl::Name::sequence_element(), and fhicl::OptionalSequence< T, N >::value_.

327  : SequenceBase{std::move(name),
328  std::move(comment),
332  , RegisterIfTableMember{this}
333  , value_{
334  ftype{std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(0ul))}}
335  {
337  }
std::variant< ftype, value_type > value_
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::string const & name() const
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
std::string const & comment() const
std::vector< std::shared_ptr< tt::fhicl_type< T >>> ftype
template<typename T >
fhicl::OptionalSequence< T,-1ull >::OptionalSequence ( Name &&  name,
Comment &&  comment,
std::function< bool()>  maybeUse 
)
explicit

Definition at line 340 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_VECTOR, fhicl::Name::sequence_element(), and fhicl::OptionalSequence< T, N >::value_.

343  : SequenceBase{std::move(name),
344  std::move(comment),
347  maybeUse}
348  , RegisterIfTableMember{this}
349  , value_{
350  ftype{std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(0ul))}}
351  {
353  }
std::variant< ftype, value_type > value_
SequenceBase(Name &&name, Comment &&comment, par_style const vt, par_type const type, std::function< bool()> maybeUse)
Definition: SequenceBase.h:19
std::string const & name() const
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
std::string const & comment() const
std::vector< std::shared_ptr< tt::fhicl_type< T >>> ftype

Member Function Documentation

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

Implements fhicl::detail::SequenceBase.

Definition at line 180 of file OptionalSequence.h.

References fhicl::NameStackRegistry::current(), fhicl::NameStackRegistry::empty(), fhicl::detail::ParameterBase::key(), n, fhicl::Name::sequence_element(), value, and fhicl::OptionalSequence< T, N >::value_.

181  {
182  // We only enter here if we do not have a preset value.
183  auto& value = std::get<ftype>(value_);
184 
185  if (n < value.size()) {
186  value.resize(n);
187  } else if (n > value.size()) {
188 
189  std::string key_fragment{key()};
190  // When emplacing a new element, do not include in the key
191  // argument the current name-stack stem--it will
192  // automatically be prepended.
193  if (!NameStackRegistry::empty()) {
194  std::string const& current_stem = NameStackRegistry::current();
195  std::size_t const pos =
196  key_fragment.find(current_stem) != std::string::npos ?
197  current_stem.size() + 1ul : // + 1ul to account for the '.'
198  0ul;
199  key_fragment.replace(0ul, pos, "");
200  }
201 
202  for (auto i = value.size(); i != n; ++i) {
203  value.emplace_back(
204  new tt::fhicl_type<T>{Name::sequence_element(key_fragment, i)});
205  }
206  }
207  }
std::variant< ftype, value_type > value_
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::OptionalSequence< T,-1ull >::do_preset_value ( fhicl::ParameterSet const &  ps)
overrideprivatevirtual

Reimplemented from fhicl::detail::ParameterBase.

Definition at line 357 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_.

358  {
359  if constexpr (std::is_same_v<tt::fhicl_type<T>, Atom<T>>) {
360  auto const trimmed_key = detail::strip_first_containing_name(key());
361  value_ = ps.get<value_type>(trimmed_key);
362  has_value_ = true;
363  return true;
364  }
365  return false;
366  }
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
std::vector< tt::return_type< T >> value_type
template<typename T >
void fhicl::OptionalSequence< T,-1ull >::do_set_value ( fhicl::ParameterSet const &  )
overrideprivatevirtual

Implements fhicl::detail::ParameterBase.

Definition at line 370 of file OptionalSequence.h.

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

371  {
372  // We do not explicitly set the sequence values here as the
373  // individual elements are set one at a time. However, this
374  // function is reached in the ValidateThenSet algorithm if the
375  // optional parameter is present. Otherwise, this override is
376  // skipped.
377  has_value_ = true;
378  }
template<typename T >
void fhicl::OptionalSequence< T,-1ull >::do_walk_elements ( detail::ParameterWalker< tt::const_flavor::require_non_const > &  pw)
inlineoverrideprivatevirtual

Implements fhicl::detail::SequenceBase.

Definition at line 219 of file OptionalSequence.h.

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

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

Implements fhicl::detail::SequenceBase.

Definition at line 228 of file OptionalSequence.h.

References fhicl::OptionalSequence< T, N >::do_preset_value(), fhicl::OptionalSequence< T, N >::do_set_value(), e, and fhicl::detail::ParameterWalker< C >::walk_over().

230  {
231  // We only enter here if we do not have a preset value.
232  cet::for_all(std::get<ftype>(value_),
233  [&pw](auto const& e) { pw.walk_over(*e); });
234  }
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 fhicl::OptionalSequence< T,-1ull >::get_size ( ) const
inlineoverrideprivatevirtualnoexcept

Implements fhicl::detail::SequenceBase.

Definition at line 210 of file OptionalSequence.h.

References fhicl::detail::SequenceBase::size(), value, and fhicl::OptionalSequence< T, N >::value_.

211  {
212  if (auto value = std::get_if<value_type>(&value_)) {
213  return value->size();
214  }
215  return std::get<ftype>(value_).size();
216  }
std::variant< ftype, value_type > value_
std::size_t size() const noexcept
Definition: SequenceBase.h:33
double value
Definition: spectrum.C:18
template<typename T >
bool fhicl::OptionalSequence< T,-1ull >::hasValue ( ) const
inlinenoexcept

Definition at line 170 of file OptionalSequence.h.

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

171  {
172  return has_value_;
173  }
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(), do_prepare_elements_for_validation(), fhicl::OptionalSequence< T, N >::do_preset_value(), 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::optional<value_type> fhicl::OptionalSequence< T,-1ull >::operator() ( ) const
inline

Definition at line 142 of file OptionalSequence.h.

References fhicl::OptionalSequence< T, N >::has_value_, value, and fhicl::OptionalSequence< T, N >::value_.

143  {
144  if (!has_value_)
145  return std::nullopt;
146 
147  if (auto value = std::get_if<value_type>(&value_)) {
148  return std::make_optional(std::move(*value));
149  }
150 
151  value_type result;
152  cet::transform_all(std::get<ftype>(value_),
153  std::back_inserter(result),
154  [](auto const& elem) { return (*elem)(); });
155  return std::make_optional(std::move(result));
156  }
std::variant< ftype, value_type > value_
double value
Definition: spectrum.C:18
std::vector< tt::return_type< T >> value_type
template<typename T >
bool fhicl::OptionalSequence< T,-1ull >::operator() ( value_type t) const
inline

Definition at line 160 of file OptionalSequence.h.

161  {
162  if (auto result = operator()()) {
163  t = *result;
164  return true;
165  }
166  return false;
167  }
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 >
bool fhicl::OptionalSequence< T,-1ull >::has_value_ {false}
private

Definition at line 177 of file OptionalSequence.h.

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

Definition at line 176 of file OptionalSequence.h.


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