2#include "CLHEP/Random/Randomize.h"
3#include "CLHEP/Random/NonRandomEngine.h"
4#include "CLHEP/Random/defs.h"
11 std::ofstream
output(
"testStaticStreamSave.cout");
13 std::ostream &
output = std::cout;
21#define TEST_STATIC_SAVE
22#define TEST_SAVE_STATIC_STATES
35 std::vector<double> ab(2);
46 output <<
"staticSave for distribution " << D::distributionName() <<
"\n";
48 double v1, v2, k1, k2;
49 for (i=0; i < n; i++) r += D::shoot();
51 std::ofstream file (
"ss1_distribution.save");
52 D::saveFullState(file);
54 D::saveFullState(file);
57 long pr =
output.precision(20);
58 output <<
"v1 = " << v1 <<
" v2 = " << v2 <<
"\n";
62 for (i=0; i < n; i++) r += D::shoot();
64 std::ifstream file (
"ss1_distribution.save");
65 D::restoreFullState(file);
67 for (i=0; i < n; i++) r += D::shoot();
68 D::restoreFullState(file);
71 long pr =
output.precision(20);
72 output <<
"k1 = " << k1 <<
" k2 = " << k2 <<
"\n";
76 if ( (k1 != v1) || (k2 != v2) ) {
77 std::cout <<
"???? restoreFullState failed for " << D::distributionName() <<
"\n";
79 output <<
"???? restoreFullState failed for " << D::distributionName() <<
"\n";
84 for (i=0; i < n; i++) r += D::shoot();
86 std::ofstream file (
"ss2_distribution.save");
87 D::saveDistState(file) << *D::getTheEngine();
89 D::saveDistState(file) << *D::getTheEngine();
92 long pr =
output.precision(20);
93 output <<
"v1 = " << v1 <<
" v2 = " << v2 <<
"\n";
97 for (i=0; i < n; i++) r += D::shoot();
99 std::ifstream file (
"ss2_distribution.save");
100 D::restoreDistState(file) >> *D::getTheEngine();
102 for (i=0; i < n; i++) r += D::shoot();
103 D::restoreDistState(file) >> *D::getTheEngine();
106 long pr =
output.precision(20);
107 output <<
"k1 = " << k1 <<
" k2 = " << k2 <<
"\n";
111 if ( (k1 != v1) || (k2 != v2) ) {
112 std::cout <<
"???? restoreDistState failed for " << D::distributionName() <<
"\n";
114 output <<
"???? restoreDistState failed for " << D::distributionName() <<
"\n";
126 output <<
"staticSaveShootBit for " << D::distributionName() <<
"\n";
130 for (i=0; i < n; i++) r += D::shoot();
131 for (i=0; i < n; i++) bit |= D::shootBit();
133 std::ofstream file (
"ss1_distribution.save");
134 D::saveFullState(file);
136 for (i=0; i<25; i++) {
140 for (i=0; i < n; i++) bit |= D::shootBit();
141 D::saveFullState(file);
143 for (i=0; i<25; i++) {
148 long pr =
output.precision(20);
149 output << std::hex <<
"v1 = " << v1 <<
" v2 = " << v2 << std::dec <<
"\n";
153 for (i=0; i < n; i++) r += D::shoot();
155 std::ifstream file (
"ss1_distribution.save");
156 D::restoreFullState(file);
158 for (i=0; i<25; i++) {
162 for (i=0; i < n; i++) r += D::shoot();
163 D::restoreFullState(file);
165 for (i=0; i<25; i++) {
170 long pr =
output.precision(20);
171 output << std::hex <<
"k1 = " << k1 <<
" k2 = " << k2 << std::dec <<
"\n";
175 if ( (k1 != v1) || (k2 != v2) ) {
176 std::cout <<
"???? restoreFullState failed for D shootBit()\n";
178 output <<
"???? restoreFullState failed for D shootBit()\n";
183 for (i=0; i < n; i++) r += D::shoot();
184 for (i=0; i < n; i++) bit |= D::shootBit();
186 std::ofstream file (
"ss2_distribution.save");
187 D::saveDistState(file) << *D::getTheEngine();
189 for (i=0; i<25; i++) {
193 for (i=0; i < n; i++) bit |= D::shootBit();
194 D::saveDistState(file) << *D::getTheEngine();
196 for (i=0; i<25; i++) {
201 long pr =
output.precision(20);
202 output << std::hex <<
"v1 = " << v1 <<
" v2 = " << v2 << std::dec <<
"\n";
206 for (i=0; i < n; i++) r += D::shoot();
208 std::ifstream file (
"ss2_distribution.save");
209 D::restoreDistState(file) >> *D::getTheEngine();
211 for (i=0; i<25; i++) {
215 for (i=0; i < n; i++) r += D::shoot();
216 for (i=0; i < n; i++) r += D::shootBit();
217 D::restoreDistState(file) >> *D::getTheEngine();
219 for (i=0; i<25; i++) {
224 long pr =
output.precision(20);
225 output << std::hex <<
"k1 = " << k1 <<
" k2 = " << k2 << std::dec <<
"\n";
229 if ( (k1 != v1) || (k2 != v2) ) {
230 std::cout <<
"???? restoreDistState failed for RnadFlat::shootBit()\n";
232 output <<
"???? restoreDistState failed for RnadFlat::shootBit()\n";
243 for (
int i=0; i<n; i++) {
266 std::vector<double> c;
271 c.push_back( RandBit::shoot() );
272 for (
int i=0; i<20; i++) {
291 std::ofstream os(filename.c_str());
292 RandGeneral::saveStaticRandomStates(os);
299 std::ifstream is(filename.c_str());
300 RandLandau::restoreStaticRandomStates(is);
311#ifdef TEST_STATIC_SAVE
312 output <<
"\n=========================================\n";
314 output <<
"Static Save/restore to/from streams \n";
315 output <<
"=========================================\n\n";
317 stat |= staticSave <RandGauss>(7);
318 stat |= staticSave <RandFlat>(7);
319 stat |= staticSaveShootBit<RandFlat> (19);
320 stat |= staticSaveShootBit<RandBit> (23);
321 for (
int ibinom=0; ibinom<15; ibinom++) {
322 stat |= staticSave <RandBinomial>(7+3*ibinom);
324 stat |= staticSave <RandBreitWigner>(7);
325 stat |= staticSave <RandChiSquare>(7);
326 stat |= staticSave <RandExponential>(7);
327 stat |= staticSave <RandGamma>(7);
328 stat |= staticSave <RandGaussQ>(7);
329 stat |= staticSave <RandGaussT>(7);
330 stat |= staticSave <RandLandau>(7);
331 stat |= staticSave <RandPoisson>(7);
332 stat |= staticSave <RandPoissonQ>(7);
333 stat |= staticSave <RandPoissonT>(7);
334 stat |= staticSave <RandSkewNormal>(7);
335 stat |= staticSave <RandStudentT>(7);
338#ifdef TEST_SAVE_STATIC_STATES
339 output <<
"\n==============================================\n";
341 output <<
"Save/restore all static states to/from streams \n";
342 output <<
"==============================================\n\n";
346 output <<
"Saved all static distributions\n";
348 output <<
"Captured output of all static distributions\n";
350 output <<
"Randomized all static distributions\n";
352 output <<
"Restored all static distributions to saved state\n";
354 output <<
"Captured output of all static distributions\n";
355 for (
unsigned int iv=0; iv<c.size(); iv++) {
356 if (c[iv] != d[iv]) {
357 std::cout <<
"???? restoreStaticRandomStates failed at random "
360 output <<
"???? restoreStaticRandomStates failed at random "
366 if ((stat & 131072) == 0) {
367 output <<
"All captured output agrees with earlier values\n";
371 output <<
"\n=============================================\n\n";
374 std::cout <<
"One or more problems detected: stat = " << stat <<
"\n";
375 output <<
"One or more problems detected: stat = " << stat <<
"\n";
377 output <<
"testStaticStreamSave passed with no problems detected.\n";
380 if (stat == 0)
return 0;
381 if (stat > 0)
return -(stat|1);
static double shoot(double a=1.0, double b=0.2)
static long shoot(double mean=1.0)
static long shoot(double mean=1.0)
static long shoot(double mean=1.0)
void saveStatics(std::string filename)
int staticSaveShootBit(int n)
void randomizeStatics(int n)
void restoreStatics(std::string filename)
bool equals(double a, double b)
std::vector< double > captureStatics()
std::ofstream output("testStaticStreamSave.cout")
bool equals01(const std::vector< double > &ab)