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

#include <DualRand.h>

Inheritance diagram for CLHEP::DualRand:
Collaboration diagram for CLHEP::DualRand:

Public Member Functions

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

Static Public Attributes

static const unsigned int VECTOR_STATE_SIZE = 9
 

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 50 of file DualRand.h.

Constructor & Destructor Documentation

CLHEP::DualRand::DualRand ( )

Definition at line 77 of file DualRand.cc.

78 : HepRandomEngine(),
79  numEngines(numberOfEngines++),
80  tausworthe (1234567 + numEngines + 175321),
81  integerCong(69607 * tausworthe + 54329, numEngines)
82 {
83  theSeed = 1234567;
84 }
CLHEP::DualRand::DualRand ( long  seed)

Definition at line 86 of file DualRand.cc.

87 : HepRandomEngine(),
88  numEngines(0),
89  tausworthe ((unsigned int)seed + 175321),
90  integerCong(69607 * tausworthe + 54329, 8043) // MF - not numEngines
91 {
92  theSeed = seed;
93 }
long seed
Definition: chem4.cc:68
CLHEP::DualRand::DualRand ( std::istream &  is)

Definition at line 95 of file DualRand.cc.

96 : HepRandomEngine(),
97  numEngines(0)
98 {
99  is >> *this;
100 }
CLHEP::DualRand::DualRand ( int  rowIndex,
int  colIndex 
)

Definition at line 102 of file DualRand.cc.

103 : HepRandomEngine(),
104  numEngines(0),
105  tausworthe (rowIndex + 1000 * colIndex + 85329),
106  integerCong(69607 * tausworthe + 54329, 1123) // MF - not numengines
107 {
108  theSeed = rowIndex;
109 }
CLHEP::DualRand::~DualRand ( )
virtual

Definition at line 111 of file DualRand.cc.

111 { }

Member Function Documentation

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

Definition at line 241 of file DualRand.cc.

241  {
242  return "DualRand-begin";
243 }
static std::string CLHEP::DualRand::engineName ( )
inlinestatic

Definition at line 96 of file DualRand.h.

96 {return "DualRand";}

Here is the caller graph for this function:

double CLHEP::DualRand::flat ( )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 113 of file DualRand.cc.

113  {
114  unsigned int ic ( integerCong );
115  unsigned int t ( tausworthe );
116  return ( (t ^ ic) * twoToMinus_32() + // most significant part
117  (t >> 11) * twoToMinus_53() + // fill in remaining bits
118  nearlyTwoToMinus_54() // make sure non-zero
119  );
120 }
static double nearlyTwoToMinus_54()
static double twoToMinus_32()
static double twoToMinus_53()

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 122 of file DualRand.cc.

122  {
123  for (int i = 0; i < size; ++i) {
124  vect[i] = flat();
125  }
126 }
double flat()
Definition: DualRand.cc:113

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 224 of file DualRand.cc.

224  {
225  char beginMarker [MarkerLen];
226  is >> std::ws;
227  is.width(MarkerLen); // causes the next read to the char* to be <=
228  // that many bytes, INCLUDING A TERMINATION \0
229  // (Stroustrup, section 21.3.2)
230  is >> beginMarker;
231  if (strcmp(beginMarker,"DualRand-begin")) {
232  is.clear(std::ios::badbit | is.rdstate());
233  std::cerr << "\nInput mispositioned or"
234  << "\nDualRand state description missing or"
235  << "\nwrong engine type found." << std::endl;
236  return is;
237  }
238  return getState(is);
239 }
static const int MarkerLen
Definition: DualRand.cc:67
virtual std::istream & getState(std::istream &is)
Definition: DualRand.cc:245

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 281 of file DualRand.cc.

281  {
282  if ((v[0] & 0xffffffffUL) != engineIDulong<DualRand>()) {
283  std::cerr <<
284  "\nDualRand get:state vector has wrong ID word - state unchanged\n";
285  return false;
286  }
287  if (v.size() != VECTOR_STATE_SIZE) {
288  std::cerr << "\nDualRand get:state vector has wrong size: "
289  << v.size() << " - state unchanged\n";
290  return false;
291  }
292  return getState(v);
293 }
static const unsigned int VECTOR_STATE_SIZE
Definition: DualRand.h:102
tuple v
Definition: test.py:18
virtual std::istream & getState(std::istream &is)
Definition: DualRand.cc:245

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 245 of file DualRand.cc.

245  {
246  if ( possibleKeywordInput ( is, "Uvec", theSeed ) ) {
247  std::vector<unsigned long> v;
248  unsigned long uu;
249  for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
250  is >> uu;
251  if (!is) {
252  is.clear(std::ios::badbit | is.rdstate());
253  std::cerr << "\nDualRand state (vector) description improper."
254  << "\ngetState() has failed."
255  << "\nInput stream is probably mispositioned now." << std::endl;
256  return is;
257  }
258  v.push_back(uu);
259  }
260  getState(v);
261  return (is);
262  }
263 
264 // is >> theSeed; Removed, encompassed by possibleKeywordInput()
265 
266  char endMarker [MarkerLen];
267  tausworthe.get(is);
268  integerCong.get(is);
269  is >> std::ws;
270  is.width(MarkerLen);
271  is >> endMarker;
272  if (strcmp(endMarker,"DualRand-end")) {
273  is.clear(std::ios::badbit | is.rdstate());
274  std::cerr << "DualRand state description incomplete."
275  << "\nInput stream is probably mispositioned now." << std::endl;
276  return is;
277  }
278  return is;
279 }
static const int MarkerLen
Definition: DualRand.cc:67
static const unsigned int VECTOR_STATE_SIZE
Definition: DualRand.h:102
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:167
tuple v
Definition: test.py:18
virtual std::istream & getState(std::istream &is)
Definition: DualRand.cc:245

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 295 of file DualRand.cc.

295  {
296  std::vector<unsigned long>::const_iterator iv = v.begin()+1;
297  if (!tausworthe.get(iv)) return false;
298  if (!integerCong.get(iv)) return false;
299  if (iv != v.end()) {
300  std::cerr <<
301  "\nDualRand get:state vector has wrong size: " << v.size()
302  << "\n Apparently " << iv-v.begin() << " words were consumed\n";
303  return false;
304  }
305  return true;
306 }
tuple v
Definition: test.py:18
std::string CLHEP::DualRand::name ( ) const
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 69 of file DualRand.cc.

69 {return "DualRand";}
CLHEP::DualRand::operator float ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 196 of file DualRand.cc.

196  {
197  return (float) ( (integerCong ^ tausworthe) * twoToMinus_32()
198  + nearlyTwoToMinus_54() );
199  // add this so that zero never happens
200 }
static double nearlyTwoToMinus_54()
static double twoToMinus_32()
CLHEP::DualRand::operator unsigned int ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 202 of file DualRand.cc.

202  {
203  return (integerCong ^ tausworthe) & 0xffffffff;
204 }
std::ostream & CLHEP::DualRand::put ( std::ostream &  os) const
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 206 of file DualRand.cc.

206  {
207  char beginMarker[] = "DualRand-begin";
208  os << beginMarker << "\nUvec\n";
209  std::vector<unsigned long> v = put();
210  for (unsigned int i=0; i<v.size(); ++i) {
211  os << v[i] << "\n";
212  }
213  return os;
214 }
tuple v
Definition: test.py:18
std::vector< unsigned long > put() const
Definition: DualRand.cc:216

Here is the call graph for this function:

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 216 of file DualRand.cc.

216  {
217  std::vector<unsigned long> v;
218  v.push_back (engineIDulong<DualRand>());
219  tausworthe.put(v);
220  integerCong.put(v);
221  return v;
222 }
tuple v
Definition: test.py:18

Here is the caller graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 150 of file DualRand.cc.

150  {
151  std::ifstream inFile(filename, std::ios::in);
152  if (!checkFile ( inFile, filename, engineName(), "restoreStatus" )) {
153  std::cerr << " -- Engine state remains unchanged\n";
154  return;
155  }
156  if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
157  std::vector<unsigned long> v;
158  unsigned long xin;
159  for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
160  inFile >> xin;
161  if (!inFile) {
162  inFile.clear(std::ios::badbit | inFile.rdstate());
163  std::cerr << "\nDualRand state (vector) description improper."
164  << "\nrestoreStatus has failed."
165  << "\nInput stream is probably mispositioned now." << std::endl;
166  return;
167  }
168  v.push_back(xin);
169  }
170  getState(v);
171  return;
172  }
173 
174  if (!inFile.bad()) {
175 // inFile >> theSeed; removed -- encompased by possibleKeywordInput
176  tausworthe.get(inFile);
177  integerCong.get(inFile);
178  }
179 }
static const unsigned int VECTOR_STATE_SIZE
Definition: DualRand.h:102
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
Definition: RandomEngine.cc:45
static std::string engineName()
Definition: DualRand.h:96
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:167
tuple v
Definition: test.py:18
virtual std::istream & getState(std::istream &is)
Definition: DualRand.cc:245

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 139 of file DualRand.cc.

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

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 128 of file DualRand.cc.

128  {
129  theSeed = seed;
130  tausworthe = Tausworthe((unsigned int)seed + 175321);
131  integerCong = IntegerCong(69607 * tausworthe + 54329, 8043);
132 }
long seed
Definition: chem4.cc:68

Here is the caller graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 134 of file DualRand.cc.

134  {
135  setSeed(seeds ? *seeds : 1234567, 0);
136  theSeeds = seeds;
137 }
void setSeed(long seed, int)
Definition: DualRand.cc:128

Here is the call graph for this function:

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

Implements CLHEP::HepRandomEngine.

Definition at line 181 of file DualRand.cc.

181  {
182  int pr=std::cout.precision(20);
183  std::cout << std::endl;
184  std::cout << "-------- DualRand engine status ---------"
185  << std::endl;
186  std::cout << "Initial seed = " << theSeed << std::endl;
187  std::cout << "Tausworthe generator = " << std::endl;
188  tausworthe.put(std::cout);
189  std::cout << "\nIntegerCong generator = " << std::endl;
190  integerCong.put(std::cout);
191  std::cout << std::endl << "-----------------------------------------"
192  << std::endl;
193  std::cout.precision(pr);
194 }

Member Data Documentation

const unsigned int CLHEP::DualRand::VECTOR_STATE_SIZE = 9
static

Definition at line 102 of file DualRand.h.


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