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

#include <Hurd160Engine.h>

+ Inheritance diagram for CLHEP::Hurd160Engine:

Public Member Functions

 Hurd160Engine ()
 
 Hurd160Engine (std::istream &is)
 
 Hurd160Engine (long seed)
 
 Hurd160Engine (int rowIndex, int colIndex)
 
virtual ~Hurd160Engine ()
 
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[]="Hurd160Engine.conf") const
 
void restoreStatus (const char filename[]="Hurd160Engine.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)
 
std::string name () const
 
virtual std::istream & getState (std::istream &is)
 
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 engineName ()
 
static std::string beginTag ()
 
- 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 = 7
 

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 41 of file Hurd160Engine.h.

Constructor & Destructor Documentation

◆ Hurd160Engine() [1/4]

CLHEP::Hurd160Engine::Hurd160Engine ( )

Definition at line 64 of file Hurd160Engine.cc.

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

◆ Hurd160Engine() [2/4]

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

Definition at line 80 of file Hurd160Engine.cc.

82{
83 is >> *this;
84}

◆ Hurd160Engine() [3/4]

CLHEP::Hurd160Engine::Hurd160Engine ( long  seed)

Definition at line 86 of file Hurd160Engine.cc.

88{
89 seeds_[0] = seed;
90 setSeeds(seeds_, 0);
91 words[0] ^= 0xa5482134; // To make unique vs default two unsigned
92 if (words[0]==0) words[0] = 1; // ints in the constructor
93 for( int i=0; i < 100; ++i ) flat(); // warm-up just a bit
94}

◆ Hurd160Engine() [4/4]

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

Definition at line 96 of file Hurd160Engine.cc.

98{
99 int cycle = std::abs(int(rowIndex/maxIndex));
100 int row = std::abs(int(rowIndex%maxIndex));
101 int col = colIndex & 0x1;
102 long mask = (( cycle & 0x000007ff ) << 20 );
103 HepRandom::getTheTableSeeds( seeds_, row );
104 // NOTE: is that really the seed wanted (PGC) ??
105 seeds_[0] = seeds_[col]^mask;
106 setSeeds(seeds_, 0);
107 for( int i=0; i < 100; ++i ) flat(); // warm-up just a bit
108}

◆ ~Hurd160Engine()

CLHEP::Hurd160Engine::~Hurd160Engine ( )
virtual

Definition at line 110 of file Hurd160Engine.cc.

110{ }

Member Function Documentation

◆ beginTag()

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

Definition at line 319 of file Hurd160Engine.cc.

319 {
320 return "Hurd160Engine-begin";
321}

◆ engineName()

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

Definition at line 83 of file Hurd160Engine.h.

83{return "Hurd160Engine";}

Referenced by restoreStatus().

◆ flat()

double CLHEP::Hurd160Engine::flat ( )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 134 of file Hurd160Engine.cc.

134 {
135
136 if( wordIndex <= 2 ) { // MF 9/15/98:
137 // skip word 0 and use two words per flat
138 advance();
139 }
140
141 // LG 6/30/2010
142 // define the order of execution for --wordIndex
143 double x = words[--wordIndex] * twoToMinus_32() ; // most significant part
144 double y = (words[--wordIndex]>>11) * twoToMinus_53() + // fill in rest of bits
145 nearlyTwoToMinus_54(); // make sure non-zero
146 return x + y ;
147}
static double twoToMinus_32()
static double twoToMinus_53()
static double nearlyTwoToMinus_54()

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

◆ flatArray()

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

Implements CLHEP::HepRandomEngine.

Definition at line 149 of file Hurd160Engine.cc.

149 {
150 for (int i = 0; i < size; ++i) {
151 vect[i] = flat();
152 }
153}

◆ get() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 362 of file Hurd160Engine.cc.

362 {
363 if ((v[0] & 0xffffffffUL) != engineIDulong<Hurd160Engine>()) {
364 std::cerr <<
365 "\nHurd160Engine get:state vector has wrong ID word - state unchanged\n";
366 return false;
367 }
368 return getState(v);
369}
virtual std::istream & getState(std::istream &is)

◆ get() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 302 of file Hurd160Engine.cc.

302 {
303 char beginMarker [MarkerLen];
304 is >> std::ws;
305 is.width(MarkerLen); // causes the next read to the char* to be <=
306 // that many bytes, INCLUDING A TERMINATION \0
307 // (Stroustrup, section 21.3.2)
308 is >> beginMarker;
309 if (strcmp(beginMarker,"Hurd160Engine-begin")) {
310 is.clear(std::ios::badbit | is.rdstate());
311 std::cerr << "\nInput mispositioned or"
312 << "\nHurd160Engine state description missing or"
313 << "\nwrong engine type found." << std::endl;
314 return is;
315 }
316 return getState(is);
317}

◆ getState() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 371 of file Hurd160Engine.cc.

371 {
372 if (v.size() != VECTOR_STATE_SIZE ) {
373 std::cerr <<
374 "\nHurd160Engine get:state vector has wrong length - state unchanged\n";
375 return false;
376 }
377 wordIndex = (int)v[1];
378 for (int i = 0; i < 5; ++i) {
379 words[i] = (unsigned int)v[i+2];
380 }
381 return true;
382}
static const unsigned int VECTOR_STATE_SIZE
Definition: Hurd160Engine.h:91

◆ getState() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 323 of file Hurd160Engine.cc.

323 {
324 if ( possibleKeywordInput ( is, "Uvec", theSeed ) ) {
325 std::vector<unsigned long> v;
326 unsigned long uu;
327 for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
328 is >> uu;
329 if (!is) {
330 is.clear(std::ios::badbit | is.rdstate());
331 std::cerr << "\nHurd160Engine state (vector) description improper."
332 << "\ngetState() has failed."
333 << "\nInput stream is probably mispositioned now." << std::endl;
334 return is;
335 }
336 v.push_back(uu);
337 }
338 getState(v);
339 return (is);
340 }
341
342// is >> theSeed; Removed, encompassed by possibleKeywordInput()
343
344 char endMarker [MarkerLen];
345 is >> wordIndex;
346 for (int i = 0; i < 5; ++i) {
347 is >> words[i];
348 }
349 is >> std::ws;
350 is.width(MarkerLen);
351 is >> endMarker;
352 if (strcmp(endMarker,"Hurd160Engine-end")) {
353 is.clear(std::ios::badbit | is.rdstate());
354 std::cerr << "\nHurd160Engine state description incomplete."
355 << "\nInput stream is probably mispositioned now." << std::endl;
356 return is;
357 }
358 return is;
359}
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:168

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

◆ name()

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

Implements CLHEP::HepRandomEngine.

Definition at line 57 of file Hurd160Engine.cc.

57{return "Hurd160Engine";}

◆ operator double()

CLHEP::Hurd160Engine::operator double ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 250 of file Hurd160Engine.cc.

250 {
251 return flat();
252}

◆ operator float()

CLHEP::Hurd160Engine::operator float ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 254 of file Hurd160Engine.cc.

254 {
255 if( wordIndex <= 1 ) { // MF 9/15/98: skip word 0
256 advance();
257 }
258 return words[--wordIndex ] * twoToMinus_32();
259}

◆ operator unsigned int()

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 261 of file Hurd160Engine.cc.

261 {
262 if( wordIndex <= 1 ) { // MF 9/15/98: skip word 0
263 advance();
264 }
265 return words[--wordIndex];
266}

◆ put() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 291 of file Hurd160Engine.cc.

291 {
292 std::vector<unsigned long> v;
293 v.push_back (engineIDulong<Hurd160Engine>());
294 v.push_back(static_cast<unsigned long>(wordIndex));
295 for (int i = 0; i < 5; ++i) {
296 v.push_back(static_cast<unsigned long>(words[i]));
297 }
298 return v;
299}

Referenced by put(), and saveStatus().

◆ put() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 268 of file Hurd160Engine.cc.

268 {
269 char beginMarker[] = "Hurd160Engine-begin";
270 os << beginMarker << "\nUvec\n";
271 std::vector<unsigned long> v = put();
272 for (unsigned int i=0; i<v.size(); ++i) {
273 os << v[i] << "\n";
274 }
275 return os;
276#ifdef REMOVED
277 char endMarker[] = "Hurd160Engine-end";
278 long pr = os.precision(20);
279 os << " " << beginMarker << " ";
280 os << theSeed << " ";
281 os << wordIndex << " ";
282 for (int i = 0; i < 5; ++i) {
283 os << words[i] << "\n";
284 }
285 os << endMarker << "\n ";
286 os.precision(pr);
287 return os;
288#endif
289}
std::vector< unsigned long > put() const

◆ restoreStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 199 of file Hurd160Engine.cc.

199 {
200 std::ifstream inFile(filename, std::ios::in);
201 if (!checkFile ( inFile, filename, engineName(), "restoreStatus" )) {
202 std::cerr << " -- Engine state remains unchanged\n";
203 return;
204 }
205 if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
206 std::vector<unsigned long> v;
207 unsigned long xin;
208 for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
209 inFile >> xin;
210 #ifdef TRACE_IO
211 std::cout << "ivec = " << ivec << " xin = " << xin << " ";
212 if (ivec%3 == 0) std::cout << "\n";
213 #endif
214 if (!inFile) {
215 inFile.clear(std::ios::badbit | inFile.rdstate());
216 std::cerr << "\nHurd160Engine state (vector) description improper."
217 << "\nrestoreStatus has failed."
218 << "\nInput stream is probably mispositioned now." << std::endl;
219 return;
220 }
221 v.push_back(xin);
222 }
223 getState(v);
224 return;
225 }
226
227 if( !inFile.bad() ) {
228// inFile >> theSeed; removed -- encompased by possibleKeywordInput
229 inFile >> wordIndex;
230 for( int i = 0; i < 5; ++i ) {
231 inFile >> words[i];
232 }
233 }
234}
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: Hurd160Engine.h:83

◆ saveStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 170 of file Hurd160Engine.cc.

170 {
171 std::ofstream outFile(filename, std::ios::out);
172 if( !outFile.bad() ) {
173 outFile << "Uvec\n";
174 std::vector<unsigned long> v = put();
175 #ifdef TRACE_IO
176 std::cout << "Result of v = put() is:\n";
177 #endif
178 for (unsigned int i=0; i<v.size(); ++i) {
179 outFile << v[i] << "\n";
180 #ifdef TRACE_IO
181 std::cout << v[i] << " ";
182 if (i%6==0) std::cout << "\n";
183 #endif
184 }
185 #ifdef TRACE_IO
186 std::cout << "\n";
187 #endif
188 }
189#ifdef REMOVED
190 outFile << std::setprecision(20) << theSeed << " ";
191 outFile << wordIndex << " ";
192 for( int i = 0; i < 5; ++i ) {
193 outFile << words[i] << " ";
194 }
195 outFile << std::endl;
196#endif
197}

◆ setSeed()

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

Implements CLHEP::HepRandomEngine.

Definition at line 155 of file Hurd160Engine.cc.

155 {
156 seeds_[0] = seed;
157 seeds_[1] = 0;
158 theSeed = seeds_[0];
159 words[0] = (unsigned int)seed;
160 for (wordIndex = 1; wordIndex < 5; ++wordIndex) {
161 words[wordIndex] = 69607 * words[wordIndex-1] + 54329;
162 }
163}

Referenced by setSeeds().

◆ setSeeds()

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

Implements CLHEP::HepRandomEngine.

Definition at line 165 of file Hurd160Engine.cc.

165 {
166 theSeeds = seeds;
167 setSeed( *seeds ? *seeds : 32767, 0 );
168}
void setSeed(long seed, int)

Referenced by Hurd160Engine().

◆ showStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 236 of file Hurd160Engine.cc.

236 {
237 long pr = std::cout.precision(20);
238 std::cout << std::endl;
239 std::cout << "----------- Hurd engine status ----------" << std::endl;
240 std::cout << "Initial seed = " << theSeed << std::endl;
241 std::cout << "Current index = " << wordIndex << std::endl;
242 std::cout << "Current words = " << std::endl;
243 for( int i = 0; i < 5 ; ++i ) {
244 std::cout << " " << words[i] << std::endl;
245 }
246 std::cout << "------------------------------------------" << std::endl;
247 std::cout.precision(pr);
248}

Member Data Documentation

◆ VECTOR_STATE_SIZE

const unsigned int CLHEP::Hurd160Engine::VECTOR_STATE_SIZE = 7
static

Definition at line 91 of file Hurd160Engine.h.

Referenced by getState(), and restoreStatus().


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