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);
74 redSpin = (
unsigned int)(
theSeed & 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;
94 redSpin = (
unsigned int)(
theSeed & 0xffffffff);
96 for (j = 0; j < numBuff*20; ++j) {
103 halfBuff(0), numFlats(0)
106 while( i < numBuff ) {
107 buffer[i] = (
unsigned int)((rowIndex + (i+1)*(colIndex+8))&0xffffffff);
111 redSpin = colIndex & 0xffffffff;
112 for( i = 0; i < 100; ++i)
flat();
118 unsigned int redAngle = (((numBuff/2) - 1) & redSpin) + halfBuff;
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;
125 halfBuff = numBuff/2 - halfBuff;
133 for (
int i = 0; i < size; ++i) {
145 while (seeds[i] && i < numBuff) {
146 buffer[i] = (
unsigned int)seeds[i];
149 while (i < numBuff) {
150 buffer[i] = buffer[i-1];
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";
171 std::ifstream inFile(filename, std::ios::in);
173 std::cerr <<
" -- Engine state remains unchanged\n";
177 std::vector<unsigned long>
v;
179 for (
unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
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) {
199 inFile >> redSpin >> numFlats >> halfBuff;
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 float() {
221 unsigned int redAngle = (((numBuff/2) - 1) & redSpin) + halfBuff;
222 unsigned int blkSpin =
buffer[redAngle] & 0xffffffff;
224 buffer[redAngle] = ((blkSpin << 17) | (blkSpin >> (32-17))) ^ redSpin;
226 redSpin = (blkSpin + numFlats++) & 0xffffffff;
227 halfBuff = numBuff/2 - halfBuff;
229 return float(blkSpin * twoToMinus_32());
232 RanshiEngine::operator
unsigned int() {
233 unsigned int redAngle = (((numBuff/2) - 1) & redSpin) + halfBuff;
234 unsigned int blkSpin =
buffer[redAngle] & 0xffffffff;
236 buffer[redAngle] = ((blkSpin << 17) | (blkSpin >> (32-17))) ^ redSpin;
238 redSpin = (blkSpin + numFlats++) & 0xffffffff;
239 halfBuff = numBuff/2 - halfBuff;
245 char beginMarker[] =
"RanshiEngine-begin";
246 os << beginMarker <<
"\nUvec\n";
247 std::vector<unsigned long>
v =
put();
248 for (
unsigned int i=0; i<v.size(); ++i) {
255 std::vector<unsigned long>
v;
256 v.push_back (engineIDulong<RanshiEngine>());
257 for (
int i = 0; i < numBuff; ++i) {
258 v.push_back(static_cast<unsigned long>(buffer[i]));
260 v.push_back(static_cast<unsigned long>(redSpin));
261 v.push_back(static_cast<unsigned long>(numFlats));
262 v.push_back(static_cast<unsigned long>(halfBuff));
273 if (strcmp(beginMarker,
"RanshiEngine-begin")) {
274 is.clear(std::ios::badbit | is.rdstate());
275 std::cerr <<
"\nInput mispositioned or"
276 <<
"\nRanshiEngine state description missing or"
277 <<
"\nwrong engine type found." << std::endl;
284 return "RanshiEngine-begin";
289 std::vector<unsigned long>
v;
291 for (
unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
294 is.clear(std::ios::badbit | is.rdstate());
295 std::cerr <<
"\nRanshiEngine state (vector) description improper."
296 <<
"\ngetState() has failed."
297 <<
"\nInput stream is probably mispositioned now." << std::endl;
309 for (
int i = 0; i < numBuff; ++i) {
312 is >> redSpin >> numFlats >> halfBuff;
316 if (strcmp(endMarker,
"RanshiEngine-end")) {
317 is.clear(std::ios::badbit | is.rdstate());
318 std::cerr <<
"\nRanshiEngine state description incomplete."
319 <<
"\nInput stream is probably mispositioned now." << std::endl;
326 if ((v[0] & 0xffffffffUL) != engineIDulong<RanshiEngine>()) {
328 "\nRanshiEngine get:state vector has wrong ID word - state unchanged\n";
335 if (v.size() != VECTOR_STATE_SIZE ) {
337 "\nRanshiEngine get:state vector has wrong length - state unchanged\n";
340 for (
int i = 0; i < numBuff; ++i) {
343 redSpin = v[numBuff+1];
344 numFlats = v[numBuff+2];
345 halfBuff = v[numBuff+3];
352 #if __GNUC__ > 3 && __GNUC_MINOR__ > 8
353 #pragma GCC diagnostic pop
static double nearlyTwoToMinus_54()
static const int MarkerLen
void restoreStatus(const char filename[]="RanshiEngine.conf")
static double twoToMinus_32()
void setSeeds(const long *seeds, int)
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
virtual std::istream & get(std::istream &is)
void setSeed(long seed, int)
void flatArray(const int size, double *vect)
#define CLHEP_ATOMIC_INT_TYPE
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
static double twoToMinus_53()
void saveStatus(const char filename[]="RanshiEngine.conf") const
virtual std::istream & getState(std::istream &is)
std::vector< unsigned long > put() const
static constexpr double L
static std::string engineName()
static std::string beginTag()