13 #include <fwk/RandomEngineRegistry.h>
14 #include <fwk/CentralConfig.h>
15 #include <utl/RandomEngine.h>
16 #include <utl/AugerException.h>
17 #include <utl/ErrorLogger.h>
18 #include <utl/Reader.h>
20 #include <CLHEP/Random/Randomize.h>
22 using namespace CLHEP;
32 const bool ok = fRegistry->insert(make_pair(
id, engine)).second;
35 msg <<
"Double insertion of random engine with id " << id;
47 Registry::iterator it = fRegistry->find(
id);
48 if (it == fRegistry->end()) {
50 msg <<
"Random engine with id " <<
id <<
" does not exist.";
58 RandomEngineRegistry::~RandomEngineRegistry()
61 for (
const auto& r : *fRegistry)
72 string msg(
"Calling Init, "
73 "but RandomEngineRegistry already initialized.");
86 WARNING(
"RandomEngine branch not found. Random seeds will be generated.");
89 if (seed[0] == seed[1] && seed[0] > 0) {
91 msg <<
"DetectorSeed = " << seed[0] <<
" = PhysicsSeed: This can lead to unwanted correlations!";
96 long randomSeed[2] = { 0 };
97 GenerateSeeds(randomSeed, 2);
98 for (
int i = 0; i < 2; ++i)
100 seed[i] = randomSeed[i];
103 RegisterOne(eDetector, detectorengine);
107 info <<
"Seeds of random streams: "
108 "eDetector = " << seed[0] <<
", "
109 "ePhysics = " << seed[1] <<
'.';
113 HepRandom::setTheEngine(&detectorengine->
GetEngine());
118 RandomEngineRegistry::GenerateSeeds(
long*
const seed,
const int n)
121 FILE*
const fd = fopen(
"/dev/urandom",
"r");
124 for (i = 0; i < n; ++i) {
128 len = fread(&s,
sizeof(s), 1, fd);
139 WARNING(
"Unable to open /dev/random, using current time instead.");
140 time_t
s = time(
nullptr);
141 for (
int i = 0; i < n; ++i)
142 seed[i] =
abs(
int(s++));
Branch GetTopBranch() const
RandomEngineType & GetEngine()
Base class for exceptions arising because configuration data are not valid.
#define INFO(message)
Macro for logging informational messages.
void Init()
Initialise the registry.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Exception to use if sequence of initialisations violated.
Class representing a document branch.
Wraps the random number engine used to generate distributions.
double abs(const SVector< n, T > &v)
#define WARNING(message)
Macro for logging warning messages.
void GetData(bool &b) const
Overloads of the GetData member template function.
std::map< RandomEngineID, utl::RandomEngine * > Registry
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.
RandomEngineID
Identifiers for all pre-defined random engines.
#define ERROR(message)
Macro for logging error messages.
Base class for exceptions in the RandomEngineRegistry.