21#include "CLHEP/Random/defs.h"
22#include "CLHEP/Random/NonRandomEngine.h"
23#include "CLHEP/Random/engineIDulong.h"
24#include "CLHEP/Random/DoubConv.h"
38 sequenceHasBeenSet(false),
39 intervalHasBeenSet(false) ,
42 randomInterval(0.1) { }
55 for (
int i=0; i<n; i++) sequence.push_back(*s++);
56 assert (sequence.size() == (
unsigned int)n);
58 sequenceHasBeenSet=
true;
65 intervalHasBeenSet=
true;
71 if (sequenceHasBeenSet) {
72 double v = sequence[nInSeq++];
73 if (nInSeq >= sequence.size() ) sequenceHasBeenSet =
false;
77 if ( !nextHasBeenSet ) {
79 <<
"Attempt to use NonRandomEngine without setting next random!\n";
83 double a = nextRandom;
84 nextHasBeenSet =
false;
86 if (intervalHasBeenSet) {
87 nextRandom += randomInterval;
88 if ( nextRandom >= 1 ) nextRandom -= 1.0;
89 nextHasBeenSet =
true;
97 for (
int i = 0; i < size; ++i) {
103 std::string beginMarker =
"NonRandomEngine-begin";
104 os << beginMarker <<
"\nUvec\n";
105 std::vector<unsigned long> v =
put();
106 for (
unsigned int i=0; i<v.size(); ++i) {
111 std::string endMarker =
"NonRandomEngine-end";
112 long pr = os.precision(20);
113 os <<
" " << beginMarker <<
"\n";
114 os << nextHasBeenSet <<
" ";
115 os << sequenceHasBeenSet <<
" ";
116 os << intervalHasBeenSet <<
"\n";
117 os << nextRandom <<
" " << nInSeq <<
" " << randomInterval <<
"\n";
118 os << sequence.size() <<
"\n";
119 for (
unsigned int i = 0; i < sequence.size(); ++i) {
120 os << sequence[i] <<
"\n";
122 os << endMarker <<
"\n ";
129 std::vector<unsigned long> v;
130 v.push_back (engineIDulong<NonRandomEngine>());
131 std::vector<unsigned long> t;
132 v.push_back(
static_cast<unsigned long>(nextHasBeenSet));
133 v.push_back(
static_cast<unsigned long>(sequenceHasBeenSet));
134 v.push_back(
static_cast<unsigned long>(intervalHasBeenSet));
136 v.push_back(t[0]); v.push_back(t[1]);
137 v.push_back(
static_cast<unsigned long>(nInSeq));
139 v.push_back(t[0]); v.push_back(t[1]);
140 v.push_back(
static_cast<unsigned long>(sequence.size()));
141 for (
unsigned int i=0; i<sequence.size(); ++i) {
143 v.push_back(t[0]); v.push_back(t[1]);
149 std::string beginMarker =
"NonRandomEngine-begin";
151 if (beginMarker !=
"NonRandomEngine-begin") {
152 is.clear(std::ios::badbit | is.rdstate());
153 std::cerr <<
"\nInput mispositioned or"
154 <<
"\nNonRandomEngine state description missing or"
155 <<
"\nwrong engine type found.\n";
162 return "NonRandomEngine-begin";
167 std::vector<unsigned long> v;
168 unsigned long uu = 99999;
169 unsigned long ssiz = 0;
173 for (
unsigned int istart=0; istart < 10; ++istart) {
176 is.clear(std::ios::badbit | is.rdstate());
177 std::cout <<
"istart = " << istart <<
"\n";
179 <<
"\nNonRandomEngine state (vector) description has no sequence size."
180 <<
"\ngetState() has failed."
181 <<
"\nInput stream is probably mispositioned now." << std::endl;
186 std::cout <<
"v[" << istart <<
"] = " << uu <<
"\n";
188 if (istart==9) ssiz = uu;
190 for (
unsigned int ivec=0; ivec < 2*ssiz; ++ivec) {
193 is.clear(std::ios::badbit | is.rdstate());
194 std::cerr <<
"\nNonRandomEngine state (vector) description improper."
195 <<
"\ngetState() has failed."
196 <<
"\nInput stream is probably mispositioned now." << std::endl;
201 std::cout <<
"v[" << v.size()-1 <<
"] = " << uu <<
"\n";
210 std::string endMarker =
"NonRandomEngine-end";
211 is >> sequenceHasBeenSet >> intervalHasBeenSet;
212 is >> nextRandom >> nInSeq >> randomInterval;
213 unsigned int seqSize;
217 for (
unsigned int i = 0; i < seqSize; ++i) {
219 sequence.push_back(x);
222 if (endMarker !=
"NonRandomEngine-end") {
223 is.clear(std::ios::badbit | is.rdstate());
224 std::cerr <<
"\n NonRandomEngine state description incomplete."
225 <<
"\nInput stream is probably mispositioned now." << std::endl;
232 if ((v[0] & 0xffffffffUL) != engineIDulong<NonRandomEngine>()) {
234 "\nNonRandomEngine get:state vector has wrong ID word - state unchanged\n";
241 unsigned long seqSize = v[9];
242 if (v.size() != 2*seqSize + 10 ) {
244 "\nNonRandomEngine get:state vector has wrong length - state unchanged\n";
245 std::cerr <<
" (length = " << v.size()
246 <<
"; expected " << 2*seqSize + 10 <<
")\n";
249 std::vector<unsigned long> t(2);
250 nextHasBeenSet = (v[1]!=0);
251 sequenceHasBeenSet = (v[2]!=0);
252 intervalHasBeenSet = (v[3]!=0);
254 nInSeq = (
unsigned int)v[6];
257 for (
unsigned long i=0; i<seqSize; ++i) {
258 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)