4#include "CLHEP/Random/Randomize.h"
5#include "CLHEP/Random/NonRandomEngine.h"
6#include "CLHEP/Random/defs.h"
13 std::ofstream
output(
"ranRestoreTest.cout");
15 std::ostream &
output = std::cout;
20#define TEST_ORIGINAL_SAVE
25#define TEST_ENGINE_NAMES
26#define TEST_INSTANCE_METHODS
27#define TEST_SHARED_ENGINES
28#define TEST_STATIC_SAVE
29#define TEST_SAVE_STATIC_STATES
30#define TEST_ANONYMOUS_ENGINE_RESTORE
31#define TEST_ANONYMOUS_RESTORE_STATICS
32#define TEST_VECTOR_ENGINE_RESTORE
37#define TEST_MISSING_FILES
38#define CREATE_OLD_SAVES
39#define VERIFY_OLD_SAVES
57 std::vector<double> ab(2);
66 output <<
"r(1) = " << r << std::endl;
69 output <<
"r(2) = " << r << std::endl;
72 output <<
"r(3) = " << r << std::endl;
73 for (
int i=0; i < 1001; i++) {
78 output <<
"r1005= " << r << std::endl;
86 output <<
"restored r(2) = " << r << std::endl;
88 output <<
"THIS DOES NOT MATCH REMEMBERED VALUE BUT THAT IS EXPECTED\n";
91 output <<
"restored r(3) = " << r << std::endl;
92 for (
int i=0; i < 1001; i++) {
96 output <<
"restored r1005= " << r << std::endl;
98 output <<
"THIS DOES NOT MATCH REMEMBERED VALUE BUT THAT IS EXPECTED\n";
105 output <<
"r(1) = " << r << std::endl;
108 output <<
"r(2) = " << r << std::endl;
111 output <<
"r(3) = " << r << std::endl;
113 for (
int i=0; i < 1001; i++) {
116 "This line inserted so clever compilers don't warn about not using d\n";
120 output <<
"r1005= " << r << std::endl;
128 output <<
"restored r(2) = " << r << std::endl;
130 output <<
"THIS DOES NOT MATCH REMEMBERED VALUE BUT THAT IS EXPECTED\n";
133 output <<
"restored r(3) = " << r << std::endl;
134 for (
int i=0; i < 1001; i++) {
138 output <<
"restored r1005= " << r << std::endl;
140 output <<
"THIS DOES NOT MATCH REMEMBERED VALUE BUT THAT IS EXPECTED\n";
150 output <<
"r(1) = " << r << std::endl;
153 output <<
"r(2) = " << r << std::endl;
156 output <<
"r(3) = " << r << std::endl;
157 for (
int i=0; i < 1001; i++) {
162 output <<
"r1005= " << r << std::endl;
171 output <<
"restored r(2) = " << r << std::endl;
173 std::cout <<
"restored r(2) = " << r << std::endl;
174 std::cout <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
178 output <<
"restored r(3) = " << r << std::endl;
179 for (
int i=0; i < 1001; i++) {
183 output <<
"restored r1005= " << r << std::endl;
185 std::cout <<
"restored r1005= " << r << std::endl;
186 std::cout <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
195 output <<
"r(1) = " << r << std::endl;
198 output <<
"r(2) = " << r << std::endl;
201 output <<
"r(3) = " << r << std::endl;
202 for (
int i=0; i < 1001; i++) {
207 output <<
"r1005 = " << r << std::endl;
210 output <<
"r1006 = " << r << std::endl;
213 output <<
"r1007 = " << r << std::endl;
222 output <<
"restored r(2) = " << r << std::endl;
225 std::cout <<
"restored r(2) = " << r << std::endl;
226 std::cout <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
229 output <<
"restored r(3) = " << r << std::endl;
230 for (
int i=0; i < 1001; i++) {
234 output <<
"restored r1005= " << r << std::endl;
237 std::cout <<
"restored r1005= " << r << std::endl;
238 std::cout <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
241 output <<
"restored r1006= " << r << std::endl;
244 std::cout <<
"restored r1006= " << r << std::endl;
245 std::cout <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
248 output <<
"restored r1007= " << r << std::endl;
251 std::cout <<
"restored r1007= " << r << std::endl;
252 std::cout <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
259template <
class E,
class D>
264 output <<
"File-not-found test restoring "<<D::distributionName()<<
":\n";
266 D::restoreEngineStatus(
"noSuchFile");
267 D::setTheEngine(old);
276 stat |= fileNotThere <E, RandBinomial>();
277 stat |= fileNotThere <E, RandBit>();
278 stat |= fileNotThere <E, RandBreitWigner>();
279 stat |= fileNotThere <E, RandChiSquare>();
280 stat |= fileNotThere <E, RandExponential>();
281 stat |= fileNotThere <E, RandFlat>();
282 stat |= fileNotThere <E, RandGamma>();
283 stat |= fileNotThere <E, RandGauss>();
284 stat |= fileNotThere <E, RandGaussQ>();
285 stat |= fileNotThere <E, RandGaussT>();
286 stat |= fileNotThere <E, RandLandau>();
287 stat |= fileNotThere <E, RandPoisson>();
288 stat |= fileNotThere <E, RandPoissonQ>();
289 stat |= fileNotThere <E, RandPoissonT>();
290 stat |= fileNotThere <E, RandSkewNormal>();
291 stat |= fileNotThere <E, RandStudentT>();
297 stat |= fileNotThereEngine<DRand48Engine>();
298 stat |= fileNotThereEngine<DualRand>();
299 stat |= fileNotThereEngine<Hurd160Engine>();
300 stat |= fileNotThereEngine<Hurd288Engine>();
301 stat |= fileNotThereEngine<HepJamesRandom>();
302 stat |= fileNotThereEngine<MixMaxRng>();
303 stat |= fileNotThereEngine<MTwistEngine>();
304 stat |= fileNotThereEngine<RandEngine>();
305 stat |= fileNotThereEngine<RanecuEngine>();
306 stat |= fileNotThereEngine<Ranlux64Engine>();
307 stat |= fileNotThereEngine<RanluxEngine>();
308 stat |= fileNotThereEngine<RanluxppEngine>();
309 stat |= fileNotThereEngine<RanshiEngine>();
310 stat |= fileNotThereEngine<TripleRand>();
316template <
class E,
class D>
323 for (
int i=0; i<3; i++) r += D::shoot();
324 D::saveEngineStatus(filename);
325 if (r == -99999999.1) stat = 999;
327 D::setTheEngine(old);
335template <
class E,
class D>
344 for (
int i=0; i<3; i++) r += D::shoot();
345 D::saveEngineStatus();
348 double keyValue = D::shoot();
351 D::restoreEngineStatus(filename);
352 if (!
equals(D::shoot(), keyValue)) {
353 std::cout <<
"???? Value mismatch from file " << filename <<
"\n";
358 D::restoreEngineStatus();
359 if (!
equals(D::shoot(),keyValue)) {
360 std::cout <<
"???? Value mismatch from new-format file \n";
364 D::setTheEngine(old);
374 output << E::engineName() <<
"\n";
375 if (E::engineName() != name) {
376 std::cout <<
"???? engineName mismatch for " << name <<
" <--> "
377 << E::engineName() <<
"\n";
381 if (e.name() != name) {
382 std::cout <<
"???? name mismatch for " << name <<
" <--> "
389template <
class E,
class D>
394 if (d.engine().name() != e.name()) {
395 std::cout <<
"???? Improper d.engine() \n";
404 output <<
"checkEngineInstanceSave for " << e.name() <<
"\n";
405 int pr=
output.precision(20);
407 for (
int i=0; i<100; i++) r += e.flat();
408 {std::ofstream os (
"engine.save"); os << e;}
409 for (
int i=0; i<100; i++) r += e.flat();
410 double keyValue1 = e.flat();
411 double keyValue2 = e.flat();
413 output << keyValue1 <<
" " << keyValue2 <<
"\n";
416 {std::ifstream is (
"engine.save"); is >> e2;}
417 for (
int i=0; i<100; i++) r += e2.flat();
418 double k1 = e2.flat();
419 double k2 = e2.flat();
421 output << k1 <<
" " << k2 <<
"\n";
423 if ( !(
equals(k1,keyValue1)) || !(
equals(k2,keyValue2)) ) {
424 std::cout <<
"???? checkInstanceSave failed for " << e.name() <<
"\n";
431template <
class E,
class D>
433 dynamic_cast<E &
>(d.engine());
435 output <<
"checkSaveDistribution with " << d.engine().name()
436 <<
", " << d.name() <<
"\n";
439 double keyValue1, keyValue2, keyValue3, keyValue4;
440 for (
int i=0; i<nth; i++) r += d();
441 {std::ofstream os (
"distribution.save1"); os << d.engine() << d;}
446 {std::ofstream os (
"distribution.save2"); os << d.engine() << d;}
449 int pr =
output.precision(20);
451 output <<
"keyValue1 = " << keyValue1 <<
452 " keyValue2 = " << keyValue2 <<
"\n";
453 output <<
"keyValue3 = " << keyValue3 <<
454 " keyValue3 = " << keyValue4 <<
"\n";
459 { std::ifstream is (
"distribution.save1"); is >> e >> d2;}
462 { std::ifstream is (
"distribution.save2"); is >> e >> d2;}
466 pr =
output.precision(20);
467 output <<
"k1 = " << k1 <<
468 " k2 = " << k2 <<
"\n";
469 output <<
"k3 = " << k3 <<
470 " k4 = " << k4 <<
"\n";
475 std::cout <<
"???? Incorrect restored value for distribution "
485 dynamic_cast<E &
>(d.
engine());
488 <<
", " << d.
name() <<
"\n";
491 double keyValue1, keyValue2, keyValue3, keyValue4;
492 for (
int i=0; i<nth; i++) r += d();
493 {std::ofstream os (
"distribution.save1"); os << d.
engine() << d;}
498 {std::ofstream os (
"distribution.save2"); os << d.
engine() << d;}
501 int pr =
output.precision(20);
503 output <<
"keyValue1 = " << keyValue1 <<
504 " keyValue2 = " << keyValue2 <<
"\n";
505 output <<
"keyValue3 = " << keyValue3 <<
506 " keyValue3 = " << keyValue4 <<
"\n";
512 { std::ifstream is (
"distribution.save1"); is >> e >> d2;}
515 { std::ifstream is (
"distribution.save2"); is >> e >> d2;}
519 pr =
output.precision(20);
520 output <<
"k1 = " << k1 <<
521 " k2 = " << k2 <<
"\n";
522 output <<
"k3 = " << k3 <<
523 " k4 = " << k4 <<
"\n";
528 std::cout <<
"???? Incorrect restored value for distribution "
540 stat |= checkSaveDistribution<E,RandGauss> (d,33); }
542 stat |= checkSaveDistribution<E,RandGauss> (d,34); }
544 stat |= checkSaveDistribution<E,RandGaussQ> (d,33); }
546 stat |= checkSaveDistribution<E,RandGaussT> (d,33); }
548 stat |= checkSaveDistribution<E,RandBinomial> (d,33); }
549 {
RandFlat d(
new E(12576),12.5,35.0);
550 stat |= checkSaveDistribution<E,RandFlat> (d,33); }
552 stat |= checkSaveDistribution<E,RandBit> (d,31); }
554 stat |= checkSaveDistribution<E,RandBit> (d,32); }
556 stat |= checkSaveDistribution<E,RandBit> (d,33); }
558 stat |= checkSaveDistribution<E,RandBreitWigner> (d,33); }
560 stat |= checkSaveDistribution<E,RandChiSquare> (d,33); }
562 stat |= checkSaveDistribution<E,RandExponential> (d,33); }
564 stat |= checkSaveDistribution<E,RandGamma> (d,33); }
566 stat |= checkSaveDistribution<E,RandLandau> (d,33); }
568 stat |= checkSaveDistribution<E,RandSkewNormal> (d,33); }
570 stat |= checkSaveDistribution<E,RandStudentT> (d,33); }
577 stat |= checkSaveDistribution<E,RandPoisson> (d,33); }
579 stat |= checkSaveDistribution<E,RandPoisson> (d,34); }
581 stat |= checkSaveDistribution<E,RandPoisson> (d,35); }
583 stat |= checkSaveDistribution<E,RandPoisson> (d,36); }
585 stat |= checkSaveDistribution<E,RandPoisson> (d,37); }
587 stat |= checkSaveDistribution<E,RandPoisson> (d,38); }
589 stat |= checkSaveDistribution<E,RandPoisson> (d,39); }
591 stat |= checkSaveDistribution<E,RandPoissonQ> (d,33); }
593 stat |= checkSaveDistribution<E,RandPoissonQ> (d,32); }
595 stat |= checkSaveDistribution<E,RandPoissonQ> (d,31); }
597 stat |= checkSaveDistribution<E,RandPoissonQ> (d,30); }
599 stat |= checkSaveDistribution<E,RandPoissonQ> (d,33); }
601 stat |= checkSaveDistribution<E,RandPoissonQ> (d,34); }
603 stat |= checkSaveDistribution<E,RandPoissonQ> (d,34); }
605 stat |= checkSaveDistribution<E,RandPoissonT> (d,33); }
607 stat |= checkSaveDistribution<E,RandPoissonT> (d,33); }
609 stat |= checkSaveDistribution<E,RandPoissonT> (d,34); }
611 stat |= checkSaveDistribution<E,RandPoissonT> (d,34); }
613 stat |= checkSaveDistribution<E,RandPoissonT> (d,10); }
615 stat |= checkSaveDistribution<E,RandPoissonT> (d,11); }
617 stat |= checkSaveDistribution<E,RandPoissonT> (d,12); }
619 {std::vector<double> pdf;
621 for (
int i = 0; i < nbins; ++i)
622 pdf.push_back( 5*i + (10.5-i) * (10.5-i) );
624 stat |= checkRandGeneralDistribution<E> (d,33); }
629template <
class E,
class D1,
class D2>
632 output <<
"checkSharingDistribution with: \n"
633 << d1.name() <<
" using " << d1.engine().name() <<
" and\n"
634 << d2.name() <<
" using " << d2.engine().name() <<
"\n";
638 double kv11,kv12,kv13,kv14;
639 double kv21,kv22,kv23,kv24;
640 for (
int i=0; i<n1; i++) r += d1();
641 for (
int j=0; j<n2; j++) r += d2();
642 {std::ofstream os (
"shared.save1"); os << d1.engine() << d1 << d2;}
649 {std::ofstream os (
"shared.save2"); os << d1.engine() << d1 << d2;}
655 int pr =
output.precision(20);
656 output <<
"kv11 = " << kv11 <<
657 " kv21 = " << kv21 <<
"\n";
658 output <<
"kv12 = " << kv12 <<
659 " kv22 = " << kv22 <<
"\n";
660 output <<
"kv13 = " << kv13 <<
661 " kv23 = " << kv23 <<
"\n";
662 output <<
"kv14 = " << kv14 <<
663 " kv24 = " << kv24 <<
"\n";
669 { std::ifstream is (
"shared.save1"); is >> e >> d1r >> d2r;}
674 { std::ifstream is (
"shared.save2"); is >> e >> d1r >> d2r;}
680 pr =
output.precision(20);
681 output <<
"k11 = " << k11 <<
682 " k21 = " << k21 <<
"\n";
683 output <<
"k12 = " << k12 <<
684 " k22 = " << k22 <<
"\n";
685 output <<
"k13 = " << k13 <<
686 " k23 = " << k23 <<
"\n";
687 output <<
"k14 = " << k14 <<
688 " k24 = " << k24 <<
"\n";
695 std::cout <<
"???? Incorrect restored value for distributions "
696 << d1.name() <<
" " << d2.name() <<
"\n";
713 stat |= checkSharingDistributions<E, RandGauss, RandPoissonQ>(g1,p1,5,4);
714 stat |= checkSharingDistributions<E, RandGauss, RandPoissonQ>(g1,p2,6,6);
715 stat |= checkSharingDistributions<E, RandGauss, RandPoissonQ>(g2,p1,8,9);
716 stat |= checkSharingDistributions<E, RandGauss, RandPoissonQ>(g1,p1,7,5);
717 stat |= checkSharingDistributions<E, RandPoissonQ, RandGauss>(p1,g2,5,4);
718 stat |= checkSharingDistributions<E, RandPoissonQ, RandGauss>(p2,g1,6,6);
719 stat |= checkSharingDistributions<E, RandPoissonQ, RandGauss>(p1,g1,8,9);
720 stat |= checkSharingDistributions<E, RandPoissonQ, RandGauss>(p2,g1,7,5);
725 std::vector<double> v;
728 for (
int i=0; i<n; i++) {
740 output <<
"staticSave for distribution " << D::distributionName() <<
"\n";
742 double v1, v2, k1, k2;
743 for (i=0; i < n; i++) r += D::shoot();
745 std::ofstream file (
"distribution.save1");
746 D::saveFullState(file);
748 D::saveFullState(file);
751 int pr =
output.precision(20);
752 output <<
"v1 = " << v1 <<
" v2 = " << v2 <<
"\n";
756 for (i=0; i < n; i++) r += D::shoot();
758 std::ifstream file (
"distribution.save1");
759 D::restoreFullState(file);
761 for (i=0; i < n; i++) r += D::shoot();
762 D::restoreFullState(file);
765 int pr =
output.precision(20);
766 output <<
"k1 = " << k1 <<
" k2 = " << k2 <<
"\n";
770 if ( (k1 != v1) || (k2 != v2) ) {
771 std::cout <<
"???? restoreFullState failed for " << D::distributionName() <<
"\n";
775 for (i=0; i < n; i++) r += D::shoot();
777 std::ofstream file (
"distribution.save2");
778 D::saveDistState(file) << *D::getTheEngine();
780 D::saveDistState(file) << *D::getTheEngine();
783 int pr =
output.precision(20);
784 output <<
"v1 = " << v1 <<
" v2 = " << v2 <<
"\n";
788 for (i=0; i < n; i++) r += D::shoot();
790 std::ifstream file (
"distribution.save2");
791 D::restoreDistState(file) >> *D::getTheEngine();
793 for (i=0; i < n; i++) r += D::shoot();
794 D::restoreDistState(file) >> *D::getTheEngine();
797 int pr =
output.precision(20);
798 output <<
"k1 = " << k1 <<
" k2 = " << k2 <<
"\n";
802 if ( (k1 != v1) || (k2 != v2) ) {
803 std::cout <<
"???? restoreDistState failed for " << D::distributionName() <<
"\n";
814 output <<
"staticSaveShootBit for " << D::distributionName() <<
"\n";
818 for (i=0; i < n; i++) r += D::shoot();
819 for (i=0; i < n; i++) bit |= D::shootBit();
821 std::ofstream file (
"distribution.save1");
822 D::saveFullState(file);
824 for (i=0; i<25; i++) {
828 for (i=0; i < n; i++) bit |= D::shootBit();
829 D::saveFullState(file);
831 for (i=0; i<25; i++) {
836 int pr =
output.precision(20);
837 output << std::hex <<
"v1 = " << v1 <<
" v2 = " << v2 << std::dec <<
"\n";
841 for (i=0; i < n; i++) r += D::shoot();
843 std::ifstream file (
"distribution.save1");
844 D::restoreFullState(file);
846 for (i=0; i<25; i++) {
850 for (i=0; i < n; i++) r += D::shoot();
851 D::restoreFullState(file);
853 for (i=0; i<25; i++) {
858 int pr =
output.precision(20);
859 output << std::hex <<
"k1 = " << k1 <<
" k2 = " << k2 << std::dec <<
"\n";
863 if ( (k1 != v1) || (k2 != v2) ) {
864 std::cout <<
"???? restoreFullState failed for D shootBit()\n";
868 for (i=0; i < n; i++) r += D::shoot();
869 for (i=0; i < n; i++) bit |= D::shootBit();
871 std::ofstream file (
"distribution.save2");
872 D::saveDistState(file) << *D::getTheEngine();
874 for (i=0; i<25; i++) {
878 for (i=0; i < n; i++) bit |= D::shootBit();
879 D::saveDistState(file) << *D::getTheEngine();
881 for (i=0; i<25; i++) {
886 int pr =
output.precision(20);
887 output << std::hex <<
"v1 = " << v1 <<
" v2 = " << v2 << std::dec <<
"\n";
891 for (i=0; i < n; i++) r += D::shoot();
893 std::ifstream file (
"distribution.save2");
894 D::restoreDistState(file) >> *D::getTheEngine();
896 for (i=0; i<25; i++) {
900 for (i=0; i < n; i++) r += D::shoot();
901 for (i=0; i < n; i++) r += D::shootBit();
902 D::restoreDistState(file) >> *D::getTheEngine();
904 for (i=0; i<25; i++) {
909 int pr =
output.precision(20);
910 output << std::hex <<
"k1 = " << k1 <<
" k2 = " << k2 << std::dec <<
"\n";
914 if ( (k1 != v1) || (k2 != v2) ) {
915 std::cout <<
"???? restoreDistState failed for RnadFlat::shootBit()\n";
925 for (
int i=0; i<n; i++) {
948 std::vector<double> c;
953 c.push_back( RandBit::shoot() );
954 for (
int i=0; i<20; i++) {
973 std::ofstream os(filename.c_str());
974 RandGeneral::saveStaticRandomStates(os);
981 std::ifstream is(filename.c_str());
982 RandLandau::restoreStaticRandomStates(is);
989 output <<
"Anonymous restore for " << E::engineName() <<
"\n";
992 for (
int i=0; i<n; i++) r += e.flat();
993 std::ofstream os(
"anonymous.save");
995 for (
int j=0; j<25; j++) v.push_back(e.flat());
997 output <<
"First four of v are: "
998 << v[0] <<
", " << v[1] <<
", " << v[2] <<
", " << v[3] <<
"\n";
1008 std::vector<double> nonRand =
aSequence(500);
1012 for (
int i=0; i<n; i++) r += e.
flat();
1013 std::ofstream os(
"anonymous.save");
1015 for (
int j=0; j<25; j++) v.push_back(e.
flat());
1017 output <<
"First four of v are: "
1018 << v[0] <<
", " << v[1] <<
", " << v[2] <<
", " << v[3] <<
"\n";
1026 std::vector<double> k;
1027 std::ifstream is(
"anonymous.save");
1030 for (
int j=0; j<25; j++) k.push_back(a->
flat());
1033 output <<
"First four of k are: "
1034 << k[0] <<
", " << k[1] <<
", " << k[2] <<
", " << k[3] <<
"\n";
1036 for (
int m=0; m<25; m++) {
1037 if ( v[m] != k[m] ) {
1038 std::cout <<
"???? Incorrect restored value for anonymous engine"
1039 << E::engineName() <<
"\n";
1050 std::vector<double> v;
1051 anonymousRestore1<E>(n,v);
1052 return anonymousRestore2<E>(v);
1063 output <<
"\nRandomized, with theEngine = " << e->
name() <<
"\n";
1065 output <<
"Saved all static distributions\n";
1067 output <<
"Captured output of all static distributions\n";
1069 output <<
"Randomized all static distributions\n";
1071 output <<
"Restored all static distributions to saved state\n";
1073 output <<
"Captured output of all static distributions\n";
1074 for (
unsigned int iv=0; iv<c.size(); iv++) {
1075 if (c[iv] != d[iv]) {
1076 std::cout <<
"???? restoreStaticRandomStates failed at random "
1081 if (stat & 131072 == 0) {
1082 output <<
"All captured output agrees with earlier values\n";
1089template <
class E1,
class E2>
1092 if ( E1::engineName() == E2::engineName() ) {
1093 return anonymousRestoreStatics1<E1>();
1098 output <<
"\nRandomized, with theEngine = " << e1->
name() <<
"\n";
1101 output <<
"Saved all static distributions\n";
1105 output <<
"Captured output of all static distributions\n";
1110 output <<
"Switched to theEngine = " << e2->
name() <<
"\n";
1112 { std::ofstream os(
"engine.save"); os << *e2; }
1113 double v1 = e2->
flat();
1114 double v2 = e2->
flat();
1115 { std::ifstream is(
"engine.save"); is >> *e2; }
1117 output <<
"Saved the " << e2->
name() <<
" engine: \n"
1118 <<
"Next randoms to be " << v1 <<
" " << v2 <<
"\n"
1119 <<
"Restored the " << e2->
name() <<
" engine to that state\n";
1123 output <<
"Restored all static distributions to saved state\n"
1124 <<
"This changes the engine type back to " << E1::engineName() <<
"\n";
1128 output <<
"Captured output of all static distributions\n";
1130 for (
unsigned int iv=0; iv<c.size(); iv++) {
1131 if (c[iv] != d[iv]) {
1132 std::cout <<
"???? restoreStaticRandomStates failed at random "
1137 if (stat & 524288 == 0) {
1138 output <<
"All captured output agrees with earlier values\n";
1140 double k1 = e2->
flat();
1141 double k2 = e2->
flat();
1143 output <<
"The " << e2->
name() <<
" engine should not have been affected: \n"
1144 <<
"Next randoms are " << k1 <<
" " << k2 <<
"\n";
1147 std::cout <<
"???? Engine used as theEngine was affected by restoring \n"
1148 <<
" static distributions to use engine of a different type.\n";
1158 output <<
"Vector restore for " << E::engineName() <<
"\n";
1161 for (
int i=0; i<n; i++) r += e.flat();
1162 std::vector<unsigned long> state = e.put();
1163 for (
int j=0; j<25; j++) v.push_back(e.flat());
1165 output <<
"First four of v are: "
1166 << v[0] <<
", " << v[1] <<
", " << v[2] <<
", " << v[3] <<
"\n";
1172std::vector<unsigned long>
1177 std::vector<double> nonRand =
aSequence(500);
1181 for (
int i=0; i<
n; i++) r += e.
flat();
1182 std::vector<unsigned long> state = e.
put();
1183 for (
int j=0; j<25; j++) v.push_back(e.
flat());
1185 output <<
"First four of v are: "
1186 << v[0] <<
", " << v[1] <<
", " << v[2] <<
", " << v[3] <<
"\n";
1193 const std::vector<double> & v) {
1195 std::vector<double> k;
1199 std::cout <<
"???? could not restore engine state from vector for "
1200 << E::engineName() <<
"\n";
1204 if (a->
name() != E::engineName()) {
1205 std::cout <<
"???? restored engine state from vector for "
1206 << E::engineName() <<
"to different type of engine: "
1207 << a->
name() <<
"\n"
1208 <<
"There is probably a clash in CRC hashes for these two names!\n";
1212 for (
int j=0; j<25; j++) k.push_back(a->
flat());
1215 output <<
"First four of k are: "
1216 << k[0] <<
", " << k[1] <<
", " << k[2] <<
", " << k[3] <<
"\n";
1218 for (
int m=0; m<25; m++) {
1219 if ( v[m] != k[m] ) {
1220 std::cout <<
"???? Incorrect vector restored value for anonymous engine: "
1221 << E::engineName() <<
"\n";
1232 std::vector<double> v;
1233 std::vector<unsigned long> state = vectorRestore1<E>(n,v);
1234 return vectorRestore2<E>(state, v);
1247#ifdef TEST_ORIGINAL_SAVE
1248 output <<
"=====================================\n";
1250 output <<
"Original tests of static save/restore\n";
1251 output <<
"=====================================\n\n";
1253 output <<
"Using old method or HepRandom::saveEngineStatus:\n";
1254 output <<
"All these tests should have a chance of failure.\n";
1256 output << RandGauss:: getTheEngine()->name();
1257 output << RandGaussQ::getTheEngine()->name();
1264 output <<
"Using the class-specific RandGauss::saveEngineStatus:\n";
1265 output <<
"All these tests should work properly.\n";
1273#ifdef TEST_MISSING_FILES
1274 output <<
"\n=======================================\n";
1276 output <<
"Test of behavior when a file is missing \n";
1277 output <<
"=======================================\n\n";
1279 output <<
"Testing restoreEngineStatus with missing file:\n";
1280 output <<
"Expect a number of <Failure to find or open> messages!\n";
1284#ifdef CREATE_OLD_SAVES
1285 stat |= saveEngine<DRand48Engine, RandPoisson>(
"DRand48Engine.oldsav");
1286 stat |= saveEngine<DualRand, RandPoisson>(
"DualRand.oldsav");
1287 stat |= saveEngine<Hurd160Engine, RandPoisson>(
"Hurd160Engine.oldsav");
1288 stat |= saveEngine<Hurd288Engine, RandPoisson>(
"Hurd288Engine.oldsav");
1289 stat |= saveEngine<HepJamesRandom,RandPoisson>(
"HepJamesRandom.oldsav");
1290 stat |= saveEngine<MixMaxRng, RandPoisson>(
"MixMaxRng.oldsav");
1291 stat |= saveEngine<MTwistEngine, RandPoisson>(
"MTwistEngine.oldsav");
1292 stat |= saveEngine<RanecuEngine, RandPoisson>(
"RanecuEngine.oldsav");
1293 stat |= saveEngine<Ranlux64Engine,RandPoisson>(
"Ranlux64Engine.oldsav");
1294 stat |= saveEngine<RanluxppEngine,RandPoisson>(
"RanluxppEngine.oldsav");
1295 stat |= saveEngine<RanluxEngine, RandPoisson>(
"RanluxEngine.oldsav");
1296 stat |= saveEngine<RanshiEngine, RandPoisson>(
"RanshiEngine.oldsav");
1297 stat |= saveEngine<TripleRand, RandPoisson>(
"TripleRand.oldsav");
1300#ifdef VERIFY_OLD_SAVES
1301 output <<
"\n==============================================\n";
1303 output <<
" Verification that changes wont invalidate \n";
1304 output <<
"invalidate engine saves from previous versions \n";
1305 output <<
"==============================================\n\n";
1307 stat |= checkSaveEngine<DRand48Engine, RandPoisson>(
"DRand48Engine.oldsav");
1308 stat |= checkSaveEngine<DualRand, RandPoisson>(
"DualRand.oldsav");
1309 stat |= checkSaveEngine<Hurd160Engine, RandPoisson>(
"Hurd160Engine.oldsav");
1310 stat |= checkSaveEngine<Hurd288Engine, RandPoisson>(
"Hurd288Engine.oldsav");
1311 stat |= checkSaveEngine<HepJamesRandom,RandPoisson>(
"HepJamesRandom.oldsav");
1312 stat |= checkSaveEngine<MixMaxRng, RandPoisson>(
"MixMaxRng.oldsav");
1313 stat |= checkSaveEngine<MTwistEngine, RandPoisson>(
"MTwistEngine.oldsav");
1314 stat |= checkSaveEngine<Ranlux64Engine,RandPoisson>(
"Ranlux64Engine.oldsav");
1315 stat |= checkSaveEngine<RanluxEngine, RandPoisson>(
"RanluxEngine.oldsav");
1316 stat |= checkSaveEngine<RanluxppEngine,RandPoisson>(
"RanluxppEngine.oldsav");
1317 stat |= checkSaveEngine<RanshiEngine, RandPoisson>(
"RanshiEngine.oldsav");
1318 stat |= checkSaveEngine<TripleRand, RandPoisson>(
"TripleRand.oldsav");
1319 stat |= checkSaveEngine<RanecuEngine, RandPoisson>(
"RanecuEngine.oldsav");
1322#ifdef TEST_ENGINE_NAMES
1323 output <<
"\n=============================================\n";
1325 output <<
"Check all engine names were entered correctly \n";
1326 output <<
"=============================================\n\n";
1328 stat |= checkEngineName<DRand48Engine >(
"DRand48Engine");
1329 stat |= checkEngineName<DualRand >(
"DualRand");
1330 stat |= checkEngineName<Hurd160Engine >(
"Hurd160Engine");
1331 stat |= checkEngineName<Hurd288Engine >(
"Hurd288Engine");
1332 stat |= checkEngineName<HepJamesRandom>(
"HepJamesRandom");
1333 stat |= checkEngineName<MixMaxRng >(
"MixMaxRng");
1334 stat |= checkEngineName<MTwistEngine >(
"MTwistEngine");
1335 stat |= checkEngineName<RandEngine >(
"RandEngine");
1336 stat |= checkEngineName<RanecuEngine >(
"RanecuEngine");
1337 stat |= checkEngineName<Ranlux64Engine>(
"Ranlux64Engine");
1338 stat |= checkEngineName<RanluxEngine >(
"RanluxEngine");
1339 stat |= checkEngineName<RanluxppEngine>(
"RanluxppEngine");
1340 stat |= checkEngineName<RanshiEngine >(
"RanshiEngine");
1341 stat |= checkEngineName<TripleRand >(
"TripleRand");
1344#ifdef TEST_INSTANCE_METHODS
1345 output <<
"===========================================\n\n";
1347 output <<
"Check instance methods for specific engines \n";
1348 output <<
" specific engines and distributions\n";
1349 output <<
"===========================================\n\n";
1365 {std::vector<double> nonRand =
aSequence(500);
1370 stat |= checkDistributions<DualRand>();
1371 stat |= checkDistributions<Hurd160Engine>();
1372 stat |= checkDistributions<Hurd288Engine>();
1373 stat |= checkDistributions<HepJamesRandom>();
1374 stat |= checkDistributions<MixMaxRng>();
1375 stat |= checkDistributions<MTwistEngine>();
1376 stat |= checkDistributions<Ranlux64Engine>();
1377 stat |= checkDistributions<RanluxEngine>();
1378 stat |= checkDistributions<RanluxppEngine>();
1379 stat |= checkDistributions<RanshiEngine>();
1380 stat |= checkDistributions<TripleRand>();
1385#ifdef TEST_SHARED_ENGINES
1386 output <<
"\n=============================================\n";
1388 output <<
"Check behavior when engines are shared \n";
1389 output <<
"=============================================\n\n";
1391 stat |= checkSharing<DualRand>();
1392 stat |= checkSharing<Hurd160Engine>();
1393 stat |= checkSharing<Hurd288Engine>();
1394 stat |= checkSharing<HepJamesRandom>();
1395 stat |= checkSharing<MixMaxRng>();
1396 stat |= checkSharing<MTwistEngine>();
1397 stat |= checkSharing<Ranlux64Engine>();
1398 stat |= checkSharing<RanluxEngine>();
1399 stat |= checkSharing<RanluxppEngine>();
1400 stat |= checkSharing<RanshiEngine>();
1401 stat |= checkSharing<TripleRand>();
1404#ifdef TEST_STATIC_SAVE
1405 output <<
"\n=========================================\n";
1407 output <<
"Static Save/restore to/from streams \n";
1408 output <<
"=========================================\n\n";
1410 stat |= staticSave <RandGauss>(7);
1411 stat |= staticSave <RandFlat>(7);
1412 stat |= staticSaveShootBit<RandFlat> (19);
1413 stat |= staticSaveShootBit<RandBit> (23);
1414 for (
int ibinom=0; ibinom<15; ibinom++) {
1415 stat |= staticSave <RandBinomial>(7+3*ibinom);
1417 stat |= staticSave <RandBreitWigner>(7);
1418 stat |= staticSave <RandChiSquare>(7);
1419 stat |= staticSave <RandExponential>(7);
1420 stat |= staticSave <RandGamma>(7);
1421 stat |= staticSave <RandGaussQ>(7);
1422 stat |= staticSave <RandGaussT>(7);
1423 stat |= staticSave <RandLandau>(7);
1424 stat |= staticSave <RandPoisson>(7);
1425 stat |= staticSave <RandPoissonQ>(7);
1426 stat |= staticSave <RandPoissonT>(7);
1427 stat |= staticSave <RandSkewNormal>(7);
1428 stat |= staticSave <RandStudentT>(7);
1431#ifdef TEST_SAVE_STATIC_STATES
1432 output <<
"\n==============================================\n";
1434 output <<
"Save/restore all static states to/from streams \n";
1435 output <<
"==============================================\n\n";
1439 output <<
"Saved all static distributions\n";
1441 output <<
"Captured output of all static distributions\n";
1443 output <<
"Randomized all static distributions\n";
1445 output <<
"Restored all static distributions to saved state\n";
1447 output <<
"Captured output of all static distributions\n";
1448 for (
unsigned int iv=0; iv<c.size(); iv++) {
1449 if (c[iv] != d[iv]) {
1450 std::cout <<
"???? restoreStaticRandomStates failed at random "
1455 if (stat & 131072 == 0) {
1456 output <<
"All captured output agrees with earlier values\n";
1460#ifdef TEST_ANONYMOUS_ENGINE_RESTORE
1461 output <<
"\n=================================\n";
1462 output <<
" Part VII \n";
1463 output <<
"Anonymous restore of engines \n";
1464 output <<
"=================================\n\n";
1466 stat |= anonymousRestore<DualRand>(13);
1467 stat |= anonymousRestore<DRand48Engine>(14);
1468 stat |= anonymousRestore<Hurd160Engine>(15);
1469 stat |= anonymousRestore<Hurd288Engine>(16);
1470 stat |= anonymousRestore<HepJamesRandom>(17);
1471 stat |= anonymousRestore<MixMaxRng>(49);
1472 stat |= anonymousRestore<MTwistEngine>(18);
1473 stat |= anonymousRestore<RandEngine>(29);
1474 stat |= anonymousRestore<RanecuEngine>(39);
1475 stat |= anonymousRestore<Ranlux64Engine>(19);
1476 stat |= anonymousRestore<RanluxEngine>(20);
1477 stat |= anonymousRestore<RanluxppEngine>(19);
1478 stat |= anonymousRestore<RanshiEngine>(21);
1479 stat |= anonymousRestore<TripleRand>(22);
1480 stat |= anonymousRestore<NonRandomEngine>(22);
1483#ifdef TEST_ANONYMOUS_RESTORE_STATICS
1484 output <<
"\n======================================\n";
1485 output <<
" Part VIII \n";
1486 output <<
"Anonymous restore static Distributions \n";
1487 output <<
"======================================\n\n";
1489 stat |= anonymousRestoreStatics<DualRand, Ranlux64Engine> ( );
1490 stat |= anonymousRestoreStatics<DRand48Engine, TripleRand> ( );
1491 stat |= anonymousRestoreStatics<RandEngine, Ranlux64Engine> ( );
1492 stat |= anonymousRestoreStatics<MTwistEngine, Hurd288Engine> ( );
1493 stat |= anonymousRestoreStatics<RanecuEngine, MTwistEngine> ( );
1494 stat |= anonymousRestoreStatics<HepJamesRandom, RanshiEngine> ( );
1495 stat |= anonymousRestoreStatics<RanecuEngine, RandEngine> ( );
1496 stat |= anonymousRestoreStatics<RanshiEngine, Hurd160Engine> ( );
1497 stat |= anonymousRestoreStatics<TripleRand, DualRand> ( );
1498 stat |= anonymousRestoreStatics<Hurd160Engine, HepJamesRandom> ( );
1499 stat |= anonymousRestoreStatics<Hurd288Engine, RanecuEngine> ( );
1500 stat |= anonymousRestoreStatics<HepJamesRandom, Ranlux64Engine> ( );
1501 stat |= anonymousRestoreStatics<HepJamesRandom, RanluxppEngine> ( );
1502 stat |= anonymousRestoreStatics<TripleRand, TripleRand> ( );
1503 stat |= anonymousRestoreStatics<HepJamesRandom, HepJamesRandom> ( );
1504 stat |= anonymousRestoreStatics<MixMaxRng, MixMaxRng> ( );
1507#ifdef TEST_VECTOR_ENGINE_RESTORE
1508 output <<
"\n=================================\n";
1510 output <<
"Save/restore of engines to vectors\n";
1511 output <<
"=================================\n\n";
1513 stat |= vectorRestore<DualRand>(113);
1514 stat |= vectorRestore<DRand48Engine>(114);
1515 stat |= vectorRestore<Hurd160Engine>(115);
1516 stat |= vectorRestore<Hurd288Engine>(116);
1517 stat |= vectorRestore<HepJamesRandom>(117);
1518 stat |= vectorRestore<MixMaxRng>(149);
1519 stat |= vectorRestore<MTwistEngine>(118);
1520 stat |= vectorRestore<RanecuEngine>(139);
1521 stat |= vectorRestore<Ranlux64Engine>(119);
1522 stat |= vectorRestore<RanluxEngine>(120);
1523 stat |= vectorRestore<RanluxppEngine>(159);
1524 stat |= vectorRestore<RanluxEngine>(120);
1525 stat |= vectorRestore<RanshiEngine>(121);
1526 stat |= vectorRestore<TripleRand>(122);
1527 stat |= vectorRestore<NonRandomEngine>(123);
1528 stat |= vectorRestore<RandEngine>(129);
1534 output <<
"\n=============================================\n\n";
1537 std::cout <<
"One or more problems detected: stat = " << stat <<
"\n";
1539 output <<
"ranRestoreTest passed with no problems detected.\n";
virtual std::string name() const =0
static HepRandomEngine * newEngine(std::istream &is)
static void restoreEngineStatus(const char filename[]="Config.conf")
static void setTheEngine(HepRandomEngine *theNewEngine)
static void saveEngineStatus(const char filename[]="Config.conf")
virtual std::ostream & put(std::ostream &os) const
void setRandomSequence(double *s, int n)
static std::string engineName()
static double shoot(double a=1.0, double b=0.2)
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")
HepRandomEngine & engine()
static long shoot(double mean=1.0)
static long shoot(double mean=1.0)
static long shoot(double mean=1.0)
std::ofstream output("ranRestoreTest.cout")
int checkEngineInstanceSave(E &e)
int checkSaveDistribution(D &d, int nth)
int saveEngine(const char *filename)
int anonymousRestoreStatics()
int checkEngineName(const std::string &name)
int checkRandGeneralDistribution(RandGeneral &d, int nth)
void saveStatics(std::string filename)
int staticSaveShootBit(int n)
void randomizeStatics(int n)
void anonymousRestore1(int n, std::vector< double > &v)
int checkSaveEngine(const char *filename)
std::vector< double > aSequence(int n)
int anonymousRestoreStatics1()
int checkSharingDistributions(D1 &d1, D2 &d2, int n1, int n2)
void restoreStatics(std::string filename)
bool equals(double a, double b)
std::vector< double > captureStatics()
bool equals01(const std::vector< double > &ab)
int vectorRestore2(const std::vector< unsigned long > state, const std::vector< double > &v)
void anonymousRestore1< NonRandomEngine >(int n, std::vector< double > &v)
int anonymousRestore2(const std::vector< double > &v)
std::vector< unsigned long > vectorRestore1< NonRandomEngine >(int n, std::vector< double > &v)
std::vector< unsigned long > vectorRestore1(int n, std::vector< double > &v)
int anonymousRestore(int n)