57 const int maxIndex = 215;
67 int numEngines = numberOfEngines++;
68 int cycle = std::abs(
int(numEngines/maxIndex));
69 int curIndex = std::abs(
int(numEngines%maxIndex));
70 long mask = ((cycle & 0x007fffff) << 8);
73 seedlist[0] = (seedlist[0])^mask;
78 for(
int i=0; i < 2000; ++i )
flat();
84 long seedlist[2]={
seed,17587};
87 for(
int i=0; i < 2000; ++i )
flat();
93 int cycle = std::abs(
int(rowIndex/maxIndex));
94 int row = std::abs(
int(rowIndex%maxIndex));
95 int col = std::abs(
int(colIndex%2));
96 long mask = (( cycle & 0x000007ff ) << 20 );
99 seedlist[0] = (seedlist[
col])^mask;
100 seedlist[1] = 690691;
103 for(
int i=0; i < 2000; ++i )
flat();
121 y = (
mt[i] & 0x80000000) | (
mt[i+1] & 0x7fffffff);
122 mt[i] =
mt[i+
M] ^ (y >> 1) ^ ((y & 0
x1) ? 0x9908b0df : 0x0 );
125 for( ; i <
N-1 ; ++i ) {
126 y = (
mt[i] & 0x80000000) | (
mt[i+1] & 0x7fffffff);
127 mt[i] =
mt[i-
NminusM] ^ (y >> 1) ^ ((y & 0
x1) ? 0x9908b0df : 0x0 );
130 y = (
mt[i] & 0x80000000) | (
mt[0] & 0x7fffffff);
131 mt[i] =
mt[
M-1] ^ (y >> 1) ^ ((y & 0
x1) ? 0x9908b0df : 0x0 );
138 y ^= ((y << 7 ) & 0x9d2c5680);
139 y ^= ((y << 15) & 0xefc60000);
148 for(
int i=0; i < size; ++i) vect[i] =
flat();
163 for (mti=1; mti<N1; mti++) {
164 mt[mti] = (1812433253UL * (
mt[mti-1] ^ (
mt[mti-1] >> 30)) + mti);
169 mt[mti] &= 0xffffffffUL;
172 for(
int i=1; i < 624; ++i ) {
180 setSeed( (*seeds ? *seeds : 43571346), k );
182 for( i=1; i < 624; ++i ) {
183 mt[i] = ( seeds[1] +
mt[i] ) & 0xffffffff;
190 std::ofstream outFile( filename, std::ios::out ) ;
191 if (!outFile.bad()) {
192 outFile <<
theSeed << std::endl;
193 for (
int i=0; i<624; ++i) outFile <<std::setprecision(20) <<
mt[i] <<
" ";
194 outFile << std::endl;
203 std::cerr <<
" -- Engine state remains unchanged\n";
207 if (!inFile.bad() && !inFile.eof()) {
209 for (
int i=0; i<624; ++i) inFile >>
mt[i];
216 std::cout << std::endl;
217 std::cout <<
"--------- MTwist engine status ---------" << std::endl;
218 std::cout << std::setprecision(20);
219 std::cout <<
" Initial seed = " <<
theSeed << std::endl;
220 std::cout <<
" Current index = " <<
count624 << std::endl;
221 std::cout <<
" Array status mt[] = " << std::endl;
224 for (
int i=0; i<620; i+=5) {
225 std::cout <<
mt[i] <<
" " <<
mt[i+1] <<
" " <<
mt[i+2] <<
" "
226 <<
mt[i+3] <<
" " <<
mt[i+4] <<
"\n";
228 std::cout <<
mt[620] <<
" " <<
mt[621] <<
" " <<
mt[622] <<
" "
229 <<
mt[623] << std::endl;
230 std::cout <<
"----------------------------------------" << std::endl;
233 MTwistEngine::operator double() {
237 MTwistEngine::operator float() {
240 if( count624 >=
N ) {
243 for( i=0; i < NminusM; ++i ) {
244 y = (mt[i] & 0x80000000) | (mt[i+1] & 0x7fffffff);
245 mt[i] = mt[i+M] ^ (y >> 1) ^ ((y & 0
x1) ? 0x9908b0df : 0x0 );
248 for( ; i <
N-1 ; ++i ) {
249 y = (mt[i] & 0x80000000) | (mt[i+1] & 0x7fffffff);
250 mt[i] = mt[i-NminusM] ^ (y >> 1) ^ ((y & 0
x1) ? 0x9908b0df : 0x0 );
253 y = (mt[i] & 0x80000000) | (mt[0] & 0x7fffffff);
254 mt[i] = mt[M-1] ^ (y >> 1) ^ ((y & 0
x1) ? 0x9908b0df : 0x0 );
261 y ^= ((y << 7 ) & 0x9d2c5680);
262 y ^= ((y << 15) & 0xefc60000);
265 return (
float)(y * twoToMinus_32());
268 MTwistEngine::operator
unsigned int() {
271 if( count624 >=
N ) {
274 for( i=0; i < NminusM; ++i ) {
275 y = (mt[i] & 0x80000000) | (mt[i+1] & 0x7fffffff);
276 mt[i] = mt[i+M] ^ (y >> 1) ^ ((y & 0
x1) ? 0x9908b0df : 0x0 );
279 for( ; i <
N-1 ; ++i ) {
280 y = (mt[i] & 0x80000000) | (mt[i+1] & 0x7fffffff);
281 mt[i] = mt[i-NminusM] ^ (y >> 1) ^ ((y & 0
x1) ? 0x9908b0df : 0x0 );
284 y = (mt[i] & 0x80000000) | (mt[0] & 0x7fffffff);
285 mt[i] = mt[M-1] ^ (y >> 1) ^ ((y & 0
x1) ? 0x9908b0df : 0x0 );
292 y ^= ((y << 7 ) & 0x9d2c5680);
293 y ^= ((y << 15) & 0xefc60000);
301 char beginMarker[] =
"MTwistEngine-begin";
302 char endMarker[] =
"MTwistEngine-end";
304 int pr = os.precision(20);
305 os <<
" " << beginMarker <<
" ";
307 for (
int i=0; i<624; ++i) {
311 os << endMarker <<
"\n";
317 std::vector<unsigned long> v;
318 v.push_back (engineIDulong<MTwistEngine>());
319 for (
int i=0; i<624; ++i) {
320 v.push_back(static_cast<unsigned long>(
mt[i]));
334 if (strcmp(beginMarker,
"MTwistEngine-begin")) {
335 is.clear(std::ios::badbit | is.rdstate());
336 std::cerr <<
"\nInput stream mispositioned or"
337 <<
"\nMTwistEngine state description missing or"
338 <<
"\nwrong engine type found." << std::endl;
345 return "MTwistEngine-begin";
352 for (
int i=0; i<624; ++i) is >>
mt[i];
357 if (strcmp(endMarker,
"MTwistEngine-end")) {
358 is.clear(std::ios::badbit | is.rdstate());
359 std::cerr <<
"\nMTwistEngine state description incomplete."
360 <<
"\nInput stream is probably mispositioned now." << std::endl;
367 if ((v[0] & 0xffffffffUL) != engineIDulong<MTwistEngine>()) {
369 "\nMTwistEngine get:state vector has wrong ID word - state unchanged\n";
378 "\nMTwistEngine get:state vector has wrong length - state unchanged\n";
381 for (
int i=0; i<624; ++i) {
Float_t x1[n_points_granero]
static double nearlyTwoToMinus_54()
static std::string engineName()
void setSeed(long seed, int)
static double twoToMinus_32()
static const int MarkerLen
virtual std::istream & getState(std::istream &is)
#define CLHEP_ATOMIC_INT_TYPE
void saveStatus(const char filename[]="MTwist.conf") const
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
void restoreStatus(const char filename[]="MTwist.conf")
static const unsigned int VECTOR_STATE_SIZE
virtual std::istream & get(std::istream &is)
std::vector< unsigned long > put() const
static double twoToMinus_53()
static bool checkFile(std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
static std::string beginTag()
static void getTheTableSeeds(long *seeds, int index)
void setSeeds(const long *seeds, int)
void flatArray(const int size, double *vect)