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 
11 #include "fhiclcpp/types/Atom.h"
12 
13 #include <memory>
14 #include <vector>
15 
16 using namespace std;
17 using namespace fhicl;
18 
19 namespace art {
20 
22  public:
23  struct Config {
24  Atom<bool> debug{Name{"debug"}, false};
25  };
27  explicit RandomNumberSaver(Parameters const&, ProcessingFrame const&);
28 
29  private:
30  void produce(Event&, ProcessingFrame const&) override;
31  // When true makes produce call rng->print_().
32  bool const debug_;
33  };
34 
35  RandomNumberSaver::RandomNumberSaver(Parameters const& config,
36  ProcessingFrame const&)
37  : SharedProducer{config}, debug_{config().debug()}
38  {
39  produces<vector<RNGsnapshot>>();
40  if (debug_) {
41  // If debugging information is desired, serialize so that the
42  // printing is not garbled.
43  serialize<InEvent>();
44  } else {
45  async<InEvent>();
46  }
47  }
48 
49  void
51  {
52  auto const sid = frame.scheduleID();
53  auto rng = frame.serviceHandle<RandomNumberGenerator const>();
54  e.put(make_unique<vector<RNGsnapshot>>(rng->accessSnapshot_(sid)));
55  if (debug_) {
56  rng->print_();
57  }
58  }
59 
60 } // namespace art
61 
STL namespace.
auto scheduleID() const
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
static Config * config
Definition: config.cpp:1054
ServiceHandle< T > serviceHandle() const
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
void produce(Event &, ProcessingFrame const &) override