Geant4-11
Data Structures | Public Member Functions | Static Public Member Functions | Static Public Attributes | Static Protected Member Functions | Protected Attributes | Private Attributes
CLHEP::DualRand Class Reference

#include <DualRand.h>

Inheritance diagram for CLHEP::DualRand:
CLHEP::HepRandomEngine

Data Structures

class  IntegerCong
 
class  Tausworthe
 

Public Member Functions

 DualRand ()
 
 DualRand (int rowIndex, int colIndex)
 
 DualRand (long seed)
 
 DualRand (std::istream &is)
 
double flat ()
 
void flatArray (const int size, double *vect)
 
bool get (const std::vector< unsigned long > &v)
 
virtual std::istream & get (std::istream &is)
 
long getSeed () const
 
const long * getSeeds () const
 
bool getState (const std::vector< unsigned long > &v)
 
virtual std::istream & getState (std::istream &is)
 
std::string name () const
 
 operator double ()
 
 operator float ()
 
 operator unsigned int ()
 
bool operator!= (const HepRandomEngine &engine)
 
bool operator== (const HepRandomEngine &engine)
 
std::vector< unsigned long > put () const
 
virtual std::ostream & put (std::ostream &os) const
 
void restoreStatus (const char filename[]="DualRand.conf")
 
void saveStatus (const char filename[]="DualRand.conf") const
 
void setSeed (long seed, int)
 
void setSeeds (const long *seeds, int)
 
void showStatus () const
 
virtual ~DualRand ()
 

Static Public Member Functions

static std::string beginTag ()
 
static std::string engineName ()
 
static HepRandomEnginenewEngine (const std::vector< unsigned long > &v)
 
static HepRandomEnginenewEngine (std::istream &is)
 

Static Public Attributes

static const unsigned int VECTOR_STATE_SIZE = 9
 

Static Protected Member Functions

static bool checkFile (std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
 
static double exponent_bit_32 ()
 
static double mantissa_bit_12 ()
 
static double mantissa_bit_24 ()
 
static double mantissa_bit_32 ()
 
static double nearlyTwoToMinus_54 ()
 
static double twoToMinus_32 ()
 
static double twoToMinus_48 ()
 
static double twoToMinus_49 ()
 
static double twoToMinus_53 ()
 

Protected Attributes

long theSeed
 
const long * theSeeds
 

Private Attributes

IntegerCong integerCong
 
int numEngines
 
Tausworthe tausworthe
 

Detailed Description

Author

Definition at line 49 of file DualRand.h.

Constructor & Destructor Documentation

◆ DualRand() [1/4]

CLHEP::DualRand::DualRand ( )

Definition at line 80 of file DualRand.cc.

83 tausworthe (1234567 + numEngines + 175321),
84 integerCong(69607 * tausworthe + 54329, numEngines)
85{
86 theSeed = 1234567;
87}
IntegerCong integerCong
Definition: DualRand.h:137
Tausworthe tausworthe
Definition: DualRand.h:136
CLHEP_ATOMIC_INT_TYPE numberOfEngines(0)

References CLHEP::HepRandomEngine::theSeed.

◆ DualRand() [2/4]

CLHEP::DualRand::DualRand ( long  seed)

Definition at line 89 of file DualRand.cc.

91 numEngines(0),
92 tausworthe ((unsigned int)seed + 175321),
93 integerCong(69607 * tausworthe + 54329, 8043) // MF - not numEngines
94{
95 theSeed = seed;
96}

References CLHEP::HepRandomEngine::theSeed.

◆ DualRand() [3/4]

CLHEP::DualRand::DualRand ( std::istream &  is)

Definition at line 98 of file DualRand.cc.

100 numEngines(0)
101{
102 is >> *this;
103}

◆ DualRand() [4/4]

CLHEP::DualRand::DualRand ( int  rowIndex,
int  colIndex 
)

Definition at line 105 of file DualRand.cc.

107 numEngines(0),
108 tausworthe (rowIndex + 1000 * colIndex + 85329),
109 integerCong(69607 * tausworthe + 54329, 1123) // MF - not numengines
110{
111 theSeed = rowIndex;
112}

References CLHEP::HepRandomEngine::theSeed.

◆ ~DualRand()

CLHEP::DualRand::~DualRand ( )
virtual

Definition at line 114 of file DualRand.cc.

114{ }

Member Function Documentation

◆ beginTag()

std::string CLHEP::DualRand::beginTag ( )
static

Definition at line 248 of file DualRand.cc.

248 {
249 return "DualRand-begin";
250}

◆ checkFile()

bool CLHEP::HepRandomEngine::checkFile ( std::istream &  file,
const std::string &  filename,
const std::string &  classname,
const std::string &  methodname 
)
staticprotectedinherited

Definition at line 47 of file RandomEngine.cc.

50 {
51 if (!file) {
52 std::cerr << "Failure to find or open file " << filename <<
53 " in " << classname << "::" << methodname << "()\n";
54 return false;
55 }
56 return true;
57}

References geant4_check_module_cycles::file.

Referenced by restoreStatus(), CLHEP::HepJamesRandom::restoreStatus(), CLHEP::MTwistEngine::restoreStatus(), CLHEP::RanecuEngine::restoreStatus(), CLHEP::RanluxEngine::restoreStatus(), CLHEP::Ranlux64Engine::restoreStatus(), and CLHEP::RanshiEngine::restoreStatus().

◆ engineName()

static std::string CLHEP::DualRand::engineName ( )
inlinestatic

Definition at line 96 of file DualRand.h.

96{return "DualRand";}

Referenced by restoreStatus().

◆ exponent_bit_32()

static double CLHEP::HepRandomEngine::exponent_bit_32 ( )
inlinestaticprotectedinherited

◆ flat()

double CLHEP::DualRand::flat ( )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 116 of file DualRand.cc.

116 {
117 unsigned int ic ( integerCong );
118 unsigned int t ( tausworthe );
119 return ( (t ^ ic) * twoToMinus_32() + // most significant part
120 (t >> 11) * twoToMinus_53() + // fill in remaining bits
121 nearlyTwoToMinus_54() // make sure non-zero
122 );
123}
static double twoToMinus_32()
static double twoToMinus_53()
static double nearlyTwoToMinus_54()

References integerCong, CLHEP::HepRandomEngine::nearlyTwoToMinus_54(), tausworthe, CLHEP::HepRandomEngine::twoToMinus_32(), and CLHEP::HepRandomEngine::twoToMinus_53().

Referenced by flatArray().

◆ flatArray()

void CLHEP::DualRand::flatArray ( const int  size,
double *  vect 
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 125 of file DualRand.cc.

125 {
126 for (int i = 0; i < size; ++i) {
127 vect[i] = flat();
128 }
129}
double flat()
Definition: DualRand.cc:116

References flat().

◆ get() [1/2]

bool CLHEP::DualRand::get ( const std::vector< unsigned long > &  v)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 288 of file DualRand.cc.

288 {
289 if ((v[0] & 0xffffffffUL) != engineIDulong<DualRand>()) {
290 std::cerr <<
291 "\nDualRand get:state vector has wrong ID word - state unchanged\n";
292 return false;
293 }
294 if (v.size() != VECTOR_STATE_SIZE) {
295 std::cerr << "\nDualRand get:state vector has wrong size: "
296 << v.size() << " - state unchanged\n";
297 return false;
298 }
299 return getState(v);
300}
static const unsigned int VECTOR_STATE_SIZE
Definition: DualRand.h:102
virtual std::istream & getState(std::istream &is)
Definition: DualRand.cc:252

References getState(), and VECTOR_STATE_SIZE.

◆ get() [2/2]

std::istream & CLHEP::DualRand::get ( std::istream &  is)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 231 of file DualRand.cc.

231 {
232 char beginMarker [MarkerLen];
233 is >> std::ws;
234 is.width(MarkerLen); // causes the next read to the char* to be <=
235 // that many bytes, INCLUDING A TERMINATION \0
236 // (Stroustrup, section 21.3.2)
237 is >> beginMarker;
238 if (strcmp(beginMarker,"DualRand-begin")) {
239 is.clear(std::ios::badbit | is.rdstate());
240 std::cerr << "\nInput mispositioned or"
241 << "\nDualRand state description missing or"
242 << "\nwrong engine type found." << std::endl;
243 return is;
244 }
245 return getState(is);
246}
static const int MarkerLen
Definition: DualRand.cc:70

References getState(), and CLHEP::MarkerLen.

◆ getSeed()

long CLHEP::HepRandomEngine::getSeed ( ) const
inlineinherited

Definition at line 112 of file RandomEngine.h.

112{ return theSeed; }

References CLHEP::HepRandomEngine::theSeed.

◆ getSeeds()

const long * CLHEP::HepRandomEngine::getSeeds ( ) const
inlineinherited

Definition at line 115 of file RandomEngine.h.

115{ return theSeeds; }

References CLHEP::HepRandomEngine::theSeeds.

◆ getState() [1/2]

bool CLHEP::DualRand::getState ( const std::vector< unsigned long > &  v)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 302 of file DualRand.cc.

302 {
303 std::vector<unsigned long>::const_iterator iv = v.begin()+1;
304 if (!tausworthe.get(iv)) return false;
305 if (!integerCong.get(iv)) return false;
306 if (iv != v.end()) {
307 std::cerr <<
308 "\nDualRand get:state vector has wrong size: " << v.size()
309 << "\n Apparently " << iv-v.begin() << " words were consumed\n";
310 return false;
311 }
312 return true;
313}
void get(std::istream &is)
Definition: DualRand.cc:495
void get(std::istream &is)
Definition: DualRand.cc:408

References CLHEP::DualRand::Tausworthe::get(), CLHEP::DualRand::IntegerCong::get(), integerCong, and tausworthe.

◆ getState() [2/2]

std::istream & CLHEP::DualRand::getState ( std::istream &  is)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 252 of file DualRand.cc.

252 {
253 if ( possibleKeywordInput ( is, "Uvec", theSeed ) ) {
254 std::vector<unsigned long> v;
255 unsigned long uu;
256 for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
257 is >> uu;
258 if (!is) {
259 is.clear(std::ios::badbit | is.rdstate());
260 std::cerr << "\nDualRand state (vector) description improper."
261 << "\ngetState() has failed."
262 << "\nInput stream is probably mispositioned now." << std::endl;
263 return is;
264 }
265 v.push_back(uu);
266 }
267 getState(v);
268 return (is);
269 }
270
271// is >> theSeed; Removed, encompassed by possibleKeywordInput()
272
273 char endMarker [MarkerLen];
274 tausworthe.get(is);
275 integerCong.get(is);
276 is >> std::ws;
277 is.width(MarkerLen);
278 is >> endMarker;
279 if (strcmp(endMarker,"DualRand-end")) {
280 is.clear(std::ios::badbit | is.rdstate());
281 std::cerr << "DualRand state description incomplete."
282 << "\nInput stream is probably mispositioned now." << std::endl;
283 return is;
284 }
285 return is;
286}
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:166

References CLHEP::DualRand::Tausworthe::get(), CLHEP::DualRand::IntegerCong::get(), getState(), integerCong, CLHEP::MarkerLen, CLHEP::possibleKeywordInput(), tausworthe, CLHEP::HepRandomEngine::theSeed, and VECTOR_STATE_SIZE.

Referenced by get(), getState(), and restoreStatus().

◆ mantissa_bit_12()

static double CLHEP::HepRandomEngine::mantissa_bit_12 ( )
inlinestaticprotectedinherited

◆ mantissa_bit_24()

static double CLHEP::HepRandomEngine::mantissa_bit_24 ( )
inlinestaticprotectedinherited

◆ mantissa_bit_32()

static double CLHEP::HepRandomEngine::mantissa_bit_32 ( )
inlinestaticprotectedinherited

◆ name()

std::string CLHEP::DualRand::name ( ) const
virtual

◆ nearlyTwoToMinus_54()

static double CLHEP::HepRandomEngine::nearlyTwoToMinus_54 ( )
inlinestaticprotectedinherited

◆ newEngine() [1/2]

HepRandomEngine * CLHEP::HepRandomEngine::newEngine ( const std::vector< unsigned long > &  v)
staticinherited

Definition at line 96 of file RandomEngine.cc.

96 {
98}
static HepRandomEngine * newEngine(std::istream &is)

References CLHEP::EngineFactory::newEngine().

◆ newEngine() [2/2]

HepRandomEngine * CLHEP::HepRandomEngine::newEngine ( std::istream &  is)
staticinherited

Definition at line 91 of file RandomEngine.cc.

91 {
92 return EngineFactory::newEngine(is);
93}

References CLHEP::EngineFactory::newEngine().

Referenced by CLHEP::StaticRandomStates::restore().

◆ operator double()

CLHEP::DualRand::operator double ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 199 of file DualRand.cc.

199 {
200 return flat();
201}

References G4AblaRandom::flat().

◆ operator float()

CLHEP::DualRand::operator float ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 203 of file DualRand.cc.

203 {
204 return (float) ( (integerCong ^ tausworthe) * twoToMinus_32()
205 + nearlyTwoToMinus_54() );
206 // add this so that zero never happens
207}

◆ operator unsigned int()

CLHEP::DualRand::operator unsigned int ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 209 of file DualRand.cc.

209 {
210 return (integerCong ^ tausworthe) & 0xffffffff;
211}

◆ operator!=()

bool CLHEP::HepRandomEngine::operator!= ( const HepRandomEngine engine)
inlineinherited

◆ operator==()

bool CLHEP::HepRandomEngine::operator== ( const HepRandomEngine engine)
inlineinherited

◆ put() [1/2]

std::vector< unsigned long > CLHEP::DualRand::put ( ) const
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 223 of file DualRand.cc.

223 {
224 std::vector<unsigned long> v;
225 v.push_back (engineIDulong<DualRand>());
226 tausworthe.put(v);
227 integerCong.put(v);
228 return v;
229}
void put(std::ostream &os) const
Definition: DualRand.cc:477
void put(std::ostream &os) const
Definition: DualRand.cc:386

References integerCong, CLHEP::DualRand::Tausworthe::put(), CLHEP::DualRand::IntegerCong::put(), and tausworthe.

Referenced by put(), and saveStatus().

◆ put() [2/2]

std::ostream & CLHEP::DualRand::put ( std::ostream &  os) const
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 213 of file DualRand.cc.

213 {
214 char beginMarker[] = "DualRand-begin";
215 os << beginMarker << "\nUvec\n";
216 std::vector<unsigned long> v = put();
217 for (unsigned int i=0; i<v.size(); ++i) {
218 os << v[i] << "\n";
219 }
220 return os;
221}
std::vector< unsigned long > put() const
Definition: DualRand.cc:223

References put().

◆ restoreStatus()

void CLHEP::DualRand::restoreStatus ( const char  filename[] = "DualRand.conf")
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 153 of file DualRand.cc.

153 {
154 std::ifstream inFile(filename, std::ios::in);
155 if (!checkFile ( inFile, filename, engineName(), "restoreStatus" )) {
156 std::cerr << " -- Engine state remains unchanged\n";
157 return;
158 }
159 if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
160 std::vector<unsigned long> v;
161 unsigned long xin;
162 for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
163 inFile >> xin;
164 if (!inFile) {
165 inFile.clear(std::ios::badbit | inFile.rdstate());
166 std::cerr << "\nDualRand state (vector) description improper."
167 << "\nrestoreStatus has failed."
168 << "\nInput stream is probably mispositioned now." << std::endl;
169 return;
170 }
171 v.push_back(xin);
172 }
173 getState(v);
174 return;
175 }
176
177 if (!inFile.bad()) {
178// inFile >> theSeed; removed -- encompased by possibleKeywordInput
179 tausworthe.get(inFile);
180 integerCong.get(inFile);
181 }
182}
static std::string engineName()
Definition: DualRand.h:96
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
Definition: RandomEngine.cc:47

References CLHEP::HepRandomEngine::checkFile(), engineName(), CLHEP::DualRand::Tausworthe::get(), CLHEP::DualRand::IntegerCong::get(), getState(), integerCong, CLHEP::possibleKeywordInput(), tausworthe, CLHEP::HepRandomEngine::theSeed, and VECTOR_STATE_SIZE.

◆ saveStatus()

void CLHEP::DualRand::saveStatus ( const char  filename[] = "DualRand.conf") const
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 142 of file DualRand.cc.

142 {
143 std::ofstream outFile(filename, std::ios::out);
144 if (!outFile.bad()) {
145 outFile << "Uvec\n";
146 std::vector<unsigned long> v = put();
147 for (unsigned int i=0; i<v.size(); ++i) {
148 outFile << v[i] << "\n";
149 }
150 }
151}

References put().

◆ setSeed()

void CLHEP::DualRand::setSeed ( long  seed,
int   
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 131 of file DualRand.cc.

131 {
132 theSeed = seed;
133 tausworthe = Tausworthe((unsigned int)seed + 175321);
134 integerCong = IntegerCong(69607 * tausworthe + 54329, 8043);
135}

References integerCong, tausworthe, and CLHEP::HepRandomEngine::theSeed.

Referenced by setSeeds().

◆ setSeeds()

void CLHEP::DualRand::setSeeds ( const long *  seeds,
int   
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 137 of file DualRand.cc.

137 {
138 setSeed(seeds ? *seeds : 1234567, 0);
139 theSeeds = seeds;
140}
void setSeed(long seed, int)
Definition: DualRand.cc:131

References setSeed(), and CLHEP::HepRandomEngine::theSeeds.

◆ showStatus()

void CLHEP::DualRand::showStatus ( ) const
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 184 of file DualRand.cc.

184 {
185 int pr=std::cout.precision(20);
186 std::cout << std::endl;
187 std::cout << "-------- DualRand engine status ---------"
188 << std::endl;
189 std::cout << "Initial seed = " << theSeed << std::endl;
190 std::cout << "Tausworthe generator = " << std::endl;
191 tausworthe.put(std::cout);
192 std::cout << "\nIntegerCong generator = " << std::endl;
193 integerCong.put(std::cout);
194 std::cout << std::endl << "-----------------------------------------"
195 << std::endl;
196 std::cout.precision(pr);
197}

References integerCong, CLHEP::DualRand::Tausworthe::put(), CLHEP::DualRand::IntegerCong::put(), tausworthe, and CLHEP::HepRandomEngine::theSeed.

◆ twoToMinus_32()

static double CLHEP::HepRandomEngine::twoToMinus_32 ( )
inlinestaticprotectedinherited

◆ twoToMinus_48()

static double CLHEP::HepRandomEngine::twoToMinus_48 ( )
inlinestaticprotectedinherited

◆ twoToMinus_49()

static double CLHEP::HepRandomEngine::twoToMinus_49 ( )
inlinestaticprotectedinherited

◆ twoToMinus_53()

static double CLHEP::HepRandomEngine::twoToMinus_53 ( )
inlinestaticprotectedinherited

Field Documentation

◆ integerCong

IntegerCong CLHEP::DualRand::integerCong
private

Definition at line 137 of file DualRand.h.

Referenced by flat(), getState(), put(), restoreStatus(), setSeed(), and showStatus().

◆ numEngines

int CLHEP::DualRand::numEngines
private

Definition at line 135 of file DualRand.h.

◆ tausworthe

Tausworthe CLHEP::DualRand::tausworthe
private

Definition at line 136 of file DualRand.h.

Referenced by flat(), getState(), put(), restoreStatus(), setSeed(), and showStatus().

◆ theSeed

long CLHEP::HepRandomEngine::theSeed
protectedinherited

Definition at line 142 of file RandomEngine.h.

Referenced by DualRand(), CLHEP::HepRandomEngine::getSeed(), getState(), CLHEP::HepJamesRandom::getState(), CLHEP::MixMaxRng::getState(), CLHEP::MTwistEngine::getState(), CLHEP::RanecuEngine::getState(), CLHEP::Ranlux64Engine::getState(), CLHEP::RanluxEngine::getState(), CLHEP::RanshiEngine::getState(), CLHEP::HepJamesRandom::HepJamesRandom(), CLHEP::MixMaxRng::MixMaxRng(), CLHEP::RanecuEngine::put(), CLHEP::MixMaxRng::put(), CLHEP::MTwistEngine::put(), CLHEP::RanecuEngine::RanecuEngine(), CLHEP::RanluxEngine::RanluxEngine(), CLHEP::RanluxppEngine::RanluxppEngine(), CLHEP::RanshiEngine::RanshiEngine(), restoreStatus(), CLHEP::HepJamesRandom::restoreStatus(), CLHEP::MTwistEngine::restoreStatus(), CLHEP::RanecuEngine::restoreStatus(), CLHEP::RanluxEngine::restoreStatus(), CLHEP::Ranlux64Engine::restoreStatus(), CLHEP::RanshiEngine::restoreStatus(), CLHEP::MTwistEngine::saveStatus(), CLHEP::RanecuEngine::setIndex(), CLHEP::RanecuEngine::setSeed(), CLHEP::HepJamesRandom::setSeed(), CLHEP::MixMaxRng::setSeed(), CLHEP::RanluxppEngine::setSeed(), CLHEP::Ranlux64Engine::setSeed(), CLHEP::RanluxEngine::setSeed(), setSeed(), CLHEP::MTwistEngine::setSeed(), CLHEP::RanecuEngine::setSeeds(), CLHEP::Ranlux64Engine::setSeeds(), CLHEP::RanluxEngine::setSeeds(), CLHEP::MixMaxRng::setSeeds(), CLHEP::RanshiEngine::setSeeds(), showStatus(), CLHEP::HepJamesRandom::showStatus(), CLHEP::MTwistEngine::showStatus(), CLHEP::RanecuEngine::showStatus(), CLHEP::Ranlux64Engine::showStatus(), CLHEP::RanluxEngine::showStatus(), and CLHEP::RanshiEngine::showStatus().

◆ theSeeds

const long* CLHEP::HepRandomEngine::theSeeds
protectedinherited

◆ VECTOR_STATE_SIZE

const unsigned int CLHEP::DualRand::VECTOR_STATE_SIZE = 9
static

Definition at line 102 of file DualRand.h.

Referenced by get(), getState(), and restoreStatus().


The documentation for this class was generated from the following files: