46 #if __GNUC__ > 3 && __GNUC_MINOR__ > 8
47 #pragma GCC diagnostic push
48 #pragma GCC diagnostic ignored "-Waggressive-loop-optimizations"
65 halfBuff(0), numFlats(0)
67 int numEngines = numberOfEngines++;
70 buffer[i] = (
unsigned int)((numEngines+19780503
L*(i+1))& 0xffffffff);
76 for( i = 0; i < 10000; ++i)
flat();
81 halfBuff(0), numFlats(0)
88 halfBuff(0), numFlats(0)
90 for (
int i = 0; i <
numBuff; ++i) {
91 buffer[i] = (
unsigned int)seed&0xffffffff;
96 for (j = 0; j < numBuff*20; ++j) {
103 halfBuff(0), numFlats(0)
107 buffer[i] = (
unsigned int)((rowIndex + (i+1)*(colIndex+8))&0xffffffff);
111 redSpin = colIndex & 0xffffffff;
112 for( i = 0; i < 100; ++i)
flat();
119 unsigned int blkSpin =
buffer[redAngle] & 0xffffffff;
120 unsigned int boostResult = blkSpin ^
redSpin;
122 buffer[redAngle] = ((blkSpin << 17) | (blkSpin >> (32-17))) ^ redSpin;
124 redSpin = (blkSpin +
numFlats++) & 0xffffffff;
133 for (
int i = 0; i < size; ++i) {
145 while (seeds[i] && i <
numBuff) {
160 std::ofstream outFile(filename, std::ios::out);
161 if (!outFile.bad()) {
163 std::vector<unsigned long> v =
put();
164 for (
unsigned int i=0; i<v.size(); ++i) {
165 outFile << v[i] <<
"\n";
173 std::cerr <<
" -- Engine state remains unchanged\n";
177 std::vector<unsigned long> v;
182 inFile.clear(std::ios::badbit | inFile.rdstate());
183 std::cerr <<
"\nRanshiEngine state (vector) description improper."
184 <<
"\nrestoreStatus has failed."
185 <<
"\nInput stream is probably mispositioned now." << std::endl;
196 for (
int i = 0; i <
numBuff; ++i) {
204 std::cout << std::setprecision(20) << std::endl;
205 std::cout <<
"----------- Ranshi engine status ----------" << std::endl;
206 std::cout <<
"Initial seed = " <<
theSeed << std::endl;
207 std::cout <<
"Current red spin = " <<
redSpin << std::endl;
208 std::cout <<
"Values produced = " <<
numFlats << std::endl;
209 std::cout <<
"Side of buffer = " << (
halfBuff ?
"upper" :
"lower")
211 std::cout <<
"Current buffer = " << std::endl;
212 for (
int i = 0; i <
numBuff; i+=4) {
214 <<
buffer[i] << std::setw(11) <<
buffer[i+1] << std::setw(11)
215 <<
buffer[i+2] << std::setw(11) <<
buffer[i+3] << std::endl;
217 std::cout <<
"-------------------------------------------" << std::endl;
220 RanshiEngine::operator double() {
224 RanshiEngine::operator float() {
225 unsigned int redAngle = (((numBuff/2) - 1) & redSpin) + halfBuff;
226 unsigned int blkSpin =
buffer[redAngle] & 0xffffffff;
228 buffer[redAngle] = ((blkSpin << 17) | (blkSpin >> (32-17))) ^ redSpin;
230 redSpin = (blkSpin + numFlats++) & 0xffffffff;
231 halfBuff = numBuff/2 - halfBuff;
233 return float(blkSpin * twoToMinus_32());
236 RanshiEngine::operator
unsigned int() {
237 unsigned int redAngle = (((numBuff/2) - 1) & redSpin) + halfBuff;
238 unsigned int blkSpin =
buffer[redAngle] & 0xffffffff;
240 buffer[redAngle] = ((blkSpin << 17) | (blkSpin >> (32-17))) ^ redSpin;
242 redSpin = (blkSpin + numFlats++) & 0xffffffff;
243 halfBuff = numBuff/2 - halfBuff;
249 char beginMarker[] =
"RanshiEngine-begin";
250 os << beginMarker <<
"\nUvec\n";
251 std::vector<unsigned long> v =
put();
252 for (
unsigned int i=0; i<v.size(); ++i) {
259 std::vector<unsigned long> v;
260 v.push_back (engineIDulong<RanshiEngine>());
261 for (
int i = 0; i <
numBuff; ++i) {
262 v.push_back(static_cast<unsigned long>(
buffer[i]));
264 v.push_back(static_cast<unsigned long>(
redSpin));
265 v.push_back(static_cast<unsigned long>(
numFlats));
266 v.push_back(static_cast<unsigned long>(
halfBuff));
277 if (strcmp(beginMarker,
"RanshiEngine-begin")) {
278 is.clear(std::ios::badbit | is.rdstate());
279 std::cerr <<
"\nInput mispositioned or"
280 <<
"\nRanshiEngine state description missing or"
281 <<
"\nwrong engine type found." << std::endl;
288 return "RanshiEngine-begin";
293 std::vector<unsigned long> v;
298 is.clear(std::ios::badbit | is.rdstate());
299 std::cerr <<
"\nRanshiEngine state (vector) description improper."
300 <<
"\ngetState() has failed."
301 <<
"\nInput stream is probably mispositioned now." << std::endl;
313 for (
int i = 0; i <
numBuff; ++i) {
320 if (strcmp(endMarker,
"RanshiEngine-end")) {
321 is.clear(std::ios::badbit | is.rdstate());
322 std::cerr <<
"\nRanshiEngine state description incomplete."
323 <<
"\nInput stream is probably mispositioned now." << std::endl;
330 if ((v[0] & 0xffffffffUL) != engineIDulong<RanshiEngine>()) {
332 "\nRanshiEngine get:state vector has wrong ID word - state unchanged\n";
341 "\nRanshiEngine get:state vector has wrong length - state unchanged\n";
344 for (
int i = 0; i <
numBuff; ++i) {
356 #if __GNUC__ > 3 && __GNUC_MINOR__ > 8
357 #pragma GCC diagnostic pop
void setSeeds(const long *seeds, int)
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
static const unsigned int VECTOR_STATE_SIZE
static std::string engineName()
virtual std::istream & get(std::istream &is)
static double nearlyTwoToMinus_54()
static std::string beginTag()
void saveStatus(const char filename[]="RanshiEngine.conf") const
static double twoToMinus_32()
static const int MarkerLen
static constexpr double L
void setSeed(long seed, int)
#define CLHEP_ATOMIC_INT_TYPE
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
void flatArray(const int size, double *vect)
static double twoToMinus_53()
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)
std::vector< unsigned long > put() const
void restoreStatus(const char filename[]="RanshiEngine.conf")
unsigned int buffer[numBuff]