LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
fhicl::detail::ValidateThenSet Class Reference

#include "ValidateThenSet.h"

Inheritance diagram for fhicl::detail::ValidateThenSet:
fhicl::detail::ParameterWalker< tt::const_flavor::require_non_const >

Public Member Functions

 ValidateThenSet (fhicl::ParameterSet const &pset, std::set< std::string > const &keysToIgnore)
 
void check_keys ()
 
void walk_over (tt::maybe_const_t< ParameterBase, C > &)
 
bool do_before_action (tt::maybe_const_t< ParameterBase, C > &p)
 
void do_after_action (tt::maybe_const_t< ParameterBase, C > &p)
 
void do_enter_table (tt::maybe_const_t< TableBase, C > &t)
 
void do_exit_table (tt::maybe_const_t< TableBase, C > &t)
 
void do_enter_sequence (tt::maybe_const_t< SequenceBase, C > &s)
 
void do_exit_sequence (tt::maybe_const_t< SequenceBase, C > &s)
 
void do_atom (tt::maybe_const_t< AtomBase, C > &a)
 
void do_delegated_parameter (tt::maybe_const_t< DelegateBase, C > &dp)
 

Private Member Functions

bool before_action (ParameterBase &p) override
 
void after_action (ParameterBase &p) override
 
void enter_sequence (SequenceBase &p) override
 
void delegated_parameter (DelegateBase &) override
 
void enter_table (TableBase &) override
 
void atom (AtomBase &) override
 

Private Attributes

ParameterSet const & pset_
 
std::set< std::string > ignorableKeys_
 
std::vector< std::string > userKeys_
 
std::vector< cet::exempt_ptr< ParameterBase > > missingParameters_
 

Detailed Description

Definition at line 16 of file ValidateThenSet.h.

Constructor & Destructor Documentation

fhicl::detail::ValidateThenSet::ValidateThenSet ( fhicl::ParameterSet const &  pset,
std::set< std::string > const &  keysToIgnore 
)
inline

Definition at line 19 of file ValidateThenSet.h.

References after_action(), before_action(), check_keys(), delegated_parameter(), enter_sequence(), ignorableKeys_, missingParameters_, and userKeys_.

21  : pset_{pset}
22  , ignorableKeys_{keysToIgnore}
23  , userKeys_{pset.get_all_keys()}
25  {
26  cet::sort_all(userKeys_);
27  }
std::set< std::string > ignorableKeys_
std::vector< std::string > userKeys_
ParameterSet const & pset_
std::vector< cet::exempt_ptr< ParameterBase > > missingParameters_

Member Function Documentation

void fhicl::detail::ValidateThenSet::after_action ( ParameterBase p)
overrideprivate

Definition at line 42 of file ValidateThenSet.cc.

References pset_, and fhicl::detail::ParameterBase::set_value().

Referenced by ValidateThenSet().

43 {
44  p.set_value(pset_, true);
45 }
ParameterSet const & pset_
void fhicl::detail::ValidateThenSet::atom ( AtomBase )
inlineoverrideprivate

Definition at line 41 of file ValidateThenSet.h.

42  {}
bool fhicl::detail::ValidateThenSet::before_action ( ParameterBase p)
overrideprivate

Definition at line 20 of file ValidateThenSet.cc.

References fhicl::detail::ParameterBase::has_default(), fhicl::ParameterSet::has_key(), ignorableKeys_, fhicl::detail::ParameterBase::is_optional(), fhicl::detail::ParameterBase::key(), missingParameters_, pset_, fhicl::detail::ParameterBase::should_use(), fhicl::detail::strip_first_containing_name(), and userKeys_.

Referenced by ValidateThenSet().

21 {
22  // 'ConfigPredicate' condition must be satisfied to continue.
23  if (!p.should_use())
24  return false;
25 
26  // Check that key exists; allow defaulted or optional keys to be
27  // absent.
28  std::string const& k = strip_first_containing_name(p.key());
29  if (!pset_.has_key(k) && !cet::search_all(ignorableKeys_, k)) {
30  if (!p.has_default() && !p.is_optional()) {
31  missingParameters_.emplace_back(&p);
32  }
33  return false;
34  }
35 
36  auto erase_from = std::remove(userKeys_.begin(), userKeys_.end(), k);
37  userKeys_.erase(erase_from, userKeys_.cend());
38  return true;
39 }
std::set< std::string > ignorableKeys_
std::vector< std::string > userKeys_
std::string strip_first_containing_name(std::string const &key)
ParameterSet const & pset_
bool has_key(std::string const &key) const
std::vector< cet::exempt_ptr< ParameterBase > > missingParameters_
void fhicl::detail::ValidateThenSet::check_keys ( )

Definition at line 178 of file ValidateThenSet.cc.

References ignorableKeys_, missingParameters_, fhicl::detail::optional_parameter_message(), pset_, and userKeys_.

Referenced by ValidateThenSet().

179 {
180  removeIgnorableKeys(ignorableKeys_, userKeys_, missingParameters_);
181  std::string errmsg;
182  errmsg += fillMissingKeysMsg(missingParameters_);
183  errmsg += fillExtraKeysMsg(pset_, userKeys_);
184  if (!errmsg.empty()) {
185  std::string fullmsg{detail::optional_parameter_message(false)};
186  fullmsg += "\n";
187  fullmsg += errmsg;
188  throw validationException{fullmsg.c_str()};
189  }
190 }
std::set< std::string > ignorableKeys_
std::vector< std::string > userKeys_
std::string optional_parameter_message(bool const with_comment=true)
ParameterSet const & pset_
std::vector< cet::exempt_ptr< ParameterBase > > missingParameters_
void fhicl::detail::ValidateThenSet::delegated_parameter ( DelegateBase dp)
overrideprivate

Definition at line 72 of file ValidateThenSet.cc.

References evd::details::end(), fhicl::ParameterSet::get_src_info(), art::left(), fhicl::detail::ParameterBase::name(), fhicl::Name::regex_safe(), fhicl::detail::strip_first_containing_name(), userKeys_, lar::dump::vector(), and fhicl::detail::ParameterWalker< C >::walk_over().

Referenced by ValidateThenSet().

73 {
74  // A delegated parameter must itself be present, but any nested
75  // parameters do not need to be present since the nested parameters
76  // are potentially validated elsewhere.
77  auto const& name = dp.name();
78  std::string const pattern{fhicl::Name::regex_safe(name) + R"((\.|\[))"};
79  std::regex const r{pattern};
80  auto erase_from =
81  std::remove_if(userKeys_.begin(), userKeys_.end(), [&r](auto const& k) {
82  return std::regex_search(k, r);
83  });
84  userKeys_.erase(erase_from, userKeys_.end());
85 }
std::vector< std::string > userKeys_
static std::string regex_safe(std::string const &key)
Definition: Name.h:32
void fhicl::detail::ParameterWalker< C >::do_after_action ( tt::maybe_const_t< ParameterBase, C > &  p)
inlineinherited

Definition at line 98 of file ParameterWalker.h.

99  {
100  after_action(p);
101  }
virtual void after_action(tt::maybe_const_t< ParameterBase, C > &)
void fhicl::detail::ParameterWalker< C >::do_atom ( tt::maybe_const_t< AtomBase, C > &  a)
inlineinherited

Definition at line 126 of file ParameterWalker.h.

127  {
128  atom(a);
129  }
virtual void atom(tt::maybe_const_t< AtomBase, C > &)=0
bool fhicl::detail::ParameterWalker< C >::do_before_action ( tt::maybe_const_t< ParameterBase, C > &  p)
inlineinherited

Definition at line 93 of file ParameterWalker.h.

94  {
95  return before_action(p);
96  }
virtual bool before_action(tt::maybe_const_t< ParameterBase, C > &)
void fhicl::detail::ParameterWalker< C >::do_delegated_parameter ( tt::maybe_const_t< DelegateBase, C > &  dp)
inlineinherited

Definition at line 132 of file ParameterWalker.h.

133  {
135  }
virtual void delegated_parameter(tt::maybe_const_t< DelegateBase, C > &)=0
void fhicl::detail::ParameterWalker< C >::do_enter_sequence ( tt::maybe_const_t< SequenceBase, C > &  s)
inlineinherited

Definition at line 115 of file ParameterWalker.h.

116  {
117  enter_sequence(s);
118  }
Float_t s
Definition: plot.C:23
virtual void enter_sequence(tt::maybe_const_t< SequenceBase, C > &)=0
void fhicl::detail::ParameterWalker< C >::do_enter_table ( tt::maybe_const_t< TableBase, C > &  t)
inlineinherited

Definition at line 104 of file ParameterWalker.h.

105  {
106  enter_table(t);
107  }
virtual void enter_table(tt::maybe_const_t< TableBase, C > &)=0
void fhicl::detail::ParameterWalker< C >::do_exit_sequence ( tt::maybe_const_t< SequenceBase, C > &  s)
inlineinherited

Definition at line 120 of file ParameterWalker.h.

121  {
122  exit_sequence(s);
123  }
Float_t s
Definition: plot.C:23
virtual void exit_sequence(tt::maybe_const_t< SequenceBase, C > &)
void fhicl::detail::ParameterWalker< C >::do_exit_table ( tt::maybe_const_t< TableBase, C > &  t)
inlineinherited

Definition at line 109 of file ParameterWalker.h.

110  {
111  exit_table(t);
112  }
virtual void exit_table(tt::maybe_const_t< TableBase, C > &)
void fhicl::detail::ValidateThenSet::enter_sequence ( SequenceBase p)
overrideprivate

Definition at line 50 of file ValidateThenSet.cc.

References fhicl::ParameterSet::is_key_to_sequence(), fhicl::detail::ParameterBase::key(), fhicl::detail::SequenceBase::prepare_elements_for_validation(), pset_, fhicl::Name::regex_safe(), fhicl::detail::strip_first_containing_name(), fhicl::type_mismatch, and userKeys_.

Referenced by ValidateThenSet().

51 {
52  // Ensure that the supplied parameter represents a sequence.
53  auto const& key = strip_first_containing_name(s.key());
54  if (!pset_.is_key_to_sequence(key)) {
55  throw fhicl::exception(type_mismatch, "error converting to sequence:\n")
56  << "The supplied value of the parameter:\n"
57  << " " << s.key() << '\n'
58  << "does not represent a sequence.\n";
59  }
60 
61  std::regex const r{fhicl::Name::regex_safe(key) + "\\[\\d+\\]"};
62  std::size_t const nElems =
63  std::count_if(userKeys_.begin(), userKeys_.end(), [&r](auto const& k) {
64  return std::regex_match(k, r);
65  });
66  s.prepare_elements_for_validation(nElems);
67 }
Float_t s
Definition: plot.C:23
std::vector< std::string > userKeys_
bool is_key_to_sequence(std::string const &key) const
Definition: ParameterSet.h:155
std::string strip_first_containing_name(std::string const &key)
ParameterSet const & pset_
static std::string regex_safe(std::string const &key)
Definition: Name.h:32
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void fhicl::detail::ValidateThenSet::enter_table ( TableBase )
inlineoverrideprivate

Definition at line 38 of file ValidateThenSet.h.

39  {}
void fhicl::detail::ParameterWalker< C >::walk_over ( tt::maybe_const_t< ParameterBase, C > &  )
inherited

Member Data Documentation

std::set<std::string> fhicl::detail::ValidateThenSet::ignorableKeys_
private

Definition at line 45 of file ValidateThenSet.h.

Referenced by before_action(), check_keys(), and ValidateThenSet().

std::vector<cet::exempt_ptr<ParameterBase> > fhicl::detail::ValidateThenSet::missingParameters_
private

Definition at line 47 of file ValidateThenSet.h.

Referenced by before_action(), check_keys(), and ValidateThenSet().

ParameterSet const& fhicl::detail::ValidateThenSet::pset_
private

Definition at line 44 of file ValidateThenSet.h.

Referenced by after_action(), before_action(), check_keys(), and enter_sequence().

std::vector<std::string> fhicl::detail::ValidateThenSet::userKeys_
private

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