Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CLHEP::RanecuEngine Class Reference

#include <RanecuEngine.h>

Inheritance diagram for CLHEP::RanecuEngine:
Collaboration 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 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)
 
long getSeed () const
 
const long * getSeeds () const
 
virtual operator double ()
 
virtual operator float ()
 

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

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

Definition at line 102 of file RanecuEngine.cc.

103 : HepRandomEngine()
104 {
105  is >> *this;
106 }
CLHEP::RanecuEngine::RanecuEngine ( )

Definition at line 68 of file RanecuEngine.cc.

70 {
71  int numEngines = numberOfEngines++;
72  int cycle = std::abs(int(numEngines/maxSeq));
73  seq = std::abs(int(numEngines%maxSeq));
74 
75  theSeed = seq;
76  long mask = ((cycle & 0x007fffff) << 8);
77  for (int i=0; i<2; ++i) {
78  for (int j=0; j<maxSeq; ++j) {
79  HepRandom::getTheTableSeeds(table[j],j);
80  table[j][i] ^= mask;
81  }
82  }
83  theSeeds = &table[seq][0];
84 }
static ush mask[]
Definition: csz_inflate.cc:317
static void getTheTableSeeds(long *seeds, int index)
Definition: Random.cc:251

Here is the call graph for this function:

CLHEP::RanecuEngine::RanecuEngine ( int  index)

Definition at line 86 of file RanecuEngine.cc.

88 {
89  int cycle = std::abs(int(index/maxSeq));
90  seq = std::abs(int(index%maxSeq));
91  theSeed = seq;
92  long mask = ((cycle & 0x000007ff) << 20);
93  for (int j=0; j<maxSeq; ++j) {
94  HepRandom::getTheTableSeeds(table[j],j);
95  table[j][0] ^= mask;
96  table[j][1] ^= mask;
97  }
98  theSeeds = &table[seq][0];
99  further_randomize (seq, 0, index, shift1); // mf 6/22/10
100 }
static const int shift1
Definition: RanecuEngine.h:112
static ush mask[]
Definition: csz_inflate.cc:317
static void getTheTableSeeds(long *seeds, int index)
Definition: Random.cc:251

Here is the call graph for this function:

CLHEP::RanecuEngine::~RanecuEngine ( )
virtual

Definition at line 108 of file RanecuEngine.cc.

108 {}

Member Function Documentation

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

Definition at line 306 of file RanecuEngine.cc.

306  {
307  return "RanecuEngine-begin";
308 }
static std::string CLHEP::RanecuEngine::engineName ( )
inlinestatic

Definition at line 96 of file RanecuEngine.h.

96 {return "RanecuEngine";}

Here is the caller graph for this function:

double CLHEP::RanecuEngine::flat ( )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 196 of file RanecuEngine.cc.

197 {
198  const int index = seq;
199  long seed1 = table[index][0];
200  long seed2 = table[index][1];
201 
202  int k1 = (int)(seed1/ecuyer_b);
203  int k2 = (int)(seed2/ecuyer_e);
204 
205  seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
206  if (seed1 < 0) seed1 += shift1;
207  seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
208  if (seed2 < 0) seed2 += shift2;
209 
210  table[index][0] = seed1;
211  table[index][1] = seed2;
212 
213  long diff = seed1-seed2;
214 
215  if (diff <= 0) diff += (shift1-1);
216  return (double)(diff*prec);
217 }
static const int shift1
Definition: RanecuEngine.h:112
static const int ecuyer_b
Definition: RanecuEngine.h:107
static const int ecuyer_f
Definition: RanecuEngine.h:111
static const int ecuyer_a
Definition: RanecuEngine.h:106
static const double prec
Definition: RanecuEngine.cc:58
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
static const int shift2
Definition: RanecuEngine.h:113
static const int ecuyer_e
Definition: RanecuEngine.h:110
static const int ecuyer_d
Definition: RanecuEngine.h:109
static const int ecuyer_c
Definition: RanecuEngine.h:108

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 219 of file RanecuEngine.cc.

220 {
221  const int index = seq;
222  long seed1 = table[index][0];
223  long seed2 = table[index][1];
224  int k1, k2;
225  int i;
226 
227  for (i=0; i<size; ++i)
228  {
229  k1 = (int)(seed1/ecuyer_b);
230  k2 = (int)(seed2/ecuyer_e);
231 
232  seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
233  if (seed1 < 0) seed1 += shift1;
234  seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
235  if (seed2 < 0) seed2 += shift2;
236 
237  long diff = seed1-seed2;
238  if (diff <= 0) diff += (shift1-1);
239 
240  vect[i] = (double)(diff*prec);
241  }
242  table[index][0] = seed1;
243  table[index][1] = seed2;
244 }
static const int shift1
Definition: RanecuEngine.h:112
static const int ecuyer_b
Definition: RanecuEngine.h:107
static const int ecuyer_f
Definition: RanecuEngine.h:111
static const int ecuyer_a
Definition: RanecuEngine.h:106
static const double prec
Definition: RanecuEngine.cc:58
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
static const int shift2
Definition: RanecuEngine.h:113
static const int ecuyer_e
Definition: RanecuEngine.h:110
static const int ecuyer_d
Definition: RanecuEngine.h:109
static const int ecuyer_c
Definition: RanecuEngine.h:108

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 287 of file RanecuEngine.cc.

288 {
289  char beginMarker [MarkerLen];
290 
291  is >> std::ws;
292  is.width(MarkerLen); // causes the next read to the char* to be <=
293  // that many bytes, INCLUDING A TERMINATION \0
294  // (Stroustrup, section 21.3.2)
295  is >> beginMarker;
296  if (strcmp(beginMarker,"RanecuEngine-begin")) {
297  is.clear(std::ios::badbit | is.rdstate());
298  std::cerr << "\nInput stream mispositioned or"
299  << "\nRanecuEngine state description missing or"
300  << "\nwrong engine type found." << std::endl;
301  return is;
302  }
303  return getState(is);
304 }
static const int MarkerLen
Definition: DualRand.cc:67
virtual std::istream & getState(std::istream &is)

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 349 of file RanecuEngine.cc.

349  {
350  if ((v[0] & 0xffffffffUL) != engineIDulong<RanecuEngine>()) {
351  std::cerr <<
352  "\nRanecuEngine get:state vector has wrong ID word - state unchanged\n";
353  return false;
354  }
355  return getState(v);
356 }
virtual std::istream & getState(std::istream &is)
tuple v
Definition: test.py:18

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 310 of file RanecuEngine.cc.

311 {
312  if ( possibleKeywordInput ( is, "Uvec", theSeed ) ) {
313  std::vector<unsigned long> v;
314  unsigned long uu;
315  for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
316  is >> uu;
317  if (!is) {
318  is.clear(std::ios::badbit | is.rdstate());
319  std::cerr << "\nRanecuEngine state (vector) description improper."
320  << "\ngetState() has failed."
321  << "\nInput stream is probably mispositioned now." << std::endl;
322  return is;
323  }
324  v.push_back(uu);
325  }
326  getState(v);
327  return (is);
328  }
329 
330 // is >> theSeed; Removed, encompassed by possibleKeywordInput()
331  char endMarker [MarkerLen];
332  for (int i=0; i<2; ++i) {
333  is >> table[theSeed][i];
334  }
335  is >> std::ws;
336  is.width(MarkerLen);
337  is >> endMarker;
338  if (strcmp(endMarker,"RanecuEngine-end")) {
339  is.clear(std::ios::badbit | is.rdstate());
340  std::cerr << "\nRanecuEngine state description incomplete."
341  << "\nInput stream is probably mispositioned now." << std::endl;
342  return is;
343  }
344 
345  seq = int(theSeed);
346  return is;
347 }
static const int MarkerLen
Definition: DualRand.cc:67
static const unsigned int VECTOR_STATE_SIZE
Definition: RanecuEngine.h:115
virtual std::istream & getState(std::istream &is)
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:167
tuple v
Definition: test.py:18

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 358 of file RanecuEngine.cc.

358  {
359  if (v.size() != VECTOR_STATE_SIZE ) {
360  std::cerr <<
361  "\nRanecuEngine get:state vector has wrong length - state unchanged\n";
362  return false;
363  }
364  theSeed = v[1];
365  table[theSeed][0] = v[2];
366  table[theSeed][1] = v[3];
367  seq = int(theSeed);
368  return true;
369 }
static const unsigned int VECTOR_STATE_SIZE
Definition: RanecuEngine.h:115
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
tuple v
Definition: test.py:18

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 60 of file RanecuEngine.cc.

60 {return "RanecuEngine";}
CLHEP::RanecuEngine::operator unsigned int ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 246 of file RanecuEngine.cc.

246  {
247  const int index = seq;
248  long seed1 = table[index][0];
249  long seed2 = table[index][1];
250 
251  int k1 = (int)(seed1/ecuyer_b);
252  int k2 = (int)(seed2/ecuyer_e);
253 
254  seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
255  if (seed1 < 0) seed1 += shift1;
256  seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
257  if (seed2 < 0) seed2 += shift2;
258 
259  table[index][0] = seed1;
260  table[index][1] = seed2;
261  long diff = seed1-seed2;
262  if( diff <= 0 ) diff += (shift1-1);
263 
264  return ((diff << 1) | (seed1&1))& 0xffffffff;
265 }
static const int shift1
Definition: RanecuEngine.h:112
static const int ecuyer_b
Definition: RanecuEngine.h:107
static const int ecuyer_f
Definition: RanecuEngine.h:111
static const int ecuyer_a
Definition: RanecuEngine.h:106
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
static const int shift2
Definition: RanecuEngine.h:113
static const int ecuyer_e
Definition: RanecuEngine.h:110
static const int ecuyer_d
Definition: RanecuEngine.h:109
static const int ecuyer_c
Definition: RanecuEngine.h:108

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 267 of file RanecuEngine.cc.

268 {
269  char beginMarker[] = "RanecuEngine-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 }
tuple v
Definition: test.py:18
std::vector< unsigned long > put() const

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 278 of file RanecuEngine.cc.

278  {
279  std::vector<unsigned long> v;
280  v.push_back (engineIDulong<RanecuEngine>());
281  v.push_back(static_cast<unsigned long>(theSeed));
282  v.push_back(static_cast<unsigned long>(table[theSeed][0]));
283  v.push_back(static_cast<unsigned long>(table[theSeed][1]));
284  return v;
285 }
tuple v
Definition: test.py:18

Here is the caller graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 152 of file RanecuEngine.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 << "\nJamesRandom 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() && !inFile.eof()) {
178 // inFile >> theSeed; removed -- encompased by possibleKeywordInput
179  for (int i=0; i<2; ++i)
180  inFile >> table[theSeed][i];
181  seq = int(theSeed);
182  }
183 }
static std::string engineName()
Definition: RanecuEngine.h:96
static const unsigned int VECTOR_STATE_SIZE
Definition: RanecuEngine.h:115
virtual std::istream & getState(std::istream &is)
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
Definition: RandomEngine.cc:45
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:167
tuple v
Definition: test.py:18

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 139 of file RanecuEngine.cc.

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

Here is the call graph for this function:

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

Definition at line 132 of file RanecuEngine.cc.

133 {
134  seq = std::abs(int(index%maxSeq));
135  theSeed = seq;
136  theSeeds = &table[seq][0];
137 }
void CLHEP::RanecuEngine::setSeed ( long  index,
int  dum = 0 
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 110 of file RanecuEngine.cc.

111 {
112  seq = std::abs(int(index%maxSeq));
113  theSeed = seq;
114  HepRandom::getTheTableSeeds(table[seq],seq);
115  theSeeds = &table[seq][0];
116  further_randomize (seq, 0, index, shift1); // mf 6/22/10
117  further_randomize (seq, 1, dum, shift2); // mf 6/22/10
118 }
static const int shift1
Definition: RanecuEngine.h:112
static const int shift2
Definition: RanecuEngine.h:113
static void getTheTableSeeds(long *seeds, int index)
Definition: Random.cc:251

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 120 of file RanecuEngine.cc.

121 {
122  if (pos != -1) {
123  seq = std::abs(int(pos%maxSeq));
124  theSeed = seq;
125  }
126  // only positive seeds are allowed
127  table[seq][0] = std::abs(seeds[0])%shift1;
128  table[seq][1] = std::abs(seeds[1])%shift2;
129  theSeeds = &table[seq][0];
130 }
static const int shift1
Definition: RanecuEngine.h:112
static const int shift2
Definition: RanecuEngine.h:113
static const G4double pos
void CLHEP::RanecuEngine::showStatus ( ) const
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 185 of file RanecuEngine.cc.

186 {
187  std::cout << std::endl;
188  std::cout << "--------- Ranecu engine status ---------" << std::endl;
189  std::cout << " Initial seed (index) = " << theSeed << std::endl;
190  std::cout << " Current couple of seeds = "
191  << table[theSeed][0] << ", "
192  << table[theSeed][1] << std::endl;
193  std::cout << "----------------------------------------" << std::endl;
194 }

Member Data Documentation

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

Definition at line 106 of file RanecuEngine.h.

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

Definition at line 107 of file RanecuEngine.h.

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

Definition at line 108 of file RanecuEngine.h.

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

Definition at line 109 of file RanecuEngine.h.

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

Definition at line 110 of file RanecuEngine.h.

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

Definition at line 111 of file RanecuEngine.h.

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

Definition at line 112 of file RanecuEngine.h.

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

Definition at line 113 of file RanecuEngine.h.

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

Definition at line 115 of file RanecuEngine.h.


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