22 #include "CLHEP/Random/JamesRandom.h"
23 #include "CLHEP/Random/Random.h"
24 #include "CLHEP/Random/StaticRandomStates.h"
25 #include "CLHEP/Utility/memory.h"
26 #include "CLHEP/Utility/thread_local.h"
32 #include "CLHEP/Random/SeedTable.h"
40 defaults( HepRandom &
g, HepJamesRandom & e )
45 void resetEngine( HepRandomEngine * newEngine ) {
49 void resetEngine( HepRandomEngine & newEngine ) {
50 theEngine.reset( &newEngine, do_nothing_deleter() );
53 bool ensureInitialized() {
65 defaults & theDefaults() {
66 static CLHEP_THREAD_LOCAL HepRandom theDefaultGenerator;
67 static CLHEP_THREAD_LOCAL HepJamesRandom theDefaultEngine;
68 static CLHEP_THREAD_LOCAL defaults theDefaults(theDefaultGenerator, theDefaultEngine);
76 HepRandom::HepRandom()
79 HepRandom::HepRandom(
long seed)
84 HepRandom::HepRandom(HepRandomEngine & algorithm)
86 theDefaults().resetEngine( algorithm );
89 HepRandom::HepRandom(HepRandomEngine * algorithm)
91 theDefaults().resetEngine( algorithm );
94 HepRandom::~HepRandom()
99 return theDefaults().theEngine->flat();
102 void HepRandom::flatArray(
const int size,
double* vect)
104 theDefaults().theEngine->flatArray(size,vect);
107 double HepRandom::operator()() {
113 std::cerr <<
"HepRandom::engine() called -- there is no assigned engine!\n";
114 return *theDefaults().theEngine.get();
117 std::ostream &
operator<< (std::ostream & os,
const HepRandom & dist) {
121 std::istream &
operator>> (std::istream & is, HepRandom & dist) {
125 std::ostream & HepRandom::put(std::ostream & os)
const {
return os;}
126 std::istream & HepRandom::get(std::istream & is) {
return is;}
132 void HepRandom::setTheSeed(
long seed,
int lux)
134 theDefaults().theEngine->setSeed(seed,lux);
137 long HepRandom::getTheSeed()
139 return theDefaults().theEngine->getSeed();
142 void HepRandom::setTheSeeds(
const long* seeds,
int aux)
144 theDefaults().theEngine->setSeeds(seeds,aux);
147 const long* HepRandom::getTheSeeds ()
149 return theDefaults().theEngine->getSeeds();
152 void HepRandom::getTheTableSeeds(
long* seeds,
int index)
154 if ((index >= 0) && (index < 215)) {
155 seeds[0] = seedTable[index][0];
156 seeds[1] = seedTable[index][1];
161 HepRandom * HepRandom::getTheGenerator()
163 return theDefaults().theGenerator.get();
166 HepRandomEngine * HepRandom::getTheEngine()
168 return theDefaults().theEngine.get();
171 void HepRandom::setTheEngine (HepRandomEngine* theNewEngine)
173 theDefaults().theEngine.reset( theNewEngine, do_nothing_deleter() );
176 void HepRandom::saveEngineStatus(
const char filename[] )
178 theDefaults().theEngine->saveStatus( filename );
181 void HepRandom::restoreEngineStatus(
const char filename[] )
183 theDefaults().theEngine->restoreStatus( filename );
186 std::ostream& HepRandom::saveFullState ( std::ostream & os ) {
187 os << *getTheEngine();
191 std::istream& HepRandom::restoreFullState ( std::istream & is ) {
192 is >> *getTheEngine();
196 std::ostream& HepRandom::saveStaticRandomStates ( std::ostream & os ) {
197 return StaticRandomStates::save(os);
200 std::istream& HepRandom::restoreStaticRandomStates ( std::istream & is ) {
201 return StaticRandomStates::restore(is);
204 void HepRandom::showEngineStatus()
206 theDefaults().theEngine->showStatus();
209 int HepRandom::createInstance()
211 return static_cast<int>( theDefaults().ensureInitialized() );
std::shared_ptr< HepRandom > theGenerator
std::shared_ptr< HepRandomEngine > theEngine
static int engine(pchar, pchar, double &, pchar &, const dic_type &)
std::istream & operator>>(std::istream &is, HepAxisAngle &aa)
std::ostream & operator<<(std::ostream &os, const HepAxisAngle &aa)