59static const int MarkerLen = 64;
61static const double prec = 4.6566128E-10;
65void RanecuEngine::further_randomize (
int seq1,
int col,
int index,
int modulus)
67 table[seq1][col] -= (index&0x3FFFFFFF);
68 while (table[seq1][col] <= 0) table[seq1][col] += (modulus-1);
74 int numEngines = numberOfEngines++;
75 int cycle = std::abs(
int(numEngines/maxSeq));
76 seq = std::abs(
int(numEngines%maxSeq));
79 long mask = ((cycle & 0x007fffff) << 8);
80 for (
int i=0; i<2; ++i) {
81 for (
int j=0; j<maxSeq; ++j) {
92 int cycle = std::abs(
int(index/maxSeq));
93 seq = std::abs(
int(index%maxSeq));
95 long mask = ((cycle & 0x000007ff) << 20);
96 for (
int j=0; j<maxSeq; ++j) {
102 further_randomize (seq, 0, index,
shift1);
115 seq = std::abs(
int(index%maxSeq));
119 further_randomize (seq, 0, index,
shift1);
120 further_randomize (seq, 1, dum,
shift2);
126 seq = std::abs(
int(pos%maxSeq));
130 table[seq][0] = std::abs(seeds[0])%
shift1;
131 table[seq][1] = std::abs(seeds[1])%
shift2;
137 seq = std::abs(
int(index%maxSeq));
144 std::ofstream outFile( filename, std::ios::out ) ;
146 if (!outFile.bad()) {
148 std::vector<unsigned long> v =
put();
149 for (
unsigned int i=0; i<v.size(); ++i) {
150 outFile << v[i] <<
"\n";
157 std::ifstream inFile( filename, std::ios::in);
159 std::cerr <<
" -- Engine state remains unchanged\n";
163 std::vector<unsigned long> v;
168 inFile.clear(std::ios::badbit | inFile.rdstate());
169 std::cerr <<
"\nJamesRandom state (vector) description improper."
170 <<
"\nrestoreStatus has failed."
171 <<
"\nInput stream is probably mispositioned now." << std::endl;
180 if (!inFile.bad() && !inFile.eof()) {
182 for (
int i=0; i<2; ++i)
190 std::cout << std::endl;
191 std::cout <<
"--------- Ranecu engine status ---------" << std::endl;
192 std::cout <<
" Initial seed (index) = " <<
theSeed << std::endl;
193 std::cout <<
" Current couple of seeds = "
195 << table[
theSeed][1] << std::endl;
196 std::cout <<
"----------------------------------------" << std::endl;
201 const int index = seq;
202 long seed1 = table[index][0];
203 long seed2 = table[index][1];
209 if (seed1 < 0) seed1 +=
shift1;
211 if (seed2 < 0) seed2 +=
shift2;
213 table[index][0] = seed1;
214 table[index][1] = seed2;
216 long diff = seed1-seed2;
218 if (diff <= 0) diff += (
shift1-1);
219 return (
double)(diff*prec);
224 const int index = seq;
225 long seed1 = table[index][0];
226 long seed2 = table[index][1];
230 for (i=0; i<size; ++i)
236 if (seed1 < 0) seed1 +=
shift1;
238 if (seed2 < 0) seed2 +=
shift2;
240 long diff = seed1-seed2;
241 if (diff <= 0) diff += (
shift1-1);
243 vect[i] = (double)(diff*prec);
245 table[index][0] = seed1;
246 table[index][1] = seed2;
249RanecuEngine::operator double() {
253RanecuEngine::operator float() {
254 return float( flat() );
257RanecuEngine::operator
unsigned int() {
258 const int index = seq;
259 long seed1 = table[index][0];
260 long seed2 = table[index][1];
262 int k1 = (int)(seed1/ecuyer_b);
263 int k2 = (int)(seed2/ecuyer_e);
265 seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
266 if (seed1 < 0) seed1 += shift1;
267 seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
268 if (seed2 < 0) seed2 += shift2;
270 table[index][0] = seed1;
271 table[index][1] = seed2;
272 long diff = seed1-seed2;
273 if( diff <= 0 ) diff += (shift1-1);
275 return ((diff << 1) | (seed1&1))& 0xffffffff;
280 char beginMarker[] =
"RanecuEngine-begin";
281 os << beginMarker <<
"\nUvec\n";
282 std::vector<unsigned long> v =
put();
283 for (
unsigned int i=0; i<v.size(); ++i) {
290 std::vector<unsigned long> v;
291 v.push_back (engineIDulong<RanecuEngine>());
292 v.push_back(
static_cast<unsigned long>(
theSeed));
293 v.push_back(
static_cast<unsigned long>(table[
theSeed][0]));
294 v.push_back(
static_cast<unsigned long>(table[
theSeed][1]));
300 char beginMarker [MarkerLen];
307 if (strcmp(beginMarker,
"RanecuEngine-begin")) {
308 is.clear(std::ios::badbit | is.rdstate());
309 std::cerr <<
"\nInput stream mispositioned or"
310 <<
"\nRanecuEngine state description missing or"
311 <<
"\nwrong engine type found." << std::endl;
318 return "RanecuEngine-begin";
324 std::vector<unsigned long> v;
329 is.clear(std::ios::badbit | is.rdstate());
330 std::cerr <<
"\nRanecuEngine state (vector) description improper."
331 <<
"\ngetState() has failed."
332 <<
"\nInput stream is probably mispositioned now." << std::endl;
342 char endMarker [MarkerLen];
343 for (
int i=0; i<2; ++i) {
349 if (strcmp(endMarker,
"RanecuEngine-end")) {
350 is.clear(std::ios::badbit | is.rdstate());
351 std::cerr <<
"\nRanecuEngine state description incomplete."
352 <<
"\nInput stream is probably mispositioned now." << std::endl;
361 if ((v[0] & 0xffffffffUL) != engineIDulong<RanecuEngine>()) {
363 "\nRanecuEngine get:state vector has wrong ID word - state unchanged\n";
372 "\nRanecuEngine get:state vector has wrong length - state unchanged\n";
#define CLHEP_ATOMIC_INT_TYPE
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
static void getTheTableSeeds(long *seeds, int index)
void restoreStatus(const char filename[]="Ranecu.conf")
void saveStatus(const char filename[]="Ranecu.conf") const
static const int ecuyer_b
static const int ecuyer_e
static std::string engineName()
static const int ecuyer_f
std::vector< unsigned long > put() const
void setSeed(long index, int dum=0)
static const int ecuyer_d
virtual std::istream & get(std::istream &is)
void flatArray(const int size, double *vect)
virtual std::istream & getState(std::istream &is)
void setIndex(long index)
static const int ecuyer_a
static const unsigned int VECTOR_STATE_SIZE
static const int ecuyer_c
void setSeeds(const long *seeds, int index=-1)
static std::string beginTag()
bool possibleKeywordInput(IS &is, const std::string &key, T &t)