CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
CLHEP::Hurd288Engine Class Reference

#include <Hurd288Engine.h>

+ Inheritance diagram for CLHEP::Hurd288Engine:

Public Member Functions

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

Static Public Member Functions

static std::string beginTag ()
 
static std::string engineName ()
 
- Static Public Member Functions inherited from CLHEP::HepRandomEngine
static std::string beginTag ()
 
static HepRandomEnginenewEngine (std::istream &is)
 
static HepRandomEnginenewEngine (const std::vector< unsigned long > &v)
 

Static Public Attributes

static const unsigned int VECTOR_STATE_SIZE = 11
 

Additional Inherited Members

- Static Protected Member Functions inherited from CLHEP::HepRandomEngine
static double exponent_bit_32 ()
 
static double mantissa_bit_12 ()
 
static double mantissa_bit_24 ()
 
static double mantissa_bit_32 ()
 
static double twoToMinus_32 ()
 
static double twoToMinus_48 ()
 
static double twoToMinus_49 ()
 
static double twoToMinus_53 ()
 
static double nearlyTwoToMinus_54 ()
 
static bool checkFile (std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
 
- Protected Attributes inherited from CLHEP::HepRandomEngine
long theSeed
 
const long * theSeeds
 

Detailed Description

Author

Definition at line 40 of file Hurd288Engine.h.

Constructor & Destructor Documentation

◆ Hurd288Engine() [1/4]

CLHEP::Hurd288Engine::Hurd288Engine ( )

Definition at line 72 of file Hurd288Engine.cc.

74{
75 int numEngines = numberOfEngines++;
76 int cycle = std::abs(int(numEngines/maxIndex));
77 int curIndex = std::abs(int(numEngines%maxIndex));
78 long mask = ((cycle & 0x007fffff) << 8);
79 HepRandom::getTheTableSeeds(seeds_, curIndex );
80 seeds_[0] ^= mask;
81 setSeeds(seeds_, 0);
82 words[0] ^= 0x1324abcd; // To make unique vs long or two unsigned
83 if (words[0]==0) words[0] = 1; // ints in the constructor
84
85 for( int i=0; i < 100; ++i ) flat(); // warm up just a bit
86}
static void getTheTableSeeds(long *seeds, int index)
Definition: Random.cc:256
void setSeeds(const long *seeds, int)

◆ Hurd288Engine() [2/4]

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

Definition at line 88 of file Hurd288Engine.cc.

90{
91 is >> *this;
92}

◆ Hurd288Engine() [3/4]

CLHEP::Hurd288Engine::Hurd288Engine ( long  seed)

Definition at line 94 of file Hurd288Engine.cc.

96{
97 seeds_[0] = seed;
98 setSeeds(seeds_, 0);
99 words[0] ^= 0xa5482134; // To make unique vs default two unsigned
100 if (words[0]==0) words[0] = 1; // ints in the constructor
101 for( int i=0; i < 100; ++i ) flat(); // warm up just a bit
102}

◆ Hurd288Engine() [4/4]

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

Definition at line 104 of file Hurd288Engine.cc.

106{
107 int cycle = std::abs(int(rowIndex/maxIndex));
108 int row = std::abs(int(rowIndex%maxIndex));
109 int col = colIndex & 0x1;
110 long mask = (( cycle & 0x000007ff ) << 20 );
111 HepRandom::getTheTableSeeds( seeds_, row );
112 seeds_[0] = seeds_[col]^mask;
113 setSeeds(seeds_, 0);
114 for( int i=0; i < 100; ++i ) flat(); // warm up just a bit
115}

◆ ~Hurd288Engine()

CLHEP::Hurd288Engine::~Hurd288Engine ( )
virtual

Definition at line 117 of file Hurd288Engine.cc.

117{ }

Member Function Documentation

◆ beginTag()

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

Definition at line 338 of file Hurd288Engine.cc.

338 {
339 return "Hurd288Engine-begin";
340}

◆ engineName()

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

Definition at line 84 of file Hurd288Engine.h.

84{return "Hurd288Engine";}

Referenced by restoreStatus().

◆ flat()

double CLHEP::Hurd288Engine::flat ( )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 155 of file Hurd288Engine.cc.

155 {
156
157 if( wordIndex <= 2 ) { // MF 9/15/98:
158 // skip word 0 and use two words per flat
159 advance();
160 }
161
162 // LG 6/30/2010
163 // define the order of execution for --wordIndex
164 double x = words[--wordIndex] * twoToMinus_32() ; // most significant part
165 double y = (words[--wordIndex]>>11) * twoToMinus_53() + // fill in rest of bits
166 nearlyTwoToMinus_54(); // make sure non-zero
167 return x + y;
168}
static double twoToMinus_32()
static double twoToMinus_53()
static double nearlyTwoToMinus_54()

Referenced by flatArray(), Hurd288Engine(), and main().

◆ flatArray()

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

Implements CLHEP::HepRandomEngine.

Definition at line 170 of file Hurd288Engine.cc.

170 {
171 for (int i = 0; i < size; ++i) {
172 vect[i] = flat();
173 }
174}

◆ get() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 380 of file Hurd288Engine.cc.

380 {
381 if ((v[0] & 0xffffffffUL) != engineIDulong<Hurd288Engine>()) {
382 std::cerr <<
383 "\nHurd288Engine get:state vector has wrong ID word - state unchanged\n";
384 std::cerr << "The correct ID would be " << engineIDulong<Hurd288Engine>()
385 << "; the actual ID is " << v[0] << "\n";
386 return false;
387 }
388 return getState(v);
389}
virtual std::istream & getState(std::istream &is)

◆ get() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 321 of file Hurd288Engine.cc.

321 {
322 char beginMarker [MarkerLen];
323 is >> std::ws;
324 is.width(MarkerLen); // causes the next read to the char* to be <=
325 // that many bytes, INCLUDING A TERMINATION \0
326 // (Stroustrup, section 21.3.2)
327 is >> beginMarker;
328 if (strcmp(beginMarker,"Hurd288Engine-begin")) {
329 is.clear(std::ios::badbit | is.rdstate());
330 std::cerr << "\nInput mispositioned or"
331 << "\nHurd288Engine state description missing or"
332 << "\nwrong engine type found." << std::endl;
333 return is;
334 }
335 return getState(is);
336}

Referenced by CLHEP::TripleRand::getState().

◆ getState() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 391 of file Hurd288Engine.cc.

391 {
392 if (v.size() != VECTOR_STATE_SIZE ) {
393 std::cerr <<
394 "\nHurd288Engine get:state vector has wrong length - state unchanged\n";
395 return false;
396 }
397 wordIndex = (int)v[1];
398 for (int i = 0; i < 9; ++i) {
399 words[i] = (unsigned int)v[i+2];
400 }
401 return true;
402}
static const unsigned int VECTOR_STATE_SIZE
Definition: Hurd288Engine.h:90

◆ getState() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 342 of file Hurd288Engine.cc.

342 {
343 if ( possibleKeywordInput ( is, "Uvec", theSeed ) ) {
344 std::vector<unsigned long> v;
345 unsigned long uu;
346 for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
347 is >> uu;
348 if (!is) {
349 is.clear(std::ios::badbit | is.rdstate());
350 std::cerr << "\nHurd288Engine state (vector) description improper."
351 << "\ngetState() has failed."
352 << "\nInput stream is probably mispositioned now." << std::endl;
353 return is;
354 }
355 v.push_back(uu);
356 }
357 getState(v);
358 return (is);
359 }
360
361// is >> theSeed; Removed, encompassed by possibleKeywordInput()
362
363 char endMarker [MarkerLen];
364 is >> wordIndex;
365 for (int i = 0; i < 9; ++i) {
366 is >> words[i];
367 }
368 is >> std::ws;
369 is.width(MarkerLen);
370 is >> endMarker;
371 if (strcmp(endMarker,"Hurd288Engine-end")) {
372 is.clear(std::ios::badbit | is.rdstate());
373 std::cerr << "\nHurd288Engine state description incomplete."
374 << "\nInput stream is probably mispositioned now." << std::endl;
375 return is;
376 }
377 return is;
378}
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:168

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

◆ name()

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

Implements CLHEP::HepRandomEngine.

Definition at line 64 of file Hurd288Engine.cc.

64{return "Hurd288Engine";}

◆ operator double()

CLHEP::Hurd288Engine::operator double ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 269 of file Hurd288Engine.cc.

269 {
270 return flat();
271}

◆ operator float()

CLHEP::Hurd288Engine::operator float ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 273 of file Hurd288Engine.cc.

273 {
274 if( wordIndex <= 1 ) { // MF 9/15/98: skip word 0
275 advance();
276 }
277 return words[--wordIndex ] * twoToMinus_32();
278}

◆ operator unsigned int()

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 280 of file Hurd288Engine.cc.

280 {
281 if( wordIndex <= 1 ) { // MF 9/15/98: skip word 0
282 advance();
283 }
284 return words[--wordIndex];
285}

◆ put() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 310 of file Hurd288Engine.cc.

310 {
311 std::vector<unsigned long> v;
312 v.push_back (engineIDulong<Hurd288Engine>());
313 v.push_back(static_cast<unsigned long>(wordIndex));
314 for (int i = 0; i < 9; ++i) {
315 v.push_back(static_cast<unsigned long>(words[i]));
316 }
317 return v;
318}

Referenced by put(), and saveStatus().

◆ put() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 287 of file Hurd288Engine.cc.

287 {
288 char beginMarker[] = "Hurd288Engine-begin";
289 os << beginMarker << "\nUvec\n";
290 std::vector<unsigned long> v = put();
291 for (unsigned int i=0; i<v.size(); ++i) {
292 os << v[i] << "\n";
293 }
294 return os;
295#ifdef REMOVED
296 char endMarker[] = "Hurd288Engine-end";
297 int pr = os.precision(20);
298 os << " " << beginMarker << " ";
299 os << theSeed << " ";
300 os << wordIndex << " ";
301 for (int i = 0; i < 9; ++i) {
302 os << words[i] << "\n";
303 }
304 os << endMarker << "\n ";
305 os.precision(pr);
306 return os;
307#endif
308}
std::vector< unsigned long > put() const

Referenced by CLHEP::TripleRand::put().

◆ restoreStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 220 of file Hurd288Engine.cc.

220 {
221 std::ifstream inFile(filename, std::ios::in);
222 if (!checkFile ( inFile, filename, engineName(), "restoreStatus" )) {
223 std::cerr << " -- Engine state remains unchanged\n";
224 return;
225 }
226 if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
227 std::vector<unsigned long> v;
228 unsigned long xin;
229 for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
230 inFile >> xin;
231 #ifdef TRACE_IO
232 std::cout << "ivec = " << ivec << " xin = " << xin << " ";
233 if (ivec%3 == 0) std::cout << "\n";
234 #endif
235 if (!inFile) {
236 inFile.clear(std::ios::badbit | inFile.rdstate());
237 std::cerr << "\nHurd288Engine state (vector) description improper."
238 << "\nrestoreStatus has failed."
239 << "\nInput stream is probably mispositioned now." << std::endl;
240 return;
241 }
242 v.push_back(xin);
243 }
244 getState(v);
245 return;
246 }
247
248 if( !inFile.bad() ) {
249// inFile >> theSeed; removed -- encompased by possibleKeywordInput
250 inFile >> wordIndex;
251 for( int i = 0; i < 9; ++i ) {
252 inFile >> words[i];
253 }
254 }
255}
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
Definition: RandomEngine.cc:49
static std::string engineName()
Definition: Hurd288Engine.h:84

◆ saveStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 191 of file Hurd288Engine.cc.

191 {
192 std::ofstream outFile(filename, std::ios::out);
193 if( !outFile.bad() ) {
194 outFile << "Uvec\n";
195 std::vector<unsigned long> v = put();
196 #ifdef TRACE_IO
197 std::cout << "Result of v = put() is:\n";
198 #endif
199 for (unsigned int i=0; i<v.size(); ++i) {
200 outFile << v[i] << "\n";
201 #ifdef TRACE_IO
202 std::cout << v[i] << " ";
203 if (i%6==0) std::cout << "\n";
204 #endif
205 }
206 #ifdef TRACE_IO
207 std::cout << "\n";
208 #endif
209 }
210#ifdef REMOVED
211 outFile << std::setprecision(20) << theSeed << " ";
212 outFile << wordIndex << " ";
213 for( int i = 0; i < 9; ++i ) {
214 outFile << words[i] << " ";
215 }
216 outFile << std::endl;
217#endif
218}

◆ setSeed()

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

Implements CLHEP::HepRandomEngine.

Definition at line 176 of file Hurd288Engine.cc.

176 {
177 seeds_[0] = seed;
178 seeds_[1] = 0;
179 theSeed = seeds_[0];
180 words[0] = (unsigned int)seed;
181 for (wordIndex = 1; wordIndex < 9; ++wordIndex) {
182 words[wordIndex] = 69607 * words[wordIndex-1] + 54329;
183 }
184}

Referenced by setSeeds().

◆ setSeeds()

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

Implements CLHEP::HepRandomEngine.

Definition at line 186 of file Hurd288Engine.cc.

186 {
187 theSeeds = seeds;
188 setSeed( *seeds ? *seeds : 32767, 0 );
189}
void setSeed(long seed, int)

Referenced by Hurd288Engine().

◆ showStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 257 of file Hurd288Engine.cc.

257 {
258 std::cout << std::setprecision(20) << std::endl;
259 std::cout << "----------- Hurd2 engine status ----------" << std::endl;
260 std::cout << "Initial seed = " << theSeed << std::endl;
261 std::cout << "Current index = " << wordIndex << std::endl;
262 std::cout << "Current words = " << std::endl;
263 for( int i = 0; i < 9 ; ++i ) {
264 std::cout << " " << words[i] << std::endl;
265 }
266 std::cout << "-------------------------------------------" << std::endl;
267}

Member Data Documentation

◆ VECTOR_STATE_SIZE

const unsigned int CLHEP::Hurd288Engine::VECTOR_STATE_SIZE = 11
static

Definition at line 90 of file Hurd288Engine.h.

Referenced by getState(), and restoreStatus().


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