LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
RandomNumberSaver_module.cc
Go to the documentation of this file.
1 // vim: set sw=2 expandtab :
2 //
3 // Store state of the RandomNumberGenerator service into the event.
4 //
5 
10 #include "fhiclcpp/types/Atom.h"
11 
12 #include <memory>
13 #include <vector>
14 
15 using namespace std;
16 using namespace fhicl;
17 
18 namespace art {
19 
21  public:
22  struct Config {
23  Atom<bool> debug{Name{"debug"}, false};
24  };
26  explicit RandomNumberSaver(Parameters const&, ProcessingFrame const&);
27 
28  private:
29  void produce(Event&, ProcessingFrame const&) override;
30  // When true makes produce call rng->print_().
31  bool const debug_;
32  };
33 
34  RandomNumberSaver::RandomNumberSaver(Parameters const& config,
35  ProcessingFrame const&)
36  : SharedProducer{config}, debug_{config().debug()}
37  {
38  produces<vector<RNGsnapshot>>();
39  if (debug_) {
40  // If debugging information is desired, serialize so that the
41  // printing is not garbled.
42  serialize<InEvent>();
43  } else {
44  async<InEvent>();
45  }
46  }
47 
48  void
50  {
51  auto const sid = frame.scheduleID();
52  auto rng = frame.serviceHandle<RandomNumberGenerator const>();
53  e.put(make_unique<vector<RNGsnapshot>>(rng->accessSnapshot_(sid)));
54  if (debug_) {
55  rng->print_();
56  }
57  }
58 
59 } // namespace art
60 
STL namespace.
auto scheduleID() const
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
DebugStuff debug
Definition: DebugStruct.cxx:4
ServiceHandle< T > serviceHandle() const
parameter set interface
void produce(Event &, ProcessingFrame const &) override
Definition: MVAAlg.h:12
Float_t e
Definition: plot.C:35