LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
MarleyParameterSetWalker.h
Go to the documentation of this file.
1 
9 #ifndef LARSIM_MARLEY_PARAMETERSET_WALKER_H
10 #define LARSIM_MARLEY_PARAMETERSET_WALKER_H
11 
12 // standard library includes
13 #include <sstream>
14 #include <string>
15 #include <vector>
16 
17 // framework includes
20 
21 // MARLEY includes
22 #include "marley/JSON.hh"
23 
24 namespace evgen {
25 
27 
28  public:
29  inline const marley::JSON& get_json() const { return full_json_; }
30  inline marley::JSON& get_json() { return full_json_; }
31 
32  private:
33  inline void enter_table(const key_t& key, const any_t&) override
34  {
35  auto& json = json_refs_.back().get();
36  json_refs_.emplace_back(json[key] = marley::JSON::make(marley::JSON::DataType::Object));
37  }
38 
39  inline void enter_sequence(const key_t& key, const any_t&) override
40  {
41  auto& json = json_refs_.back().get();
42  in_seq_ = true;
43  seq_index_ = 0u;
44  json_refs_.emplace_back(json[key] = marley::JSON::make(marley::JSON::DataType::Array));
45  }
46 
47  inline void atom(const key_t& key, const any_t& any) override
48  {
49  auto& json = json_refs_.back().get();
50  // Convert the atom to a string. Add an extra space to keep some
51  // of MARLEY's JSON parsing routines (which rely on looking ahead
52  // in some cases) happy
53  std::string atom_val = fhicl::detail::atom::value(any) + ' ';
54  marley::JSON json_atom;
55  // Hard-coded value taken from fhiclcpp/detail/printing_helpers.cc
56  if (atom_val != "@nil") {
57  std::istringstream iss(atom_val);
58  // Utility function defined in marley/JSON.hh
59  json_atom = marley::parse_next(iss);
60  }
61  if (in_seq_) { json[seq_index_++] = json_atom; }
62  else {
63  json[key] = json_atom;
64  }
65  }
66 
67  inline void exit_table(const key_t&, const any_t&) override { json_refs_.pop_back(); }
68 
69  inline void exit_sequence(const key_t&, const any_t&) override
70  {
71  json_refs_.pop_back();
72  in_seq_ = false;
73  }
74 
76  marley::JSON full_json_;
77 
79  std::vector<std::reference_wrapper<marley::JSON>> json_refs_ = {full_json_};
80 
81  unsigned seq_index_ = 0u;
82  bool in_seq_ = false;
83  };
84 
85 }
86 
87 #endif // LARSIM_MARLEY_PARAMETERSET_WALKER_H
std::unique_ptr< InputSource > make(fhicl::ParameterSet const &conf, InputSourceDescription &desc)
const marley::JSON & get_json() const
void exit_sequence(const key_t &, const any_t &) override
void enter_sequence(const key_t &key, const any_t &) override
std::string value(std::any const &)
marley::JSON full_json_
Owned JSON object used to store the converted FHiCL parameters.
void enter_table(const key_t &key, const any_t &) override
void exit_table(const key_t &, const any_t &) override
void atom(const key_t &key, const any_t &any) override
std::vector< std::reference_wrapper< marley::JSON > > json_refs_
References to the owned JSON object or a sub-object thereof.
Event Generation using GENIE, cosmics or single particles.