CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
testSaveSharedEngines.cc File Reference
#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_SHARED_ENGINES
 
#define VERBOSER
 
#define VERBOSER2
 

Functions

std::ofstream output ("testSaveSharedEngines.cout")
 
bool equals01 (const std::vector< double > &ab)
 
bool equals (double a, double b)
 
template<class E , class D1 , class D2 >
int checkSharingDistributions (D1 &d1, D2 &d2, int n1, int n2)
 
template<class E >
int checkSharing ()
 
int main ()
 

Macro Definition Documentation

◆ CLEAN_OUTPUT

#define CLEAN_OUTPUT

Definition at line 9 of file testSaveSharedEngines.cc.

◆ TEST_SHARED_ENGINES

#define TEST_SHARED_ENGINES

Definition at line 21 of file testSaveSharedEngines.cc.

◆ VERBOSER

#define VERBOSER

Definition at line 25 of file testSaveSharedEngines.cc.

◆ VERBOSER2

#define VERBOSER2

Definition at line 26 of file testSaveSharedEngines.cc.

Function Documentation

◆ checkSharing()

template<class E >
int checkSharing ( )

Definition at line 122 of file testSaveSharedEngines.cc.

122 {
123 int stat = 0;
124 E e1(98746);
125 RandGauss g1(e1,50.0,4.0);
126 RandPoissonQ p1(e1, 112.0);
127 RandGauss g2(e1,5.0,44.0);
128 RandPoissonQ p2(e1, 212.0);
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);
137 return stat;
138}

◆ checkSharingDistributions()

template<class E , class D1 , class D2 >
int checkSharingDistributions ( D1 &  d1,
D2 &  d2,
int  n1,
int  n2 
)

Definition at line 42 of file testSaveSharedEngines.cc.

42 {
43 int stat = 0;
44 output << "checkSharingDistribution with: \n"
45 << d1.name() << " using " << d1.engine().name() << " and\n"
46 << d2.name() << " using " << d2.engine().name() << "\n";
47 double r=0;
48 r = d1();
49 r += d2();
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;}
55 kv11 = d1();
56 kv21 = d2();
57 kv12 = d1();
58 kv22 = d2();
59 r += d1() + d2();
60 // A second capture will test non-cached if first tested cached case:
61 {std::ofstream os ("t2_shared.save"); os << d1.engine() << d1 << d2;}
62 kv13 = d1();
63 kv23 = d2();
64 kv14 = d1();
65 kv24 = d2();
66#ifdef VERBOSER2
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";
76 output.precision(pr);
77#endif
78 E e;
79 D1 d1r(e);
80 D2 d2r(e);
81 { std::ifstream is ("t1_shared.save"); is >> e >> d1r >> d2r;}
82 double k11 = d1r();
83 double k21 = d2r();
84 double k12 = d1r();
85 double k22 = d2r();
86 { std::ifstream is ("t2_shared.save"); is >> e >> d1r >> d2r;}
87 double k13 = d1r();
88 double k23 = d2r();
89 double k14 = d1r();
90 double k24 = d2r();
91#ifdef VERBOSER2
92 pr = output.precision(20);
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";
101 output.precision(pr);
102#endif
103 if ( !equals(k11,kv11) || !equals(k21,kv21) ||
104 !equals(k12,kv12) || !equals(k22,kv22) ||
105 !equals(k13,kv13) || !equals(k23,kv23) ||
106 !equals(k14,kv14) || !equals(k24,kv24) ) {
107 std::cout << "???? Incorrect restored value for distributions "
108 << d1.name() << " " << d2.name() << "\n";
109 #ifdef CLEAN_OUTPUT
110 output << "???? Incorrect restored value for distributions "
111 << d1.name() << " " << d2.name() << "\n";
112 #endif
113 stat |= 4096;
114 }
115// if (stat) exit(-1);
116 return stat;
117}
std::ofstream output("testSaveSharedEngines.cout")
bool equals(double a, double b)

◆ equals()

bool equals ( double  a,
double  b 
)

Definition at line 35 of file testSaveSharedEngines.cc.

35 {
36 std::vector<double> ab(2);
37 ab[0]=a; ab[1]=b;
38 return (equals01(ab));
39}
bool equals01(const std::vector< double > &ab)

Referenced by checkSharingDistributions().

◆ equals01()

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

Definition at line 32 of file testSaveSharedEngines.cc.

32 {
33 return ab[1]==ab[0];
34}

Referenced by equals().

◆ main()

int main ( )

Definition at line 146 of file testSaveSharedEngines.cc.

146 {
147 int stat = 0;
148
149#ifdef TEST_SHARED_ENGINES
150 output << "\n=============================================\n";
151 output << " Part IV \n";
152 output << "Check behavior when engines are shared \n";
153 output << "=============================================\n\n";
154
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>();
164#endif
165
166 output << "\n=============================================\n\n";
167
168 if (stat != 0) {
169 std::cout << "One or more problems detected: stat = " << stat << "\n";
170 output << "One or more problems detected: stat = " << stat << "\n";
171 } else {
172 output << "testSaveSharedEngines passed with no problems detected.\n";
173 }
174
175 if (stat == 0) return 0;
176 if (stat > 0) return -(stat|1);
177 return stat|1;
178 return stat > 0 ? -stat : stat;
179}

◆ output()

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

Referenced by checkSharingDistributions(), and main().