4#include "CLHEP/Random/Randomize.h"
5#include "CLHEP/Random/NonRandomEngine.h"
6#include "CLHEP/Random/defs.h"
13 std::ofstream
output(
"testVectorSave.cout");
15 std::ostream &
output = std::cout;
23#define TEST_VECTOR_ENGINE_RESTORE
35 std::vector<double> ab(2);
41 std::vector<double> v;
44 for (
int i=0; i<n; i++) {
57 output <<
"Vector restore 64bit test for " << E::engineName() <<
"\n";
61 for (
int i=0; i<n; i++) x += e.flat();
62 std::vector<unsigned long> v = e.put();
64 output <<
"x = " << x << std::endl;
70 output <<
"y = " << y << std::endl;
71 if( x != y )
return n;
80 std::vector<double> nonRand =
aSequence(500);
85 for (
int i=0; i<n; i++) x += e.
flat();
86 std::vector<unsigned long> v = e.
put();
88 output <<
"x = " << x << std::endl;
91 f.setRandomSequence(&nonRand[0], (
int)nonRand.size());
96 output <<
"y = " << y << std::endl;
97 if( x != y )
return n;
104 output <<
"Vector restore for " << E::engineName() <<
"\n";
107 for (
int i=0; i<n; i++) r += e.flat();
108 std::vector<unsigned long> state = e.put();
109 for (
int j=0; j<25; j++) v.push_back(e.flat());
111 output <<
"First four of v are: "
112 << v[0] <<
", " << v[1] <<
", " << v[2] <<
", " << v[3] <<
"\n";
118std::vector<unsigned long>
123 std::vector<double> nonRand =
aSequence(500);
126 double __attribute__ ((unused)) r = 0;
127 for (
int i=0; i<
n; i++) r += e.
flat();
128 std::vector<unsigned long> state = e.
put();
129 for (
int j=0; j<25; j++) v.push_back(e.
flat());
131 output <<
"First four of v are: "
132 << v[0] <<
", " << v[1] <<
", " << v[2] <<
", " << v[3] <<
"\n";
139 const std::vector<double> & v) {
141 std::vector<double> k;
145 std::cout <<
"???? could not restore engine state from vector for "
146 << E::engineName() <<
"\n";
148 output <<
"???? could not restore engine state from vector for "
149 << E::engineName() <<
"\n";
154 if (a->
name() != E::engineName()) {
156 std::cout <<
"???? restored engine state from vector for "
157 << E::engineName() <<
"to different type of engine: "
159 <<
"There is probably a clash in CRC hashes for these two names!\n";
160 output <<
"???? restored engine state from vector for "
161 << E::engineName() <<
"to different type of engine: "
163 <<
"There is probably a clash in CRC hashes for these two names!\n";
168 for (
int j=0; j<25; j++) k.push_back(a->
flat());
171 output <<
"First four of k are: "
172 << k[0] <<
", " << k[1] <<
", " << k[2] <<
", " << k[3] <<
"\n";
174 for (
int m=0; m<25; m++) {
175 if ( v[m] != k[m] ) {
176 std::cout <<
"???? Incorrect vector restored value for anonymous engine: "
177 << E::engineName() <<
"\n";
179 output <<
"???? Incorrect vector restored value for anonymous engine: "
180 << E::engineName() <<
"\n";
192 std::vector<double> v;
193 int status1 = vectorTest64<E>(n);
194 std::vector<unsigned long> state = vectorRestore1<E>(n,v);
195 int status2 = vectorRestore2<E>(state, v);
196 return (status1 | status2);
209#ifdef TEST_VECTOR_ENGINE_RESTORE
210 output <<
"\n=================================\n";
212 output <<
"Save/restore of engines to vectors\n";
213 output <<
"=================================\n\n";
215 stat |= vectorRestore<DualRand>(113);
216 stat |= vectorRestore<DRand48Engine>(114);
217 stat |= vectorRestore<Hurd160Engine>(115);
218 stat |= vectorRestore<Hurd288Engine>(116);
219 stat |= vectorRestore<HepJamesRandom>(117);
220 stat |= vectorRestore<MTwistEngine>(118);
221 stat |= vectorRestore<RanecuEngine>(139);
222 stat |= vectorRestore<Ranlux64Engine>(119);
223 stat |= vectorRestore<RanluxEngine>(120);
224 stat |= vectorRestore<RanshiEngine>(121);
225 stat |= vectorRestore<TripleRand>(122);
226 stat |= vectorRestore<NonRandomEngine>(123);
227 stat |= vectorRestore<RandEngine>(129);
230 output <<
"\n=============================================\n\n";
233 std::cout <<
"One or more problems detected: stat = " << stat <<
"\n";
234 output <<
"One or more problems detected: stat = " << stat <<
"\n";
236 output <<
"ranRestoreTest passed with no problems detected.\n";
239 if (stat == 0)
return 0;
240 if (stat > 0)
return -(stat|1);
virtual std::string name() const =0
static HepRandomEngine * newEngine(std::istream &is)
virtual std::ostream & put(std::ostream &os) const
void setRandomSequence(double *s, int n)
static std::string engineName()
int vectorTest64< NonRandomEngine >(int n)
std::ofstream output("testVectorSave.cout")
std::vector< double > aSequence(int n)
bool equals(double a, double b)
bool equals01(const std::vector< double > &ab)
int vectorRestore2(const std::vector< unsigned long > state, const std::vector< double > &v)
std::vector< unsigned long > vectorRestore1< NonRandomEngine >(int n, std::vector< double > &v)
std::vector< unsigned long > vectorRestore1(int n, std::vector< double > &v)