2#include "CLHEP/Random/Randomize.h"
3#include "CLHEP/Random/NonRandomEngine.h"
4#include "CLHEP/Random/defs.h"
11 std::ofstream
output(
"testSaveSharedEngines.cout");
13 std::ostream &
output = std::cout;
21#define TEST_SHARED_ENGINES
36 std::vector<double> ab(2);
41template <
class E,
class D1,
class D2>
44 output <<
"checkSharingDistribution with: \n"
45 << d1.name() <<
" using " << d1.engine().name() <<
" and\n"
46 << d2.name() <<
" using " << d2.engine().name() <<
"\n";
50 double kv11,kv12,kv13,kv14;
51 double kv21,kv22,kv23,kv24;
52 for (
int i=0; i<n1; i++) r += d1();
53 for (
int j=0; j<n2; j++) r += d2();
54 {std::ofstream os (
"t1_shared.save"); os << d1.engine() << d1 << d2;}
61 {std::ofstream os (
"t2_shared.save"); os << d1.engine() << d1 << d2;}
67 long pr =
output.precision(20);
68 output <<
"kv11 = " << kv11 <<
69 " kv21 = " << kv21 <<
"\n";
70 output <<
"kv12 = " << kv12 <<
71 " kv22 = " << kv22 <<
"\n";
72 output <<
"kv13 = " << kv13 <<
73 " kv23 = " << kv23 <<
"\n";
74 output <<
"kv14 = " << kv14 <<
75 " kv24 = " << kv24 <<
"\n";
81 { std::ifstream is (
"t1_shared.save"); is >> e >> d1r >> d2r;}
86 { std::ifstream is (
"t2_shared.save"); is >> e >> d1r >> d2r;}
93 output <<
"k11 = " << k11 <<
94 " k21 = " << k21 <<
"\n";
95 output <<
"k12 = " << k12 <<
96 " k22 = " << k22 <<
"\n";
97 output <<
"k13 = " << k13 <<
98 " k23 = " << k23 <<
"\n";
99 output <<
"k14 = " << k14 <<
100 " k24 = " << k24 <<
"\n";
107 std::cout <<
"???? Incorrect restored value for distributions "
108 << d1.name() <<
" " << d2.name() <<
"\n";
110 output <<
"???? Incorrect restored value for distributions "
111 << d1.name() <<
" " << d2.name() <<
"\n";
129 stat |= checkSharingDistributions<E, RandGauss, RandPoissonQ>(g1,p1,5,4);
130 stat |= checkSharingDistributions<E, RandGauss, RandPoissonQ>(g1,p2,6,6);
131 stat |= checkSharingDistributions<E, RandGauss, RandPoissonQ>(g2,p1,8,9);
132 stat |= checkSharingDistributions<E, RandGauss, RandPoissonQ>(g1,p1,7,5);
133 stat |= checkSharingDistributions<E, RandPoissonQ, RandGauss>(p1,g2,5,4);
134 stat |= checkSharingDistributions<E, RandPoissonQ, RandGauss>(p2,g1,6,6);
135 stat |= checkSharingDistributions<E, RandPoissonQ, RandGauss>(p1,g1,8,9);
136 stat |= checkSharingDistributions<E, RandPoissonQ, RandGauss>(p2,g1,7,5);
149#ifdef TEST_SHARED_ENGINES
150 output <<
"\n=============================================\n";
152 output <<
"Check behavior when engines are shared \n";
153 output <<
"=============================================\n\n";
155 stat |= checkSharing<DualRand>();
156 stat |= checkSharing<Hurd160Engine>();
157 stat |= checkSharing<Hurd288Engine>();
158 stat |= checkSharing<HepJamesRandom>();
159 stat |= checkSharing<MTwistEngine>();
160 stat |= checkSharing<Ranlux64Engine>();
161 stat |= checkSharing<RanluxEngine>();
162 stat |= checkSharing<RanshiEngine>();
163 stat |= checkSharing<TripleRand>();
166 output <<
"\n=============================================\n\n";
169 std::cout <<
"One or more problems detected: stat = " << stat <<
"\n";
170 output <<
"One or more problems detected: stat = " << stat <<
"\n";
172 output <<
"testSaveSharedEngines passed with no problems detected.\n";
175 if (stat == 0)
return 0;
176 if (stat > 0)
return -(stat|1);
178 return stat > 0 ? -stat : stat;
std::ofstream output("testSaveSharedEngines.cout")
int checkSharingDistributions(D1 &d1, D2 &d2, int n1, int n2)
bool equals(double a, double b)
bool equals01(const std::vector< double > &ab)