30#include "CLHEP/Random/defs.h"
31#include "CLHEP/Random/RandFlat.h"
32#include "CLHEP/Random/DoubConv.h"
40const int RandFlat::MSBBits= 15;
41const unsigned long RandFlat::MSB= 1ul<<RandFlat::MSBBits;
42CLHEP_THREAD_LOCAL
unsigned long RandFlat::staticRandomInt= 0;
43CLHEP_THREAD_LOCAL
unsigned long RandFlat::staticFirstUnusedBit= 0;
52 return fire( defaultA, defaultB );
72 double lx,
double dx )
76 for (i=0; i<size; ++i)
77 vect[i] =
shoot(lx,dx);
81 const int size,
double* vect,
82 double lx,
double dx )
86 for (i=0; i<size; ++i)
87 vect[i] =
shoot(anEngine,lx,dx);
94 for (i=0; i<size; ++i)
95 vect[i] =
fire( defaultA, defaultB );
99 double lx,
double dx )
103 for (i=0; i<size; ++i)
104 vect[i] =
fire( lx, dx );
114 std::ofstream outfile ( filename, std::ios::app );
116 outfile <<
"RANDFLAT staticRandomInt: " << staticRandomInt
117 <<
" staticFirstUnusedBit: " << staticFirstUnusedBit <<
"\n";
129 std::ifstream infile ( filename, std::ios::in );
131 char inputword[] =
"NO_KEYWORD ";
135 if (strcmp(inputword,
"RANDFLAT")==0)
break;
136 if (infile.eof())
break;
145 if (strcmp(inputword,
"RANDFLAT")==0) {
150 infile >> staticRandomInt;
154 infile >> staticFirstUnusedBit;
160 long pr=os.precision(20);
161 std::vector<unsigned long> t(2);
162 os <<
" " <<
name() <<
"\n";
163 os <<
"Uvec" <<
"\n";
164 os << randomInt <<
" " << firstUnusedBit <<
"\n";
166 os << defaultWidth <<
" " << t[0] <<
" " << t[1] <<
"\n";
168 os << defaultA <<
" " << t[0] <<
" " << t[1] <<
"\n";
170 os << defaultB <<
" " << t[0] <<
" " << t[1] <<
"\n";
172 std::cout <<
"RandFlat::put(): randomInt = " << randomInt
173 <<
" firstUnusedBit = " << firstUnusedBit
174 <<
"\ndefaultWidth = " << defaultWidth
175 <<
" defaultA = " << defaultA
176 <<
" defaultB = " << defaultB <<
"\n";
181 long pr=os.precision(20);
182 os <<
" " <<
name() <<
"\n";
183 os << randomInt <<
" " << firstUnusedBit <<
"\n";
184 os << defaultWidth <<
" " << defaultA <<
" " << defaultB <<
"\n";
193 if (inName !=
name()) {
194 is.clear(std::ios::badbit | is.rdstate());
195 std::cerr <<
"Mismatch when expecting to read state of a "
196 <<
name() <<
" distribution\n"
197 <<
"Name found was " << inName
198 <<
"\nistream is left in the badbit state\n";
202 std::vector<unsigned long> t(2);
203 is >> randomInt >> firstUnusedBit;
208 std::cout <<
"RandFlat::get(): randomInt = " << randomInt
209 <<
" firstUnusedBit = " << firstUnusedBit
210 <<
"\ndefaultWidth = " << defaultWidth
211 <<
" defaultA = " << defaultA
212 <<
" defaultB = " << defaultB <<
"\n";
215 is.clear(std::ios::badbit | is.rdstate());
216 std::cerr <<
"\nRandFlat input failed"
217 <<
"\nInput stream is probably mispositioned now." << std::endl;
223 is >> firstUnusedBit;
224 is >> defaultWidth >> defaultA >> defaultB;
230 long prec = os.precision(20);
231 os <<
"RANDFLAT staticRandomInt: " << staticRandomInt
232 <<
" staticFirstUnusedBit: " << staticFirstUnusedBit <<
"\n";
241 is.clear(std::ios::badbit | is.rdstate());
242 std::cerr <<
"Mismatch when expecting to read static state of a "
244 <<
"Name found was " << inName
245 <<
"\nistream is left in the badbit state\n";
252 if (keyword!=
"RANDFLAT") {
253 is.clear(std::ios::badbit | is.rdstate());
254 std::cerr <<
"Mismatch when expecting to read RANDFLAT bit cache info: "
258 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)