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};
139 int cycle = std::abs(
int(rowIndex/maxIndex));
140 int row = std::abs(
int(rowIndex%maxIndex));
141 long mask = (( cycle & 0x000007ff ) << 20 );
220 for ( m = 0, nr = 11, ns = 4; m <
endIters; ++
m, --nr ) {
236 for (m=0; m<12; m++) {
241 for (m=11; m>=0; --
m) {
283 for ( k = dozens; k > 0; --k ) {
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];
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 int64_t topbits1, topbits2;
427 topbits1 = ( (int64_t) seed >> 32) & 0xffff ;
428 topbits2 = ( (int64_t) 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];
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";
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) {
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 = "
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) {
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];
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
static const unsigned int VECTOR_STATE_SIZE
virtual std::istream & getState(std::istream &is)
Float_t y1[n_points_granero]
unsigned long rshift(unsigned long value)
void flatArray(const int size, double *vect)
static constexpr double ns
void setSeed(long seed, int lux=1)
virtual std::istream & get(std::istream &is)
static double twoToMinus_32()
static double twoToMinus_48()
static double longs2double(const std::vector< unsigned long > &v)
Float_t y2[n_points_geant4]
unsigned long operator()(unsigned long)
virtual ~Ranlux64Engine()
static const int MarkerLen
const XML_Char int const XML_Char * value
#define CLHEP_ATOMIC_INT_TYPE
static std::string engineName()
static std::vector< unsigned long > dto2longs(double d)
void saveStatus(const char filename[]="Ranlux64.conf") const
static constexpr double m
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
static constexpr double lux
static void getTheTableSeeds(long *seeds, int index)
std::vector< unsigned long > put() const
static double twoToMinus_49()
static std::string beginTag()
void setSeeds(const long *seeds, int lux=1)
void restoreStatus(const char filename[]="Ranlux64.conf")