CORSIKA  @c8_version@
The framework to simulate particle cascades for astroparticle physics
RNGManager.hpp
1 /*
2  * (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
3  *
4  * This software is distributed under the terms of the GNU General Public
5  * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
6  * the license.
7  */
8 
9 #pragma once
10 
11 #include <map>
12 #include <cstdint>
13 #include <random>
14 #include <string>
15 
16 #include <corsika/framework/utility/Singleton.hpp>
18 #include <corsika/detail/framework/random/random_iterator/Stream.hpp>
23 namespace corsika {
24 
25  template <typename CBPRNG = random_iterator::philox>
26  class RNGManager : public corsika::Singleton<RNGManager<CBPRNG>> {
27 
28  friend class corsika::Singleton<RNGManager<CBPRNG>>;
29 
30  public:
31  typedef CBPRNG prng_type;
32  typedef std::uint64_t seed_type;
33  typedef std::string string_type;
34  typedef std::map<std::string, prng_type> streams_type;
35 
36  RNGManager(RNGManager<CBPRNG> const&) = delete; // since it is a singleton
37 
38  RNGManager<CBPRNG>& operator=(RNGManager<CBPRNG> const&) = delete;
39 
46  inline void registerRandomStream(string_type const& streamName);
47 
52  inline prng_type& getRandomStream(string_type const& streamName);
53 
57  inline bool isRegistered(string_type const& streamName) const;
58 
63  inline std::stringstream dumpState() const;
64 
73  const streams_type& getRngs() const { return rngs_; }
74 
83  streams_type& Rngs() { return rngs_; }
84 
85  seed_type getSeed() const { return seed_; }
86 
87  void setSeed(seed_type seed) {
88  seed_ = seed;
89  // update the rgn states
90  for (auto& [streamName, rng] : rngs_) rng.setSeed(seed_);
91  }
92 
93  protected:
94  RNGManager() = default;
95 
96  private:
97  streams_type rngs_;
98  seed_type seed_;
99  };
100 
101  typedef typename RNGManager<>::prng_type default_prng_type;
102 
103 } // namespace corsika
104 
105 #include <corsika/detail/framework/random/RNGManager.inl>
streams_type & Rngs()
Non-constant access to the streams.
Definition: RNGManager.hpp:83
CORSIKA8 logging utilities.
void registerRandomStream(string_type const &streamName)
Curiously Recurring Template Pattern (CRTP) for Meyers singleton.
Definition: Singleton.hpp:40
bool isRegistered(string_type const &streamName) const
std::stringstream dumpState() const
`, since they are used everywhere as integral part of the framework.
prng_type & getRandomStream(string_type const &streamName)