30#include "CLHEP/Random/defs.h"
31#include "CLHEP/Random/RandFlat.h"
32#include "CLHEP/Random/DoubConv.hh"
37const int RandFlat::MSBBits= 15;
38const unsigned long RandFlat::MSB= 1ul<<RandFlat::MSBBits;
39unsigned long RandFlat::staticRandomInt= 0;
40unsigned long RandFlat::staticFirstUnusedBit= 0;
49 return fire( defaultA, defaultB );
69 double lx,
double dx )
73 for (i=0; i<size; ++i)
74 vect[i] =
shoot(lx,dx);
78 const int size,
double* vect,
79 double lx,
double dx )
83 for (i=0; i<size; ++i)
84 vect[i] =
shoot(anEngine,lx,dx);
91 for (i=0; i<size; ++i)
92 vect[i] =
fire( defaultA, defaultB );
96 double lx,
double dx )
100 for (i=0; i<size; ++i)
101 vect[i] =
fire( lx, dx );
111 std::ofstream outfile ( filename, std::ios::app );
113 outfile <<
"RANDFLAT staticRandomInt: " << staticRandomInt
114 <<
" staticFirstUnusedBit: " << staticFirstUnusedBit <<
"\n";
126 std::ifstream infile ( filename, std::ios::in );
128 char inputword[] =
"NO_KEYWORD ";
132 if (strcmp(inputword,
"RANDFLAT")==0)
break;
133 if (infile.eof())
break;
142 if (strcmp(inputword,
"RANDFLAT")==0) {
147 infile >> staticRandomInt;
151 infile >> staticFirstUnusedBit;
157 int pr=os.precision(20);
158 std::vector<unsigned long> t(2);
159 os <<
" " <<
name() <<
"\n";
160 os <<
"Uvec" <<
"\n";
161 os << randomInt <<
" " << firstUnusedBit <<
"\n";
163 os << defaultWidth <<
" " << t[0] <<
" " << t[1] <<
"\n";
165 os << defaultA <<
" " << t[0] <<
" " << t[1] <<
"\n";
167 os << defaultB <<
" " << t[0] <<
" " << t[1] <<
"\n";
169 std::cout <<
"RandFlat::put(): randomInt = " << randomInt
170 <<
" firstUnusedBit = " << firstUnusedBit
171 <<
"\ndefaultWidth = " << defaultWidth
172 <<
" defaultA = " << defaultA
173 <<
" defaultB = " << defaultB <<
"\n";
178 int pr=os.precision(20);
179 os <<
" " <<
name() <<
"\n";
180 os << randomInt <<
" " << firstUnusedBit <<
"\n";
181 os << defaultWidth <<
" " << defaultA <<
" " << defaultB <<
"\n";
190 if (inName !=
name()) {
191 is.clear(std::ios::badbit | is.rdstate());
192 std::cerr <<
"Mismatch when expecting to read state of a "
193 <<
name() <<
" distribution\n"
194 <<
"Name found was " << inName
195 <<
"\nistream is left in the badbit state\n";
199 std::vector<unsigned long> t(2);
200 is >> randomInt >> firstUnusedBit;
205 std::cout <<
"RandFlat::get(): randomInt = " << randomInt
206 <<
" firstUnusedBit = " << firstUnusedBit
207 <<
"\ndefaultWidth = " << defaultWidth
208 <<
" defaultA = " << defaultA
209 <<
" defaultB = " << defaultB <<
"\n";
212 is.clear(std::ios::badbit | is.rdstate());
213 std::cerr <<
"\nRandFlat input failed"
214 <<
"\nInput stream is probably mispositioned now." << std::endl;
220 is >> firstUnusedBit;
221 is >> defaultWidth >> defaultA >> defaultB;
227 int prec = os.precision(20);
228 os <<
"RANDFLAT staticRandomInt: " << staticRandomInt
229 <<
" staticFirstUnusedBit: " << staticFirstUnusedBit <<
"\n";
238 is.clear(std::ios::badbit | is.rdstate());
239 std::cerr <<
"Mismatch when expecting to read static state of a "
241 <<
"Name found was " << inName
242 <<
"\nistream is left in the badbit state\n";
249 if (keyword!=
"RANDFLAT") {
250 is.clear(std::ios::badbit | is.rdstate());
251 std::cerr <<
"Mismatch when expecting to read RANDFLAT bit cache info: "
255 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)