38const int RandFlat::MSBBits= 15;
39const unsigned long RandFlat::MSB= 1ul<<RandFlat::MSBBits;
50 return fire( defaultA, defaultB );
70 double lx,
double dx )
74 for (i=0; i<size; ++i)
75 vect[i] =
shoot(lx,dx);
79 const int size,
double* vect,
80 double lx,
double dx )
84 for (i=0; i<size; ++i)
85 vect[i] =
shoot(anEngine,lx,dx);
92 for (i=0; i<size; ++i)
93 vect[i] =
fire( defaultA, defaultB );
97 double lx,
double dx )
101 for (i=0; i<size; ++i)
102 vect[i] =
fire( lx, dx );
105void RandFlat::shootBits() {
106 const double factor= 2.0*MSB;
107 staticFirstUnusedBit= MSB;
108 staticRandomInt= (
unsigned long)(factor*
shoot());
112 if (staticFirstUnusedBit==0)
114 unsigned long temp= staticFirstUnusedBit&staticRandomInt;
115 staticFirstUnusedBit>>= 1;
120 const double factor= 2.0*MSB;
121 staticFirstUnusedBit= MSB;
122 staticRandomInt= (
unsigned long)(factor*
shoot(engine));
126 if (staticFirstUnusedBit==0)
128 unsigned long temp= staticFirstUnusedBit&staticRandomInt;
129 staticFirstUnusedBit>>= 1;
140 std::ofstream outfile ( filename, std::ios::app );
142 outfile <<
"RANDFLAT staticRandomInt: " << staticRandomInt
143 <<
" staticFirstUnusedBit: " << staticFirstUnusedBit <<
"\n";
155 std::ifstream infile ( filename, std::ios::in );
157 char inputword[] =
"NO_KEYWORD ";
161 if (strcmp(inputword,
"RANDFLAT")==0)
break;
162 if (infile.eof())
break;
171 if (strcmp(inputword,
"RANDFLAT")==0) {
176 infile >> staticRandomInt;
180 infile >> staticFirstUnusedBit;
186 long pr=os.precision(20);
187 std::vector<unsigned long> t(2);
188 os <<
" " <<
name() <<
"\n";
189 os <<
"Uvec" <<
"\n";
190 os << randomInt <<
" " << firstUnusedBit <<
"\n";
192 os << defaultWidth <<
" " << t[0] <<
" " << t[1] <<
"\n";
194 os << defaultA <<
" " << t[0] <<
" " << t[1] <<
"\n";
196 os << defaultB <<
" " << t[0] <<
" " << t[1] <<
"\n";
204 if (inName !=
name()) {
205 is.clear(std::ios::badbit | is.rdstate());
206 std::cerr <<
"Mismatch when expecting to read state of a "
207 <<
name() <<
" distribution\n"
208 <<
"Name found was " << inName
209 <<
"\nistream is left in the badbit state\n";
213 std::vector<unsigned long> t(2);
214 is >> randomInt >> firstUnusedBit;
219 is.clear(std::ios::badbit | is.rdstate());
220 std::cerr <<
"\nRandFlat input failed"
221 <<
"\nInput stream is probably mispositioned now." << std::endl;
227 is >> firstUnusedBit;
228 is >> defaultWidth >> defaultA >> defaultB;
234 long prec = os.precision(20);
235 os <<
"RANDFLAT staticRandomInt: " << staticRandomInt
236 <<
" staticFirstUnusedBit: " << staticFirstUnusedBit <<
"\n";
245 is.clear(std::ios::badbit | is.rdstate());
246 std::cerr <<
"Mismatch when expecting to read static state of a "
248 <<
"Name found was " << inName
249 <<
"\nistream is left in the badbit state\n";
256 if (keyword!=
"RANDFLAT") {
257 is.clear(std::ios::badbit | is.rdstate());
258 std::cerr <<
"Mismatch when expecting to read RANDFLAT bit cache info: "
262 is >> c1 >> staticRandomInt >> c2 >> staticFirstUnusedBit;
static double longs2double(const std::vector< unsigned long > &v)
static std::vector< unsigned long > dto2longs(double d)
virtual void restoreStatus(const char filename[]="Config.conf")=0
virtual void saveStatus(const char filename[]="Config.conf") const =0
virtual void flatArray(const int size, double *vect)=0
static HepRandomEngine * getTheEngine()
static std::ostream & saveFullState(std::ostream &os)
static std::istream & restoreFullState(std::istream &is)
static std::ostream & saveFullState(std::ostream &os)
std::ostream & put(std::ostream &os) const
static void restoreEngineStatus(const char filename[]="Config.conf")
void fireArray(const int size, double *vect)
static std::string distributionName()
static void saveEngineStatus(const char filename[]="Config.conf")
static std::ostream & saveDistState(std::ostream &os)
static std::istream & restoreDistState(std::istream &is)
static void shootArray(const int size, double *vect)
static std::istream & restoreFullState(std::istream &is)
std::istream & get(std::istream &is)
HepRandomEngine & engine()
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
#define CLHEP_THREAD_LOCAL