CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
testEngineCopy.cc File Reference
#include "CLHEP/Units/GlobalPhysicalConstants.h"
#include "CLHEP/Random/Randomize.h"
#include "CLHEP/Random/NonRandomEngine.h"
#include "CLHEP/Random/defs.h"
#include <iostream>
#include <iomanip>
#include <vector>

Go to the source code of this file.

Macros

#define CLEAN_OUTPUT
 
#define TEST_ENGINE_COPY
 
#define VERBOSER
 
#define VERBOSER2
 

Functions

std::ofstream output ("testEngineCopy.cout")
 
bool equals01 (const std::vector< double > &ab)
 
bool equals (double a, double b)
 
std::vector< doubleaSequence (int n)
 
template<class E >
int vectorTest64 (int n)
 
template<>
int vectorTest64< NonRandomEngine > (int n)
 
template<class E >
vectorRestore1 (int n, std::vector< double > &v)
 
template<>
NonRandomEngine vectorRestore1< NonRandomEngine > (int n, std::vector< double > &v)
 
template<class E >
int vectorRestore2 (E &f, const std::vector< double > &v)
 
template<class E >
int vectorRestore (int n)
 
int main ()
 

Macro Definition Documentation

◆ CLEAN_OUTPUT

#define CLEAN_OUTPUT

Definition at line 12 of file testEngineCopy.cc.

◆ TEST_ENGINE_COPY

#define TEST_ENGINE_COPY

Definition at line 24 of file testEngineCopy.cc.

◆ VERBOSER

#define VERBOSER

Definition at line 26 of file testEngineCopy.cc.

◆ VERBOSER2

#define VERBOSER2

Definition at line 27 of file testEngineCopy.cc.

Function Documentation

◆ aSequence()

std::vector< double > aSequence ( int  n)

Definition at line 47 of file testEngineCopy.cc.

47 {
48 std::vector<double> v;
49 DualRand e(13542);
50 RandFlat f(e);
51 for (int i=0; i<n; i++) {
52 v.push_back(f());
53 }
54 return v;
55}
void f(void g())
Definition: excDblThrow.cc:38

Referenced by vectorRestore1< NonRandomEngine >(), and vectorTest64< NonRandomEngine >().

◆ equals()

bool equals ( double  a,
double  b 
)

Definition at line 41 of file testEngineCopy.cc.

41 {
42 std::vector<double> ab(2);
43 ab[0]=a; ab[1]=b;
44 return (equals01(ab));
45}
bool equals01(const std::vector< double > &ab)

Referenced by vectorTest64().

◆ equals01()

bool equals01 ( const std::vector< double > &  ab)

Definition at line 38 of file testEngineCopy.cc.

38 {
39 return ab[1]==ab[0];
40}

Referenced by equals().

◆ main()

int main ( )

Definition at line 193 of file testEngineCopy.cc.

193 {
194 int stat = 0;
195
196#ifdef TEST_ENGINE_COPY
197 output << "\n=================================\n";
198 output << " Part IX \n";
199 output << " Copy test of engines\n";
200 output << "=================================\n\n";
201
202 stat |= vectorRestore<DualRand>(113);
203 // copies of DRand48Engine are not allowed
204 //stat |= vectorRestore<DRand48Engine>(114);
205 stat |= vectorRestore<Hurd160Engine>(115);
206 stat |= vectorRestore<Hurd288Engine>(116);
207 stat |= vectorRestore<HepJamesRandom>(117);
208 stat |= vectorRestore<MixMaxRng>(149);
209 stat |= vectorRestore<MTwistEngine>(118);
210 stat |= vectorRestore<RanecuEngine>(139);
211 stat |= vectorRestore<Ranlux64Engine>(119);
212 stat |= vectorRestore<RanluxEngine>(120);
213 stat |= vectorRestore<RanluxppEngine>(119);
214 stat |= vectorRestore<RanshiEngine>(121);
215 stat |= vectorRestore<TripleRand>(122);
216 stat |= vectorRestore<NonRandomEngine>(123);
217 // anonymous engines are not copyable
218 //stat |= vectorRestore<RandEngine>(129);
219#endif
220
221 output << "\n=============================================\n\n";
222
223 if (stat != 0) {
224 std::cout << "One or more problems detected: stat = " << stat << "\n";
225 output << "One or more problems detected: stat = " << stat << "\n";
226 } else {
227 output << "ranRestoreTest passed with no problems detected.\n";
228 }
229
230 if (stat == 0) return 0;
231 if (stat > 0) return -(stat|1);
232 return stat|1;
233}
std::ofstream output("testEngineCopy.cout")

◆ output()

std::ofstream output ( "testEngineCopy.cout"  )

◆ vectorRestore()

template<class E >
int vectorRestore ( int  n)

Definition at line 178 of file testEngineCopy.cc.

178 {
179 std::vector<double> v;
180 int status1 = vectorTest64<E>(n);
181 E f = vectorRestore1<E>(n,v);
182 int status2 = vectorRestore2<E>(f, v);
183 return (status1 | status2);
184}

◆ vectorRestore1()

template<class E >
E vectorRestore1 ( int  n,
std::vector< double > &  v 
)

Definition at line 118 of file testEngineCopy.cc.

118 {
119 output << "Copy for " << E::engineName() << "\n";
120 E e(97538466);
121 double r=0;
122 for (int i=0; i<n; i++) r += e.flat();
123 E f(e);
124 for (int j=0; j<25; j++) v.push_back(e.flat());
125#ifdef VERBOSER2
126 output << "First four of v are: "
127 << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3] << "\n";
128#endif
129 return f;
130}

◆ vectorRestore1< NonRandomEngine >()

template<>
NonRandomEngine vectorRestore1< NonRandomEngine > ( int  n,
std::vector< double > &  v 
)

Definition at line 133 of file testEngineCopy.cc.

134 {
135#ifdef VERBOSER2
136 output << "Copy for " << NonRandomEngine::engineName() << "\n";
137#endif
138 std::vector<double> nonRand = aSequence(500);
140 e.setRandomSequence(&nonRand[0], (int)nonRand.size());
141 double r=0;
142 for (int i=0; i<n; i++) r += e.flat();
144 for (int j=0; j<25; j++) v.push_back(e.flat());
145#ifdef VERBOSER2
146 output << "First four of v are: "
147 << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3] << "\n";
148#endif
149 return f;
150}
void setRandomSequence(double *s, int n)
static std::string engineName()
std::vector< double > aSequence(int n)

◆ vectorRestore2()

template<class E >
int vectorRestore2 ( E &  f,
const std::vector< double > &  v 
)

Definition at line 153 of file testEngineCopy.cc.

153 {
154 int stat = 0;
155 std::vector<double> k;
156 for (int j=0; j<25; j++) k.push_back(f.flat());
157#ifdef VERBOSER2
158 output << "First four of k are: "
159 << k[0] << ", " << k[1] << ", " << k[2] << ", " << k[3] << "\n";
160#endif
161 for (int m1=0; m1<25; m1++) {
162 if ( v[m1] != k[m1] ) {
163 std::cout << "???? Incorrect copy restored value for engine: "
164 << E::engineName() << "\n";
165 #ifdef CLEAN_OUTPUT
166 output << "???? Incorrect copy restored value for engine: "
167 << E::engineName() << "\n";
168 #endif
169 stat |= 1048576;
170 return stat;
171 }
172 }
173 return stat;
174}

◆ vectorTest64()

template<class E >
int vectorTest64 ( int  n)

Definition at line 61 of file testEngineCopy.cc.

61 {
62 output << "Copy 64bit test for " << E::engineName() << "\n";
63
64 E e;
65 double x = 0;
66 for (int i=0; i<n; i++) x += e.flat();
67 E f( e );
68 x = e.flat();
69 output << "x = " << x << std::endl;
70
71 double y = f.flat();
72 output << "y = " << y << std::endl;
73 if( x != y ) return n;
74
75 for( int i=0; i<1000; ++i ) {
76 x = e.flat();
77 y = f.flat();
78 if( !equals(x,y) ) {
79 output << "i = " << i << " x, y " << x << " " << y
80 << " vectorTest64 problem: e != f \n";
81 return n+i;
82 }
83 }
84
85 return 0;
86}
bool equals(double a, double b)

◆ vectorTest64< NonRandomEngine >()

template<>
int vectorTest64< NonRandomEngine > ( int  n)

Definition at line 89 of file testEngineCopy.cc.

89 {
90 output << "Copy 64bit test for " << NonRandomEngine::engineName() << "\n";
91
92 std::vector<double> nonRand = aSequence(500);
94 e.setRandomSequence(&nonRand[0], (int)nonRand.size());
95
96 double x = 0;
97 for (int i=0; i<n; i++) x += e.flat();
98 std::vector<unsigned long> v = e.put();
100 x = e.flat();
101 output << "x = " << x << std::endl;
102
103 double y = f.flat();
104 output << "y = " << y << std::endl;
105 if( x != y ) return n;
106
107 for( int i=0; i<300; ++i ) {
108 if( e.flat() != f.flat() ) {
109 output << "i = " << i << " vectorTest64 for NonRandomEngine problem: e != f \n";
110 return n+i;
111 }
112 }
113
114 return 0;
115}
virtual std::ostream & put(std::ostream &os) const