73 const int maxIndex = 215;
82 template< std::size_t
n,
83 bool = n < std::size_t(std::numeric_limits<unsigned long>::digits) >
84 struct do_right_shift;
85 template< std::
size_t n >
86 struct do_right_shift<n,true>
88 unsigned long operator()(
unsigned long value) {
return value >>
n; }
90 template< std::
size_t n >
91 struct do_right_shift<
n,false>
96 template< std::
size_t nbits >
98 {
return do_right_shift<nbits>()(value); }
109 int numEngines = numberOfEngines++;
110 int cycle = std::abs(
int(numEngines/maxIndex));
111 int curIndex = std::abs(
int(numEngines%maxIndex));
113 long mask = ((cycle & 0x007fffff) << 8);
129 long seedlist[2]={seed,0};
131 advance ( 2*lux + 1 );
139 int cycle = std::abs(
int(rowIndex/maxIndex));
140 int row = std::abs(
int(rowIndex%maxIndex));
141 long mask = (( cycle & 0x000007ff ) << 20 );
163 if (index <= 0) update();
167 void Ranlux64Engine::update() {
196 if ( endIters == 1 ) {
197 y1 = randoms[ 4] - randoms[11] - carry;
204 randoms[11] = randoms[10];
205 randoms[10] = randoms[ 9];
206 randoms[ 9] = randoms[ 8];
207 randoms[ 8] = randoms[ 7];
208 randoms[ 7] = randoms[ 6];
209 randoms[ 6] = randoms[ 5];
210 randoms[ 5] = randoms[ 4];
211 randoms[ 4] = randoms[ 3];
212 randoms[ 3] = randoms[ 2];
213 randoms[ 2] = randoms[ 1];
214 randoms[ 1] = randoms[ 0];
220 for ( m = 0, nr = 11, ns = 4; m < endIters; ++
m, --nr ) {
221 y1 = randoms [
ns] - randoms[nr] - carry;
236 for (m=0; m<12; m++) {
241 for (m=11; m>=0; --
m) {
242 randoms[
m] = temp[
ns];
257 void Ranlux64Engine::advance(
int dozens) {
283 for ( k = dozens; k > 0; --k ) {
285 y1 = randoms[ 4] - randoms[11] - carry;
287 y2 = randoms[ 3] - randoms[10];
294 y3 = randoms[ 2] - randoms[ 9];
301 y1 = randoms[ 1] - randoms[ 8];
308 y2 = randoms[ 0] - randoms[ 7];
315 y3 = randoms[11] - randoms[ 6];
322 y1 = randoms[10] - randoms[ 5];
329 y2 = randoms[ 9] - randoms[ 4];
336 y3 = randoms[ 8] - randoms[ 3];
343 y1 = randoms[ 7] - randoms[ 2];
350 y2 = randoms[ 6] - randoms[ 1];
357 y3 = randoms[ 5] - randoms[ 0];
375 for(
int i=0; i < size; ++i ) {
388 const int ecuyer_a(53668);
389 const int ecuyer_b(40014);
390 const int ecuyer_c(12211);
391 const int ecuyer_d(2147483563);
393 const int lux_levels[3] = {109, 202, 397};
396 if( (lux > 2)||(lux < 0) ){
397 pDiscard = (lux >= 12) ? (lux-12) : lux_levels[1];
399 pDiscard = lux_levels[luxury];
401 pDozens = pDiscard / 12;
402 endIters = pDiscard % 12;
405 long next_seed = seed;
408 next_seed &= 0xffffffff;
409 while( next_seed >= ecuyer_d ) {
410 next_seed -= ecuyer_d;
413 for(i = 0;i != 24;i++){
414 k_multiple = next_seed / ecuyer_a;
415 next_seed = ecuyer_b * (next_seed - k_multiple * ecuyer_a)
416 - k_multiple * ecuyer_c;
418 next_seed += ecuyer_d;
420 next_seed &= 0xffffffff;
421 init_table[i] = next_seed;
424 if(
sizeof(
long) >= 8 ) {
425 long topbits1, topbits2;
427 topbits1 = ( seed >> 32) & 0xffff ;
428 topbits2 = ( seed >> 48) & 0xffff ;
430 topbits1 = detail::rshift<32>(seed) & 0xffff ;
431 topbits2 = detail::rshift<48>(seed) & 0xffff ;
433 init_table[0] ^= topbits1;
434 init_table[2] ^= topbits2;
439 for(i = 0;i < 12; i++){
463 const int ecuyer_a = 53668;
464 const int ecuyer_b = 40014;
465 const int ecuyer_c = 12211;
466 const int ecuyer_d = 2147483563;
468 const int lux_levels[3] = {109, 202, 397};
485 if( (lux > 2)||(lux < 0) ){
486 pDiscard = (lux >= 12) ? (lux-12) : lux_levels[1];
488 pDiscard = lux_levels[luxury];
490 pDozens = pDiscard / 12;
491 endIters = pDiscard % 12;
494 long next_seed = *seeds;
498 for( i = 0;(i != 24)&&(*seedptr != 0);i++){
499 init_table[i] = *seedptr & 0xffffffff;
504 next_seed = init_table[i-1];
506 k_multiple = next_seed / ecuyer_a;
507 next_seed = ecuyer_b * (next_seed - k_multiple * ecuyer_a)
508 - k_multiple * ecuyer_c;
510 next_seed += ecuyer_d;
512 next_seed &= 0xffffffff;
513 init_table[i] = next_seed;
517 for(i = 0;i < 12; i++){
530 std::ofstream outFile( filename, std::ios::out ) ;
531 if (!outFile.bad()) {
533 std::vector<unsigned long> v =
put();
534 for (
unsigned int i=0; i<v.size(); ++i) {
535 outFile << v[i] <<
"\n";
542 std::ifstream inFile( filename, std::ios::in);
544 std::cerr <<
" -- Engine state remains unchanged\n";
548 std::vector<unsigned long> v;
553 inFile.clear(std::ios::badbit | inFile.rdstate());
554 std::cerr <<
"\nJamesRandom state (vector) description improper."
555 <<
"\nrestoreStatus has failed."
556 <<
"\nInput stream is probably mispositioned now." << std::endl;
565 if (!inFile.bad() && !inFile.eof()) {
567 for (
int i=0; i<12; ++i) {
568 inFile >> randoms[i];
570 inFile >> carry; inFile >> index;
571 inFile >> luxury; inFile >> pDiscard;
572 pDozens = pDiscard / 12;
573 endIters = pDiscard % 12;
579 std::cout << std::endl;
580 std::cout <<
"--------- Ranlux engine status ---------" << std::endl;
581 std::cout <<
" Initial seed = " <<
theSeed << std::endl;
582 std::cout <<
" randoms[] = ";
583 for (
int i=0; i<12; ++i) {
584 std::cout << randoms[i] << std::endl;
586 std::cout << std::endl;
587 std::cout <<
" carry = " << carry <<
", index = " << index << std::endl;
588 std::cout <<
" luxury = " << luxury <<
" pDiscard = "
589 << pDiscard << std::endl;
590 std::cout <<
"----------------------------------------" << std::endl;
595 char beginMarker[] =
"Ranlux64Engine-begin";
596 os << beginMarker <<
"\nUvec\n";
597 std::vector<unsigned long> v =
put();
598 for (
unsigned int i=0; i<v.size(); ++i) {
605 std::vector<unsigned long> v;
606 v.push_back (engineIDulong<Ranlux64Engine>());
607 std::vector<unsigned long> t;
608 for (
int i=0; i<12; ++i) {
610 v.push_back(t[0]); v.push_back(t[1]);
613 v.push_back(t[0]); v.push_back(t[1]);
614 v.push_back(static_cast<unsigned long>(index));
615 v.push_back(static_cast<unsigned long>(luxury));
616 v.push_back(static_cast<unsigned long>(pDiscard));
628 if (strcmp(beginMarker,
"Ranlux64Engine-begin")) {
629 is.clear(std::ios::badbit | is.rdstate());
630 std::cerr <<
"\nInput stream mispositioned or"
631 <<
"\nRanlux64Engine state description missing or"
632 <<
"\nwrong engine type found." << std::endl;
639 return "Ranlux64Engine-begin";
645 std::vector<unsigned long> v;
650 is.clear(std::ios::badbit | is.rdstate());
651 std::cerr <<
"\nRanlux64Engine state (vector) description improper."
652 <<
"\ngetState() has failed."
653 <<
"\nInput stream is probably mispositioned now." << std::endl;
665 for (
int i=0; i<12; ++i) {
668 is >> carry; is >> index;
669 is >> luxury; is >> pDiscard;
670 pDozens = pDiscard / 12;
671 endIters = pDiscard % 12;
675 if (strcmp(endMarker,
"Ranlux64Engine-end")) {
676 is.clear(std::ios::badbit | is.rdstate());
677 std::cerr <<
"\nRanlux64Engine state description incomplete."
678 <<
"\nInput stream is probably mispositioned now." << std::endl;
685 if ((v[0] & 0xffffffffUL) != engineIDulong<Ranlux64Engine>()) {
687 "\nRanlux64Engine get:state vector has wrong ID word - state unchanged\n";
696 "\nRanlux64Engine get:state vector has wrong length - state unchanged\n";
699 std::vector<unsigned long> t(2);
700 for (
int i=0; i<12; ++i) {
701 t[0] = v[2*i+1]; t[1] = v[2*i+2];
704 t[0] = v[25]; t[1] = v[26];
static constexpr double m
unsigned long rshift(unsigned long value)
static const int MarkerLen
virtual ~Ranlux64Engine()
static constexpr double ns
static double twoToMinus_48()
static double twoToMinus_32()
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
static std::string engineName()
std::vector< unsigned long > put() const
void setSeeds(const long *seeds, int lux=1)
const XML_Char int const XML_Char * value
static const unsigned int VECTOR_STATE_SIZE
void setSeed(long seed, int lux=1)
#define CLHEP_ATOMIC_INT_TYPE
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
void restoreStatus(const char filename[]="Ranlux64.conf")
static std::vector< unsigned long > dto2longs(double d)
static constexpr double lux
static std::string beginTag()
virtual std::istream & getState(std::istream &is)
unsigned long operator()(unsigned long)
void flatArray(const int size, double *vect)
static double twoToMinus_49()
void saveStatus(const char filename[]="Ranlux64.conf") const
virtual std::istream & get(std::istream &is)
static void getTheTableSeeds(long *seeds, int index)
static double longs2double(const std::vector< unsigned long > &v)