LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
RandomNumberSaver_module.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // RandomNumberSaver_plugin: Store state of the RandomNumberGenerator
4 // service into the event.
5 //
6 // ======================================================================
7 
14 #include "fhiclcpp/types/Atom.h"
15 
16 #include <memory>
17 #include <mutex>
18 
19 namespace art {
20  class RandomNumberSaver;
21 }
22 
23 using namespace fhicl;
25 
26 // ======================================================================
27 
30 
31 public:
32  // --- Characteristics:
35 
36  // --- Configuration
37  struct Config {
38  Atom<bool> debug{Name{"debug"}, false};
39  };
40 
42  explicit RandomNumberSaver(Parameters const&);
43 
44  void produce(Event&) override;
45 
46 private:
47  bool debug_;
48  std::mutex m_{};
49 }; // RandomNumberSaver
50 
51 // ======================================================================
52 
54  : debug_{config().debug()}
55 {
56  produces<snapshot_t>();
57 }
58 
59 // ----------------------------------------------------------------------
60 
61 void
63 {
64  // MT-TODO: Placeholder until we're multithreaded.
65  auto const sid = ScheduleID::first();
67  e.put(std::make_unique<snapshot_t>(rng->accessSnapshot_(sid)));
68 
69  if (debug_) {
70  // Only take out the lock if running in debug mode.
71  std::lock_guard<std::mutex> hold{m_};
72  rng->print_();
73  }
74 }
75 
RNGservice::label_t label_t
Definition: EngineCreator.h:37
void produce(Event &) override
RNGservice::snapshot_t snapshot_t
static ScheduleID first()
Definition: ScheduleID.h:82
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
std::vector< RNGsnapshot > snapshot_t
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
DebugStuff debug
Definition: DebugStruct.cxx:4
parameter set interface
snapshot_t const & accessSnapshot_(ScheduleID const schedule_id) const
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
HLT enums.
Float_t e
Definition: plot.C:34
RandomNumberSaver(Parameters const &)