Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
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
 
- Public Member Functions inherited from fhicl::detail::SequenceBase
 SequenceBase (Name &&name, Comment &&comment, par_style const vt, par_type const type, std::function< bool()> maybeUse)
 
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
 
- Public Member Functions inherited from fhicl::detail::ParameterBase
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
 
 ParameterBase (Name const &name, Comment const &comment, par_style const vt, par_type const type, std::function< bool()> maybeUse=AlwaysUse())
 
virtual ~ParameterBase ()=default
 
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 Member Functions inherited from fhicl::detail::RegisterIfTableMember
 RegisterIfTableMember (ParameterBase *pb)
 

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.

423  : Sequence{std::move(name), Comment{""}}
424  {}
std::string const & name() const
Definition: ParameterBase.h:43
def move(depos, offset)
Definition: depos.py:107
#define Comment
template<typename T >
fhicl::Sequence< T,-1ull >::Sequence ( Name &&  name,
Comment &&  comment 
)
explicit

Definition at line 427 of file Sequence.h.

433  , RegisterIfTableMember{this}
434  , value_{
435  ftype{std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(0ul))}}
436  {
438  }
std::string const & name() const
Definition: ParameterBase.h:43
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
def move(depos, offset)
Definition: depos.py:107
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
std::string const & comment() const
Definition: ParameterBase.h:48
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.

448  maybeUse}
449  , RegisterIfTableMember{this}
450  , value_{
451  ftype{std::make_shared<tt::fhicl_type<T>>(Name::sequence_element(0ul))}}
452  {
454  }
std::string const & name() const
Definition: ParameterBase.h:43
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
def move(depos, offset)
Definition: depos.py:107
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
std::string const & comment() const
Definition: ParameterBase.h:48
template<typename T >
fhicl::Sequence< T,-1ull >::Sequence ( Name &&  name,
default_type const &  defaults 
)
explicit

Definition at line 458 of file Sequence.h.

459  : Sequence{std::move(name), Comment{""}, defaults}
460  {}
std::string const & name() const
Definition: ParameterBase.h:43
def move(depos, offset)
Definition: depos.py:107
#define Comment
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.

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::string const & name() const
Definition: ParameterBase.h:43
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
def move(depos, offset)
Definition: depos.py:107
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
std::string const & comment() const
Definition: ParameterBase.h:48
#define NO_DEFAULTS_FOR_TABLE
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.

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::string const & name() const
Definition: ParameterBase.h:43
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
def move(depos, offset)
Definition: depos.py:107
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
std::string const & comment() const
Definition: ParameterBase.h:48
#define NO_DEFAULTS_FOR_TABLE

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.

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
std::string string
Definition: nybbler.cc:12
typename fhicl_type_impl< T >::type fhicl_type
Definition: type_traits.h:315
std::void_t< T > n
static std::string current()
std::string const & key() const
Definition: ParameterBase.h:38
static Name sequence_element(std::size_t const i)
Definition: Name.h:16
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.

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
static constexpr double ps
Definition: Units.h:99
std::vector< tt::return_type< T >> value_type
Definition: Sequence.h:190
std::string const & key() const
Definition: ParameterBase.h:38
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.

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
const double e
auto for_all(FwdCont &, Func)
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.

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
const double e
auto for_all(FwdCont &, Func)
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.

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
template<typename T >
auto fhicl::Sequence< T,-1ull >::operator() ( ) const
inline

Definition at line 209 of file Sequence.h.

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

Definition at line 222 of file Sequence.h.

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

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: