Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CLHEP::RanshiEngine Class Reference

#include <RanshiEngine.h>

Inheritance diagram for CLHEP::RanshiEngine:
Collaboration diagram for CLHEP::RanshiEngine:

Public Member Functions

 RanshiEngine ()
 
 RanshiEngine (std::istream &is)
 
 RanshiEngine (long seed)
 
 RanshiEngine (int rowIndex, int colIndex)
 
virtual ~RanshiEngine ()
 
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[]="RanshiEngine.conf") const
 
void restoreStatus (const char filename[]="RanshiEngine.conf")
 
void showStatus () const
 
 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)
 
long getSeed () const
 
const long * getSeeds () const
 
virtual operator double ()
 

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)
 

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 52 of file RanshiEngine.h.

Constructor & Destructor Documentation

CLHEP::RanshiEngine::RanshiEngine ( )

Definition at line 63 of file RanshiEngine.cc.

64 : HepRandomEngine(),
65  halfBuff(0), numFlats(0)
66 {
67  int numEngines = numberOfEngines++;
68  int i = 0;
69  while (i < numBuff) {
70  buffer[i] = (unsigned int)((numEngines+19780503L*(i+1))& 0xffffffff);
71  ++i;
72  }
73  theSeed = numEngines+19780503L*++i;
74  redSpin = (unsigned int)(theSeed & 0xffffffff);
75 
76  for( i = 0; i < 10000; ++i) flat(); // Warm-up by running thorugh 10000 nums
77 }
#define buffer
Definition: xmlparse.cc:628
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
static constexpr double L

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 79 of file RanshiEngine.cc.

80 : HepRandomEngine(),
81  halfBuff(0), numFlats(0)
82 {
83  is >> *this;
84 }
CLHEP::RanshiEngine::RanshiEngine ( long  seed)

Definition at line 86 of file RanshiEngine.cc.

87 : HepRandomEngine(),
88  halfBuff(0), numFlats(0)
89 {
90  for (int i = 0; i < numBuff; ++i) {
91  buffer[i] = (unsigned int)seed&0xffffffff;
92  }
93  theSeed = seed;
94  redSpin = (unsigned int)(theSeed & 0xffffffff);
95  int j;
96  for (j = 0; j < numBuff*20; ++j) { // "warm-up" for engine to hit
97  flat(); // every ball on average 20X.
98  }
99 }
#define buffer
Definition: xmlparse.cc:628
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)

Here is the call graph for this function:

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

Definition at line 101 of file RanshiEngine.cc.

102 : HepRandomEngine(),
103  halfBuff(0), numFlats(0)
104 {
105  int i = 0;
106  while( i < numBuff ) {
107  buffer[i] = (unsigned int)((rowIndex + (i+1)*(colIndex+8))&0xffffffff);
108  ++i;
109  }
110  theSeed = rowIndex;
111  redSpin = colIndex & 0xffffffff;
112  for( i = 0; i < 100; ++i) flat(); // Warm-up by running thorugh 100 nums
113 }
#define buffer
Definition: xmlparse.cc:628
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)

Here is the call graph for this function:

CLHEP::RanshiEngine::~RanshiEngine ( )
virtual

Definition at line 115 of file RanshiEngine.cc.

115 { }

Member Function Documentation

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

Definition at line 283 of file RanshiEngine.cc.

283  {
284  return "RanshiEngine-begin";
285 }
static std::string CLHEP::RanshiEngine::engineName ( )
inlinestatic

Definition at line 95 of file RanshiEngine.h.

95 {return "RanshiEngine";}

Here is the caller graph for this function:

double CLHEP::RanshiEngine::flat ( )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 117 of file RanshiEngine.cc.

117  {
118  unsigned int redAngle = (((numBuff/2) - 1) & redSpin) + halfBuff;
119  unsigned int blkSpin = buffer[redAngle] & 0xffffffff;
120  unsigned int boostResult = blkSpin ^ redSpin;
121 
122  buffer[redAngle] = ((blkSpin << 17) | (blkSpin >> (32-17))) ^ redSpin;
123 
124  redSpin = (blkSpin + numFlats++) & 0xffffffff;
125  halfBuff = numBuff/2 - halfBuff;
126 
127  return ( blkSpin * twoToMinus_32() + // most significant part
128  (boostResult>>11) * twoToMinus_53() + // fill in remaining bits
129  nearlyTwoToMinus_54()); // non-zero
130 }
static double nearlyTwoToMinus_54()
static double twoToMinus_32()
#define buffer
Definition: xmlparse.cc:628
static double twoToMinus_53()

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 132 of file RanshiEngine.cc.

132  {
133  for (int i = 0; i < size; ++i) {
134  vect[i] = flat();
135  }
136 }

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 266 of file RanshiEngine.cc.

266  {
267  char beginMarker [MarkerLen];
268  is >> std::ws;
269  is.width(MarkerLen); // causes the next read to the char* to be <=
270  // that many bytes, INCLUDING A TERMINATION \0
271  // (Stroustrup, section 21.3.2)
272  is >> beginMarker;
273  if (strcmp(beginMarker,"RanshiEngine-begin")) {
274  is.clear(std::ios::badbit | is.rdstate());
275  std::cerr << "\nInput mispositioned or"
276  << "\nRanshiEngine state description missing or"
277  << "\nwrong engine type found." << std::endl;
278  return is;
279  }
280  return getState(is);
281 }
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::RanshiEngine::get ( const std::vector< unsigned long > &  v)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 325 of file RanshiEngine.cc.

325  {
326  if ((v[0] & 0xffffffffUL) != engineIDulong<RanshiEngine>()) {
327  std::cerr <<
328  "\nRanshiEngine get:state vector has wrong ID word - state unchanged\n";
329  return false;
330  }
331  return getState(v);
332 }
virtual std::istream & getState(std::istream &is)

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 287 of file RanshiEngine.cc.

287  {
288  if ( possibleKeywordInput ( is, "Uvec", theSeed ) ) {
289  std::vector<unsigned long> v;
290  unsigned long uu;
291  for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
292  is >> uu;
293  if (!is) {
294  is.clear(std::ios::badbit | is.rdstate());
295  std::cerr << "\nRanshiEngine state (vector) description improper."
296  << "\ngetState() has failed."
297  << "\nInput stream is probably mispositioned now." << std::endl;
298  return is;
299  }
300  v.push_back(uu);
301  }
302  getState(v);
303  return (is);
304  }
305 
306 // is >> theSeed; Removed, encompassed by possibleKeywordInput()
307 
308  char endMarker [MarkerLen];
309  for (int i = 0; i < numBuff; ++i) {
310  is >> buffer[i];
311  }
312  is >> redSpin >> numFlats >> halfBuff;
313  is >> std::ws;
314  is.width(MarkerLen);
315  is >> endMarker;
316  if (strcmp(endMarker,"RanshiEngine-end")) {
317  is.clear(std::ios::badbit | is.rdstate());
318  std::cerr << "\nRanshiEngine state description incomplete."
319  << "\nInput stream is probably mispositioned now." << std::endl;
320  return is;
321  }
322  return is;
323 }
static const int MarkerLen
Definition: DualRand.cc:67
#define buffer
Definition: xmlparse.cc:628
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:167
virtual std::istream & getState(std::istream &is)

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 334 of file RanshiEngine.cc.

334  {
335  if (v.size() != VECTOR_STATE_SIZE ) {
336  std::cerr <<
337  "\nRanshiEngine get:state vector has wrong length - state unchanged\n";
338  return false;
339  }
340  for (int i = 0; i < numBuff; ++i) {
341  buffer[i] = v[i+1];
342  }
343  redSpin = v[numBuff+1];
344  numFlats = v[numBuff+2];
345  halfBuff = v[numBuff+3];
346  return true;
347 }
#define buffer
Definition: xmlparse.cc:628
std::string CLHEP::RanshiEngine::name ( ) const
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 61 of file RanshiEngine.cc.

61 {return "RanshiEngine";}
CLHEP::RanshiEngine::operator float ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 220 of file RanshiEngine.cc.

220  {
221  unsigned int redAngle = (((numBuff/2) - 1) & redSpin) + halfBuff;
222  unsigned int blkSpin = buffer[redAngle] & 0xffffffff;
223 
224  buffer[redAngle] = ((blkSpin << 17) | (blkSpin >> (32-17))) ^ redSpin;
225 
226  redSpin = (blkSpin + numFlats++) & 0xffffffff;
227  halfBuff = numBuff/2 - halfBuff;
228 
229  return float(blkSpin * twoToMinus_32());
230 }
static double twoToMinus_32()
#define buffer
Definition: xmlparse.cc:628
CLHEP::RanshiEngine::operator unsigned int ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 232 of file RanshiEngine.cc.

232  {
233  unsigned int redAngle = (((numBuff/2) - 1) & redSpin) + halfBuff;
234  unsigned int blkSpin = buffer[redAngle] & 0xffffffff;
235 
236  buffer[redAngle] = ((blkSpin << 17) | (blkSpin >> (32-17))) ^ redSpin;
237 
238  redSpin = (blkSpin + numFlats++) & 0xffffffff;
239  halfBuff = numBuff/2 - halfBuff;
240 
241  return blkSpin;
242 }
#define buffer
Definition: xmlparse.cc:628
std::ostream & CLHEP::RanshiEngine::put ( std::ostream &  os) const
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 244 of file RanshiEngine.cc.

244  {
245  char beginMarker[] = "RanshiEngine-begin";
246  os << beginMarker << "\nUvec\n";
247  std::vector<unsigned long> v = put();
248  for (unsigned int i=0; i<v.size(); ++i) {
249  os << v[i] << "\n";
250  }
251  return os;
252 }
std::vector< unsigned long > put() const

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 254 of file RanshiEngine.cc.

254  {
255  std::vector<unsigned long> v;
256  v.push_back (engineIDulong<RanshiEngine>());
257  for (int i = 0; i < numBuff; ++i) {
258  v.push_back(static_cast<unsigned long>(buffer[i]));
259  }
260  v.push_back(static_cast<unsigned long>(redSpin));
261  v.push_back(static_cast<unsigned long>(numFlats));
262  v.push_back(static_cast<unsigned long>(halfBuff));
263  return v;
264 }
#define buffer
Definition: xmlparse.cc:628

Here is the caller graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 170 of file RanshiEngine.cc.

170  {
171  std::ifstream inFile(filename, std::ios::in);
172  if (!checkFile ( inFile, filename, engineName(), "restoreStatus" )) {
173  std::cerr << " -- Engine state remains unchanged\n";
174  return;
175  }
176  if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
177  std::vector<unsigned long> v;
178  unsigned long xin;
179  for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
180  inFile >> xin;
181  if (!inFile) {
182  inFile.clear(std::ios::badbit | inFile.rdstate());
183  std::cerr << "\nRanshiEngine state (vector) description improper."
184  << "\nrestoreStatus has failed."
185  << "\nInput stream is probably mispositioned now." << std::endl;
186  return;
187  }
188  v.push_back(xin);
189  }
190  getState(v);
191  return;
192  }
193 
194  if (!inFile.bad()) {
195 // inFile >> theSeed; removed -- encompased by possibleKeywordInput
196  for (int i = 0; i < numBuff; ++i) {
197  inFile >> buffer[i];
198  }
199  inFile >> redSpin >> numFlats >> halfBuff;
200  }
201 }
#define buffer
Definition: xmlparse.cc:628
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
Definition: RandomEngine.cc:45
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:167
virtual std::istream & getState(std::istream &is)
static std::string engineName()
Definition: RanshiEngine.h:95

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 159 of file RanshiEngine.cc.

159  {
160  std::ofstream outFile(filename, std::ios::out);
161  if (!outFile.bad()) {
162  outFile << "Uvec\n";
163  std::vector<unsigned long> v = put();
164  for (unsigned int i=0; i<v.size(); ++i) {
165  outFile << v[i] << "\n";
166  }
167  }
168 }
std::vector< unsigned long > put() const

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 138 of file RanshiEngine.cc.

138  {
139  *this = RanshiEngine(seed);
140 }

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 142 of file RanshiEngine.cc.

142  {
143  if (*seeds) {
144  int i = 0;
145  while (seeds[i] && i < numBuff) {
146  buffer[i] = (unsigned int)seeds[i];
147  ++i;
148  }
149  while (i < numBuff) {
150  buffer[i] = buffer[i-1];
151  ++i;
152  }
153  theSeed = seeds[0];
154  redSpin = (unsigned int)theSeed;
155  }
156  theSeeds = seeds;
157 }
#define buffer
Definition: xmlparse.cc:628
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 203 of file RanshiEngine.cc.

203  {
204  std::cout << std::setprecision(20) << std::endl;
205  std::cout << "----------- Ranshi engine status ----------" << std::endl;
206  std::cout << "Initial seed = " << theSeed << std::endl;
207  std::cout << "Current red spin = " << redSpin << std::endl;
208  std::cout << "Values produced = " << numFlats << std::endl;
209  std::cout << "Side of buffer = " << (halfBuff ? "upper" : "lower")
210  << std::endl;
211  std::cout << "Current buffer = " << std::endl;
212  for (int i = 0; i < numBuff; i+=4) {
213  std::cout << std::setw(10) << std::setiosflags(std::ios::right)
214  << buffer[i] << std::setw(11) << buffer[i+1] << std::setw(11)
215  << buffer[i+2] << std::setw(11) << buffer[i+3] << std::endl;
216  }
217  std::cout << "-------------------------------------------" << std::endl;
218 }
#define buffer
Definition: xmlparse.cc:628

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