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

#include <DRand48Engine.h>

+ Inheritance diagram for CLHEP::DRand48Engine:

Public Member Functions

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

Additional Inherited Members

- Protected Member Functions inherited from CLHEP::noncopyable
 noncopyable () throw ()
 
 ~noncopyable () throw ()
 
- 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

◆ DRand48Engine() [1/4]

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

Definition at line 98 of file DRand48Engine.cc.

100{
101 is >> *this;
102}

◆ DRand48Engine() [2/4]

CLHEP::DRand48Engine::DRand48Engine ( )

Definition at line 66 of file DRand48Engine.cc.

68{
69 long seeds[2];
70 long seed;
71
72 int cycle = abs(int(numEngines/maxIndex));
73 int curIndex = abs(int(numEngines%maxIndex));
74 ++numEngines;
75 long mask = ((cycle & 0x007fffff) << 8);
76 HepRandom::getTheTableSeeds( seeds, curIndex );
77 seed = seeds[0]^mask;
78 setSeed(seed,0);
79 setSeeds(&theSeed,0);
80}
void setSeed(long seed, int dum=0)
void setSeeds(const long *seeds, int dum=0)
static void getTheTableSeeds(long *seeds, int index)
Definition: Random.cc:256

◆ DRand48Engine() [3/4]

CLHEP::DRand48Engine::DRand48Engine ( long  seed)

Definition at line 59 of file DRand48Engine.cc.

61{
62 setSeed(seed,0);
63 setSeeds(&theSeed,0);
64}

◆ DRand48Engine() [4/4]

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

Definition at line 82 of file DRand48Engine.cc.

84{
85 long seed;
86 long seeds[2];
87
88 int cycle = abs(int(rowIndex/maxIndex));
89 int row = abs(int(rowIndex%maxIndex));
90 int col = abs(int(colIndex%2));
91 long mask = ((cycle & 0x000007ff) << 20);
92 HepRandom::getTheTableSeeds( seeds, row );
93 seed = (seeds[col])^mask;
94 setSeed(seed,0);
95 setSeeds(&theSeed,0);
96}

◆ ~DRand48Engine()

CLHEP::DRand48Engine::~DRand48Engine ( )
virtual

Definition at line 104 of file DRand48Engine.cc.

104{}

Member Function Documentation

◆ beginTag()

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

Definition at line 283 of file DRand48Engine.cc.

283 {
284 return "DRand48Engine-begin";
285}

◆ engineName()

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

Definition at line 101 of file DRand48Engine.h.

101{return "DRand48Engine";}

Referenced by restoreStatus().

◆ flat()

double CLHEP::DRand48Engine::flat ( )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 209 of file DRand48Engine.cc.

210{
211 double num = 0.;
212
213 while (num == 0.)
214 num = drand48();
215 return num;
216}
double drand48(void)

Referenced by flatArray().

◆ flatArray()

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

Implements CLHEP::HepRandomEngine.

Definition at line 218 of file DRand48Engine.cc.

219{
220 int i;
221
222 for (i=0; i<size; ++i)
223 vect[i]=flat();
224}

◆ get() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 336 of file DRand48Engine.cc.

336 {
337 if ((v[0] & 0xffffffffUL) != engineIDulong<DRand48Engine>()) {
338 std::cerr <<
339 "\nDRand48Engine get:state vector has wrong ID word - state unchanged\n";
340 return false;
341 }
342 return getState(v);
343}
virtual std::istream & getState(std::istream &is)

◆ get() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 265 of file DRand48Engine.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,"DRand48Engine-begin")) {
274 is.clear(std::ios::badbit | is.rdstate());
275 std::cerr << "\nInput stream mispositioned or"
276 << "\nDRand48Engine state description missing or"
277 << "\nwrong engine type found." << std::endl;
278 return is;
279 }
280 return getState(is);
281}

◆ getState() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 345 of file DRand48Engine.cc.

345 {
346 if (v.size() != VECTOR_STATE_SIZE ) {
347 std::cerr <<
348 "\nDRand48Engine getState:state vector has wrong length - state unchanged\n";
349 return false;
350 }
351 unsigned short cseed[3];
352 for (int i=0; i<3; ++i) {
353 cseed[i] = static_cast<unsigned short>(v[i+1]);
354 }
355 seed48(cseed);
356 return true;
357}
unsigned short * seed48(unsigned short int[3])
static const unsigned int VECTOR_STATE_SIZE

◆ getState() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 287 of file DRand48Engine.cc.

288{
289 unsigned short cseed[3];
290 if ( possibleKeywordInput ( is, "Uvec", cseed[0] ) ) {
291 std::vector<unsigned long> v;
292 unsigned long uu;
293 #ifdef TRACE_IO
294 std::cout << "DRand48Engine::getState detected Uvec keyword\n";
295 uu = 999999;
296 #endif
297 for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
298 uu = 999999;
299 is >> uu;
300 #ifdef TRACE_IO
301 std::cout << "ivec = " << ivec << " uu = " << uu << "\n";
302 #endif
303 if (!is) {
304 is.clear(std::ios::badbit | is.rdstate());
305 std::cerr << "\nDRand48Engine state (vector) description improper."
306 << "\ngetState() has failed."
307 << "\nInput stream is probably mispositioned now." << std::endl;
308 return is;
309 }
310 v.push_back(uu);
311 }
312 getState(v);
313 return (is);
314 }
315
316// is >> cseed[0] was removed from loop, encompassed by possibleKeywordInput()
317
318 char endMarker [MarkerLen];
319 is >> theSeed;
320 for (int i=1; i<3; ++i) {
321 is >> cseed[i];
322 }
323 is >> std::ws;
324 is.width(MarkerLen);
325 is >> endMarker;
326 if (strcmp(endMarker,"DRand48Engine-end")) {
327 is.clear(std::ios::badbit | is.rdstate());
328 std::cerr << "\nDRand48Engine state description incomplete."
329 << "\nInput stream is probably mispositioned now." << std::endl;
330 return is;
331 }
332 seed48(cseed);
333 return is;
334}
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:168

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

◆ name()

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

Implements CLHEP::HepRandomEngine.

Definition at line 54 of file DRand48Engine.cc.

54{return "DRand48Engine";}

◆ put() [1/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 252 of file DRand48Engine.cc.

252 {
253 std::vector<unsigned long> v;
254 v.push_back (engineIDulong<DRand48Engine>());
255 unsigned short dummy[] = { 0, 0, 0 };
256 unsigned short* cseed = seed48(dummy);
257 for (int i=0; i<3; ++i) {
258 dummy[i] = cseed[i];
259 v.push_back (static_cast<unsigned long>(cseed[i]));
260 }
261 seed48(dummy);
262 return v;
263}

Referenced by put(), and saveStatus().

◆ put() [2/2]

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

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 226 of file DRand48Engine.cc.

227{
228 char beginMarker[] = "DRand48Engine-begin";
229 os << beginMarker << "\nUvec\n";
230 std::vector<unsigned long> v = put();
231 for (unsigned int i=0; i<v.size(); ++i) {
232 os << v[i] << "\n";
233 }
234 return os;
235
236#ifdef REMOVED
237 unsigned short dummy[] = { 0, 0, 0 };
238 unsigned short* cseed = seed48(dummy);
239 char endMarker[] = "DRand48Engine-end";
240 os << " " << beginMarker << " ";
241 os << theSeed << " ";
242 for (int i=0; i<3; ++i) {
243 dummy[i] = cseed[i];
244 os << cseed[i] << " ";
245 }
246 os << endMarker << " ";
247 seed48(dummy);
248 return os;
249#endif
250}
std::vector< unsigned long > put() const

◆ restoreStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 154 of file DRand48Engine.cc.

155{
156 std::ifstream inFile( filename, std::ios::in);
157 unsigned short cseed[3];
158
159 if (!checkFile ( inFile, filename, engineName(), "restoreStatus" )) {
160 std::cerr << " -- Engine state remains unchanged\n";
161 return;
162 }
163 if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
164 std::vector<unsigned long> v;
165 unsigned long xin;
166 for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
167 inFile >> xin;
168 #ifdef TRACE_IO
169 std::cout << "ivec = " << ivec << " xin = " << xin << " ";
170 if (ivec%3 == 0) std::cout << "\n";
171 #endif
172 if (!inFile) {
173 inFile.clear(std::ios::badbit | inFile.rdstate());
174 std::cerr << "\nDRand48Engine state (vector) description improper."
175 << "\nrestoreStatus has failed."
176 << "\nInput stream is probably mispositioned now." << std::endl;
177 return;
178 }
179 v.push_back(xin);
180 }
181 getState(v);
182 return;
183 }
184
185 if (!inFile.bad() && !inFile.eof()) {
186 inFile >> theSeed;
187 for (int i=0; i<3; ++i)
188// inFile >> theSeed; removed -- encompased by possibleKeywordInput
189 seed48(cseed);
190 }
191}
static std::string engineName()
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
Definition: RandomEngine.cc:49

◆ saveStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 118 of file DRand48Engine.cc.

119{
120 std::ofstream outFile( filename, std::ios::out ) ;
121
122 if (!outFile.bad()) {
123 outFile << "Uvec\n";
124 std::vector<unsigned long> v = put();
125 #ifdef TRACE_IO
126 std::cout << "Result of v = put() is:\n";
127 #endif
128 for (unsigned int i=0; i<v.size(); ++i) {
129 outFile << v[i] << "\n";
130 #ifdef TRACE_IO
131 std::cout << v[i] << " ";
132 if (i%6==0) std::cout << "\n";
133 #endif
134 }
135 #ifdef TRACE_IO
136 std::cout << "\n";
137 #endif
138 }
139
140#ifdef REMOVED
141 unsigned short dummy[] = { 0, 0, 0 };
142 unsigned short* cseed = seed48(dummy);
143 if (!outFile.bad()) {
144 outFile << theSeed << std::endl;
145 for (int i=0; i<3; ++i) {
146 outFile << cseed[i] << std::endl;
147 dummy[i] = cseed[i];
148 }
149 seed48(dummy);
150 }
151#endif
152}

◆ setSeed()

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

Implements CLHEP::HepRandomEngine.

Definition at line 106 of file DRand48Engine.cc.

107{
108 srand48( seed );
109 theSeed = seed;
110}
void srand48(long)

Referenced by DRand48Engine(), and setSeeds().

◆ setSeeds()

void CLHEP::DRand48Engine::setSeeds ( const long *  seeds,
int  dum = 0 
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 112 of file DRand48Engine.cc.

113{
114 setSeed(seeds ? *seeds : 19780503L, 0);
115 theSeeds = seeds;
116}

Referenced by DRand48Engine().

◆ showStatus()

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

Implements CLHEP::HepRandomEngine.

Definition at line 193 of file DRand48Engine.cc.

194{
195 unsigned short dummy[] = { 0, 0, 0 };
196 unsigned short* cseed = seed48(dummy);
197 std::cout << std::endl;
198 std::cout << "-------- DRand48 engine status ---------" << std::endl;
199 std::cout << " Initial seed = " << theSeed << std::endl;
200 std::cout << " Current seeds = " << cseed[0] << ", ";
201 std::cout << cseed[1] << ", ";
202 std::cout << cseed[2] << std::endl;
203 std::cout << "----------------------------------------" << std::endl;
204 for (int i=0; i<3; ++i)
205 dummy[i] = cseed[i];
206 seed48(dummy);
207}

Member Data Documentation

◆ VECTOR_STATE_SIZE

const unsigned int CLHEP::DRand48Engine::VECTOR_STATE_SIZE = 4
static

Definition at line 107 of file DRand48Engine.h.

Referenced by getState(), and restoreStatus().


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