1 #ifndef fhiclcpp_ParameterSet_h 2 #define fhiclcpp_ParameterSet_h 10 #include "cetlib_except/demangle.h" 27 #include <unordered_map> 40 using annot_t = std::unordered_map<std::string, std::string>;
48 cet::filepath_maker& maker);
51 bool is_empty()
const;
55 std::string to_compact_string()
const;
57 std::string to_indented_string()
const;
58 std::string to_indented_string(
unsigned initial_indent_level)
const;
59 std::string to_indented_string(
unsigned initial_indent_level,
61 std::string to_indented_string(
unsigned initial_indent_level,
64 std::vector<std::string>
get_names()
const;
65 std::vector<std::string> get_pset_names()
const;
66 std::vector<std::string> get_all_keys()
const;
69 bool has_key(std::string
const& key)
const;
70 bool is_key_to_table(std::string
const& key)
const;
71 bool is_key_to_sequence(std::string
const& key)
const;
72 bool is_key_to_atom(std::string
const& key)
const;
75 std::optional<T> get_if_present(std::string
const& key)
const;
76 template <
class T,
class Via>
77 std::optional<T> get_if_present(std::string
const& key,
78 T convert(Via
const&))
const;
82 bool get_if_present(std::string
const& key, T&
value)
const;
83 template <
class T,
class Via>
84 bool get_if_present(std::string
const& key,
86 T convert(Via
const&))
const;
89 T
get(std::string
const& key)
const;
90 template <
class T,
class Via>
91 T
get(std::string
const& key, T convert(Via
const&))
const;
93 T
get(std::string
const& key, T
const& default_value)
const;
94 template <
class T,
class Via>
95 T
get(std::string
const& key,
96 T
const& default_value,
97 T convert(Via
const&))
const;
99 std::string get_src_info(std::string
const& key)
const;
105 void put(std::string
const& key);
107 void put(std::string
const& key, T
const& value);
108 void put_or_replace(std::string
const& key);
110 void put_or_replace(std::string
const& key, T
const& value);
112 void put_or_replace_compatible(std::string
const& key, T
const& value);
115 bool erase(std::string
const& key);
122 using map_t = std::map<std::string, std::any>;
130 void insert_(std::string
const& key, std::any
const& value);
131 void insert_or_replace_(std::string
const& key, std::any
const& value);
132 void insert_or_replace_compatible_(std::string
const& key,
133 std::any
const& value);
135 std::string to_string_(
bool compact =
false)
const;
136 std::string stringify_(std::any
const& a,
bool compact =
false)
const;
138 bool key_is_type_(std::string
const& key,
139 std::function<
bool(std::any
const&)> func)
const;
143 std::optional<T> get_one_(std::string
const& key)
const;
144 bool find_one_(std::string
const& key)
const;
145 std::optional<ParameterSet> descend_(
146 std::vector<std::string>
const& names)
const;
153 #define _DECODE_ATOM_(T) void fhicl::detail::decode<T>(std::any const&, T&) 155 #define _DECODE_SEQUENCE_(T) \ 156 void fhicl::detail::decode<T::value_type>(std::any const&, T&) 158 #define _GET_ONE_(T) \ 159 std::optional<T> fhicl::ParameterSet::get_one_<T>(std::string const&) const 161 #define _GET(T) T fhicl::ParameterSet::get<T>(std::string const&) const 163 #define _GET_WITH_DEFAULT(T) \ 164 T fhicl::ParameterSet::get<T>(std::string const&, T const&) const 166 #define _GET_IF_PRESENT(T) \ 167 std::optional<T> fhicl::ParameterSet::get_if_present<T>(std::string const&) \ 170 #define _EXTERN_INSTANTIATE_GET(FHICL_TYPE, T) \ 171 extern template _DECODE_##FHICL_TYPE##_(T); \ 172 extern template _GET_ONE_(T); \ 173 extern template _GET(T); \ 174 extern template _GET_WITH_DEFAULT(T); \ 175 extern template _GET_IF_PRESENT(T) 204 return to_string_(
true);
222 return key_is_type_(key, [](std::any
const& a) {
231 auto insert = [
this, &
value](
auto const& key) {
233 this->insert_(key, std::any(
encode(value)));
242 auto insert_or_replace = [
this, &
value](
auto const& key) {
244 this->insert_or_replace_(key, std::any(
encode(value)));
245 srcMapping_.erase(key);
255 auto insert_or_replace_compatible = [
this, &
value](
auto const& key) {
257 this->insert_or_replace_compatible_(key, std::any(
encode(value)));
258 srcMapping_.erase(key);
270 if (
auto ps = descend_(keys.tables())) {
271 return ps->get_one_<T>(keys.last());
276 template <
class T,
class Via>
279 T convert(Via
const&))
const 281 auto go_between = get_if_present<Via>(key);
282 if (not go_between) {
285 return std::make_optional(convert(*go_between));
292 if (
auto present_parameter = get_if_present<T>(key)) {
293 value = *present_parameter;
299 template <
class T,
class Via>
303 T convert(Via
const&))
const 305 if (
auto present_parameter = get_if_present<T>(key, convert)) {
306 result = *present_parameter;
316 auto result = get_if_present<T>(key);
320 template <
class T,
class Via>
324 auto result = get_if_present<T>(key, convert);
332 auto result = get_if_present<T>(key);
333 return result ? *result : default_value;
336 template <
class T,
class Via>
339 T
const& default_value,
340 T convert(Via
const&))
const 342 auto result = get_if_present<T>(key, convert);
343 return result ? *result : default_value;
351 return id() == other.
id();
371 if (it == mapping_.end()) {
377 skey.indices().cbegin(), skey.indices().cend(), a)) {
383 return std::make_optional(value);
386 std::ostringstream errmsg;
387 errmsg <<
"\nUnsuccessful attempt to convert FHiCL parameter '" << key
388 <<
"' to type '" << cet::demangle_symbol(
typeid(value).name())
390 <<
"[Specific error:]";
394 std::ostringstream errmsg;
395 errmsg <<
"\nUnsuccessful attempt to convert FHiCL parameter '" << key
396 <<
"' to type '" << cet::demangle_symbol(
typeid(value).name())
398 <<
"[Specific error:]\n" 399 << e.what() <<
"\n\n";
408 void ParameterSet::put(std::string
const& key,
bool operator!=(ParameterSet const &other) const
Keys get_names(std::string const &key)
std::unordered_map< std::string, std::string > annot_t
#define _EXTERN_INSTANTIATE_GET(FHICL_TYPE, T)
map_t::const_iterator map_iter_t
::fhicl::detail::ps_atom_t encode(Interval< Args... > const &iv)
Encodes a quantity interval into a FHiCL parameter set atom.
std::vector< std::any > ps_sequence_t
bool is_key_to_sequence(std::string const &key) const
void try_insert(L l, std::string const &key)
bool is_key_to_table(std::string const &key) const
std::map< std::string, std::any > map_t
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
T get(std::string const &key) const
bool operator==(ParameterSet const &other) const
void put_or_replace_compatible(std::string const &key, T const &value)
fhicl::detail::ps_atom_t ps_atom_t
std::string to_compact_string() const
bool find_an_any(std::vector< std::size_t >::const_iterator it, std::vector< std::size_t >::const_iterator const cend, std::any &a)
SequenceKey get_sequence_indices(std::string const &key)
fhicl::detail::ps_sequence_t ps_sequence_t
ParameterSetID id() const
void decode(std::any const &src, Interval< Args... > &iv)
Decodes an interval.
std::optional< T > get_if_present(std::string const &key) const
std::optional< T > get_one_(std::string const &key) const
bool is_key_to_atom(std::string const &key) const
bool operator!=(infinite_endcount_iterator< T > const &, count_iterator< T > const &)
Never admit a infinite_endcount_iterator to be equal to anything else.
bool is_table(std::any const &val)
void put_or_replace(std::string const &key)
bool operator==(infinite_endcount_iterator< T > const &, count_iterator< T > const &)
void put(std::string const &key)
cet::coded_exception< error, detail::translate > exception
bool is_sequence(std::any const &val)
std::string to_string() const