48 #if __GNUC__ > 3 && __GNUC_MINOR__ > 8
49 #pragma GCC diagnostic push
50 #pragma GCC diagnostic ignored "-Waggressive-loop-optimizations"
61static const int MarkerLen = 64;
67 halfBuff(0), numFlats(0)
69 int numEngines = numberOfEngines++;
72 buffer[i] = (
unsigned int)((numEngines+19780503L*(i+1))& 0xffffffff);
75 theSeed = numEngines+19780503L*++i;
76 redSpin = (
unsigned int)(
theSeed & 0xffffffff);
78 for( i = 0; i < 10000; ++i)
flat();
83 halfBuff(0), numFlats(0)
90 halfBuff(0), numFlats(0)
92 for (
int i = 0; i < numBuff; ++i) {
93 buffer[i] = (
unsigned int)seed&0xffffffff;
96 redSpin = (
unsigned int)(
theSeed & 0xffffffff);
98 for (j = 0; j < numBuff*20; ++j) {
105 halfBuff(0), numFlats(0)
108 while( i < numBuff ) {
109 buffer[i] = (
unsigned int)((rowIndex + (i+1)*(colIndex+8))&0xffffffff);
113 redSpin = colIndex & 0xffffffff;
114 for( i = 0; i < 100; ++i)
flat();
120 unsigned int redAngle = (((numBuff/2) - 1) & redSpin) + halfBuff;
121 unsigned int blkSpin = buffer[redAngle] & 0xffffffff;
122 unsigned int boostResult = blkSpin ^ redSpin;
124 buffer[redAngle] = ((blkSpin << 17) | (blkSpin >> (32-17))) ^ redSpin;
126 redSpin = (blkSpin + numFlats++) & 0xffffffff;
127 halfBuff = numBuff/2 - halfBuff;
135 for (
int i = 0; i < size; ++i) {
147 while (seeds[i] && i < numBuff) {
148 buffer[i] = (
unsigned int)seeds[i];
151 while (i < numBuff) {
152 buffer[i] = buffer[i-1];
156 redSpin = (
unsigned int)
theSeed;
162 std::ofstream outFile(filename, std::ios::out);
163 if (!outFile.bad()) {
165 std::vector<unsigned long> v =
put();
166 for (
unsigned int i=0; i<v.size(); ++i) {
167 outFile << v[i] <<
"\n";
173 std::ifstream inFile(filename, std::ios::in);
175 std::cerr <<
" -- Engine state remains unchanged\n";
179 std::vector<unsigned long> v;
181 for (
unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
184 inFile.clear(std::ios::badbit | inFile.rdstate());
185 std::cerr <<
"\nRanshiEngine state (vector) description improper."
186 <<
"\nrestoreStatus has failed."
187 <<
"\nInput stream is probably mispositioned now." << std::endl;
198 for (
int i = 0; i < numBuff; ++i) {
201 inFile >> redSpin >> numFlats >> halfBuff;
206 std::cout << std::setprecision(20) << std::endl;
207 std::cout <<
"----------- Ranshi engine status ----------" << std::endl;
208 std::cout <<
"Initial seed = " <<
theSeed << std::endl;
209 std::cout <<
"Current red spin = " << redSpin << std::endl;
210 std::cout <<
"Values produced = " << numFlats << std::endl;
211 std::cout <<
"Side of buffer = " << (halfBuff ?
"upper" :
"lower")
213 std::cout <<
"Current buffer = " << std::endl;
214 for (
int i = 0; i < numBuff; i+=4) {
215 std::cout << std::setw(10) << std::setiosflags(std::ios::right)
216 << buffer[i] << std::setw(11) << buffer[i+1] << std::setw(11)
217 << buffer[i+2] << std::setw(11) << buffer[i+3] << std::endl;
219 std::cout <<
"-------------------------------------------" << std::endl;
222RanshiEngine::operator double() {
226RanshiEngine::operator float() {
227 unsigned int redAngle = (((numBuff/2) - 1) & redSpin) + halfBuff;
228 unsigned int blkSpin =
buffer[redAngle] & 0xffffffff;
230 buffer[redAngle] = ((blkSpin << 17) | (blkSpin >> (32-17))) ^ redSpin;
232 redSpin = (blkSpin + numFlats++) & 0xffffffff;
233 halfBuff = numBuff/2 - halfBuff;
235 return float(blkSpin * twoToMinus_32());
238RanshiEngine::operator
unsigned int() {
239 unsigned int redAngle = (((numBuff/2) - 1) & redSpin) + halfBuff;
240 unsigned int blkSpin =
buffer[redAngle] & 0xffffffff;
242 buffer[redAngle] = ((blkSpin << 17) | (blkSpin >> (32-17))) ^ redSpin;
244 redSpin = (blkSpin + numFlats++) & 0xffffffff;
245 halfBuff = numBuff/2 - halfBuff;
251 char beginMarker[] =
"RanshiEngine-begin";
252 os << beginMarker <<
"\nUvec\n";
253 std::vector<unsigned long> v =
put();
254 for (
unsigned int i=0; i<v.size(); ++i) {
261 std::vector<unsigned long> v;
262 v.push_back (engineIDulong<RanshiEngine>());
263 for (
int i = 0; i < numBuff; ++i) {
264 v.push_back(
static_cast<unsigned long>(buffer[i]));
266 v.push_back(
static_cast<unsigned long>(redSpin));
267 v.push_back(
static_cast<unsigned long>(numFlats));
268 v.push_back(
static_cast<unsigned long>(halfBuff));
273 char beginMarker [MarkerLen];
279 if (strcmp(beginMarker,
"RanshiEngine-begin")) {
280 is.clear(std::ios::badbit | is.rdstate());
281 std::cerr <<
"\nInput mispositioned or"
282 <<
"\nRanshiEngine state description missing or"
283 <<
"\nwrong engine type found." << std::endl;
290 return "RanshiEngine-begin";
295 std::vector<unsigned long> v;
297 for (
unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
300 is.clear(std::ios::badbit | is.rdstate());
301 std::cerr <<
"\nRanshiEngine state (vector) description improper."
302 <<
"\ngetState() has failed."
303 <<
"\nInput stream is probably mispositioned now." << std::endl;
314 char endMarker [MarkerLen];
315 for (
int i = 0; i < numBuff; ++i) {
318 is >> redSpin >> numFlats >> halfBuff;
322 if (strcmp(endMarker,
"RanshiEngine-end")) {
323 is.clear(std::ios::badbit | is.rdstate());
324 std::cerr <<
"\nRanshiEngine state description incomplete."
325 <<
"\nInput stream is probably mispositioned now." << std::endl;
332 if ((v[0] & 0xffffffffUL) != engineIDulong<RanshiEngine>()) {
334 "\nRanshiEngine get:state vector has wrong ID word - state unchanged\n";
341 if (v.size() != VECTOR_STATE_SIZE ) {
343 "\nRanshiEngine get:state vector has wrong length - state unchanged\n";
346 for (
int i = 0; i < numBuff; ++i) {
349 redSpin = v[numBuff+1];
350 numFlats = v[numBuff+2];
351 halfBuff = v[numBuff+3];
358 #if __GNUC__ > 3 && __GNUC_MINOR__ > 8
359 #pragma GCC diagnostic pop
#define CLHEP_ATOMIC_INT_TYPE
static double twoToMinus_32()
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)
virtual std::istream & getState(std::istream &is)
static std::string beginTag()
void flatArray(const int size, double *vect)
virtual std::istream & get(std::istream &is)
void saveStatus(const char filename[]="RanshiEngine.conf") const
std::vector< unsigned long > put() const
static std::string engineName()
void restoreStatus(const char filename[]="RanshiEngine.conf")
void setSeeds(const long *seeds, int)
void setSeed(long seed, int)
bool possibleKeywordInput(IS &is, const std::string &key, T &t)