MarleyParameterSetWalker.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////
2 /// \file MarleyParameterSetWalker.h
3 /// \brief Concrete fhicl::ParameterSetWalker that converts a
4 /// fhicl::ParameterSet into a marley::JSON object
5 ///
6 /// \author Steven Gardiner <gardiner@fnal.gov>
7 //////////////////////////////////////////////////////////////////////////////
8 
9 #ifndef LARSIM_MARLEY_PARAMETERSET_WALKER_H
10 #define LARSIM_MARLEY_PARAMETERSET_WALKER_H
11 
12 // standard library includes
13 #include <string>
14 #include <vector>
15 
16 // framework includes
19 
20 // MARLEY includes
21 #include "marley/JSON.hh"
22 
23 namespace evgen {
24 
26 
27  public:
28 
29  inline const marley::JSON& get_json() const { return full_json_; }
30  inline marley::JSON& get_json() { return full_json_; }
31 
32  private:
33 
34  inline void enter_table( const key_t& key, const any_t& ) override {
35  auto& json = json_refs_.back().get();
36  json_refs_.emplace_back( json[ key ]
38  }
39 
40  inline void enter_sequence( const key_t& key, const any_t& ) override {
41  auto& json = json_refs_.back().get();
42  in_seq_ = true;
43  seq_index_ = 0u;
44  json_refs_.emplace_back( json[ key ]
46  }
47 
48  inline void atom( const key_t& key, const any_t& any ) override {
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_ ) {
62  json[ seq_index_++ ] = json_atom;
63  }
64  else {
65  json[ key ] = json_atom;
66  }
67  }
68 
69  inline void exit_table( const key_t&, const any_t& ) override {
70  json_refs_.pop_back();
71  }
72 
73  inline void exit_sequence( const key_t&, const any_t& ) override {
74  json_refs_.pop_back();
75  in_seq_ = false;
76  }
77 
78  /// Owned JSON object used to store the converted FHiCL parameters
79  marley::JSON full_json_;
80 
81  /// References to the owned JSON object or a sub-object thereof
82  std::vector< std::reference_wrapper<marley::JSON> >
83  json_refs_ = { full_json_ };
84 
85  unsigned seq_index_ = 0u;
86  bool in_seq_ = false;
87  };
88 
89 }
90 
91 #endif // LARSIM_MARLEY_PARAMETERSET_WALKER_H
std::string string
Definition: nybbler.cc:12
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
#define Array
Definition: scanner.cpp:11549
def key(type, name=None)
Definition: graph.py:13
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
struct Object Object
Object type.
Definition: manual.c:5
void exit_table(const key_t &, const any_t &) override
unique_ptr< InputSource > make(ParameterSet const &conf, InputSourceDescription &desc)
std::vector< std::reference_wrapper< marley::JSON > > json_refs_
References to the owned JSON object or a sub-object thereof.
void atom(const key_t &key, const any_t &any) override
Event Generation using GENIE, cosmics or single particles.