79 numEngines(numberOfEngines++),
80 tausworthe (1234567 + numEngines + 175321),
81 integerCong(69607 * tausworthe + 54329, numEngines)
89 tausworthe ((unsigned
int)seed + 175321),
90 integerCong(69607 * tausworthe + 54329, 8043)
105 tausworthe (rowIndex + 1000 * colIndex + 85329),
106 integerCong(69607 * tausworthe + 54329, 1123)
123 for (
int i = 0; i < size; ++i) {
135 setSeed(seeds ? *seeds : 1234567, 0);
140 std::ofstream outFile(filename, std::ios::out);
141 if (!outFile.bad()) {
143 std::vector<unsigned long> v =
put();
144 for (
unsigned int i=0; i<v.size(); ++i) {
145 outFile << v[i] <<
"\n";
153 std::cerr <<
" -- Engine state remains unchanged\n";
157 std::vector<unsigned long> v;
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;
182 int pr=std::cout.precision(20);
183 std::cout << std::endl;
184 std::cout <<
"-------- DualRand engine status ---------"
186 std::cout <<
"Initial seed = " <<
theSeed << std::endl;
187 std::cout <<
"Tausworthe generator = " << std::endl;
189 std::cout <<
"\nIntegerCong generator = " << std::endl;
191 std::cout << std::endl <<
"-----------------------------------------"
193 std::cout.precision(pr);
196 DualRand::operator double() {
200 DualRand::operator float() {
201 return (
float) ( (integerCong ^ tausworthe) * twoToMinus_32()
202 + nearlyTwoToMinus_54() );
206 DualRand::operator
unsigned int() {
207 return (integerCong ^ tausworthe) & 0xffffffff;
211 char beginMarker[] =
"DualRand-begin";
212 os << beginMarker <<
"\nUvec\n";
213 std::vector<unsigned long> v =
put();
214 for (
unsigned int i=0; i<v.size(); ++i) {
221 std::vector<unsigned long> v;
222 v.push_back (engineIDulong<DualRand>());
235 if (strcmp(beginMarker,
"DualRand-begin")) {
236 is.clear(std::ios::badbit | is.rdstate());
237 std::cerr <<
"\nInput mispositioned or"
238 <<
"\nDualRand state description missing or"
239 <<
"\nwrong engine type found." << std::endl;
246 return "DualRand-begin";
251 std::vector<unsigned long> v;
256 is.clear(std::ios::badbit | is.rdstate());
257 std::cerr <<
"\nDualRand state (vector) description improper."
258 <<
"\ngetState() has failed."
259 <<
"\nInput stream is probably mispositioned now." << std::endl;
276 if (strcmp(endMarker,
"DualRand-end")) {
277 is.clear(std::ios::badbit | is.rdstate());
278 std::cerr <<
"DualRand state description incomplete."
279 <<
"\nInput stream is probably mispositioned now." << std::endl;
286 if ((v[0] & 0xffffffffUL) != engineIDulong<DualRand>()) {
288 "\nDualRand get:state vector has wrong ID word - state unchanged\n";
292 std::cerr <<
"\nDualRand get:state vector has wrong size: "
293 << v.size() <<
" - state unchanged\n";
300 std::vector<unsigned long>::const_iterator iv = v.begin()+1;
305 "\nDualRand get:state vector has wrong size: " << v.size()
306 <<
"\n Apparently " << iv-v.begin() <<
" words were consumed\n";
321 for (wordIndex = 1; wordIndex < 4; ++wordIndex) {
322 words[wordIndex] = 69607 * words[wordIndex-1] + 54329;
326 DualRand::Tausworthe::operator
unsigned int() {
372 if (wordIndex <= 0) {
373 for (wordIndex = 0; wordIndex < 4; ++wordIndex) {
374 words[wordIndex] = ( (words[(wordIndex+1) & 3] << 1 ) |
375 (words[wordIndex] >> 31) )
376 ^ ( (words[(wordIndex+1) & 3] << 31) |
377 (words[wordIndex] >> 1) );
380 return words[--wordIndex] & 0xffffffff;
384 char beginMarker[] =
"Tausworthe-begin";
385 char endMarker[] =
"Tausworthe-end";
387 int pr=os.precision(20);
388 os <<
" " << beginMarker <<
" ";
389 for (
int i = 0; i < 4; ++i) {
390 os << words[i] <<
" ";
393 os <<
" " << endMarker <<
" ";
399 for (
int i = 0; i < 4; ++i) {
400 v.push_back(static_cast<unsigned long>(words[i]));
402 v.push_back(static_cast<unsigned long>(wordIndex));
414 if (strcmp(beginMarker,
"Tausworthe-begin")) {
415 is.clear(std::ios::badbit | is.rdstate());
416 std::cerr <<
"\nInput mispositioned or"
417 <<
"\nTausworthe state description missing or"
418 <<
"\nwrong engine type found." << std::endl;
420 for (
int i = 0; i < 4; ++i) {
427 if (strcmp(endMarker,
"Tausworthe-end")) {
428 is.clear(std::ios::badbit | is.rdstate());
429 std::cerr <<
"\nTausworthe state description incomplete."
430 <<
"\nInput stream is probably mispositioned now." << std::endl;
436 for (
int i = 0; i < 4; ++i) {
444 : state((unsigned
int)3758656018U),
452 multiplier(65536 + 1024 + 5 + (8 * 1017 * streamNumber)),
470 DualRand::IntegerCong::operator
unsigned int() {
471 return state = (state * multiplier + addend) & 0xffffffff;
475 char beginMarker[] =
"IntegerCong-begin";
476 char endMarker[] =
"IntegerCong-end";
478 int pr=os.precision(20);
479 os <<
" " << beginMarker <<
" ";
480 os << state <<
" " << multiplier <<
" " << addend;
481 os <<
" " << endMarker <<
" ";
487 v.push_back(static_cast<unsigned long>(state));
488 v.push_back(static_cast<unsigned long>(multiplier));
489 v.push_back(static_cast<unsigned long>(addend));
501 if (strcmp(beginMarker,
"IntegerCong-begin")) {
502 is.clear(std::ios::badbit | is.rdstate());
503 std::cerr <<
"\nInput mispositioned or"
504 <<
"\nIntegerCong state description missing or"
505 <<
"\nwrong engine type found." << std::endl;
507 is >> state >> multiplier >> addend;
511 if (strcmp(endMarker,
"IntegerCong-end")) {
512 is.clear(std::ios::badbit | is.rdstate());
513 std::cerr <<
"\nIntegerCong state description incomplete."
514 <<
"\nInput stream is probably mispositioned now." << std::endl;
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
void flatArray(const int size, double *vect)
static std::string engineName()
void restoreStatus(const char filename[]="DualRand.conf")
void put(std::ostream &os) const
static double nearlyTwoToMinus_54()
void get(std::istream &is)
void saveStatus(const char filename[]="DualRand.conf") const
static double twoToMinus_32()
virtual std::istream & get(std::istream &is)
static std::string beginTag()
static const int MarkerLen
virtual std::istream & getState(std::istream &is)
std::vector< unsigned long > put() const
static const unsigned int VECTOR_STATE_SIZE
#define CLHEP_ATOMIC_INT_TYPE
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
void put(std::ostream &os) const
void setSeeds(const long *seeds, int)
static double twoToMinus_53()
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
void setSeed(long seed, int)
void get(std::istream &is)