RNGsnapshot.h
Go to the documentation of this file.
1 #ifndef canvas_Persistency_Common_RNGsnapshot_h
2 #define canvas_Persistency_Common_RNGsnapshot_h
3 // vim: set sw=2 expandtab :
4 
5 // ======================================================================
6 // RNGsnapshot is a data product holding saved state from/for the
7 // RandomNumberGenerator.
8 // ======================================================================
9 
10 #include <limits>
11 #include <string>
12 #include <vector>
13 
14 namespace art {
15 
16  class RNGsnapshot {
17  public:
18  // --- CLHEP engine state characteristics:
19  using CLHEP_t = unsigned long;
20  using engine_state_t = std::vector<CLHEP_t>;
21 
22  // --- Our state characteristics:
23  using saved_t = unsigned int;
24  using snapshot_state_t = std::vector<saved_t>;
26 
27  // CLHEP specifies that an engine's state will be returned as an
28  // object of type vector<unsigned long>. These static asserts
29  // ensure that (a) the schema we use is portable between
30  // platforms, and (b) the schema is large enough to hold the
31  // necessary data, but not too large to allow data loss when
32  // converting from unsigned int (our type) to unsigned long
33  // (CLHEP's type).
34  static_assert(std::numeric_limits<saved_t>::digits == 32,
35  "std::numeric_limits<saved_t>::digits != 32");
36  static_assert(sizeof(saved_t) <= sizeof(CLHEP_t),
37  "sizeof(saved_t) > sizeof(CLHEP_t)");
38 
39  RNGsnapshot() = default;
40  explicit RNGsnapshot(std::string const& ekind,
41  label_t const& label,
42  engine_state_t const& est);
43 
44  // --- Access:
45  std::string const&
46  ekind() const
47  {
48  return engine_kind_;
49  }
50  label_t const&
51  label() const
52  {
53  return label_;
54  }
55  snapshot_state_t const&
56  state() const
57  {
58  return state_;
59  }
60 
61  // --- Save/restore:
62  void saveFrom(std::string const&, label_t const&, engine_state_t const&);
64 
65  private:
69 
70  }; // RNGsnapshot
71 
72 } // art
73 
74 #endif /* canvas_Persistency_Common_RNGsnapshot_h */
75 
76 // Local Variables:
77 // mode: c++
78 // End:
std::string const & ekind() const
Definition: RNGsnapshot.h:46
std::string string
Definition: nybbler.cc:12
std::vector< saved_t > snapshot_state_t
Definition: RNGsnapshot.h:24
snapshot_state_t const & state() const
Definition: RNGsnapshot.h:56
void saveFrom(std::string const &, label_t const &, engine_state_t const &)
Definition: RNGsnapshot.cc:21
std::vector< CLHEP_t > engine_state_t
Definition: RNGsnapshot.h:20
unsigned long CLHEP_t
Definition: RNGsnapshot.h:19
unsigned int saved_t
Definition: RNGsnapshot.h:23
RNGsnapshot()=default
std::string engine_kind_
Definition: RNGsnapshot.h:66
engine_state_t restoreState() const
Definition: RNGsnapshot.cc:32
label_t const & label() const
Definition: RNGsnapshot.h:51
snapshot_state_t state_
Definition: RNGsnapshot.h:68
std::string label_t
Definition: RNGsnapshot.h:25