Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
fhicl::ParameterSet Class Reference

#include <ParameterSet.h>

Public Types

using ps_atom_t = fhicl::detail::ps_atom_t
 
using ps_sequence_t = fhicl::detail::ps_sequence_t
 
using annot_t = std::unordered_map< std::string, std::string >
 

Public Member Functions

bool is_empty () const
 
ParameterSetID id () const
 
std::string to_string () const
 
std::string to_compact_string () const
 
std::string to_indented_string () const
 
std::string to_indented_string (unsigned initial_indent_level) const
 
std::string to_indented_string (unsigned initial_indent_level, bool annotate) const
 
std::string to_indented_string (unsigned initial_indent_level, detail::print_mode pm) const
 
std::vector< std::stringget_names () const
 
std::vector< std::stringget_pset_names () const
 
std::vector< std::stringget_all_keys () const
 
bool has_key (std::string const &key) const
 
bool is_key_to_table (std::string const &key) const
 
bool is_key_to_sequence (std::string const &key) const
 
bool is_key_to_atom (std::string const &key) const
 
template<class T >
std::optional< T > get_if_present (std::string const &key) const
 
template<class T , class Via >
std::optional< T > get_if_present (std::string const &key, T convert(Via const &)) const
 
template<class T >
bool get_if_present (std::string const &key, T &value) const
 
template<class T , class Via >
bool get_if_present (std::string const &key, T &value, T convert(Via const &)) const
 
template<class T >
get (std::string const &key) const
 
template<class T , class Via >
get (std::string const &key, T convert(Via const &)) const
 
template<class T >
get (std::string const &key, T const &default_value) const
 
template<class T , class Via >
get (std::string const &key, T const &default_value, T convert(Via const &)) const
 
std::string get_src_info (std::string const &key) const
 
void walk (ParameterSetWalker &psw) const
 
void put (std::string const &key)
 
template<class T >
void put (std::string const &key, T const &value)
 
void put_or_replace (std::string const &key)
 
template<class T >
void put_or_replace (std::string const &key, T const &value)
 
template<class T >
void put_or_replace_compatible (std::string const &key, T const &value)
 
bool erase (std::string const &key)
 
bool operator== (ParameterSet const &other) const
 
bool operator!= (ParameterSet const &other) const
 
template<>
void put (std::string const &key, fhicl::extended_value const &value)
 

Static Public Member Functions

static ParameterSet make (intermediate_table const &tbl)
 
static ParameterSet make (extended_value const &xval)
 
static ParameterSet make (std::string const &str)
 
static ParameterSet make (std::string const &filename, cet::filepath_maker &maker)
 

Private Types

using map_t = std::map< std::string, std::any >
 
using map_iter_t = map_t::const_iterator
 

Private Member Functions

void insert_ (std::string const &key, std::any const &value)
 
void insert_or_replace_ (std::string const &key, std::any const &value)
 
void insert_or_replace_compatible_ (std::string const &key, std::any const &value)
 
std::string to_string_ (bool compact=false) const
 
std::string stringify_ (std::any const &a, bool compact=false) const
 
bool key_is_type_ (std::string const &key, std::function< bool(std::any const &)> func) const
 
template<class T >
std::optional< T > get_one_ (std::string const &key) const
 
bool find_one_ (std::string const &key) const
 
std::optional< ParameterSetdescend_ (std::vector< std::string > const &names) const
 

Private Attributes

map_t mapping_
 
annot_t srcMapping_
 
ParameterSetID id_
 

Detailed Description

Definition at line 36 of file ParameterSet.h.

Member Typedef Documentation

Definition at line 40 of file ParameterSet.h.

Definition at line 123 of file ParameterSet.h.

using fhicl::ParameterSet::map_t = std::map<std::string, std::any>
private

Definition at line 122 of file ParameterSet.h.

Definition at line 38 of file ParameterSet.h.

Definition at line 39 of file ParameterSet.h.

Member Function Documentation

std::optional< ParameterSet > ParameterSet::descend_ ( std::vector< std::string > const &  names) const
private

Definition at line 223 of file ParameterSet.cc.

224 {
225  if (empty(names)) {
226  return std::make_optional(*this);
227  }
228  ParameterSet const* p{this};
229  std::optional<ParameterSet> result;
230  for (auto const& name : names) {
231  if (!p->find_one_(name)) {
232  return std::nullopt;
233  }
234  if (!p->is_key_to_table(name)) {
235  return std::nullopt;
236  }
237 
238  if (result = p->get_one_<ParameterSet>(name); not result) {
239  return std::nullopt;
240  }
241  p = &result.value();
242  }
243  return result;
244 }
static QCString name
Definition: declinfo.cpp:673
static QCString result
p
Definition: test.py:223
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:97
bool ParameterSet::erase ( std::string const &  key)

Definition at line 338 of file ParameterSet.cc.

339 {
340  bool const did_erase{1u == mapping_.erase(key)};
341  id_.invalidate();
342  return did_erase;
343 }
def key(type, name=None)
Definition: graph.py:13
void invalidate() noexcept
ParameterSetID id_
Definition: ParameterSet.h:127
bool ParameterSet::find_one_ ( std::string const &  key) const
private

Definition at line 209 of file ParameterSet.cc.

210 {
211  auto skey = detail::get_sequence_indices(simple_key);
212 
213  auto it = mapping_.find(skey.name());
214  if (it == mapping_.end()) {
215  return false;
216  }
217 
218  auto a = it->second;
219  return detail::find_an_any(skey.indices().cbegin(), skey.indices().cend(), a);
220 }
bool find_an_any(cit_size_t it, cit_size_t const cend, std::any &a)
const double a
SequenceKey get_sequence_indices(std::string const &key)
template<class T >
T fhicl::ParameterSet::get ( std::string const &  key) const

Definition at line 271 of file ParameterSet.h.

272 {
273  auto result = get_if_present<T>(key);
274  return result ? *result : throw fhicl::exception(cant_find, key);
275 }
static QCString result
def key(type, name=None)
Definition: graph.py:13
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<class T , class Via >
T fhicl::ParameterSet::get ( std::string const &  key,
T   convertVia const & 
) const

Definition at line 279 of file ParameterSet.h.

280 {
281  auto result = get_if_present<T>(key, convert);
282  return result ? *result : throw fhicl::exception(cant_find, key);
283 }
static QCString result
def key(type, name=None)
Definition: graph.py:13
def convert(inputfile, outputfile="wire-cell-garfield-fine-response.json.bz2", average=False, shaped=False)
Definition: garfield.py:262
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<class T >
T fhicl::ParameterSet::get ( std::string const &  key,
T const &  default_value 
) const

Definition at line 287 of file ParameterSet.h.

288 {
289  auto result = get_if_present<T>(key);
290  return result ? *result : default_value;
291 }
static QCString result
def key(type, name=None)
Definition: graph.py:13
template<class T , class Via >
T fhicl::ParameterSet::get ( std::string const &  key,
T const &  default_value,
T   convertVia const & 
) const

Definition at line 295 of file ParameterSet.h.

298 {
299  auto result = get_if_present<T>(key, convert);
300  return result ? *result : default_value;
301 }
static QCString result
def key(type, name=None)
Definition: graph.py:13
def convert(inputfile, outputfile="wire-cell-garfield-fine-response.json.bz2", average=False, shaped=False)
Definition: garfield.py:262
vector< string > ParameterSet::get_all_keys ( ) const

Definition at line 201 of file ParameterSet.cc.

202 {
203  KeyAssembler ka;
204  walk(ka);
205  return ka.result();
206 }
void walk(ParameterSetWalker &psw) const
std::vector< key_t > const & result()
Definition: KeyAssembler.h:75
template<class T >
std::optional< T > fhicl::ParameterSet::get_if_present ( std::string const &  key) const

Definition at line 224 of file ParameterSet.h.

225 {
226  auto keys = detail::get_names(key);
227  if (auto ps = descend_(keys.tables())) {
228  return ps->get_one_<T>(keys.last());
229  }
230  return std::nullopt;
231 }
Keys get_names(std::string const &key)
def key(type, name=None)
Definition: graph.py:13
std::optional< ParameterSet > descend_(std::vector< std::string > const &names) const
static constexpr double ps
Definition: Units.h:99
template<class T , class Via >
std::optional< T > fhicl::ParameterSet::get_if_present ( std::string const &  key,
T   convertVia const & 
) const

Definition at line 235 of file ParameterSet.h.

237 {
238  auto go_between = get_if_present<Via>(key);
239  if (not go_between) {
240  return std::nullopt;
241  }
242  return std::make_optional(convert(*go_between));
243 } // get_if_present<>()
def key(type, name=None)
Definition: graph.py:13
def convert(inputfile, outputfile="wire-cell-garfield-fine-response.json.bz2", average=False, shaped=False)
Definition: garfield.py:262
template<class T >
bool fhicl::ParameterSet::get_if_present ( std::string const &  key,
T &  value 
) const

Definition at line 247 of file ParameterSet.h.

248 {
249  if (auto present_parameter = get_if_present<T>(key)) {
250  value = *present_parameter;
251  return true;
252  }
253  return false;
254 }
def key(type, name=None)
Definition: graph.py:13
template<class T , class Via >
bool fhicl::ParameterSet::get_if_present ( std::string const &  key,
T &  value,
T   convertVia const & 
) const

Definition at line 258 of file ParameterSet.h.

261 {
262  if (auto present_parameter = get_if_present<T>(key, convert)) {
263  result = *present_parameter;
264  return true;
265  }
266  return false;
267 } // get_if_present<>()
static QCString result
def key(type, name=None)
Definition: graph.py:13
def convert(inputfile, outputfile="wire-cell-garfield-fine-response.json.bz2", average=False, shaped=False)
Definition: garfield.py:262
vector< string > ParameterSet::get_names ( ) const

Definition at line 179 of file ParameterSet.cc.

180 {
181  vector<string> keys;
182  cet::transform_all(mapping_, std::back_inserter(keys), [](auto const& pr) {
183  return pr.first;
184  });
185  return keys;
186 }
auto transform_all(Container &, OutputIt, UnaryOp)
template<class T >
std::optional< T > fhicl::ParameterSet::get_one_ ( std::string const &  key) const
private

Definition at line 321 of file ParameterSet.h.

322 {
323  T value;
324  try {
325  auto skey = detail::get_sequence_indices(key);
326 
327  map_iter_t it = mapping_.find(skey.name());
328  if (it == mapping_.end()) {
329  return std::nullopt;
330  }
331 
332  auto a = it->second;
333  if (!detail::find_an_any(
334  skey.indices().cbegin(), skey.indices().cend(), a)) {
336  }
337 
338  using detail::decode;
339  decode(a, value);
340  return std::make_optional(value);
341  }
342  catch (fhicl::exception const& e) {
343  std::ostringstream errmsg;
344  errmsg << "\nUnsuccessful attempt to convert FHiCL parameter '" << key
345  << "' to type '" << cet::demangle_symbol(typeid(value).name())
346  << "'.\n\n"
347  << "[Specific error:]";
348  throw fhicl::exception(type_mismatch, errmsg.str(), e);
349  }
350  catch (std::exception const& e) {
351  std::ostringstream errmsg;
352  errmsg << "\nUnsuccessful attempt to convert FHiCL parameter '" << key
353  << "' to type '" << cet::demangle_symbol(typeid(value).name())
354  << "'.\n\n"
355  << "[Specific error:]\n"
356  << e.what() << "\n\n";
357  throw fhicl::exception(type_mismatch, errmsg.str());
358  }
359 }
static QCString name
Definition: declinfo.cpp:673
bool find_an_any(cit_size_t it, cit_size_t const cend, std::any &a)
map_t::const_iterator map_iter_t
Definition: ParameterSet.h:123
void decode(std::any const &, std::string &)
const double e
def key(type, name=None)
Definition: graph.py:13
const double a
SequenceKey get_sequence_indices(std::string const &key)
void decode(std::any const &a, Hep2Vector &result)
Definition: CLHEP_ps.h:12
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
vector< string > ParameterSet::get_pset_names ( ) const

Definition at line 189 of file ParameterSet.cc.

190 {
191  vector<string> keys;
192  for (auto const& [key, value] : mapping_) {
193  if (is_table(value)) {
194  keys.push_back(key);
195  }
196  }
197  return keys;
198 }
def key(type, name=None)
Definition: graph.py:13
bool is_table(par_type const pt)
std::string ParameterSet::get_src_info ( std::string const &  key) const

Definition at line 257 of file ParameterSet.cc.

258 {
259  auto result = srcMapping_.find(key);
260  return result != srcMapping_.cend() ? result->second : "";
261 }
static QCString result
def key(type, name=None)
Definition: graph.py:13
bool ParameterSet::has_key ( std::string const &  key) const

Definition at line 247 of file ParameterSet.cc.

248 {
249  auto keys = detail::get_names(key);
250  auto ps = descend_(keys.tables());
251  return ps ? ps->find_one_(keys.last()) : false;
252 }
Keys get_names(std::string const &key)
def key(type, name=None)
Definition: graph.py:13
std::optional< ParameterSet > descend_(std::vector< std::string > const &names) const
static constexpr double ps
Definition: Units.h:99
ParameterSetID ParameterSet::id ( ) const

Definition at line 153 of file ParameterSet.cc.

154 {
155  if (!id_.is_valid()) {
156  id_.reset(*this);
157  }
158  return id_;
159 }
bool is_valid() const noexcept
void reset(ParameterSet const &)
ParameterSetID id_
Definition: ParameterSet.h:127
void ParameterSet::insert_ ( std::string const &  key,
std::any const &  value 
)
private

Definition at line 290 of file ParameterSet.cc.

291 {
292  check_put_local_key(key);
293  if (!mapping_.emplace(key, value).second) {
294  throw exception(cant_insert) << "key " << key << " already exists.";
295  }
296  id_.invalidate();
297 }
def key(type, name=None)
Definition: graph.py:13
void invalidate() noexcept
ParameterSetID id_
Definition: ParameterSet.h:127
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void ParameterSet::insert_or_replace_ ( std::string const &  key,
std::any const &  value 
)
private

Definition at line 300 of file ParameterSet.cc.

301 {
302  check_put_local_key(key);
303  mapping_[key] = value;
304  id_.invalidate();
305 }
def key(type, name=None)
Definition: graph.py:13
void invalidate() noexcept
ParameterSetID id_
Definition: ParameterSet.h:127
void ParameterSet::insert_or_replace_compatible_ ( std::string const &  key,
std::any const &  value 
)
private

Definition at line 308 of file ParameterSet.cc.

309 {
310  check_put_local_key(key);
311  auto item = mapping_.find(key);
312  if (item == mapping_.end()) {
313  insert_(key, value);
314  return;
315  } else {
316  if (!detail::is_nil(value)) {
317  auto is_non_nil_atom = [](any const& v) {
318  return !(detail::is_sequence(v) || detail::is_table(v) ||
319  detail::is_nil(v));
320  };
321  if (detail::is_sequence(item->second) && !detail::is_sequence(value)) {
322  throw exception(cant_insert)
323  << "can't use non-sequence to replace sequence.";
324  } else if (detail::is_table(item->second) && !detail::is_table(value)) {
325  throw exception(cant_insert) << "can't use non-table to replace table.";
326  } else if (is_non_nil_atom(item->second) &&
328  throw exception(cant_insert)
329  << "can't use non-atom to replace non-nil atom.";
330  }
331  }
332  item->second = value;
333  }
334  id_.invalidate();
335 }
def key(type, name=None)
Definition: graph.py:13
void insert_(std::string const &key, std::any const &value)
bool is_nil(std::any const &val)
Definition: coding.cc:75
bool is_table(std::any const &val)
Definition: coding.h:55
void invalidate() noexcept
ParameterSetID id_
Definition: ParameterSet.h:127
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
bool is_sequence(std::any const &val)
Definition: coding.h:49
bool ParameterSet::is_empty ( ) const

Definition at line 147 of file ParameterSet.cc.

148 {
149  return mapping_.empty();
150 }
bool fhicl::ParameterSet::is_key_to_atom ( std::string const &  key) const
inline

Definition at line 177 of file ParameterSet.h.

178 {
179  return key_is_type_(key, [](std::any const& a) {
180  return !(detail::is_sequence(a) || detail::is_table(a));
181  });
182 }
def key(type, name=None)
Definition: graph.py:13
const double a
bool key_is_type_(std::string const &key, std::function< bool(std::any const &)> func) const
bool is_table(std::any const &val)
Definition: coding.h:55
bool is_sequence(std::any const &val)
Definition: coding.h:49
bool fhicl::ParameterSet::is_key_to_sequence ( std::string const &  key) const
inline

Definition at line 171 of file ParameterSet.h.

172 {
174 }
def key(type, name=None)
Definition: graph.py:13
bool key_is_type_(std::string const &key, std::function< bool(std::any const &)> func) const
bool is_sequence(std::any const &val)
Definition: coding.h:49
bool fhicl::ParameterSet::is_key_to_table ( std::string const &  key) const
inline

Definition at line 165 of file ParameterSet.h.

166 {
168 }
def key(type, name=None)
Definition: graph.py:13
bool key_is_type_(std::string const &key, std::function< bool(std::any const &)> func) const
bool is_table(std::any const &val)
Definition: coding.h:55
bool ParameterSet::key_is_type_ ( std::string const &  key,
std::function< bool(std::any const &)>  func 
) const
private

Definition at line 346 of file ParameterSet.cc.

348 {
349  auto split_keys = detail::get_names(key);
350  auto ps = descend_(split_keys.tables());
351  if (not ps) {
353  }
354 
355  auto skey = detail::get_sequence_indices(split_keys.last());
356 
357  auto it = ps->mapping_.find(skey.name());
358  if (it == ps->mapping_.end()) {
360  }
361 
362  auto a = it->second;
363  return detail::find_an_any(
364  skey.indices().cbegin(), skey.indices().cend(), a) ?
365  func(a) :
366  throw exception(error::cant_find, key);
367 }
Keys get_names(std::string const &key)
error
Definition: include.cc:26
bool find_an_any(cit_size_t it, cit_size_t const cend, std::any &a)
def key(type, name=None)
Definition: graph.py:13
const double a
std::optional< ParameterSet > descend_(std::vector< std::string > const &names) const
static constexpr double ps
Definition: Units.h:99
SequenceKey get_sequence_indices(std::string const &key)
def func()
Definition: docstring.py:7
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
fhicl::ParameterSet fhicl::ParameterSet::make ( intermediate_table const &  tbl)
static

Definition at line 68 of file ParameterSet.cc.

69 {
71  for (auto const& [key, value] : tbl) {
72  if (!value.in_prolog)
73  result.put(key, value);
74  }
75  return result;
76 }
static QCString result
def key(type, name=None)
Definition: graph.py:13
void put(std::string const &key)
fhicl::ParameterSet fhicl::ParameterSet::make ( extended_value const &  xval)
static

Definition at line 81 of file ParameterSet.cc.

82 {
83  if (!xval.is_a(TABLE))
84  throw fhicl::exception(type_mismatch, "extended value not a table");
85 
87  auto const& tbl = table_t(xval);
88  for (auto const& [key, value] : tbl) {
89  if (!value.in_prolog)
90  result.put(key, value);
91  }
92  return result;
93 }
static QCString result
intermediate_table::table_t table_t
Definition: ParameterSet.cc:32
def key(type, name=None)
Definition: graph.py:13
void put(std::string const &key)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
fhicl::ParameterSet fhicl::ParameterSet::make ( std::string const &  str)
static

Definition at line 98 of file ParameterSet.cc.

99 {
100  auto const tbl = parse_document(str);
101  return ParameterSet::make(tbl);
102 }
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68
intermediate_table parse_document(std::string const &filename, cet::filepath_maker &maker)
Definition: parse.cc:720
static QCString str
fhicl::ParameterSet fhicl::ParameterSet::make ( std::string const &  filename,
cet::filepath_maker maker 
)
static

Definition at line 107 of file ParameterSet.cc.

109 {
110  auto const tbl = parse_document(filename, maker);
111  return ParameterSet::make(tbl);
112 }
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68
string filename
Definition: train.py:213
intermediate_table parse_document(std::string const &filename, cet::filepath_maker &maker)
Definition: parse.cc:720
bool fhicl::ParameterSet::operator!= ( ParameterSet const &  other) const
inline

Definition at line 312 of file ParameterSet.h.

313 {
314  return !operator==(other);
315 }
bool operator==(ParameterSet const &other) const
Definition: ParameterSet.h:306
bool fhicl::ParameterSet::operator== ( ParameterSet const &  other) const
inline

Definition at line 306 of file ParameterSet.h.

307 {
308  return id() == other.id();
309 }
ParameterSetID id() const
void ParameterSet::put ( std::string const &  key)

Definition at line 266 of file ParameterSet.cc.

267 {
268  put(key, nullptr);
269 }
def key(type, name=None)
Definition: graph.py:13
void put(std::string const &key)
template<class T >
void fhicl::ParameterSet::put ( std::string const &  key,
T const &  value 
)

Definition at line 186 of file ParameterSet.h.

187 {
188  auto insert = [this, &value](auto const& key) {
189  using detail::encode;
190  this->insert_(key, std::any(encode(value)));
191  };
192  detail::try_insert(insert, key);
193 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:87
void try_insert(L l, std::string const &key)
Definition: try_blocks.h:11
def key(type, name=None)
Definition: graph.py:13
void insert_(std::string const &key, std::any const &value)
void fhicl::ParameterSet::put ( std::string const &  key,
fhicl::extended_value const &  value 
)

Definition at line 409 of file ParameterSet.cc.

410  {
411  auto insert = [this, &value](auto const& key) {
412  using detail::encode;
413  this->insert_(key, std::any(encode(value)));
414  fill_src_info(value, key, srcMapping_);
415  };
416  detail::try_insert(insert, key);
417  }
ps_atom_t encode(std::string const &)
Definition: coding.cc:87
void try_insert(L l, std::string const &key)
Definition: try_blocks.h:11
def key(type, name=None)
Definition: graph.py:13
void insert_(std::string const &key, std::any const &value)
void ParameterSet::put_or_replace ( std::string const &  key)

Definition at line 272 of file ParameterSet.cc.

273 {
274  put_or_replace(key, nullptr); // Replace with nil is always OK.
275 }
def key(type, name=None)
Definition: graph.py:13
void put_or_replace(std::string const &key)
template<class T >
void fhicl::ParameterSet::put_or_replace ( std::string const &  key,
T const &  value 
)

Definition at line 197 of file ParameterSet.h.

198 {
199  auto insert_or_replace = [this, &value](auto const& key) {
200  using detail::encode;
201  this->insert_or_replace_(key, std::any(encode(value)));
202  srcMapping_.erase(key);
203  };
204  detail::try_insert(insert_or_replace, key);
205 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:87
void try_insert(L l, std::string const &key)
Definition: try_blocks.h:11
def key(type, name=None)
Definition: graph.py:13
void insert_or_replace_(std::string const &key, std::any const &value)
template<class T >
void fhicl::ParameterSet::put_or_replace_compatible ( std::string const &  key,
T const &  value 
)

Definition at line 209 of file ParameterSet.h.

211 {
212  auto insert_or_replace_compatible = [this, &value](auto const& key) {
213  using detail::encode;
214  this->insert_or_replace_compatible_(key, std::any(encode(value)));
215  srcMapping_.erase(key);
216  };
217  detail::try_insert(insert_or_replace_compatible, key);
218 }
ps_atom_t encode(std::string const &)
Definition: coding.cc:87
void try_insert(L l, std::string const &key)
Definition: try_blocks.h:11
def key(type, name=None)
Definition: graph.py:13
void insert_or_replace_compatible_(std::string const &key, std::any const &value)
string ParameterSet::stringify_ ( std::any const &  a,
bool  compact = false 
) const
private

Definition at line 117 of file ParameterSet.cc.

118 {
119  string result;
120  if (is_table(a)) {
121  auto const& psid = any_cast<ParameterSetID>(a);
122  result = '{' + ParameterSetRegistry::get(psid).to_string() + '}';
123  if (compact && result.size() > (5 + ParameterSetID::max_str_size())) {
124  // Replace with a reference to the ParameterSetID;
125  result = std::string("@id::") + psid.to_string();
126  }
127  } else if (is_sequence(a)) {
128  auto const& seq = any_cast<ps_sequence_t>(a);
129  result = '[';
130  if (!seq.empty()) {
131  result.append(stringify_(*seq.begin(), compact));
132  for (auto it = seq.cbegin(), e = seq.cend(); ++it != e;) {
133  result.append(1, ',').append(stringify_(*it, compact));
134  }
135  }
136  result.append(1, ']');
137  } else { // is_atom(a)
138  ps_atom_t const str = any_cast<ps_atom_t>(a);
139  result = str == string(9, '\0') ? "@nil" : str;
140  }
141  return result;
142 } // stringify_()
static QCString result
std::string string
Definition: nybbler.cc:12
static collection_type const & get() noexcept
bool is_sequence(par_type const pt)
std::vector< std::any > ps_sequence_t
Definition: coding.h:45
const double e
const double a
static constexpr std::size_t max_str_size() noexcept
std::string ps_atom_t
Definition: coding.h:44
std::string stringify_(std::any const &a, bool compact=false) const
bool is_table(par_type const pt)
static QCString str
std::string fhicl::ParameterSet::to_compact_string ( ) const
inline

Definition at line 159 of file ParameterSet.h.

160 {
161  return to_string_(true);
162 }
std::string to_string_(bool compact=false) const
string ParameterSet::to_indented_string ( ) const

Definition at line 466 of file ParameterSet.cc.

467 {
468  return to_indented_string(0u);
469 }
std::string to_indented_string() const
string ParameterSet::to_indented_string ( unsigned  initial_indent_level) const

Definition at line 472 of file ParameterSet.cc.

473 {
474  return to_indented_string(initial_indent_level, false);
475 }
std::string to_indented_string() const
string ParameterSet::to_indented_string ( unsigned  initial_indent_level,
bool  annotate 
) const

Definition at line 478 of file ParameterSet.cc.

480 {
481  if (annotate) {
482  return to_indented_string(initial_indent_level, print_mode::annotated);
483  }
484  return to_indented_string(initial_indent_level, print_mode::raw);
485 }
std::string to_indented_string() const
string ParameterSet::to_indented_string ( unsigned  initial_indent_level,
detail::print_mode  pm 
) const

Definition at line 488 of file ParameterSet.cc.

490 {
492  switch (pm) {
493  case print_mode::raw: {
494  Prettifier p{initial_indent_level};
495  walk(p);
496  result = p.result();
497  break;
498  }
499  case print_mode::annotated: {
500  PrettifierAnnotated p{initial_indent_level};
501  walk(p);
502  result = p.result();
503  break;
504  }
505  case print_mode::prefix_annotated: {
507  walk(p);
508  result = p.result();
509  break;
510  }
511  }
512  return result;
513 }
static QCString result
std::string string
Definition: nybbler.cc:12
p
Definition: test.py:223
void walk(ParameterSetWalker &psw) const
std::string fhicl::ParameterSet::to_string ( ) const
inline

Definition at line 153 of file ParameterSet.h.

154 {
155  return to_string_();
156 }
std::string to_string_(bool compact=false) const
string ParameterSet::to_string_ ( bool  compact = false) const
private

Definition at line 162 of file ParameterSet.cc.

163 {
164  string result;
165  if (mapping_.empty()) {
166  return result;
167  }
168  auto it = mapping_.begin();
169  result.append(it->first).append(1, ':').append(
170  stringify_(it->second, compact));
171  for (auto const e = mapping_.end(); ++it != e;) {
172  result.append(1, ' ').append(it->first).append(1, ':').append(
173  stringify_(it->second, compact));
174  }
175  return result;
176 }
static QCString result
const double e
std::string stringify_(std::any const &a, bool compact=false) const
void ParameterSet::walk ( ParameterSetWalker psw) const

Definition at line 423 of file ParameterSet.cc.

424 {
425  std::stack<ParameterSet const*> ps_stack;
426  ps_stack.push(this);
427 
428  std::function<void(std::string const&, std::any const&)> act_on_element =
429  [&psw, &ps_stack, &act_on_element](std::string const& key,
430  std::any const& a) {
431  auto const* ps = ps_stack.top();
432  psw.do_before_action(key, a, ps);
433 
434  if (is_table(a)) {
435  ParameterSet const* ps = &get_pset_via_any(a);
436  ps_stack.push(ps);
437  psw.do_enter_table(key, a);
438  for (auto const& [nested_key, nested_a] : ps->mapping_) {
439  act_on_element(nested_key, nested_a);
440  }
441  psw.do_exit_table(key, a);
442  ps_stack.pop();
443  } else if (is_sequence(a)) {
444  psw.do_enter_sequence(key, a);
445  std::size_t i{};
446  for (auto const& elem : any_cast<ps_sequence_t>(a)) {
447  std::string const new_key = key + "["s + std::to_string(i++) + "]";
448  act_on_element(new_key, elem);
449  }
450  psw.do_exit_sequence(key, a);
451  } else {
452  psw.do_atom(key, a);
453  }
454 
455  psw.do_after_action(key);
456  };
457 
458  for (auto const& [key, value] : mapping_) {
459  act_on_element(key, value);
460  }
461 }
void do_before_action(key_t const &k, any_t const &a, ParameterSet const *ps)
std::string string
Definition: nybbler.cc:12
bool is_sequence(par_type const pt)
void do_enter_sequence(key_t const &k, any_t const &a)
void do_exit_table(key_t const &k, any_t const &a)
def key(type, name=None)
Definition: graph.py:13
const double a
static constexpr double ps
Definition: Units.h:99
void do_after_action(key_t const &k)
void do_exit_sequence(key_t const &k, any_t const &a)
bool is_table(par_type const pt)
void do_atom(key_t const &k, any_t const &a)
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
static QCString * s
Definition: config.cpp:1042
void do_enter_table(key_t const &k, any_t const &a)

Member Data Documentation

ParameterSetID fhicl::ParameterSet::id_
mutableprivate

Definition at line 127 of file ParameterSet.h.

map_t fhicl::ParameterSet::mapping_
private

Definition at line 125 of file ParameterSet.h.

annot_t fhicl::ParameterSet::srcMapping_
private

Definition at line 126 of file ParameterSet.h.


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