LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
fhicl::detail Namespace Reference

Namespaces

 atom
 
 no_defaults
 
 sequence
 
 table
 
 yes_defaults
 

Classes

struct  AllowedConfiguration
 
struct  void_t< decltype(typename T::Parameters{ std::declval< fhicl::Name >()})>
 
class  AtomBase
 
class  DelegateBase
 
class  HashParameterSetID
 
class  Indentation
 
class  it_value_get
 
class  it_value_get< std::complex< U >, typename tt::disable_if< std::is_reference_v< std::complex< U > >|| std::is_pointer_v< std::complex< U > > >::type >
 
class  it_value_get< intermediate_table::sequence_t & >
 
class  it_value_get< intermediate_table::sequence_t >
 
class  it_value_get< intermediate_table::sequence_t const & >
 
class  it_value_get< intermediate_table::table_t & >
 
class  it_value_get< intermediate_table::table_t >
 
class  it_value_get< intermediate_table::table_t const & >
 
class  it_value_get< T, typename tt::disable_if< std::is_reference_v< T >|| std::is_pointer_v< T > >::type >
 
class  KeyAssembler
 
class  Keys
 
class  MaybeDisplayParent
 
class  ParameterBase
 
class  ParameterMetadata
 
class  ParameterWalker
 
struct  per_entry
 
struct  per_entry< 0, TUPLE >
 
class  per_thread_holder
 
class  Prettifier
 
class  PrettifierAnnotated
 
class  PrettifierPrefixAnnotated
 
class  PrintAllowedConfiguration
 
class  RegisterIfTableMember
 
class  SearchAllowedConfiguration
 
class  SequenceBase
 
class  SequenceKey
 
class  TableBase
 
class  TableMemberRegistry
 
struct  thread_hash_compare
 
class  ValidateThenSet
 
class  validationException
 
class  ValuePrinter
 

Typedefs

using ps_atom_t = std::string
 
using ps_sequence_t = std::vector< std::any >
 
using ldbl = long double
 
using key_t = std::string
 
using name_t = std::string
 
template<typename T >
using insertion_expression_t = decltype(std::declval< std::ostream & >()<< std::declval< T const & >())
 
using base_ptr = cet::exempt_ptr< ParameterBase >
 

Enumerations

enum  binding_modifier : unsigned char { binding_modifier::NONE, binding_modifier::PROTECT_IGNORE, binding_modifier::PROTECT_ERROR }
 
enum  print_mode { print_mode::raw, print_mode::annotated, print_mode::prefix_annotated }
 

Functions

bool is_sequence (std::any const &val)
 
bool is_table (std::any const &val)
 
bool is_nil (std::any const &val)
 
ps_atom_t encode (std::string const &)
 
ps_atom_t encode (char const *)
 
ps_atom_t encode (std::nullptr_t)
 
ps_atom_t encode (bool)
 
ParameterSetID encode (ParameterSet const &)
 
ps_atom_t encode (std::uintmax_t)
 
template<class T >
std::enable_if_t< tt::is_uint< T >::value, ps_atom_tencode (T const &)
 
ps_atom_t encode (std::intmax_t)
 
template<class T >
std::enable_if_t< tt::is_int< T >::value, ps_atom_tencode (T const &)
 
ps_atom_t encode (ldbl)
 
template<class T >
std::enable_if_t< std::is_floating_point_v< T >, ps_atom_tencode (T const &)
 
template<class T >
ps_atom_t encode (std::complex< T > const &)
 
template<class T >
ps_sequence_t encode (std::vector< T > const &)
 
template<class T >
tt::disable_if_t< tt::is_numeric< T >::value, std::string > encode (T const &)
 
void decode (std::any const &, std::string &)
 
void decode (std::any const &, std::nullptr_t &)
 
void decode (std::any const &, bool &)
 
void decode (std::any const &, ParameterSet &)
 
void decode (std::any const &, std::uintmax_t &)
 
template<class T >
std::enable_if_t< tt::is_uint< T >::valuedecode (std::any const &, T &)
 
void decode (std::any const &, std::intmax_t &)
 
template<class T >
std::enable_if_t< tt::is_int< T >::valuedecode (std::any const &, T &)
 
void decode (std::any const &, ldbl &)
 
template<class T >
std::enable_if_t< std::is_floating_point_v< T > > decode (std::any const &, T &)
 
void decode (std::any const &, std::complex< ldbl > &)
 
template<class T >
void decode (std::any const &, std::complex< T > &)
 
template<class T >
void decode (std::any const &, std::vector< T > &)
 
template<typename U >
void decode_tuple (std::any const &, U &tuple)
 
template<typename T , std::size_t SIZE>
void decode (std::any const &a, std::array< T, SIZE > &result)
 
template<typename KEY , typename VALUE >
void decode (std::any const &a, std::pair< KEY, VALUE > &result)
 
template<typename... ARGS>
void decode (std::any const &a, std::tuple< ARGS... > &result)
 
template<class T >
tt::disable_if_t< tt::is_numeric< T >::valuedecode (std::any const &, T &)
 
template<typename TUPLE , size_t I>
auto decode_entry (ps_sequence_t const &vec)
 
template<typename TUPLE , size_t... I>
void decode_tuple_entries (ps_sequence_t const &vec, TUPLE &result, std::index_sequence< I... >)
 
std::any encode (extended_value const &xval)
 
Keys get_names (std::string const &key)
 
SequenceKey get_sequence_indices (std::string const &key)
 
bool find_an_any (std::vector< std::size_t >::const_iterator it, std::vector< std::size_t >::const_iterator const cend, std::any &a)
 
std::string nl (std::size_t i=1)
 
std::string printed_suffix (std::string const &key, std::size_t const sz)
 
std::string print_prefix_annotated_info (std::string const &curr_info)
 
std::string print_annotated_info (std::string const &curr_info, std::string const &cached_info)
 
bool is_sequence_element (std::string const &key)
 
bool is_table_member (std::string const &key)
 
std::size_t index_for_sequence_element (std::string const &name)
 
template<typename L >
void try_insert (L l, std::string const &key)
 
std::string translate (error)
 
void throwOnSQLiteFailure (int rc, char *msg=nullptr)
 
void throwOnSQLiteFailure (sqlite3 *db, char *msg=nullptr)
 
std::function< bool()> AlwaysUse ()
 
void check_nargs_for_bounded_sequences (std::string const &key, std::size_t expected, std::size_t provided)
 
template<typename T >
std::string maybe_insert (T const &t)
 
std::string optional_parameter_message (bool const with_comment=true)
 
std::string strip_first_containing_name (std::string const &key)
 
std::string strip_all_containing_names (std::string const &key)
 
std::ostream & operator<< (std::ostream &os, TableBase const &t)
 
template<typename T >
std::set< std::string > ensure_callable ()
 
std::set< std::string > & concatenate_keys (std::set< std::string > &keys)
 
template<typename H , typename... T>
std::set< std::string > & concatenate_keys (std::set< std::string > &keys, H const &h, T const &...t)
 
int fhicl_get_impl (int argc, char **argv)
 
template<typename T >
std::string name_of ()
 
template<>
std::string name_of< std::string > ()
 

Variables

template<typename T , typename = void>
constexpr bool has_insertion_operator {false}
 

Typedef Documentation

using fhicl::detail::base_ptr = typedef cet::exempt_ptr<ParameterBase>

Definition at line 16 of file MaybeDisplayParent.h.

template<typename T >
using fhicl::detail::insertion_expression_t = typedef decltype(std::declval<std::ostream&>() << std::declval<T const&>())

Definition at line 12 of file maybe_insert.h.

using fhicl::detail::key_t = typedef std::string

Definition at line 69 of file KeyAssembler.h.

using fhicl::detail::ldbl = typedef long double

Definition at line 46 of file coding.h.

using fhicl::detail::name_t = typedef std::string

Definition at line 70 of file KeyAssembler.h.

using fhicl::detail::ps_atom_t = typedef std::string

Definition at line 44 of file coding.h.

using fhicl::detail::ps_sequence_t = typedef std::vector<std::any>

Definition at line 45 of file coding.h.

Enumeration Type Documentation

enum fhicl::detail::binding_modifier : unsigned char
strong
Enumerator
NONE 
PROTECT_IGNORE 
PROTECT_ERROR 

Definition at line 5 of file binding_modifier.h.

5  : unsigned char {
6  NONE,
9 #if 0 /* Preparation for issue #7231. */
10  INITIAL,
11  REPLACE,
12  REPLACE_COMPAT,
13  ADD_OR_REPLACE_COMPAT
14 #endif
15  };
Enumerator
raw 
annotated 
prefix_annotated 

Definition at line 5 of file print_mode.h.

Function Documentation

void fhicl::detail::check_nargs_for_bounded_sequences ( std::string const &  key,
std::size_t  expected,
std::size_t  provided 
)

Definition at line 9 of file check_nargs_for_bounded_sequences.cc.

Referenced by fhicl::OptionalTuple< ARGS... >::do_prepare_elements_for_validation(), fhicl::OptionalSequence< art::InputTag >::do_prepare_elements_for_validation(), fhicl::Tuple< T >::do_prepare_elements_for_validation(), and fhicl::Sequence< float, 3u >::do_prepare_elements_for_validation().

12 {
13  constexpr auto maybe_plural = [](std::size_t const nargs) {
14  return nargs == 1ull ? "" : "s";
15  };
16  constexpr auto has_or_have = [](std::size_t const nargs) {
17  return nargs == 1ull ? "has" : "have";
18  };
19  if (nargs != expected) {
20  std::ostringstream oss;
21  oss << '\n'
22  << nargs << " value" << maybe_plural(nargs) << ' ' << has_or_have(nargs)
23  << " been provided for the parameter with key:\n"
24  << " " << key << '\n'
25  << "which expects " << expected << " value" << maybe_plural(expected)
26  << '.';
27  throw detail::validationException{oss.str().c_str()};
28  }
29 }
std::set<std::string>& fhicl::detail::concatenate_keys ( std::set< std::string > &  keys)
inline

Definition at line 22 of file KeysToIgnore.h.

Referenced by concatenate_keys(), and fhicl::KeysToIgnore< H, T >::operator()().

23  {
24  return keys;
25  }
template<typename H , typename... T>
std::set<std::string>& fhicl::detail::concatenate_keys ( std::set< std::string > &  keys,
H const &  h,
T const &...  t 
)

Definition at line 29 of file KeysToIgnore.h.

References util::begin(), concatenate_keys(), and util::end().

30  {
31  keys.insert(begin(h), end(h));
32  return concatenate_keys(keys, t...);
33  }
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
std::set< std::string > & concatenate_keys(std::set< std::string > &keys, H const &h, T const &...t)
Definition: KeysToIgnore.h:29
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
void fhicl::detail::decode ( std::any const &  ,
std::nullptr_t &   
)
void fhicl::detail::decode ( std::any const &  ,
bool &   
)
void fhicl::detail::decode ( std::any const &  ,
ParameterSet  
)
void fhicl::detail::decode ( std::any const &  ,
std::uintmax_t &   
)
template<class T >
std::enable_if_t< tt::is_uint< T >::value > fhicl::detail::decode ( std::any const &  a,
T &  result 
)

Definition at line 214 of file coding.h.

References decode(), and value.

215 {
216  std::uintmax_t via;
217  decode(a, via);
218  result = boost::numeric_cast<T>(via);
219 }
tt::disable_if_t< tt::is_numeric< T >::value > decode(std::any const &, T &)
Definition: coding.h:351
void fhicl::detail::decode ( std::any const &  ,
std::intmax_t &   
)
template<class T >
std::enable_if_t< tt::is_int< T >::value > fhicl::detail::decode ( std::any const &  a,
T &  result 
)

Definition at line 225 of file coding.h.

References decode().

226 {
227  std::intmax_t via;
228  decode(a, via);
229  result = boost::numeric_cast<T>(via);
230 }
tt::disable_if_t< tt::is_numeric< T >::value > decode(std::any const &, T &)
Definition: coding.h:351
void fhicl::detail::decode ( std::any const &  ,
ldbl  
)
template<class T >
std::enable_if_t< std::is_floating_point_v< T > > fhicl::detail::decode ( std::any const &  a,
T &  result 
)

Definition at line 236 of file coding.h.

References decode().

237 {
238  ldbl via;
239  decode(a, via);
240  result = via; // boost::numeric_cast<T>(via);
241 }
long double ldbl
Definition: ParameterSet.cc:33
tt::disable_if_t< tt::is_numeric< T >::value > decode(std::any const &, T &)
Definition: coding.h:351
void fhicl::detail::decode ( std::any const &  ,
std::complex< ldbl > &   
)
template<class T >
void fhicl::detail::decode ( std::any const &  a,
std::complex< T > &  result 
)

Definition at line 247 of file coding.h.

References decode().

248 {
249  std::complex<ldbl> via;
250  decode(a, via);
251  result = {boost::numeric_cast<T>(via.real()),
252  boost::numeric_cast<T>(via.imag())};
253 }
tt::disable_if_t< tt::is_numeric< T >::value > decode(std::any const &, T &)
Definition: coding.h:351
template<class T >
void fhicl::detail::decode ( std::any const &  a,
std::vector< T > &  result 
)

Definition at line 259 of file coding.h.

References decode(), e, fhicl::extended_value::is_a(), fhicl::parse_value_string(), fhicl::SEQUENCE, and fhicl::type_mismatch.

260 {
261  if (a.type() == typeid(std::string)) {
262  std::string str;
263  decode(a, str);
264 
265  extended_value xval;
266  std::string unparsed;
267  if (!parse_value_string(str, xval, unparsed) || !xval.is_a(SEQUENCE))
268  throw fhicl::exception(type_mismatch, "error in sequence string:\n")
269  << str << "\nat or before:\n"
270  << unparsed;
271 
272  auto const& seq = fhicl::extended_value::sequence_t(xval);
273  result.clear();
274  T via;
275  for (auto const& e : seq) {
276  decode(e.to_string(), via);
277  result.push_back(via);
278  }
279  }
280 
281  else if (a.type() == typeid(ps_sequence_t)) {
282  ps_sequence_t const& seq = std::any_cast<ps_sequence_t>(a);
283  result.clear();
284  T via;
285  for (auto const& e : seq) {
286  decode(e, via);
287  result.push_back(via);
288  }
289  }
290 
291  else
292  throw fhicl::exception(type_mismatch, "invalid sequence");
293 }
bool parse_value_string(std::string const &s, extended_value &v, std::string &unparsed)
Definition: parse.cc:658
tt::disable_if_t< tt::is_numeric< T >::value > decode(std::any const &, T &)
Definition: coding.h:351
std::vector< std::any > ps_sequence_t
Definition: coding.h:45
std::vector< extended_value > sequence_t
ParameterSet::ps_sequence_t ps_sequence_t
Float_t e
Definition: plot.C:35
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<typename T , std::size_t SIZE>
void fhicl::detail::decode ( std::any const &  a,
std::array< T, SIZE > &  result 
)

Definition at line 125 of file coding.h.

References decode_tuple().

126  {
127  decode_tuple(a, result);
128  }
void decode_tuple(std::any const &, U &tuple)
Definition: coding.h:321
template<typename KEY , typename VALUE >
void fhicl::detail::decode ( std::any const &  a,
std::pair< KEY, VALUE > &  result 
)

Definition at line 132 of file coding.h.

References decode_tuple().

133  {
134  decode_tuple(a, result);
135  }
void decode_tuple(std::any const &, U &tuple)
Definition: coding.h:321
template<typename... ARGS>
void fhicl::detail::decode ( std::any const &  a,
std::tuple< ARGS... > &  result 
)

Definition at line 139 of file coding.h.

References decode_tuple().

140  {
141  decode_tuple(a, result);
142  }
void decode_tuple(std::any const &, U &tuple)
Definition: coding.h:321
template<class T >
tt::disable_if_t< tt::is_numeric< T >::value > fhicl::detail::decode ( std::any const &  a,
T &  result 
)

Definition at line 351 of file coding.h.

352 {
353  result = std::any_cast<T>(a);
354 }
template<typename TUPLE , size_t I>
auto fhicl::detail::decode_entry ( ps_sequence_t const &  vec)

Definition at line 301 of file coding.h.

References decode(), and fhicl::TUPLE.

302  {
303  std::tuple_element_t<I, TUPLE> result_elem;
304  decode(vec.at(I), result_elem);
305  return result_elem;
306  }
tt::disable_if_t< tt::is_numeric< T >::value > decode(std::any const &, T &)
Definition: coding.h:351
template<typename U >
void fhicl::detail::decode_tuple ( std::any const &  a,
U &  tuple 
)

Definition at line 321 of file coding.h.

References decode(), decode_tuple_entries(), and tmp.

Referenced by decode(), and is_table().

322 {
323  auto const seq = std::any_cast<ps_sequence_t>(a);
324 
325  constexpr std::size_t TUPLE_SIZE = std::tuple_size_v<U>;
326 
327  if (seq.size() != TUPLE_SIZE) {
328  std::ostringstream errmsg;
329  errmsg << "Number of expected arguments (" << TUPLE_SIZE
330  << ") does not match "
331  << "number of FHiCL sequence entries (" << seq.size() << "): [ ";
332  for (auto ca = seq.begin(); ca != seq.cend(); ++ca) {
333  std::string tmp;
334  decode(*ca, tmp);
335  errmsg << tmp;
336  if (ca != seq.cend() - 1) {
337  errmsg << ", ";
338  }
339  }
340  errmsg << " ]";
341  throw std::length_error(errmsg.str());
342  }
343 
344  decode_tuple_entries(seq, result, std::make_index_sequence<TUPLE_SIZE>());
345  // per_entry<TUPLE_SIZE - 1, U>::decode_tuple_entry(seq, result);
346 }
Float_t tmp
Definition: plot.C:35
tt::disable_if_t< tt::is_numeric< T >::value > decode(std::any const &, T &)
Definition: coding.h:351
void decode_tuple_entries(ps_sequence_t const &vec, TUPLE &result, std::index_sequence< I... >)
Definition: coding.h:310
ParameterSet::ps_sequence_t ps_sequence_t
template<typename TUPLE , size_t... I>
void fhicl::detail::decode_tuple_entries ( ps_sequence_t const &  vec,
TUPLE &  result,
std::index_sequence< I... >   
)

Definition at line 310 of file coding.h.

Referenced by decode_tuple().

313  {
314  ((std::get<I>(result) = decode_entry<TUPLE, I>(vec)), ...);
315  }
std::any fhicl::detail::encode ( extended_value const &  xval)

Definition at line 24 of file encode_extended_value.cc.

References fhicl::BOOL, fhicl::COMPLEX, e, util::quantities::concepts::encode(), fhicl::NIL, fhicl::NUMBER, fhicl::ParameterSetRegistry::put(), fhicl::ParameterSet::put(), fhicl::SEQUENCE, fhicl::STRING, fhicl::TABLE, fhicl::TABLEID, fhicl::extended_value::tag, fhicl::type_mismatch, fhicl::UNKNOWN, and value.

25 {
26  switch (xval.tag) {
27  case NIL:
28  case BOOL:
29  case NUMBER:
30  case STRING:
31  return atom_t(xval);
32 
33  case COMPLEX: {
34  auto const [real, imag] = complex_t(xval);
35  return '(' + real + ',' + imag + ')';
36  }
37 
38  case SEQUENCE: {
39  ps_sequence_t result;
40  for (auto const& e : sequence_t(xval)) {
41  result.push_back(encode(e));
42  }
43  return result;
44  }
45 
46  case TABLE: {
47  ParameterSet result;
48  for (auto const& [key, value] : table_t(xval)) {
49  if (!value.in_prolog)
50  result.put(key, value);
51  }
52  return ParameterSetRegistry::put(result);
53  }
54 
55  case TABLEID: {
56  atom_t const& tableID = atom_t(xval);
57  return ParameterSetID(tableID);
58  }
59 
60  case UNKNOWN:
61  default: {
62  throw fhicl::exception(type_mismatch, "unknown extended value");
63  }
64  }
65 } // encode()
intermediate_table::complex_t complex_t
intermediate_table::table_t table_t
::fhicl::detail::ps_atom_t encode(Interval< Args... > const &iv)
Encodes a quantity interval into a FHiCL parameter set atom.
intermediate_table::sequence_t sequence_t
double value
Definition: spectrum.C:18
intermediate_table::atom_t atom_t
ParameterSet::ps_sequence_t ps_sequence_t
Float_t e
Definition: plot.C:35
void put(std::string const &key)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
ps_atom_t fhicl::detail::encode ( std::string const &  value)

Definition at line 83 of file coding.cc.

References fhicl::extended_value::is_a(), fhicl::parse_value_string(), fhicl::STRING, and fhicl::type_mismatch.

Referenced by encode(), is_table(), fhicl::intermediate_table::put(), fhicl::ParameterSet::put(), and fhicl::intermediate_table::putNil().

84 {
85  bool is_quoted = value.size() >= 2 && value[0] == value.end()[-1] &&
86  (value[0] == '\"' || value[0] == '\'');
87 
88  std::string const& str = is_quoted ? value : '\'' + value + '\'';
89 
90  extended_value xval;
91  std::string unparsed;
92  if (!parse_value_string(str, xval, unparsed) || !xval.is_a(STRING))
93  throw fhicl::exception(type_mismatch, "error in input string:\n")
94  << str << "\nat or before:\n"
95  << unparsed;
96 
97  return extended_value::atom_t(xval);
98 }
bool parse_value_string(std::string const &s, extended_value &v, std::string &unparsed)
Definition: parse.cc:658
bool is_a(value_tag const t) const noexcept
double value
Definition: spectrum.C:18
intermediate_table::atom_t atom_t
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
ps_atom_t fhicl::detail::encode ( char const *  value)

Definition at line 101 of file coding.cc.

References encode().

102 {
103  return encode(std::string(value));
104 }
::fhicl::detail::ps_atom_t encode(Interval< Args... > const &iv)
Encodes a quantity interval into a FHiCL parameter set atom.
double value
Definition: spectrum.C:18
ps_atom_t fhicl::detail::encode ( std::nullptr_t  )

Definition at line 107 of file coding.cc.

References canon_nil().

108 {
109  return canon_nil();
110 }
static std::string canon_nil()
Definition: coding.cc:30
ps_atom_t fhicl::detail::encode ( bool  value)

Definition at line 113 of file coding.cc.

References literal_false(), and literal_true().

114 {
115  return value ? literal_true() : literal_false();
116 }
static ps_atom_t literal_false()
Definition: coding.cc:44
static ps_atom_t literal_true()
Definition: coding.cc:37
double value
Definition: spectrum.C:18
ParameterSetID fhicl::detail::encode ( ParameterSet const &  value)

Definition at line 119 of file coding.cc.

References fhicl::ParameterSetRegistry::put().

120 {
121  return ParameterSetRegistry::put(value);
122 }
double value
Definition: spectrum.C:18
ps_atom_t fhicl::detail::encode ( std::uintmax_t  value)

Definition at line 125 of file coding.cc.

References value.

126 {
127  std::string result = lexical_cast<std::string>(value);
128  if (result.size() > 6) {
129  std::size_t sz = result.size() - 1;
130  result.insert(1, ".");
131  result += "e+" + lexical_cast<std::string>(sz);
132  }
133  return result;
134 }
double value
Definition: spectrum.C:18
template<class T >
std::enable_if_t<tt::is_uint<T>::value, ps_atom_t> fhicl::detail::encode ( T const &  )
ps_atom_t fhicl::detail::encode ( std::intmax_t  value)

Definition at line 137 of file coding.cc.

References util::abs(), and encode().

138 {
139  std::string result = encode(std::uintmax_t(std::abs(value)));
140  if (value < 0)
141  result.insert(0, "-");
142  return result;
143 }
constexpr auto abs(T v)
Returns the absolute value of the argument.
::fhicl::detail::ps_atom_t encode(Interval< Args... > const &iv)
Encodes a quantity interval into a FHiCL parameter set atom.
double value
Definition: spectrum.C:18
template<class T >
std::enable_if_t<tt::is_int<T>::value, ps_atom_t> fhicl::detail::encode ( T const &  )
ps_atom_t fhicl::detail::encode ( ldbl  value)

Definition at line 146 of file coding.cc.

References atom_rep(), fhicl::BOOL, canon_nil(), fhicl::COMPLEX, decode(), encode(), fhicl::ParameterSetRegistry::get(), fhicl::extended_value::is_a(), literal_infinity(), literal_true(), fhicl::NUMBER, fhicl::parse_value_string(), fhicl::type_mismatch, and value.

147 {
148  if (value == std::numeric_limits<ldbl>::infinity())
149  return '+' + literal_infinity();
150  if (value == -std::numeric_limits<ldbl>::infinity())
151  return '-' + literal_infinity();
152 
153  std::intmax_t chopped = static_cast<std::intmax_t>(value);
154  if (static_cast<ldbl>(chopped) == value)
155  return encode(chopped);
156 
157  std::string result;
158  cet::canonical_number(lexical_cast<std::string>(value), result);
159  return result;
160 }
::fhicl::detail::ps_atom_t encode(Interval< Args... > const &iv)
Encodes a quantity interval into a FHiCL parameter set atom.
double value
Definition: spectrum.C:18
static ps_atom_t literal_infinity()
Definition: coding.cc:51
template<class T >
std::enable_if_t<std::is_floating_point_v<T>, ps_atom_t> fhicl::detail::encode ( T const &  )
template<class T >
ps_atom_t fhicl::detail::encode ( std::complex< T > const &  )
template<class T >
ps_sequence_t fhicl::detail::encode ( std::vector< T > const &  )
template<class T >
tt::disable_if_t< tt::is_numeric< T >::value, std::string > fhicl::detail::encode ( T const &  value)

Definition at line 203 of file coding.h.

References value.

204 {
205  return boost::lexical_cast<std::string>(value);
206 }
double value
Definition: spectrum.C:18
template<typename T >
std::set<std::string> fhicl::detail::ensure_callable ( )

Definition at line 15 of file KeysToIgnore.h.

16  {
17  static_assert(tt::is_callable<T>::value);
18  return T{}();
19  }
int fhicl::detail::fhicl_get_impl ( int  argc,
char **  argv 
)

Definition at line 231 of file fhicl_get_impl.cc.

References e, util::empty(), and fhicl::ParameterSet::make().

Referenced by main().

232  {
233  supported_types_t const printer_for_types{};
234  auto const maybe_opts = process_arguments(argc, argv, printer_for_types);
235 
236  if (std::holds_alternative<Help>(maybe_opts)) {
237  std::cout << std::get<Help>(maybe_opts).msg;
238  return 0;
239  }
240 
241  auto const& opts = std::get<Options>(maybe_opts);
242 
243  auto const pset =
244  fhicl::ParameterSet::make(opts.input_filename, *opts.policy);
245 
246  auto const& key = opts.parameter_key;
247 
248  if (opts.names_in) {
249  print_table_names(pset, key, opts.allow_missing);
250  return 0;
251  }
252 
253  if (not pset.has_key(key)) {
254  throw cet::exception{config} << "A parameter with the fully-qualified key '"
255  << key << "' does not exist.";
256  }
257 
258  if (not empty(opts.atom_as)) {
259  printer_for_types.value_for_atom(pset, opts.atom_as, key);
260  return 0;
261  }
262 
263  if (not empty(opts.sequence_of)) {
264  printer_for_types.value_for_sequence(pset, opts.sequence_of, key);
265  return 0;
266  }
267 
268  return 0;
269 }
270 catch (std::exception const& e) {
271  std::cerr << e.what();
272  return 1;
273 }
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68
Float_t e
Definition: plot.C:35
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:109
bool fhicl::detail::find_an_any ( std::vector< std::size_t >::const_iterator  it,
std::vector< std::size_t >::const_iterator const  cend,
std::any &  a 
)

Definition at line 96 of file ParameterSetImplHelpers.cc.

Referenced by fhicl::ParameterSet::find_one_(), fhicl::ParameterSet::get_one_(), and fhicl::ParameterSet::key_is_type_().

99  {
100  if (it == cend) {
101  // If we got this far, that means the element must exist,
102  // otherwise the previous recursive 'find_parameter' call would
103  // have returned false.
104  return true;
105  }
106 
107  auto seq = std::any_cast<ps_sequence_t>(a);
108  if (*it >= seq.size())
109  return false;
110 
111  a = std::move(seq[*it]);
112 
113  return find_an_any(++it, cend, a);
114  }
bool find_an_any(std::vector< std::size_t >::const_iterator it, std::vector< std::size_t >::const_iterator const cend, std::any &a)
ParameterSet::ps_sequence_t ps_sequence_t
Keys fhicl::detail::get_names ( std::string const &  key)

Definition at line 38 of file ParameterSetImplHelpers.cc.

References fhicl::cant_find, and fhicl::detail::Keys::last().

Referenced by fhicl::ParameterSet::get_if_present(), fhicl::ParameterSet::has_key(), and fhicl::ParameterSet::key_is_type_().

39  {
40  std::vector<std::string> keys;
41  boost::algorithm::split(keys, key, boost::algorithm::is_any_of("."));
42 
43  // Remove empty keys
44  keys.erase(std::remove(keys.begin(), keys.end(), ""), keys.end());
45 
46  if (keys.empty())
47  throw fhicl::exception(fhicl::cant_find, "vacuous key");
48 
49  std::string const last = keys.back();
50  keys.pop_back();
51 
52  return Keys{keys, last};
53  }
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
SequenceKey fhicl::detail::get_sequence_indices ( std::string const &  key)

Definition at line 78 of file ParameterSetImplHelpers.cc.

References fhicl::detail::SequenceKey::indices(), and fhicl::detail::SequenceKey::name().

Referenced by fhicl::ParameterSet::find_one_(), fhicl::ParameterSet::get_one_(), and fhicl::ParameterSet::key_is_type_().

79  {
80  // Split "name[0][5][1]" according to delimiters "][", "[", and "]"
81  // to give {"name","0","5","1"};
82  auto tokens = cet::split_by_regex(key, reBrackets);
83 
84  auto const name = tokens.front();
85  tokens.erase(tokens.begin());
86 
87  std::vector<std::size_t> indices;
88  cet::transform_all(
89  tokens, std::back_inserter(indices), [](std::string const& index) {
90  return std::stoul(index);
91  });
92  return SequenceKey{name, indices};
93  }
constexpr std::array< std::size_t, geo::vect::dimension< Vector >)> indices()
Returns a sequence of indices valid for a vector of the specified type.
std::size_t fhicl::detail::index_for_sequence_element ( std::string const &  name)

Definition at line 111 of file printing_helpers.cc.

References e, is_sequence_element(), and fhicl::other.

Referenced by is_table_member().

112 {
113  if (!is_sequence_element(name)) {
114  throw exception{error::other,
115  "An error occurred while converting a name to a sequence "
116  "element index.\n"}
117  << "The name '" << name << "' does not correspond to a sequence element.";
118  }
119  auto const b = name.find_last_of("[");
120  assert(b != std::string::npos);
121  auto const e = name.find_last_of("]");
122  assert(e == name.length() - 1);
123  auto const start = b + 1;
124  assert(start < e);
125  return std::stoull(name.substr(start, e - start));
126 }
bool is_sequence_element(std::string const &key)
Float_t e
Definition: plot.C:35
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
bool fhicl::detail::is_nil ( std::any const &  val)

Definition at line 71 of file coding.cc.

References atom_rep(), canon_nil(), is_sequence(), and is_table().

Referenced by fhicl::ParameterSet::insert_or_replace_compatible_(), and is_table().

72 {
73  bool result = false;
74  if (!(is_table(val) || is_sequence(val))) {
75  std::string str;
76  atom_rep(val, str);
77  result = (str == canon_nil());
78  }
79  return result;
80 }
static std::string canon_nil()
Definition: coding.cc:30
static void atom_rep(any const &a, std::string &result)
Definition: coding.cc:58
bool is_table(std::any const &val)
Definition: coding.h:55
bool is_sequence(std::any const &val)
Definition: coding.h:49
bool fhicl::detail::is_sequence_element ( std::string const &  key)
inline
bool fhicl::detail::is_table_member ( std::string const &  key)
inline

Definition at line 71 of file printing_helpers.h.

References index_for_sequence_element(), and is_sequence_element().

Referenced by fhicl::detail::RegisterIfTableMember::RegisterIfTableMember().

72  {
73  auto pos1 = key.find_last_of(".");
74  if (pos1 == std::string::npos)
75  return false;
76 
77  return not is_sequence_element(key);
78  }
bool is_sequence_element(std::string const &key)
template<typename T >
std::string fhicl::detail::maybe_insert ( T const &  t)

Definition at line 23 of file maybe_insert.h.

Referenced by fhicl::TupleAs< T(ARGS...)>::conversion_comment(), and fhicl::TableAs< T, Config >::conversion_comment().

24  {
25  if constexpr (has_insertion_operator<T>) {
26  std::ostringstream os;
27  os << " with a default value of:\n"
28  << " " << t;
29  return os.str();
30  }
31  return " A default value is present, but it cannot be\n"
32  " printed out since no 'operator<<' overload has\n"
33  " been provided for the above type.";
34  }
template<typename T >
std::string fhicl::detail::name_of ( )

Definition at line 61 of file Printer.h.

62  {
63  return cet::demangle_symbol(typeid(T).name());
64  }
template<>
std::string fhicl::detail::name_of< std::string > ( )

Definition at line 68 of file Printer.h.

69  {
70  return "string";
71  }
std::ostream & fhicl::detail::operator<< ( std::ostream &  os,
TableBase const &  t 
)

Definition at line 139 of file TableBase.cc.

References fhicl::detail::TableBase::print_allowed_configuration().

140  {
141  std::ostringstream config;
142  t.print_allowed_configuration(config);
143  return os << config.str();
144  }
std::string fhicl::detail::optional_parameter_message ( bool const  with_comment = true)
inline

Definition at line 6 of file optional_parameter_message.h.

Referenced by fhicl::detail::ValidateThenSet::check_keys(), and fhicl::detail::TableBase::print_allowed_configuration().

7  {
8  std::string result;
9  if (with_comment) {
10  result += "## ";
11  }
12  result += "Any parameters prefaced with '#' are optional.";
13  return result;
14  }
std::string fhicl::detail::print_annotated_info ( std::string const &  curr_info,
std::string const &  cached_info 
)

Definition at line 29 of file printing_helpers.cc.

Referenced by fhicl::detail::PrettifierAnnotated::atom(), fhicl::detail::PrettifierAnnotated::enter_sequence(), fhicl::detail::PrettifierAnnotated::enter_table(), and nl().

31 {
32  if (!allowed_info(curr_info))
33  return "";
34  std::string const tag = " # ";
35  std::string const printed_info =
36  curr_info == cached_info ? "\"\"" : curr_info;
37  return tag + printed_info;
38 }
std::string fhicl::detail::print_prefix_annotated_info ( std::string const &  curr_info)

Definition at line 41 of file printing_helpers.cc.

Referenced by fhicl::detail::PrettifierPrefixAnnotated::atom(), fhicl::detail::PrettifierPrefixAnnotated::enter_sequence(), fhicl::detail::PrettifierPrefixAnnotated::enter_table(), and nl().

42 {
43  std::string const printed_info = allowed_info(info) ? info : "";
44  return "#SRC|" + printed_info + "|";
45 }
std::string fhicl::detail::printed_suffix ( std::string const &  key,
std::size_t const  sz 
)
std::string fhicl::detail::strip_all_containing_names ( std::string const &  key)

Definition at line 14 of file strip_containing_names.cc.

15 {
16  auto const pos = key.find_last_of(".") + 1;
17  return key.substr(pos);
18 }
void fhicl::detail::throwOnSQLiteFailure ( int  rc,
char *  msg = nullptr 
)

Definition at line 41 of file ParameterSetRegistry.cc.

References fhicl::sql_error.

Referenced by fhicl::ParameterSetRegistry::exportTo(), fhicl::ParameterSetRegistry::find_(), fhicl::ParameterSetRegistry::importFrom(), throwOnSQLiteFailure(), and fhicl::ParameterSetRegistry::~ParameterSetRegistry().

42 {
43  std::string const msgString{msg ? msg : ""};
44  sqlite3_free(msg);
45  if (errcode != SQLITE_OK) {
46  // Caller's responsibility to make sure this really is an error
47  // and not (say) SQLITE_ROW or SQLITE_DONE,
48  throw exception(error::sql_error, "SQLite error:")
49  << sqlite3_errstr(errcode) << " (" << errcode << ')'
50  << (msgString.empty() ? "" : (std::string(": ") + msgString));
51  }
52 }
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void fhicl::detail::throwOnSQLiteFailure ( sqlite3 *  db,
char *  msg = nullptr 
)

Definition at line 55 of file ParameterSetRegistry.cc.

References fhicl::cant_open_db, and throwOnSQLiteFailure().

56 {
57  if (db == nullptr) {
58  sqlite3_free(msg);
59  throw fhicl::exception(fhicl::error::cant_open_db) << "Can't open DB.";
60  }
61  auto const errcode = sqlite3_errcode(db);
62  throwOnSQLiteFailure(errcode, msg);
63 }
void throwOnSQLiteFailure(int rc, char *msg=nullptr)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::string fhicl::detail::translate ( error  code)

Definition at line 12 of file exception.cc.

References fhicl::cant_find, fhicl::cant_happen, fhicl::cant_insert, fhicl::cant_open_db, fhicl::number_is_too_large, fhicl::other, fhicl::parse_error, fhicl::protection_violation, fhicl::sql_error, fhicl::type_mismatch, and fhicl::unimplemented.

13 {
14  switch (code) {
15  case cant_find:
16  return "Can't find key";
17  case cant_happen:
18  return "Can't happen";
19  case cant_insert:
20  return "Can't insert key";
22  return "Excessive value";
23  case parse_error:
24  return "Parse error";
25  case type_mismatch:
26  return "Type mismatch";
28  return "Protection violation";
29  case cant_open_db:
30  return "Can't open DB";
31  case sql_error:
32  return "SQL error";
33  case unimplemented:
34  return "Unimplemented feature";
35  case other:
36  return "Other error";
37  default:
38  return "Unknown code";
39  }
40 }
template<typename L >
void fhicl::detail::try_insert ( l,
std::string const &  key 
)

Definition at line 11 of file try_blocks.h.

References fhicl::cant_insert, and e.

Referenced by fhicl::ParameterSet::put(), fhicl::ParameterSet::put_or_replace(), and fhicl::ParameterSet::put_or_replace_compatible().

12  {
13  l(key);
14  }
15  catch (boost::bad_lexical_cast const& e) {
16  throw fhicl::exception{cant_insert, key} << e.what();
17  }
18  catch (boost::bad_numeric_cast const& e) {
19  throw fhicl::exception{cant_insert, key} << e.what();
20  }
21  catch (fhicl::exception const& e) {
22  throw fhicl::exception{cant_insert, key, e};
23  }
24  catch (std::exception const& e) {
25  throw fhicl::exception{cant_insert, key} << e.what();
26  }
Float_t e
Definition: plot.C:35
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33

Variable Documentation

template<typename T , typename = void>
constexpr bool fhicl::detail::has_insertion_operator {false}

Definition at line 15 of file maybe_insert.h.