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>;
51 bool is_empty()
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;
76 template <
class T,
class Via>
83 template <
class T,
class Via>
90 template <
class T,
class Via>
94 template <
class T,
class Via>
96 T const& default_value,
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);
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;
143 std::optional<T> get_one_(
std::string const& key)
const;
145 std::optional<ParameterSet> descend_(
146 std::vector<std::string>
const&
names)
const;
161 return to_string_(
true);
179 return key_is_type_(key, [](std::any
const&
a) {
188 auto insert = [
this, &
value](
auto const&
key) {
190 this->insert_(key, std::any(
encode(value)));
199 auto insert_or_replace = [
this, &
value](
auto const&
key) {
201 this->insert_or_replace_(key, std::any(
encode(value)));
202 srcMapping_.erase(key);
212 auto insert_or_replace_compatible = [
this, &
value](
auto const&
key) {
214 this->insert_or_replace_compatible_(key, std::any(
encode(value)));
215 srcMapping_.erase(key);
227 if (
auto ps = descend_(
keys.tables())) {
228 return ps->get_one_<
T>(
keys.last());
233 template <
class T,
class Via>
238 auto go_between = get_if_present<Via>(
key);
239 if (not go_between) {
242 return std::make_optional(
convert(*go_between));
249 if (
auto present_parameter = get_if_present<T>(key)) {
250 value = *present_parameter;
256 template <
class T,
class Via>
262 if (
auto present_parameter = get_if_present<T>(key,
convert)) {
263 result = *present_parameter;
273 auto result = get_if_present<T>(
key);
277 template <
class T,
class Via>
281 auto result = get_if_present<T>(
key,
convert);
289 auto result = get_if_present<T>(
key);
290 return result ? *result : default_value;
293 template <
class T,
class Via>
296 T const& default_value,
299 auto result = get_if_present<T>(
key,
convert);
300 return result ? *result : default_value;
308 return id() == other.
id();
328 if (it == mapping_.end()) {
334 skey.indices().cbegin(), skey.indices().cend(),
a)) {
340 return std::make_optional(value);
343 std::ostringstream errmsg;
344 errmsg <<
"\nUnsuccessful attempt to convert FHiCL parameter '" << key
345 <<
"' to type '" << cet::demangle_symbol(
typeid(value).
name())
347 <<
"[Specific error:]";
351 std::ostringstream errmsg;
352 errmsg <<
"\nUnsuccessful attempt to convert FHiCL parameter '" << key
353 <<
"' to type '" << cet::demangle_symbol(
typeid(value).
name())
355 <<
"[Specific error:]\n" 356 << e.what() <<
"\n\n";
bool operator!=(ParameterSet const &other) const
ps_atom_t encode(std::string const &)
Keys get_names(std::string const &key)
std::unordered_map< std::string, std::string > annot_t
bool find_an_any(cit_size_t it, cit_size_t const cend, std::any &a)
map_t::const_iterator map_iter_t
bool operator!=(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept
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
def convert(inputfile, outputfile="wire-cell-garfield-fine-response.json.bz2", average=False, shaped=False)
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)
def walk(top, topdown=True)
fhicl::detail::ps_atom_t ps_atom_t
std::string to_compact_string() const
static constexpr double ps
SequenceKey get_sequence_indices(std::string const &key)
fhicl::detail::ps_sequence_t ps_sequence_t
ParameterSetID id() const
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 is_table(std::any const &val)
void decode(std::any const &a, Hep2Vector &result)
static std::vector< std::string > const names
def maker(G, ac, typename)
void put_or_replace(std::string const &key)
void function(int client, int *resource, int parblock, int *test, int p)
std::string to_string(ModuleType const mt)
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
bool operator==(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept