9#include <boost/python.hpp>
13#include <framework/core/RandomNumbers.h>
14#include <framework/pcore/ProcHandler.h>
15#include <framework/pcore/ProcHelper.h>
16#include <framework/logging/Logger.h>
36 std::random_device random_device;
37 std::stringstream seed;
38 for (
int i = 0; i < 8; ++i) {
39 seed << std::hex << random_device();
56 B2DEBUG(100,
"Replacing gRandom from " << gRandom <<
" to " << gen);
60 s_evtRng->setSeed((
const unsigned char*)seed.c_str(), seed.size());
61 s_runRng->setSeed((
const unsigned char*)seed.c_str(), seed.size());
73 B2ERROR(
"Random Generator gRandom is not Belle2::RandomGenerator, cannot increase barrier");
82 B2INFO(
"The random number seed is set to \"" << seed <<
'"');
139 std::string pythonObjectToString(
const boost::python::object& obj)
141 return boost::python::extract<std::string>(obj.attr(
"__str__")());
144 void setPythonSeed(
const boost::python::object& obj)
152 using namespace boost::python;
155 docstring_options options(
true,
true,
false);
157 def(
"set_random_seed", &setPythonSeed, args(
"seed"), R
"DOCSTRING(
158Set the random seed. The argument can be any object and will be converted to a
159string using the builtin str() function and will be used to initialize the
160random generator.)DOCSTRING");
static bool isInputProcess()
Return true if the process is an input process.
static bool parallelProcessingUsed()
Returns true if multiple processes have been spawned, false in single-core mode.
Fast Random number Generator using on xorshift1024* [arXiv:1402.6246].
@ c_runDependent
Use experiment and run number to generate state.
@ c_eventDependent
Use experiment, run and event number to generate state.
@ c_independent
Don't use event info to generate state.
static int s_barrierOffset
barrier index offset to be used in begin/endRun.
static void initializeEndRun()
Initialize run independent random generator for end run.
static bool isInitialized()
Truth that the random number generator has been initialized.
static RandomGenerator * s_runRng
event independent random generator to be used for begin/end run processing
static void setSeed(const std::string &seed)
Sets the seed for the random number generator.
static void initializeBeginRun()
Initialize run independent random generator for begin run.
static std::string getSeed()
Get the random number generator seed.
static void initialize()
Initialize the random number generator with a unique random seed;.
static void useEventDependent()
Set Event dependent Random Generator as current one.
static std::string s_initialSeed
The random number generator seed set by the user.
static void exposePythonAPI()
Exposes methods of the RandomNumbers class to Python.
static RandomGenerator * s_evtRng
event dependent random generator to be used for event processing
static void barrier()
Increase random barrier.
static void initializeEvent(bool force=false)
Initialize event information.
Abstract base class for different kinds of events.