21 #include "CLHEP/Random/JamesRandom.h"
22 #include "CLHEP/Random/Random.h"
23 #include "CLHEP/Random/StaticRandomStates.h"
24 #include "CLHEP/Utility/memory.h"
25 #include "CLHEP/Utility/thread_local.h"
31 #include "CLHEP/Random/SeedTable.h"
39 defaults( HepRandom &
g, HepJamesRandom & e )
44 void resetEngine( HepRandomEngine * newEngine ) {
48 void resetEngine( HepRandomEngine & newEngine ) {
49 theEngine.reset( &newEngine, do_nothing_deleter() );
52 bool ensureInitialized() {
64 defaults & theDefaults() {
65 static CLHEP_THREAD_LOCAL HepRandom theDefaultGenerator;
66 static CLHEP_THREAD_LOCAL HepJamesRandom theDefaultEngine;
67 static CLHEP_THREAD_LOCAL defaults theDefaults(theDefaultGenerator, theDefaultEngine);
75 HepRandom::HepRandom()
78 HepRandom::HepRandom(
long seed)
83 HepRandom::HepRandom(HepRandomEngine & algorithm)
85 theDefaults().resetEngine( algorithm );
88 HepRandom::HepRandom(HepRandomEngine * algorithm)
90 theDefaults().resetEngine( algorithm );
93 HepRandom::~HepRandom()
98 return theDefaults().theEngine->flat();
101 void HepRandom::flatArray(
const int size,
double* vect)
103 theDefaults().theEngine->flatArray(size,vect);
106 double HepRandom::operator()() {
112 std::cerr <<
"HepRandom::engine() called -- there is no assigned engine!\n";
113 return *theDefaults().theEngine.get();
116 std::ostream &
operator<< (std::ostream & os,
const HepRandom & dist) {
120 std::istream &
operator>> (std::istream & is, HepRandom & dist) {
124 std::ostream & HepRandom::put(std::ostream & os)
const {
return os;}
125 std::istream & HepRandom::get(std::istream & is) {
return is;}
131 void HepRandom::setTheSeed(
long seed,
int lux)
133 theDefaults().theEngine->setSeed(seed,lux);
136 long HepRandom::getTheSeed()
138 return theDefaults().theEngine->getSeed();
141 void HepRandom::setTheSeeds(
const long* seeds,
int aux)
143 theDefaults().theEngine->setSeeds(seeds,aux);
146 const long* HepRandom::getTheSeeds ()
148 return theDefaults().theEngine->getSeeds();
151 void HepRandom::getTheTableSeeds(
long* seeds,
int index)
153 if ((index >= 0) && (index < 215)) {
154 seeds[0] = seedTable[index][0];
155 seeds[1] = seedTable[index][1];
160 HepRandom * HepRandom::getTheGenerator()
162 return theDefaults().theGenerator.get();
165 HepRandomEngine * HepRandom::getTheEngine()
167 return theDefaults().theEngine.get();
170 void HepRandom::setTheEngine (HepRandomEngine* theNewEngine)
172 theDefaults().theEngine.reset( theNewEngine, do_nothing_deleter() );
175 void HepRandom::saveEngineStatus(
const char filename[] )
177 theDefaults().theEngine->saveStatus( filename );
180 void HepRandom::restoreEngineStatus(
const char filename[] )
182 theDefaults().theEngine->restoreStatus( filename );
185 std::ostream& HepRandom::saveFullState ( std::ostream & os ) {
186 os << *getTheEngine();
190 std::istream& HepRandom::restoreFullState ( std::istream & is ) {
191 is >> *getTheEngine();
195 std::ostream& HepRandom::saveStaticRandomStates ( std::ostream & os ) {
196 return StaticRandomStates::save(os);
199 std::istream& HepRandom::restoreStaticRandomStates ( std::istream & is ) {
200 return StaticRandomStates::restore(is);
203 void HepRandom::showEngineStatus()
205 theDefaults().theEngine->showStatus();
208 int HepRandom::createInstance()
210 return static_cast<int>( theDefaults().ensureInitialized() );
shared_ptr< HepRandom > theGenerator
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)