LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
RNGsnapshot.h
Go to the documentation of this file.
1 #ifndef canvas_Persistency_Common_RNGsnapshot_h
2 #define canvas_Persistency_Common_RNGsnapshot_h
3 
4 // ======================================================================
5 //
6 // RNGsnapshot - a data product holding saved state from/for the
7 // RandomNumberGenerator
8 //
9 // ======================================================================
10 //
11 // Notes:
12 // ------
13 //
14 // CLHEP specifies that the state of any of its engines will be returned
15 // as a vector<unsigned long>. However, the size of such a long is
16 // machine-dependent. If unsigned long is an 8 byte variable, only the
17 // least significant 4 bytes are filled and the most significant 4 bytes
18 // are zero. We choose to store only the useful 32 bits, making the
19 // assumption (verified at compile-time) that unsigned int is always a
20 // 32-bit type.
21 //
22 // We would prefer to be more explicit about this by using a standard
23 // typedef such as saved_t32_t. However, ROOT would have issues with this
24 // since ROOT sees only the underlying type, and not the typedef proper.
25 // Thus values written on one system and read on another would be
26 // problematic whenever the two systems did not agree on the underlying
27 // type.
28 //
29 // ======================================================================
30 
31 #include <limits>
32 #include <string>
33 #include <type_traits>
34 #include <vector>
35 
36 // ======================================================================
37 
38 namespace art {
39 
40  class RNGsnapshot {
41  public:
42  // --- CLHEP engine state characteristics:
43  using CLHEP_t = unsigned long;
44  using engine_state_t = std::vector<CLHEP_t>;
45 
46  // --- Our state characteristics:
47  using saved_t = unsigned int;
48  using snapshot_state_t = std::vector<saved_t>;
49  using label_t = std::string;
50 
51  static_assert(std::numeric_limits<saved_t>::digits == 32,
52  "std::numeric_limits<saved_t>::digits != 32");
53  static_assert(sizeof(saved_t) <= sizeof(CLHEP_t),
54  "sizeof(saved_t) > sizeof(CLHEP_t)");
55 
56  RNGsnapshot() = default;
57  explicit RNGsnapshot(std::string const& ekind,
58  label_t const& label,
59  engine_state_t const& est);
60 
61  // --- Access:
62  std::string const&
63  ekind() const
64  {
65  return engine_kind_;
66  }
67  label_t const&
68  label() const
69  {
70  return label_;
71  }
72  snapshot_state_t const&
73  state() const
74  {
75  return state_;
76  }
77 
78  // --- Save/restore:
79  void saveFrom(std::string const&, label_t const&, engine_state_t const&);
81 
82  private:
83  std::string engine_kind_{};
86 
87  }; // RNGsnapshot
88 
89 } // art
90 
91  // ======================================================================
92 
93 #endif /* canvas_Persistency_Common_RNGsnapshot_h */
94 
95 // Local Variables:
96 // mode: c++
97 // End:
std::string const & ekind() const
Definition: RNGsnapshot.h:63
std::vector< saved_t > snapshot_state_t
Definition: RNGsnapshot.h:48
snapshot_state_t const & state() const
Definition: RNGsnapshot.h:73
std::vector< CLHEP_t > engine_state_t
Definition: RNGsnapshot.h:44
unsigned long CLHEP_t
Definition: RNGsnapshot.h:43
unsigned int saved_t
Definition: RNGsnapshot.h:47
RNGsnapshot()=default
std::string engine_kind_
Definition: RNGsnapshot.h:83
label_t const & label() const
Definition: RNGsnapshot.h:68
snapshot_state_t state_
Definition: RNGsnapshot.h:85
std::string label_t
Definition: RNGsnapshot.h:49
HLT enums.
void saveFrom(std::string const &, label_t const &, engine_state_t const &)
Definition: RNGsnapshot.cc:20
engine_state_t restoreState() const
Definition: RNGsnapshot.cc:30