34 sequenceHasBeenSet(false),
35 intervalHasBeenSet(false) ,
38 randomInterval(0.1) { }
51 for (
int i=0; i<n; i++) sequence.push_back(*s++);
52 assert (sequence.size() == (
unsigned int)n);
54 sequenceHasBeenSet=
true;
61 intervalHasBeenSet=
true;
67 if (sequenceHasBeenSet) {
68 double v = sequence[nInSeq++];
69 if (nInSeq >= sequence.size() ) sequenceHasBeenSet =
false;
73 if ( !nextHasBeenSet ) {
75 <<
"Attempt to use NonRandomEngine without setting next random!\n";
79 double a = nextRandom;
80 nextHasBeenSet =
false;
82 if (intervalHasBeenSet) {
83 nextRandom += randomInterval;
84 if ( nextRandom >= 1 ) nextRandom -= 1.0;
85 nextHasBeenSet =
true;
93 for (
int i = 0; i < size; ++i) {
99 std::string beginMarker =
"NonRandomEngine-begin";
100 os << beginMarker <<
"\nUvec\n";
101 std::vector<unsigned long> v =
put();
102 for (
unsigned int i=0; i<v.size(); ++i) {
109 std::vector<unsigned long> v;
111 std::vector<unsigned long> t;
112 v.push_back(
static_cast<unsigned long>(nextHasBeenSet));
113 v.push_back(
static_cast<unsigned long>(sequenceHasBeenSet));
114 v.push_back(
static_cast<unsigned long>(intervalHasBeenSet));
116 v.push_back(t[0]); v.push_back(t[1]);
117 v.push_back(
static_cast<unsigned long>(nInSeq));
119 v.push_back(t[0]); v.push_back(t[1]);
120 v.push_back(
static_cast<unsigned long>(sequence.size()));
121 for (
unsigned int i=0; i<sequence.size(); ++i) {
123 v.push_back(t[0]); v.push_back(t[1]);
129 std::string beginMarker =
"NonRandomEngine-begin";
131 if (beginMarker !=
"NonRandomEngine-begin") {
132 is.clear(std::ios::badbit | is.rdstate());
133 std::cerr <<
"\nInput mispositioned or"
134 <<
"\nNonRandomEngine state description missing or"
135 <<
"\nwrong engine type found.\n";
142 return "NonRandomEngine-begin";
147 std::vector<unsigned long> v;
148 unsigned long uu = 99999;
149 unsigned long ssiz = 0;
150 for (
unsigned int istart=0; istart < 10; ++istart) {
153 is.clear(std::ios::badbit | is.rdstate());
154 std::cout <<
"istart = " << istart <<
"\n";
156 <<
"\nNonRandomEngine state (vector) description has no sequence size."
157 <<
"\ngetState() has failed."
158 <<
"\nInput stream is probably mispositioned now." << std::endl;
162 if (istart==9) ssiz = uu;
164 for (
unsigned int ivec=0; ivec < 2*ssiz; ++ivec) {
167 is.clear(std::ios::badbit | is.rdstate());
168 std::cerr <<
"\nNonRandomEngine state (vector) description improper."
169 <<
"\ngetState() has failed."
170 <<
"\nInput stream is probably mispositioned now." << std::endl;
181 std::string endMarker =
"NonRandomEngine-end";
182 is >> sequenceHasBeenSet >> intervalHasBeenSet;
183 is >> nextRandom >> nInSeq >> randomInterval;
184 unsigned int seqSize;
188 for (
unsigned int i = 0; i < seqSize; ++i) {
190 sequence.push_back(x);
193 if (endMarker !=
"NonRandomEngine-end") {
194 is.clear(std::ios::badbit | is.rdstate());
195 std::cerr <<
"\n NonRandomEngine state description incomplete."
196 <<
"\nInput stream is probably mispositioned now." << std::endl;
205 "\nNonRandomEngine get:state vector has wrong ID word - state unchanged\n";
212 unsigned long seqSize = v[9];
213 if (v.size() != 2*seqSize + 10 ) {
215 "\nNonRandomEngine get:state vector has wrong length - state unchanged\n";
216 std::cerr <<
" (length = " << v.size()
217 <<
"; expected " << 2*seqSize + 10 <<
")\n";
220 std::vector<unsigned long> t(2);
221 nextHasBeenSet = (v[1]!=0);
222 sequenceHasBeenSet = (v[2]!=0);
223 intervalHasBeenSet = (v[3]!=0);
225 nInSeq = (
unsigned int)v[6];
228 for (
unsigned long i=0; i<seqSize; ++i) {
229 t[0] = v[2*i+10]; t[1] = v[2*i+11];
static double longs2double(const std::vector< unsigned long > &v)
static std::vector< unsigned long > dto2longs(double d)
virtual ~NonRandomEngine()
void setRandomSequence(double *s, int n)
void setNextRandom(double r)
virtual std::istream & getState(std::istream &is)
virtual std::istream & get(std::istream &is)
static std::string beginTag()
void setRandomInterval(double x)
std::vector< unsigned long > put() const
void flatArray(const int size, double *vect)
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
unsigned long engineIDulong()