2#include "CLHEP/Random/Randomize.h"
3#include "CLHEP/Random/NonRandomEngine.h"
4#include "CLHEP/Random/defs.h"
11 std::ofstream
output(
"testSaveEngineStatus.cout");
13 std::ostream &
output = std::cout;
18#define TEST_ORIGINAL_SAVE
23#define TEST_MISSING_FILES
24#define CREATE_OLD_SAVES
25#define VERIFY_OLD_SAVES
43 std::vector<double> ab(2);
52 output <<
"r(1) = " << r << std::endl;
55 output <<
"r(2) = " << r << std::endl;
58 output <<
"r(3) = " << r << std::endl;
59 for (
int i=0; i < 1001; i++) {
64 output <<
"r1005= " << r << std::endl;
72 output <<
"restored r(2) = " << r << std::endl;
74 output <<
"THIS DOES NOT MATCH REMEMBERED VALUE BUT THAT IS EXPECTED\n";
77 output <<
"restored r(3) = " << r << std::endl;
78 for (
int i=0; i < 1001; i++) {
82 output <<
"restored r1005= " << r << std::endl;
84 output <<
"THIS DOES NOT MATCH REMEMBERED VALUE BUT THAT IS EXPECTED\n";
91 output <<
"r(1) = " << r << std::endl;
94 output <<
"r(2) = " << r << std::endl;
97 output <<
"r(3) = " << r << std::endl;
99 for (
int i=0; i < 1001; i++) {
102 "This line inserted so clever compilers don't warn about not using d\n";
106 output <<
"r1005= " << r << std::endl;
114 output <<
"restored r(2) = " << r << std::endl;
116 output <<
"THIS DOES NOT MATCH REMEMBERED VALUE BUT THAT IS EXPECTED\n";
119 output <<
"restored r(3) = " << r << std::endl;
120 for (
int i=0; i < 1001; i++) {
124 output <<
"restored r1005= " << r << std::endl;
126 output <<
"THIS DOES NOT MATCH REMEMBERED VALUE BUT THAT IS EXPECTED\n";
136 output <<
"r(1) = " << r << std::endl;
139 output <<
"r(2) = " << r << std::endl;
142 output <<
"r(3) = " << r << std::endl;
143 for (
int i=0; i < 1001; i++) {
148 output <<
"r1005= " << r << std::endl;
157 output <<
"restored r(2) = " << r << std::endl;
159 std::cout <<
"restored r(2) = " << r << std::endl;
160 std::cout <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
162 output <<
"restored r(2) = " << r << std::endl;
163 output <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
168 output <<
"restored r(3) = " << r << std::endl;
169 for (
int i=0; i < 1001; i++) {
173 output <<
"restored r1005= " << r << std::endl;
175 std::cout <<
"restored r1005= " << r << std::endl;
176 std::cout <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
178 output <<
"restored r1005= " << r << std::endl;
179 output <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
189 output <<
"r(1) = " << r << std::endl;
192 output <<
"r(2) = " << r << std::endl;
195 output <<
"r(3) = " << r << std::endl;
196 for (
int i=0; i < 1001; i++) {
201 output <<
"r1005 = " << r << std::endl;
204 output <<
"r1006 = " << r << std::endl;
207 output <<
"r1007 = " << r << std::endl;
216 output <<
"restored r(2) = " << r << std::endl;
219 std::cout <<
"restored r(2) = " << r << std::endl;
220 std::cout <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
222 output <<
"restored r(2) = " << r << std::endl;
223 output <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
227 output <<
"restored r(3) = " << r << std::endl;
228 for (
int i=0; i < 1001; i++) {
232 output <<
"restored r1005= " << r << std::endl;
235 std::cout <<
"restored r1005= " << r << std::endl;
236 std::cout <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
238 output <<
"restored r1005= " << r << std::endl;
239 output <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
243 output <<
"restored r1006= " << r << std::endl;
246 std::cout <<
"restored r1006= " << r << std::endl;
247 std::cout <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
249 output <<
"restored r1006= " << r << std::endl;
250 output <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
254 output <<
"restored r1007= " << r << std::endl;
257 std::cout <<
"restored r1007= " << r << std::endl;
258 std::cout <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
260 output <<
"restored r1007= " << r << std::endl;
261 output <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
269template <
class E,
class D>
274 output <<
"File-not-found test restoring "<<D::distributionName()<<
":\n";
276 D::restoreEngineStatus(
"noSuchFile");
277 D::setTheEngine(old);
286 stat |= fileNotThere <E, RandBinomial>();
287 stat |= fileNotThere <E, RandBit>();
288 stat |= fileNotThere <E, RandBreitWigner>();
289 stat |= fileNotThere <E, RandChiSquare>();
290 stat |= fileNotThere <E, RandExponential>();
291 stat |= fileNotThere <E, RandFlat>();
292 stat |= fileNotThere <E, RandGamma>();
293 stat |= fileNotThere <E, RandGauss>();
294 stat |= fileNotThere <E, RandGaussQ>();
295 stat |= fileNotThere <E, RandGaussT>();
296 stat |= fileNotThere <E, RandLandau>();
297 stat |= fileNotThere <E, RandPoisson>();
298 stat |= fileNotThere <E, RandPoissonQ>();
299 stat |= fileNotThere <E, RandPoissonT>();
300 stat |= fileNotThere <E, RandSkewNormal>();
301 stat |= fileNotThere <E, RandStudentT>();
307 stat |= fileNotThereEngine<DRand48Engine>();
308 stat |= fileNotThereEngine<DualRand>();
309 stat |= fileNotThereEngine<Hurd160Engine>();
310 stat |= fileNotThereEngine<Hurd288Engine>();
311 stat |= fileNotThereEngine<HepJamesRandom>();
312 stat |= fileNotThereEngine<MixMaxRng>();
313 stat |= fileNotThereEngine<MTwistEngine>();
314 stat |= fileNotThereEngine<RandEngine>();
315 stat |= fileNotThereEngine<RanecuEngine>();
316 stat |= fileNotThereEngine<Ranlux64Engine>();
317 stat |= fileNotThereEngine<RanluxEngine>();
318 stat |= fileNotThereEngine<RanluxppEngine>();
319 stat |= fileNotThereEngine<RanshiEngine>();
320 stat |= fileNotThereEngine<TripleRand>();
326template <
class E,
class D>
333 for (
int i=0; i<3; i++) r += D::shoot();
334 D::saveEngineStatus(filename);
335 if (r == -99999999.1) stat = 999;
337 D::setTheEngine(old);
345template <
class E,
class D>
354 for (
int i=0; i<3; i++) r += D::shoot();
355 D::saveEngineStatus();
358 double keyValue = D::shoot();
361 D::restoreEngineStatus(filename);
362 if (!
equals(D::shoot(), keyValue)) {
363 std::cout <<
"???? Value mismatch from file " << filename <<
"\n";
365 output <<
"???? Value mismatch from file " << filename <<
"\n";
371 D::restoreEngineStatus();
372 if (!
equals(D::shoot(),keyValue)) {
373 std::cout <<
"???? Value mismatch from new-format file \n";
375 output <<
"???? Value mismatch from new-format file \n";
380 D::setTheEngine(old);
392#ifdef TEST_ORIGINAL_SAVE
393 output <<
"=====================================\n";
395 output <<
"Original tests of static save/restore\n";
396 output <<
"=====================================\n\n";
398 output <<
"Using old method or HepRandom::saveEngineStatus:\n";
399 output <<
"All these tests should have a chance of failure.\n";
401 output << RandGauss:: getTheEngine()->name();
402 output << RandGaussQ::getTheEngine()->name();
409 output <<
"Using the class-specific RandGauss::saveEngineStatus:\n";
410 output <<
"All these tests should work properly.\n";
418#ifdef TEST_MISSING_FILES
419 output <<
"\n=======================================\n";
421 output <<
"Test of behavior when a file is missing \n";
422 output <<
"=======================================\n\n";
424 output <<
"Testing restoreEngineStatus with missing file:\n";
425 output <<
"Expect a number of <Failure to find or open> messages!\n";
429#ifdef CREATE_OLD_SAVES
430 stat |= saveEngine<DRand48Engine, RandPoisson>(
"DRand48Engine.oldsav");
431 stat |= saveEngine<DualRand, RandPoisson>(
"DualRand.oldsav");
432 stat |= saveEngine<Hurd160Engine, RandPoisson>(
"Hurd160Engine.oldsav");
433 stat |= saveEngine<Hurd288Engine, RandPoisson>(
"Hurd288Engine.oldsav");
434 stat |= saveEngine<HepJamesRandom,RandPoisson>(
"HepJamesRandom.oldsav");
435 stat |= saveEngine<MixMaxRng, RandPoisson>(
"MixMaxRng.oldsav");
436 stat |= saveEngine<MTwistEngine, RandPoisson>(
"MTwistEngine.oldsav");
437 stat |= saveEngine<RanecuEngine, RandPoisson>(
"RanecuEngine.oldsav");
438 stat |= saveEngine<Ranlux64Engine,RandPoisson>(
"Ranlux64Engine.oldsav");
439 stat |= saveEngine<RanluxEngine, RandPoisson>(
"RanluxEngine.oldsav");
440 stat |= saveEngine<RanluxppEngine,RandPoisson>(
"RanluxppEngine.oldsav");
441 stat |= saveEngine<RanshiEngine, RandPoisson>(
"RanshiEngine.oldsav");
442 stat |= saveEngine<TripleRand, RandPoisson>(
"TripleRand.oldsav");
445#ifdef VERIFY_OLD_SAVES
446 output <<
"\n==============================================\n";
448 output <<
" Verification that changes wont invalidate \n";
449 output <<
"invalidate engine saves from previous versions \n";
450 output <<
"==============================================\n\n";
452 stat |= checkSaveEngine<DRand48Engine, RandPoisson>(
"DRand48Engine.oldsav");
453 stat |= checkSaveEngine<DualRand, RandPoisson>(
"DualRand.oldsav");
454 stat |= checkSaveEngine<Hurd160Engine, RandPoisson>(
"Hurd160Engine.oldsav");
455 stat |= checkSaveEngine<Hurd288Engine, RandPoisson>(
"Hurd288Engine.oldsav");
456 stat |= checkSaveEngine<HepJamesRandom,RandPoisson>(
"HepJamesRandom.oldsav");
457 stat |= checkSaveEngine<MixMaxRng, RandPoisson>(
"MixMaxRng.oldsav");
458 stat |= checkSaveEngine<MTwistEngine, RandPoisson>(
"MTwistEngine.oldsav");
459 stat |= checkSaveEngine<Ranlux64Engine,RandPoisson>(
"Ranlux64Engine.oldsav");
460 stat |= checkSaveEngine<RanluxEngine, RandPoisson>(
"RanluxEngine.oldsav");
461 stat |= checkSaveEngine<RanluxppEngine,RandPoisson>(
"RanluxppEngine.oldsav");
462 stat |= checkSaveEngine<RanshiEngine, RandPoisson>(
"RanshiEngine.oldsav");
463 stat |= checkSaveEngine<TripleRand, RandPoisson>(
"TripleRand.oldsav");
464 stat |= checkSaveEngine<RanecuEngine, RandPoisson>(
"RanecuEngine.oldsav");
467 output <<
"\n=============================================\n\n";
470 std::cout <<
"One or more problems detected: stat = " << stat <<
"\n";
471 output <<
"One or more problems detected: stat = " << stat <<
"\n";
473 output <<
"testSaveEngineStatus passed with no problems detected.\n";
476 if (stat == 0)
return 0;
477 if (stat > 0)
return -(stat|1);
static void restoreEngineStatus(const char filename[]="Config.conf")
static void saveEngineStatus(const char filename[]="Config.conf")
static void restoreEngineStatus(const char filename[]="Config.conf")
static void saveEngineStatus(const char filename[]="Config.conf")
static void restoreEngineStatus(const char filename[]="Config.conf")
static void saveEngineStatus(const char filename[]="Config.conf")
int saveEngine(const char *filename)
int checkSaveEngine(const char *filename)
bool equals(double a, double b)
bool equals01(const std::vector< double > &ab)
std::ofstream output("testSaveEngineStatus.cout")