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

#include <TripleRand.h>

+ Inheritance diagram for CLHEP::TripleRand:

Public Member Functions

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

static const unsigned int VECTOR_STATE_SIZE = 20
 

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 TripleRand.h.

Constructor & Destructor Documentation

◆ TripleRand() [1/4]

CLHEP::TripleRand::TripleRand ( )

Definition at line 66 of file TripleRand.cc.

68 numEngines(numberOfEngines++),
69 tausworthe (1234567 + numEngines + 175321),
70 integerCong(69607 * tausworthe + 54329, numEngines),
71 hurd(19781127 + integerCong)
72{
73 theSeed = 1234567;
74}

◆ TripleRand() [2/4]

CLHEP::TripleRand::TripleRand ( long  seed)

Definition at line 76 of file TripleRand.cc.

78 numEngines(0),
79 tausworthe ((unsigned int)seed + 175321),
80 integerCong(69607 * tausworthe + 54329, 1313),
81 hurd(19781127 + integerCong)
82{
83 theSeed = seed;
84}

◆ TripleRand() [3/4]

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

Definition at line 86 of file TripleRand.cc.

88 numEngines(0)
89{
90 is >> *this;
91}

◆ TripleRand() [4/4]

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

Definition at line 93 of file TripleRand.cc.

95 numEngines(numberOfEngines),
96 tausworthe (rowIndex + numEngines * colIndex + 175321),
97 integerCong(69607 * tausworthe + 54329, 19),
98 hurd(19781127 + integerCong)
99{
100 theSeed = rowIndex;
101}

◆ ~TripleRand()

CLHEP::TripleRand::~TripleRand ( )
virtual

Definition at line 103 of file TripleRand.cc.

103{ }

Member Function Documentation

◆ beginTag()

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

Definition at line 281 of file TripleRand.cc.

281 {
282 return "TripleRand-begin";
283}

◆ engineName()

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

Definition at line 96 of file TripleRand.h.

96{return "TripleRand";}

Referenced by restoreStatus().

◆ flat()

double CLHEP::TripleRand::flat ( )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 105 of file TripleRand.cc.

105 {
106 unsigned int ic ( integerCong );
107 unsigned int t ( tausworthe );
108 unsigned int h ( hurd );
109 return ( (t ^ ic ^ h) * twoToMinus_32() + // most significant part
110 (h >> 11) * twoToMinus_53() + // fill in remaining bits
111 nearlyTwoToMinus_54() // make sure non-zero
112 );
113}
static double twoToMinus_32()
static double twoToMinus_53()
static double nearlyTwoToMinus_54()

Referenced by flatArray(), and main().

◆ flatArray()

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

Implements CLHEP::HepRandomEngine.

Definition at line 115 of file TripleRand.cc.

115 {
116 for (int i = 0; i < size; ++i) {
117 vect[i] = flat();
118 }
119}

◆ get() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 322 of file TripleRand.cc.

322 {
323 if ((v[0] & 0xffffffffUL) != engineIDulong<TripleRand>()) {
324 std::cerr <<
325 "\nTripleRand get:state vector has wrong ID word - state unchanged\n";
326 return false;
327 }
328 if (v.size() != VECTOR_STATE_SIZE) {
329 std::cerr << "\nTripleRand get:state vector has wrong size: "
330 << v.size() << " - state unchanged\n";
331 return false;
332 }
333 return getState(v);
334}
static const unsigned int VECTOR_STATE_SIZE
Definition: TripleRand.h:102
virtual std::istream & getState(std::istream &is)
Definition: TripleRand.cc:285

◆ get() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 264 of file TripleRand.cc.

264 {
265 char beginMarker [MarkerLen];
266 is >> std::ws;
267 is.width(MarkerLen); // causes the next read to the char* to be <=
268 // that many bytes, INCLUDING A TERMINATION \0
269 // (Stroustrup, section 21.3.2)
270 is >> beginMarker;
271 if (strcmp(beginMarker,"TripleRand-begin")) {
272 is.clear(std::ios::badbit | is.rdstate());
273 std::cerr << "\nInput mispositioned or"
274 << "\nTripleRand state description missing or"
275 << "\nwrong engine type found." << std::endl;
276 return is;
277 }
278 return getState(is);
279}

◆ getState() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 336 of file TripleRand.cc.

336 {
337 std::vector<unsigned long>::const_iterator iv = v.begin()+1;
338 if (!tausworthe.get(iv)) return false;
339 if (!integerCong.get(iv)) return false;
340 std::vector<unsigned long> vHurd;
341 while (iv != v.end()) {
342 vHurd.push_back(*iv++);
343 }
344 if (!hurd.get(vHurd)) {
345 std::cerr <<
346 "\nTripleRand get from vector: problem getting the hurd sub-engine state\n";
347 return false;
348 }
349 return true;
350}
virtual std::istream & get(std::istream &is)

◆ getState() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 285 of file TripleRand.cc.

285 {
286 if ( possibleKeywordInput ( is, "Uvec", theSeed ) ) {
287 std::vector<unsigned long> v;
288 unsigned long uu;
289 for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
290 is >> uu;
291 if (!is) {
292 is.clear(std::ios::badbit | is.rdstate());
293 std::cerr << "\nTripleRand state (vector) description improper."
294 << "\ngetState() has failed."
295 << "\nInput stream is probably mispositioned now." << std::endl;
296 return is;
297 }
298 v.push_back(uu);
299 }
300 getState(v);
301 return (is);
302 }
303
304// is >> theSeed; Removed, encompassed by possibleKeywordInput()
305
306 char endMarker [MarkerLen];
307 tausworthe.get( is );
308 integerCong.get( is );
309 is >> Hurd();
310 is >> std::ws;
311 is.width(MarkerLen);
312 is >> endMarker;
313 if (strcmp(endMarker,"TripleRand-end")) {
314 is.clear(std::ios::badbit | is.rdstate());
315 std::cerr << "\nTripleRand state description incomplete."
316 << "\nInput stream is probably mispositioned now." << std::endl;
317 return is;
318 }
319 return is;
320}
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:168

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

◆ name()

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

Implements CLHEP::HepRandomEngine.

Definition at line 64 of file TripleRand.cc.

64{return "TripleRand";}

◆ operator double()

CLHEP::TripleRand::operator double ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 210 of file TripleRand.cc.

210 {
211 return flat();
212}

◆ operator float()

CLHEP::TripleRand::operator float ( )
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 214 of file TripleRand.cc.

214 {
215 return (float)
216 ( ( integerCong ^ tausworthe ^ (unsigned int)hurd ) * twoToMinus_32()
218 // make sure non-zero!
219}

◆ operator unsigned int()

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 221 of file TripleRand.cc.

221 {
222 return integerCong ^ tausworthe ^ (unsigned int)hurd;
223}

◆ put() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 252 of file TripleRand.cc.

252 {
253 std::vector<unsigned long> v;
254 v.push_back (engineIDulong<TripleRand>());
255 tausworthe.put(v);
256 integerCong.put(v);
257 std::vector<unsigned long> vHurd = hurd.put();
258 for (unsigned int i = 0; i < vHurd.size(); ++i) {
259 v.push_back (vHurd[i]);
260 }
261 return v;
262}
virtual std::ostream & put(std::ostream &os) const

Referenced by put(), and saveStatus().

◆ put() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 230 of file TripleRand.cc.

230 {
231 char beginMarker[] = "TripleRand-begin";
232 os << beginMarker << "\nUvec\n";
233 std::vector<unsigned long> v = put();
234 for (unsigned int i=0; i<v.size(); ++i) {
235 os << v[i] << "\n";
236 }
237 return os;
238#ifdef REMOVED
239 char endMarker[] = "TripleRand-end";
240 int pr=os.precision(20);
241 os << " " << beginMarker << "\n";
242 os << theSeed << "\n";
243 tausworthe.put( os );
244 integerCong.put( os );
245 os << ConstHurd();
246 os << " " << endMarker << "\n";
247 os.precision(pr);
248 return os;
249#endif
250}
std::vector< unsigned long > put() const
Definition: TripleRand.cc:252

◆ restoreStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 160 of file TripleRand.cc.

160 {
161 std::ifstream inFile(filename, std::ios::in);
162 if (!checkFile ( inFile, filename, engineName(), "restoreStatus" )) {
163 std::cerr << " -- Engine state remains unchanged\n";
164 return;
165 }
166 if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
167 std::vector<unsigned long> v;
168 unsigned long xin;
169 for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
170 inFile >> xin;
171 #ifdef TRACE_IO
172 std::cout << "ivec = " << ivec << " xin = " << xin << " ";
173 if (ivec%3 == 0) std::cout << "\n";
174 #endif
175 if (!inFile) {
176 inFile.clear(std::ios::badbit | inFile.rdstate());
177 std::cerr << "\nTripleRand state (vector) description improper."
178 << "\nrestoreStatus has failed."
179 << "\nInput stream is probably mispositioned now." << std::endl;
180 return;
181 }
182 v.push_back(xin);
183 }
184 getState(v);
185 return;
186 }
187
188 if (!inFile.bad()) {
189// inFile >> theSeed; removed -- encompased by possibleKeywordInput
190 tausworthe.get ( inFile );
191 integerCong.get( inFile );
192 inFile >> Hurd();
193 }
194}
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: TripleRand.h:96

◆ saveStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 133 of file TripleRand.cc.

133 {
134 std::ofstream outFile(filename, std::ios::out);
135 if (!outFile.bad()) {
136 outFile << "Uvec\n";
137 std::vector<unsigned long> v = put();
138 #ifdef TRACE_IO
139 std::cout << "Result of v = put() is:\n";
140 #endif
141 for (unsigned int i=0; i<v.size(); ++i) {
142 outFile << v[i] << "\n";
143 #ifdef TRACE_IO
144 std::cout << v[i] << " ";
145 if (i%6==0) std::cout << "\n";
146 #endif
147 }
148 #ifdef TRACE_IO
149 std::cout << "\n";
150 #endif
151 }
152#ifdef REMOVED
153 outFile << std::setprecision(20) << theSeed << " ";
154 tausworthe.put ( outFile );
155 integerCong.put( outFile);
156 outFile << ConstHurd() << std::endl;
157#endif
158}

◆ setSeed()

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

Implements CLHEP::HepRandomEngine.

Definition at line 121 of file TripleRand.cc.

121 {
122 theSeed = seed;
123 tausworthe = Tausworthe((unsigned int)seed + 175321);
124 integerCong = IntegerCong(69607 * tausworthe + 54329, 1313);
125 hurd = Hurd288Engine( 19781127 + integerCong );
126}

Referenced by setSeeds().

◆ setSeeds()

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

Implements CLHEP::HepRandomEngine.

Definition at line 128 of file TripleRand.cc.

128 {
129 setSeed(seeds ? *seeds : 1234567, 0);
130 theSeeds = seeds;
131}
void setSeed(long seed, int)
Definition: TripleRand.cc:121

◆ showStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 196 of file TripleRand.cc.

196 {
197 std::cout << std::setprecision(20) << std::endl;
198 std::cout << "-------- TripleRand engine status ---------"
199 << std::endl;
200 std::cout << "Initial seed = " << theSeed << std::endl;
201 std::cout << "Tausworthe generator = " << std::endl;
202 tausworthe.put( std::cout );
203 std::cout << "IntegerCong generator = " << std::endl;
204 integerCong.put( std::cout );
205 std::cout << "Hurd288Engine generator= " << std::endl << ConstHurd();
206 std::cout << std::endl << "-----------------------------------------"
207 << std::endl;
208}

Member Data Documentation

◆ VECTOR_STATE_SIZE

const unsigned int CLHEP::TripleRand::VECTOR_STATE_SIZE = 20
static

Definition at line 102 of file TripleRand.h.

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


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