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

#include <MixMaxRng.h>

Inheritance diagram for CLHEP::MixMaxRng:
Collaboration diagram for CLHEP::MixMaxRng:

Public Member Functions

 MixMaxRng (std::istream &is)
 
 MixMaxRng ()
 
 MixMaxRng (long seed)
 
 MixMaxRng (int rowIndex, int colIndex)
 
virtual ~MixMaxRng ()
 
 MixMaxRng (const MixMaxRng &rng)
 
MixMaxRngoperator= (const MixMaxRng &rng)
 
double flat ()
 
void flatArray (const int size, double *vect)
 
void setSeed (long seed, int dum=0)
 
void setSeeds (const long *seeds, int seedNum=0)
 
void saveStatus (const char filename[]="MixMaxRngState.conf") const
 
void restoreStatus (const char filename[]="MixMaxRngState.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 Public Attributes

static const unsigned int VECTOR_STATE_SIZE = 2*N+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

Author
K. Savvidy

Definition at line 41 of file MixMaxRng.h.

Constructor & Destructor Documentation

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

Definition at line 68 of file MixMaxRng.cc.

70 {
71  get(is);
72 }
CLHEP::MixMaxRng::MixMaxRng ( )

Definition at line 53 of file MixMaxRng.cc.

55 {
56  int numEngines = ++numberOfEngines;
57  fRngState= rng_alloc();
58  setSeed(static_cast<long>(numEngines));
59 }
rng_state_t * rng_alloc()
Definition: mixmax.cc:151
void setSeed(long seed, int dum=0)
Definition: MixMaxRng.cc:136

Here is the call graph for this function:

CLHEP::MixMaxRng::MixMaxRng ( long  seed)

Definition at line 61 of file MixMaxRng.cc.

63 {
64  fRngState= rng_alloc();
65  setSeed(seed);
66 }
rng_state_t * rng_alloc()
Definition: mixmax.cc:151
void setSeed(long seed, int dum=0)
Definition: MixMaxRng.cc:136

Here is the call graph for this function:

CLHEP::MixMaxRng::MixMaxRng ( int  rowIndex,
int  colIndex 
)
CLHEP::MixMaxRng::~MixMaxRng ( )
virtual

Definition at line 74 of file MixMaxRng.cc.

75 {
76  rng_free( fRngState );
77 }
int rng_free(rng_state_t *X)
Definition: mixmax.cc:159

Here is the call graph for this function:

CLHEP::MixMaxRng::MixMaxRng ( const MixMaxRng rng)

Definition at line 79 of file MixMaxRng.cc.

80  : HepRandomEngine(rng)
81 {
82  fRngState= rng_copy( rng.fRngState->V );
83  fRngState->sumtot= rng.fRngState->sumtot;
84  fRngState->counter= rng.fRngState->counter;
85 }
rng_state_t * rng_copy(myuint *Y)
Definition: mixmax.cc:165

Here is the call graph for this function:

Member Function Documentation

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

Definition at line 250 of file MixMaxRng.cc.

251 {
252  return "MixMaxRng-begin";
253 }
static std::string CLHEP::MixMaxRng::engineName ( )
inlinestatic

Definition at line 92 of file MixMaxRng.h.

92 {return "MixMaxRng";}
double CLHEP::MixMaxRng::flat ( )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 180 of file MixMaxRng.cc.

181 {
182  return get_next_float(fRngState);
183 }
double get_next_float(rng_state_t *X)
Definition: mixmax.cc:86

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 185 of file MixMaxRng.cc.

186 {
187  // fill_array( fRngState, size, arrayDbl );
188  for (int i=0; i<size; ++i) { vect[i] = flat(); }
189 }

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 232 of file MixMaxRng.cc.

233 {
234  char beginMarker [MarkerLen];
235  is >> std::ws;
236  is.width(MarkerLen); // causes the next read to the char* to be <=
237  // that many bytes, INCLUDING A TERMINATION \0
238  // (Stroustrup, section 21.3.2)
239  is >> beginMarker;
240  if (strcmp(beginMarker,"MixMaxRng-begin")) {
241  is.clear(std::ios::badbit | is.rdstate());
242  std::cerr << "\nInput stream mispositioned or"
243  << "\nMixMaxRng state description missing or"
244  << "\nwrong engine type found." << std::endl;
245  return is;
246  }
247  return getState(is);
248 }
static const int MarkerLen
Definition: DualRand.cc:67
virtual std::istream & getState(std::istream &is)
Definition: MixMaxRng.cc:255

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 288 of file MixMaxRng.cc.

289 {
290  if ((v[0] & 0xffffffffUL) != engineIDulong<MixMaxRng>()) {
291  std::cerr <<
292  "\nMixMaxRng::get(): vector has wrong ID word - state unchanged\n";
293  return false;
294  }
295  return getState(v);
296 }
virtual std::istream & getState(std::istream &is)
Definition: MixMaxRng.cc:255

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 255 of file MixMaxRng.cc.

256 {
257  char endMarker[MarkerLen];
258  is >> theSeed;
259  for (int i=0; i<rng_get_N(); ++i) is >> fRngState->V[i];
260  is >> fRngState->counter;
261  myuint checksum;
262  is >> checksum;
263  is >> std::ws;
264  is.width(MarkerLen);
265  is >> endMarker;
266  if (strcmp(endMarker,"MixMaxRng-end")) {
267  is.clear(std::ios::badbit | is.rdstate());
268  std::cerr << "\nMixMaxRng state description incomplete."
269  << "\nInput stream is probably mispositioned now.\n";
270  return is;
271  }
272  if ( fRngState->counter < 0 || fRngState->counter > rng_get_N() ) {
273  std::cerr << "\nMixMaxRng::getState(): "
274  << "vector read wrong value of counter from file!"
275  << "\nInput stream is probably mispositioned now.\n";
276  return is;
277  }
278  precalc(fRngState);
279  if ( checksum != fRngState->sumtot) {
280  std::cerr << "\nMixMaxRng::getState(): "
281  << "checksum disagrees with value stored in file!"
282  << "\nInput stream is probably mispositioned now.\n";
283  return is;
284  }
285  return is;
286 }
static const int MarkerLen
Definition: DualRand.cc:67
int rng_get_N(void)
Definition: mixmax.cc:237
uint64_t myuint
Definition: mixmax.h:50
myuint V[N]
Definition: mixmax.h:59
myuint precalc(rng_state_t *X)
Definition: mixmax.cc:225

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 298 of file MixMaxRng.cc.

299 {
300  if (v.size() != VECTOR_STATE_SIZE ) {
301  std::cerr <<
302  "\nMixMaxRng::getState(): vector has wrong length - state unchanged\n";
303  return false;
304  }
305  for (int i=1; i<2*rng_get_N() ; i=i+2) {
306  fRngState->V[i/2]= ( (v[i] & MASK32) | ( (myuint)(v[i+1]) << 32 ) );
307  // unpack from a data structure which is 32-bit on some platforms
308  }
309  fRngState->counter = v[2*rng_get_N()+1];
310  precalc(fRngState);
311  if ( ( (v[2*rng_get_N()+2] & MASK32)
312  | ( (myuint)(v[2*rng_get_N()+3]) << 32 ) ) != fRngState->sumtot) {
313  std::cerr << "\nMixMaxRng::getState(): vector has wrong checksum!"
314  << "\nInput vector is probably mispositioned now.\n";
315  return false;
316  }
317  return true;
318 }
int rng_get_N(void)
Definition: mixmax.cc:237
const unsigned long MASK32
Definition: MixMaxRng.cc:40
uint64_t myuint
Definition: mixmax.h:50
static const unsigned int VECTOR_STATE_SIZE
Definition: MixMaxRng.h:98
myuint V[N]
Definition: mixmax.h:59
myuint precalc(rng_state_t *X)
Definition: mixmax.cc:225

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 51 of file MixMaxRng.cc.

51 { return "MixMaxRng"; } // N=" + N
CLHEP::MixMaxRng::operator unsigned int ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 191 of file MixMaxRng.cc.

192 {
193  return static_cast<unsigned int>(get_next(fRngState));
194  // get_next returns a 64-bit integer, of which the lower 61 bits
195  // are random and upper 3 bits are zero
196 }
myuint get_next(rng_state_t *X)
Definition: mixmax.cc:82

Here is the call graph for this function:

MixMaxRng & CLHEP::MixMaxRng::operator= ( const MixMaxRng rng)

Definition at line 87 of file MixMaxRng.cc.

88 {
89  // Check assignment to self
90  //
91  if (this == &rng) { return *this; }
92 
93  // Copy base class data
94  //
95  HepRandomEngine::operator=(rng);
96 
97  // Copy data
98  //
99  rng_free( fRngState );
100  fRngState= rng_copy( rng.fRngState->V );
101  fRngState->sumtot= rng.fRngState->sumtot;
102  fRngState->counter= rng.fRngState->counter;
103 
104  return *this;
105 }
int rng_free(rng_state_t *X)
Definition: mixmax.cc:159
rng_state_t * rng_copy(myuint *Y)
Definition: mixmax.cc:165

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 198 of file MixMaxRng.cc.

199 {
200  char beginMarker[] = "MixMaxRng-begin";
201  char endMarker[] = "MixMaxRng-end";
202 
203  int pr = os.precision(24);
204  os << beginMarker << " ";
205  os << theSeed << " ";
206  for (int i=0; i<rng_get_N(); ++i) {
207  os << fRngState->V[i] << "\n";
208  }
209  os << fRngState->counter << "\n";
210  os << fRngState->sumtot << "\n";
211  os << endMarker << "\n";
212  os.precision(pr);
213  return os;
214 }
int rng_get_N(void)
Definition: mixmax.cc:237
myuint V[N]
Definition: mixmax.h:59

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 216 of file MixMaxRng.cc.

217 {
218  std::vector<unsigned long> v;
219  v.push_back (engineIDulong<MixMaxRng>());
220  for (int i=0; i<rng_get_N(); ++i) {
221  v.push_back(static_cast<unsigned long>(fRngState->V[i] & MASK32));
222  // little-ended order on all platforms
223  v.push_back(static_cast<unsigned long>(fRngState->V[i] >> 32 ));
224  // pack uint64 into a data structure which is 32-bit on some platforms
225  }
226  v.push_back(static_cast<unsigned long>(fRngState->counter));
227  v.push_back(static_cast<unsigned long>(fRngState->sumtot & MASK32));
228  v.push_back(static_cast<unsigned long>(fRngState->sumtot >> 32));
229  return v;
230 }
int rng_get_N(void)
Definition: mixmax.cc:237
const unsigned long MASK32
Definition: MixMaxRng.cc:40
myuint V[N]
Definition: mixmax.h:59

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 120 of file MixMaxRng.cc.

121 {
122  read_state(fRngState, filename);
123 }
void read_state(rng_state_t *X, const char filename[])
Definition: mixmax.cc:283

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 107 of file MixMaxRng.cc.

108 {
109  // Create a C file-handle or an object that can accept the same output
110  FILE *fh= fopen(filename, "w");
111  if( fh )
112  {
113  fRngState->fh= fh;
114  print_state(fRngState);
115  fclose(fh);
116  }
117  fRngState->fh= 0;
118 }
void print_state(rng_state_t *X)
Definition: mixmax.cc:270

Here is the call graph for this function:

void CLHEP::MixMaxRng::setSeed ( long  seed,
int  dum = 0 
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 136 of file MixMaxRng.cc.

137 {
138  unsigned long seed0;
139 
140  theSeed = longSeed;
141  if( sizeof(long) > 4) // C standard says long is at least 32-bits
142  seed0= static_cast<unsigned long>(longSeed) & MASK32 ;
143  else
144  seed0= longSeed;
145 
146  seed_spbox(fRngState, seed0);
147 }
const unsigned long MASK32
Definition: MixMaxRng.cc:40
void seed_spbox(rng_state_t *X, myuint seed)
Definition: mixmax.cc:202

Here is the call graph for this function:

Here is the caller graph for this function:

void CLHEP::MixMaxRng::setSeeds ( const long *  seeds,
int  seedNum = 0 
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 153 of file MixMaxRng.cc.

154 {
155  unsigned long seed0, seed1= 0, seed2= 0, seed3= 0;
156 
157  if( seedNum < 1 ) { // Assuming at least 2 seeds in vector...
158  seed0= static_cast<unsigned long>(Seeds[0]) & MASK32;
159  seed1= static_cast<unsigned long>(Seeds[1]) & MASK32;
160  }
161  else
162  {
163  if( seedNum < 4 ) {
164  seed0= static_cast<unsigned long>(Seeds[0]) & MASK32;
165  if( seedNum > 1){ seed1= static_cast<unsigned long>(Seeds[1]) & MASK32; }
166  if( seedNum > 2){ seed2= static_cast<unsigned long>(Seeds[2]) & MASK32; }
167  }
168  if( seedNum >= 4 ) {
169  seed0= static_cast<unsigned long>(Seeds[0]) & MASK32;
170  seed1= static_cast<unsigned long>(Seeds[1]) & MASK32;
171  seed2= static_cast<unsigned long>(Seeds[2]) & MASK32;
172  seed3= static_cast<unsigned long>(Seeds[3]) & MASK32;
173  }
174  }
175  theSeed = Seeds[0];
176  theSeeds = Seeds;
177  seed_uniquestream(fRngState, seed3, seed2, seed1, seed0);
178 }
const unsigned long MASK32
Definition: MixMaxRng.cc:40
void seed_uniquestream(rng_state_t *X, myID_t clusterID, myID_t machineID, myID_t runID, myID_t streamID)
Definition: mixmax.cc:435

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 125 of file MixMaxRng.cc.

126 {
127  std::cout << std::endl;
128  std::cout << "------- MixMaxRng engine status -------" << std::endl;
129 
130  std::cout << " Current state vector is:" << std::endl;
131  fRngState->fh=stdout;
132  print_state(fRngState);
133  std::cout << "---------------------------------------" << std::endl;
134 }
void print_state(rng_state_t *X)
Definition: mixmax.cc:270

Here is the call graph for this function:

Member Data Documentation

const unsigned int CLHEP::MixMaxRng::VECTOR_STATE_SIZE = 2*N+4
static

Definition at line 98 of file MixMaxRng.h.


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