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

#include <RanecuEngine.h>

+ Inheritance diagram for CLHEP::RanecuEngine:

Public Member Functions

 RanecuEngine (std::istream &is)
 
 RanecuEngine ()
 
 RanecuEngine (int index)
 
virtual ~RanecuEngine ()
 
double flat ()
 
void flatArray (const int size, double *vect)
 
void setIndex (long index)
 
void setSeed (long index, int dum=0)
 
void setSeeds (const long *seeds, int index=-1)
 
void saveStatus (const char filename[]="Ranecu.conf") const
 
void restoreStatus (const char filename[]="Ranecu.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 Protected Attributes

static const int ecuyer_a = 40014
 
static const int ecuyer_b = 53668
 
static const int ecuyer_c = 12211
 
static const int ecuyer_d = 40692
 
static const int ecuyer_e = 52774
 
static const int ecuyer_f = 3791
 
static const int shift1 = 2147483563
 
static const int shift2 = 2147483399
 
static const unsigned int VECTOR_STATE_SIZE = 4
 

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

Constructor & Destructor Documentation

◆ RanecuEngine() [1/3]

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

Definition at line 108 of file RanecuEngine.cc.

110{
111 is >> *this;
112}

◆ RanecuEngine() [2/3]

CLHEP::RanecuEngine::RanecuEngine ( )

Definition at line 74 of file RanecuEngine.cc.

76{
77 int numEngines = numberOfEngines++;
78 int cycle = std::abs(int(numEngines/maxSeq));
79 seq = std::abs(int(numEngines%maxSeq));
80
81 theSeed = seq;
82 long mask = ((cycle & 0x007fffff) << 8);
83 for (int i=0; i<2; ++i) {
84 for (int j=0; j<maxSeq; ++j) {
86 table[j][i] ^= mask;
87 }
88 }
89 theSeeds = &table[seq][0];
90}
static void getTheTableSeeds(long *seeds, int index)
Definition: Random.cc:256

◆ RanecuEngine() [3/3]

CLHEP::RanecuEngine::RanecuEngine ( int  index)

Definition at line 92 of file RanecuEngine.cc.

94{
95 int cycle = std::abs(int(index/maxSeq));
96 seq = std::abs(int(index%maxSeq));
97 theSeed = seq;
98 long mask = ((cycle & 0x000007ff) << 20);
99 for (int j=0; j<maxSeq; ++j) {
100 HepRandom::getTheTableSeeds(table[j],j);
101 table[j][0] ^= mask;
102 table[j][1] ^= mask;
103 }
104 theSeeds = &table[seq][0];
105 further_randomize (seq, 0, index, shift1); // mf 6/22/10
106}
static const int shift1
Definition: RanecuEngine.h:117

◆ ~RanecuEngine()

CLHEP::RanecuEngine::~RanecuEngine ( )
virtual

Definition at line 114 of file RanecuEngine.cc.

114{}

Member Function Documentation

◆ beginTag()

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

Definition at line 352 of file RanecuEngine.cc.

352 {
353 return "RanecuEngine-begin";
354}

◆ engineName()

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

Definition at line 101 of file RanecuEngine.h.

101{return "RanecuEngine";}

Referenced by restoreStatus().

◆ flat()

double CLHEP::RanecuEngine::flat ( )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 224 of file RanecuEngine.cc.

225{
226 const int index = seq;
227 long seed1 = table[index][0];
228 long seed2 = table[index][1];
229
230 int k1 = (int)(seed1/ecuyer_b);
231 int k2 = (int)(seed2/ecuyer_e);
232
233 seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
234 if (seed1 < 0) seed1 += shift1;
235 seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
236 if (seed2 < 0) seed2 += shift2;
237
238 table[index][0] = seed1;
239 table[index][1] = seed2;
240
241 long diff = seed1-seed2;
242
243 if (diff <= 0) diff += (shift1-1);
244 return (double)(diff*prec);
245}
static const int ecuyer_b
Definition: RanecuEngine.h:112
static const int ecuyer_e
Definition: RanecuEngine.h:115
static const int ecuyer_f
Definition: RanecuEngine.h:116
static const int ecuyer_d
Definition: RanecuEngine.h:114
static const int ecuyer_a
Definition: RanecuEngine.h:111
static const int shift2
Definition: RanecuEngine.h:118
static const int ecuyer_c
Definition: RanecuEngine.h:113

Referenced by main(), and useSeed().

◆ flatArray()

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

Implements CLHEP::HepRandomEngine.

Definition at line 247 of file RanecuEngine.cc.

248{
249 const int index = seq;
250 long seed1 = table[index][0];
251 long seed2 = table[index][1];
252 int k1, k2;
253 int i;
254
255 for (i=0; i<size; ++i)
256 {
257 k1 = (int)(seed1/ecuyer_b);
258 k2 = (int)(seed2/ecuyer_e);
259
260 seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
261 if (seed1 < 0) seed1 += shift1;
262 seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
263 if (seed2 < 0) seed2 += shift2;
264
265 long diff = seed1-seed2;
266 if (diff <= 0) diff += (shift1-1);
267
268 vect[i] = (double)(diff*prec);
269 }
270 table[index][0] = seed1;
271 table[index][1] = seed2;
272}
#define double(obj)
Definition: excDblThrow.cc:32

◆ get() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 395 of file RanecuEngine.cc.

395 {
396 if ((v[0] & 0xffffffffUL) != engineIDulong<RanecuEngine>()) {
397 std::cerr <<
398 "\nRanecuEngine get:state vector has wrong ID word - state unchanged\n";
399 return false;
400 }
401 return getState(v);
402}
virtual std::istream & getState(std::istream &is)

◆ get() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 333 of file RanecuEngine.cc.

334{
335 char beginMarker [MarkerLen];
336
337 is >> std::ws;
338 is.width(MarkerLen); // causes the next read to the char* to be <=
339 // that many bytes, INCLUDING A TERMINATION \0
340 // (Stroustrup, section 21.3.2)
341 is >> beginMarker;
342 if (strcmp(beginMarker,"RanecuEngine-begin")) {
343 is.clear(std::ios::badbit | is.rdstate());
344 std::cerr << "\nInput stream mispositioned or"
345 << "\nRanecuEngine state description missing or"
346 << "\nwrong engine type found." << std::endl;
347 return is;
348 }
349 return getState(is);
350}

◆ getState() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 404 of file RanecuEngine.cc.

404 {
405 if (v.size() != VECTOR_STATE_SIZE ) {
406 std::cerr <<
407 "\nRanecuEngine get:state vector has wrong length - state unchanged\n";
408 return false;
409 }
410 theSeed = v[1];
411 table[theSeed][0] = v[2];
412 table[theSeed][1] = v[3];
413 seq = int(theSeed);
414 return true;
415}
static const unsigned int VECTOR_STATE_SIZE
Definition: RanecuEngine.h:120

◆ getState() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 356 of file RanecuEngine.cc.

357{
358 if ( possibleKeywordInput ( is, "Uvec", theSeed ) ) {
359 std::vector<unsigned long> v;
360 unsigned long uu;
361 for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
362 is >> uu;
363 if (!is) {
364 is.clear(std::ios::badbit | is.rdstate());
365 std::cerr << "\nRanecuEngine state (vector) description improper."
366 << "\ngetState() has failed."
367 << "\nInput stream is probably mispositioned now." << std::endl;
368 return is;
369 }
370 v.push_back(uu);
371 }
372 getState(v);
373 return (is);
374 }
375
376// is >> theSeed; Removed, encompassed by possibleKeywordInput()
377 char endMarker [MarkerLen];
378 for (int i=0; i<2; ++i) {
379 is >> table[theSeed][i];
380 }
381 is >> std::ws;
382 is.width(MarkerLen);
383 is >> endMarker;
384 if (strcmp(endMarker,"RanecuEngine-end")) {
385 is.clear(std::ios::badbit | is.rdstate());
386 std::cerr << "\nRanecuEngine state description incomplete."
387 << "\nInput stream is probably mispositioned now." << std::endl;
388 return is;
389 }
390
391 seq = int(theSeed);
392 return is;
393}
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:168

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

◆ name()

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

Implements CLHEP::HepRandomEngine.

Definition at line 66 of file RanecuEngine.cc.

66{return "RanecuEngine";}

◆ operator double()

CLHEP::RanecuEngine::operator double ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 274 of file RanecuEngine.cc.

274 {
275 return flat();
276}

◆ operator float()

CLHEP::RanecuEngine::operator float ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 278 of file RanecuEngine.cc.

278 {
279 return float( flat() );
280}

◆ operator unsigned int()

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 282 of file RanecuEngine.cc.

282 {
283 const int index = seq;
284 long seed1 = table[index][0];
285 long seed2 = table[index][1];
286
287 int k1 = (int)(seed1/ecuyer_b);
288 int k2 = (int)(seed2/ecuyer_e);
289
290 seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
291 if (seed1 < 0) seed1 += shift1;
292 seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
293 if (seed2 < 0) seed2 += shift2;
294
295 table[index][0] = seed1;
296 table[index][1] = seed2;
297 long diff = seed1-seed2;
298 if( diff <= 0 ) diff += (shift1-1);
299
300 return ((diff << 1) | (seed1&1))& 0xffffffff;
301}

◆ put() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 324 of file RanecuEngine.cc.

324 {
325 std::vector<unsigned long> v;
326 v.push_back (engineIDulong<RanecuEngine>());
327 v.push_back(static_cast<unsigned long>(theSeed));
328 v.push_back(static_cast<unsigned long>(table[theSeed][0]));
329 v.push_back(static_cast<unsigned long>(table[theSeed][1]));
330 return v;
331}

Referenced by put(), and saveStatus().

◆ put() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 303 of file RanecuEngine.cc.

304{
305 char beginMarker[] = "RanecuEngine-begin";
306 os << beginMarker << "\nUvec\n";
307 std::vector<unsigned long> v = put();
308 for (unsigned int i=0; i<v.size(); ++i) {
309 os << v[i] << "\n";
310 }
311 return os;
312#ifdef REMOVED
313 char endMarker[] = "RanecuEngine-end";
314 os << " " << beginMarker << "\n";
315 os << theSeed << " ";
316 for (int i=0; i<2; ++i) {
317 os << table[theSeed][i] << "\n";
318 }
319 os << endMarker << "\n";
320 return os;
321#endif
322}
std::vector< unsigned long > put() const

◆ restoreStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 176 of file RanecuEngine.cc.

177{
178 std::ifstream inFile( filename, std::ios::in);
179 if (!checkFile ( inFile, filename, engineName(), "restoreStatus" )) {
180 std::cerr << " -- Engine state remains unchanged\n";
181 return;
182 }
183 if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
184 std::vector<unsigned long> v;
185 unsigned long xin;
186 for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
187 inFile >> xin;
188 #ifdef TRACE_IO
189 std::cout << "ivec = " << ivec << " xin = " << xin << " ";
190 if (ivec%3 == 0) std::cout << "\n";
191 #endif
192 if (!inFile) {
193 inFile.clear(std::ios::badbit | inFile.rdstate());
194 std::cerr << "\nJamesRandom state (vector) description improper."
195 << "\nrestoreStatus has failed."
196 << "\nInput stream is probably mispositioned now." << std::endl;
197 return;
198 }
199 v.push_back(xin);
200 }
201 getState(v);
202 return;
203 }
204
205 if (!inFile.bad() && !inFile.eof()) {
206// inFile >> theSeed; removed -- encompased by possibleKeywordInput
207 for (int i=0; i<2; ++i)
208 inFile >> table[theSeed][i];
209 seq = int(theSeed);
210 }
211}
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: RanecuEngine.h:101

◆ saveStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 145 of file RanecuEngine.cc.

146{
147 std::ofstream outFile( filename, std::ios::out ) ;
148
149 if (!outFile.bad()) {
150 outFile << "Uvec\n";
151 std::vector<unsigned long> v = put();
152 #ifdef TRACE_IO
153 std::cout << "Result of v = put() is:\n";
154 #endif
155 for (unsigned int i=0; i<v.size(); ++i) {
156 outFile << v[i] << "\n";
157 #ifdef TRACE_IO
158 std::cout << v[i] << " ";
159 if (i%6==0) std::cout << "\n";
160 #endif
161 }
162 #ifdef TRACE_IO
163 std::cout << "\n";
164 #endif
165 }
166#ifdef REMOVED
167 if (!outFile.bad()) {
168 outFile << theSeed << std::endl;
169 for (int i=0; i<2; ++i)
170 outFile << table[theSeed][i] << " ";
171 outFile << std::endl;
172 }
173#endif
174}

◆ setIndex()

void CLHEP::RanecuEngine::setIndex ( long  index)

Definition at line 138 of file RanecuEngine.cc.

139{
140 seq = std::abs(int(index%maxSeq));
141 theSeed = seq;
142 theSeeds = &table[seq][0];
143}

◆ setSeed()

void CLHEP::RanecuEngine::setSeed ( long  index,
int  dum = 0 
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 116 of file RanecuEngine.cc.

117{
118 seq = std::abs(int(index%maxSeq));
119 theSeed = seq;
120 HepRandom::getTheTableSeeds(table[seq],seq);
121 theSeeds = &table[seq][0];
122 further_randomize (seq, 0, (int)index, shift1); // mf 6/22/10
123 further_randomize (seq, 1, dum, shift2); // mf 6/22/10
124}

Referenced by useSeed().

◆ setSeeds()

void CLHEP::RanecuEngine::setSeeds ( const long *  seeds,
int  index = -1 
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 126 of file RanecuEngine.cc.

127{
128 if (pos != -1) {
129 seq = std::abs(int(pos%maxSeq));
130 theSeed = seq;
131 }
132 // only positive seeds are allowed
133 table[seq][0] = std::abs(seeds[0])%shift1;
134 table[seq][1] = std::abs(seeds[1])%shift2;
135 theSeeds = &table[seq][0];
136}

Referenced by useSeed().

◆ showStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 213 of file RanecuEngine.cc.

214{
215 std::cout << std::endl;
216 std::cout << "--------- Ranecu engine status ---------" << std::endl;
217 std::cout << " Initial seed (index) = " << theSeed << std::endl;
218 std::cout << " Current couple of seeds = "
219 << table[theSeed][0] << ", "
220 << table[theSeed][1] << std::endl;
221 std::cout << "----------------------------------------" << std::endl;
222}

Member Data Documentation

◆ ecuyer_a

const int CLHEP::RanecuEngine::ecuyer_a = 40014
staticprotected

Definition at line 111 of file RanecuEngine.h.

Referenced by flat(), and flatArray().

◆ ecuyer_b

const int CLHEP::RanecuEngine::ecuyer_b = 53668
staticprotected

Definition at line 112 of file RanecuEngine.h.

Referenced by flat(), and flatArray().

◆ ecuyer_c

const int CLHEP::RanecuEngine::ecuyer_c = 12211
staticprotected

Definition at line 113 of file RanecuEngine.h.

Referenced by flat(), and flatArray().

◆ ecuyer_d

const int CLHEP::RanecuEngine::ecuyer_d = 40692
staticprotected

Definition at line 114 of file RanecuEngine.h.

Referenced by flat(), and flatArray().

◆ ecuyer_e

const int CLHEP::RanecuEngine::ecuyer_e = 52774
staticprotected

Definition at line 115 of file RanecuEngine.h.

Referenced by flat(), and flatArray().

◆ ecuyer_f

const int CLHEP::RanecuEngine::ecuyer_f = 3791
staticprotected

Definition at line 116 of file RanecuEngine.h.

Referenced by flat(), and flatArray().

◆ shift1

const int CLHEP::RanecuEngine::shift1 = 2147483563
staticprotected

Definition at line 117 of file RanecuEngine.h.

Referenced by flat(), flatArray(), RanecuEngine(), setSeed(), and setSeeds().

◆ shift2

const int CLHEP::RanecuEngine::shift2 = 2147483399
staticprotected

Definition at line 118 of file RanecuEngine.h.

Referenced by flat(), flatArray(), setSeed(), and setSeeds().

◆ VECTOR_STATE_SIZE

const unsigned int CLHEP::RanecuEngine::VECTOR_STATE_SIZE = 4
staticprotected

Definition at line 120 of file RanecuEngine.h.

Referenced by getState(), and restoreStatus().


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