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
45 using namespace CLHEP;
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";
259 template <
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<MTwistEngine>();
303 stat |= fileNotThereEngine<RandEngine>();
304 stat |= fileNotThereEngine<RanecuEngine>();
305 stat |= fileNotThereEngine<Ranlux64Engine>();
306 stat |= fileNotThereEngine<RanluxEngine>();
307 stat |= fileNotThereEngine<RanshiEngine>();
308 stat |= fileNotThereEngine<TripleRand>();
314 template <
class E,
class D>
321 for (
int i=0;
i<3;
i++) r += D::shoot();
322 D::saveEngineStatus(filename);
323 if (r == -99999999.1) stat = 999;
325 D::setTheEngine(old);
333 template <
class E,
class D>
342 for (
int i=0;
i<3;
i++) r += D::shoot();
343 D::saveEngineStatus();
346 double keyValue = D::shoot();
349 D::restoreEngineStatus(filename);
350 if (!
equals(D::shoot(), keyValue)) {
351 std::cout <<
"???? Value mismatch from file " << filename <<
"\n";
356 D::restoreEngineStatus();
357 if (!
equals(D::shoot(),keyValue)) {
358 std::cout <<
"???? Value mismatch from new-format file \n";
362 D::setTheEngine(old);
372 output << E::engineName() <<
"\n";
373 if (E::engineName() !=
name) {
374 std::cout <<
"???? engineName mismatch for " <<
name <<
" <--> "
375 << E::engineName() <<
"\n";
379 if (e.name() !=
name) {
380 std::cout <<
"???? name mismatch for " <<
name <<
" <--> "
387 template <
class E,
class D>
392 if (d.engine().name() != e.name()) {
393 std::cout <<
"???? Improper d.engine() \n";
402 output <<
"checkEngineInstanceSave for " << e.name() <<
"\n";
403 int pr=
output.precision(20);
405 for (
int i=0;
i<100;
i++) r += e.flat();
406 {std::ofstream os (
"engine.save"); os << e;}
407 for (
int i=0;
i<100;
i++) r += e.flat();
408 double keyValue1 = e.flat();
409 double keyValue2 = e.flat();
411 output << keyValue1 <<
" " << keyValue2 <<
"\n";
414 {std::ifstream
is (
"engine.save");
is >> e2;}
415 for (
int i=0;
i<100;
i++) r += e2.flat();
416 double k1 = e2.flat();
417 double k2 = e2.flat();
419 output << k1 <<
" " << k2 <<
"\n";
421 if ( !(
equals(k1,keyValue1)) || !(
equals(k2,keyValue2)) ) {
422 std::cout <<
"???? checkInstanceSave failed for " << e.name() <<
"\n";
429 template <
class E,
class D>
431 dynamic_cast<E &
>(d.engine());
433 output <<
"checkSaveDistribution with " << d.engine().name()
434 <<
", " << d.name() <<
"\n";
437 double keyValue1, keyValue2, keyValue3, keyValue4;
438 for (
int i=0;
i<nth;
i++) r += d();
439 {std::ofstream os (
"distribution.save1"); os << d.engine() << d;}
444 {std::ofstream os (
"distribution.save2"); os << d.engine() << d;}
447 int pr =
output.precision(20);
449 output <<
"keyValue1 = " << keyValue1 <<
450 " keyValue2 = " << keyValue2 <<
"\n";
451 output <<
"keyValue3 = " << keyValue3 <<
452 " keyValue3 = " << keyValue4 <<
"\n";
457 { std::ifstream
is (
"distribution.save1");
is >> e >> d2;}
460 { std::ifstream
is (
"distribution.save2");
is >> e >> d2;}
464 pr =
output.precision(20);
465 output <<
"k1 = " << k1 <<
466 " k2 = " << k2 <<
"\n";
467 output <<
"k3 = " << k3 <<
468 " k4 = " << k4 <<
"\n";
473 std::cout <<
"???? Incorrect restored value for distribution "
483 dynamic_cast<E &
>(d.
engine());
486 <<
", " << d.
name() <<
"\n";
489 double keyValue1, keyValue2, keyValue3, keyValue4;
490 for (
int i=0;
i<nth;
i++) r += d();
491 {std::ofstream os (
"distribution.save1"); os << d.
engine() << d;}
496 {std::ofstream os (
"distribution.save2"); os << d.
engine() << d;}
499 int pr =
output.precision(20);
501 output <<
"keyValue1 = " << keyValue1 <<
502 " keyValue2 = " << keyValue2 <<
"\n";
503 output <<
"keyValue3 = " << keyValue3 <<
504 " keyValue3 = " << keyValue4 <<
"\n";
510 { std::ifstream
is (
"distribution.save1");
is >> e >> d2;}
513 { std::ifstream
is (
"distribution.save2");
is >> e >> d2;}
517 pr =
output.precision(20);
518 output <<
"k1 = " << k1 <<
519 " k2 = " << k2 <<
"\n";
520 output <<
"k3 = " << k3 <<
521 " k4 = " << k4 <<
"\n";
526 std::cout <<
"???? Incorrect restored value for distribution "
538 stat |= checkSaveDistribution<E,RandGauss> (d,33); }
540 stat |= checkSaveDistribution<E,RandGauss> (d,34); }
542 stat |= checkSaveDistribution<E,RandGaussQ> (d,33); }
544 stat |= checkSaveDistribution<E,RandGaussT> (d,33); }
546 stat |= checkSaveDistribution<E,RandBinomial> (d,33); }
547 {
RandFlat d(
new E(12576),12.5,35.0);
548 stat |= checkSaveDistribution<E,RandFlat> (d,33); }
550 stat |= checkSaveDistribution<E,RandBit> (d,31); }
552 stat |= checkSaveDistribution<E,RandBit> (d,32); }
554 stat |= checkSaveDistribution<E,RandBit> (d,33); }
556 stat |= checkSaveDistribution<E,RandBreitWigner> (d,33); }
558 stat |= checkSaveDistribution<E,RandChiSquare> (d,33); }
560 stat |= checkSaveDistribution<E,RandExponential> (d,33); }
562 stat |= checkSaveDistribution<E,RandGamma> (d,33); }
564 stat |= checkSaveDistribution<E,RandLandau> (d,33); }
566 stat |= checkSaveDistribution<E,RandSkewNormal> (d,33); }
568 stat |= checkSaveDistribution<E,RandStudentT> (d,33); }
575 stat |= checkSaveDistribution<E,RandPoisson> (d,33); }
577 stat |= checkSaveDistribution<E,RandPoisson> (d,34); }
579 stat |= checkSaveDistribution<E,RandPoisson> (d,35); }
581 stat |= checkSaveDistribution<E,RandPoisson> (d,36); }
583 stat |= checkSaveDistribution<E,RandPoisson> (d,37); }
585 stat |= checkSaveDistribution<E,RandPoisson> (d,38); }
587 stat |= checkSaveDistribution<E,RandPoisson> (d,39); }
589 stat |= checkSaveDistribution<E,RandPoissonQ> (d,33); }
591 stat |= checkSaveDistribution<E,RandPoissonQ> (d,32); }
593 stat |= checkSaveDistribution<E,RandPoissonQ> (d,31); }
595 stat |= checkSaveDistribution<E,RandPoissonQ> (d,30); }
597 stat |= checkSaveDistribution<E,RandPoissonQ> (d,33); }
599 stat |= checkSaveDistribution<E,RandPoissonQ> (d,34); }
601 stat |= checkSaveDistribution<E,RandPoissonQ> (d,34); }
603 stat |= checkSaveDistribution<E,RandPoissonT> (d,33); }
605 stat |= checkSaveDistribution<E,RandPoissonT> (d,33); }
607 stat |= checkSaveDistribution<E,RandPoissonT> (d,34); }
609 stat |= checkSaveDistribution<E,RandPoissonT> (d,34); }
611 stat |= checkSaveDistribution<E,RandPoissonT> (d,10); }
613 stat |= checkSaveDistribution<E,RandPoissonT> (d,11); }
615 stat |= checkSaveDistribution<E,RandPoissonT> (d,12); }
617 {std::vector<double> pdf;
619 for (
int i = 0;
i < nbins; ++
i)
620 pdf.push_back( 5*
i + (10.5-
i) * (10.5-
i) );
622 stat |= checkRandGeneralDistribution<E> (d,33); }
627 template <
class E,
class D1,
class D2>
630 output <<
"checkSharingDistribution with: \n"
631 << d1.name() <<
" using " << d1.engine().name() <<
" and\n"
632 << d2.name() <<
" using " << d2.engine().name() <<
"\n";
636 double kv11,kv12,kv13,kv14;
637 double kv21,kv22,kv23,kv24;
638 for (
int i=0;
i<n1;
i++) r += d1();
639 for (
int j=0;
j<n2;
j++) r += d2();
640 {std::ofstream os (
"shared.save1"); os << d1.engine() << d1 << d2;}
647 {std::ofstream os (
"shared.save2"); os << d1.engine() << d1 << d2;}
653 int pr =
output.precision(20);
654 output <<
"kv11 = " << kv11 <<
655 " kv21 = " << kv21 <<
"\n";
656 output <<
"kv12 = " << kv12 <<
657 " kv22 = " << kv22 <<
"\n";
658 output <<
"kv13 = " << kv13 <<
659 " kv23 = " << kv23 <<
"\n";
660 output <<
"kv14 = " << kv14 <<
661 " kv24 = " << kv24 <<
"\n";
667 { std::ifstream
is (
"shared.save1");
is >> e >> d1r >> d2r;}
672 { std::ifstream
is (
"shared.save2");
is >> e >> d1r >> d2r;}
678 pr =
output.precision(20);
679 output <<
"k11 = " << k11 <<
680 " k21 = " << k21 <<
"\n";
681 output <<
"k12 = " << k12 <<
682 " k22 = " << k22 <<
"\n";
683 output <<
"k13 = " << k13 <<
684 " k23 = " << k23 <<
"\n";
685 output <<
"k14 = " << k14 <<
686 " k24 = " << k24 <<
"\n";
693 std::cout <<
"???? Incorrect restored value for distributions "
694 << d1.name() <<
" " << d2.name() <<
"\n";
711 stat |= checkSharingDistributions<E, RandGauss, RandPoissonQ>(g1,p1,5,4);
712 stat |= checkSharingDistributions<E, RandGauss, RandPoissonQ>(g1,p2,6,6);
713 stat |= checkSharingDistributions<E, RandGauss, RandPoissonQ>(g2,p1,8,9);
714 stat |= checkSharingDistributions<E, RandGauss, RandPoissonQ>(g1,p1,7,5);
715 stat |= checkSharingDistributions<E, RandPoissonQ, RandGauss>(p1,g2,5,4);
716 stat |= checkSharingDistributions<E, RandPoissonQ, RandGauss>(p2,g1,6,6);
717 stat |= checkSharingDistributions<E, RandPoissonQ, RandGauss>(p1,g1,8,9);
718 stat |= checkSharingDistributions<E, RandPoissonQ, RandGauss>(p2,g1,7,5);
723 std::vector<double>
v;
726 for (
int i=0;
i<
n;
i++) {
738 output <<
"staticSave for distribution " << D::distributionName() <<
"\n";
740 double v1, v2, k1, k2;
741 for (
i=0;
i <
n;
i++) r += D::shoot();
743 std::ofstream file (
"distribution.save1");
744 D::saveFullState(file);
746 D::saveFullState(file);
749 int pr =
output.precision(20);
750 output <<
"v1 = " << v1 <<
" v2 = " << v2 <<
"\n";
754 for (
i=0;
i <
n;
i++) r += D::shoot();
756 std::ifstream file (
"distribution.save1");
757 D::restoreFullState(file);
759 for (
i=0;
i <
n;
i++) r += D::shoot();
760 D::restoreFullState(file);
763 int pr =
output.precision(20);
764 output <<
"k1 = " << k1 <<
" k2 = " << k2 <<
"\n";
768 if ( (k1 != v1) || (k2 != v2) ) {
769 std::cout <<
"???? restoreFullState failed for " << D::distributionName() <<
"\n";
773 for (
i=0;
i <
n;
i++) r += D::shoot();
775 std::ofstream file (
"distribution.save2");
776 D::saveDistState(file) << *D::getTheEngine();
778 D::saveDistState(file) << *D::getTheEngine();
781 int pr =
output.precision(20);
782 output <<
"v1 = " << v1 <<
" v2 = " << v2 <<
"\n";
786 for (
i=0;
i <
n;
i++) r += D::shoot();
788 std::ifstream file (
"distribution.save2");
789 D::restoreDistState(file) >> *D::getTheEngine();
791 for (
i=0;
i <
n;
i++) r += D::shoot();
792 D::restoreDistState(file) >> *D::getTheEngine();
795 int pr =
output.precision(20);
796 output <<
"k1 = " << k1 <<
" k2 = " << k2 <<
"\n";
800 if ( (k1 != v1) || (k2 != v2) ) {
801 std::cout <<
"???? restoreDistState failed for " << D::distributionName() <<
"\n";
812 output <<
"staticSaveShootBit for " << D::distributionName() <<
"\n";
816 for (
i=0;
i <
n;
i++) r += D::shoot();
817 for (
i=0;
i <
n;
i++) bit |= D::shootBit();
819 std::ofstream file (
"distribution.save1");
820 D::saveFullState(file);
822 for (
i=0;
i<25;
i++) {
826 for (
i=0;
i <
n;
i++) bit |= D::shootBit();
827 D::saveFullState(file);
829 for (
i=0;
i<25;
i++) {
834 int pr =
output.precision(20);
835 output << std::hex <<
"v1 = " << v1 <<
" v2 = " << v2 << std::dec <<
"\n";
839 for (
i=0;
i <
n;
i++) r += D::shoot();
841 std::ifstream file (
"distribution.save1");
842 D::restoreFullState(file);
844 for (
i=0;
i<25;
i++) {
848 for (
i=0;
i <
n;
i++) r += D::shoot();
849 D::restoreFullState(file);
851 for (
i=0;
i<25;
i++) {
856 int pr =
output.precision(20);
857 output << std::hex <<
"k1 = " << k1 <<
" k2 = " << k2 << std::dec <<
"\n";
861 if ( (k1 != v1) || (k2 != v2) ) {
862 std::cout <<
"???? restoreFullState failed for D shootBit()\n";
866 for (
i=0;
i <
n;
i++) r += D::shoot();
867 for (
i=0;
i <
n;
i++) bit |= D::shootBit();
869 std::ofstream file (
"distribution.save2");
870 D::saveDistState(file) << *D::getTheEngine();
872 for (
i=0;
i<25;
i++) {
876 for (
i=0;
i <
n;
i++) bit |= D::shootBit();
877 D::saveDistState(file) << *D::getTheEngine();
879 for (
i=0;
i<25;
i++) {
884 int pr =
output.precision(20);
885 output << std::hex <<
"v1 = " << v1 <<
" v2 = " << v2 << std::dec <<
"\n";
889 for (
i=0;
i <
n;
i++) r += D::shoot();
891 std::ifstream file (
"distribution.save2");
892 D::restoreDistState(file) >> *D::getTheEngine();
894 for (
i=0;
i<25;
i++) {
898 for (
i=0;
i <
n;
i++) r += D::shoot();
899 for (
i=0;
i <
n;
i++) r += D::shootBit();
900 D::restoreDistState(file) >> *D::getTheEngine();
902 for (
i=0;
i<25;
i++) {
907 int pr =
output.precision(20);
908 output << std::hex <<
"k1 = " << k1 <<
" k2 = " << k2 << std::dec <<
"\n";
912 if ( (k1 != v1) || (k2 != v2) ) {
913 std::cout <<
"???? restoreDistState failed for RnadFlat::shootBit()\n";
923 for (
int i=0;
i<
n;
i++) {
946 std::vector<double> c;
952 for (
int i=0;
i<20;
i++) {
971 std::ofstream os(filename.c_str());
979 std::ifstream
is(filename.c_str());
987 output <<
"Anonymous restore for " << E::engineName() <<
"\n";
990 for (
int i=0;
i<
n;
i++) r += e.flat();
991 std::ofstream os(
"anonymous.save");
993 for (
int j=0;
j<25;
j++)
v.push_back(e.flat());
995 output <<
"First four of v are: "
996 <<
v[0] <<
", " <<
v[1] <<
", " <<
v[2] <<
", " <<
v[3] <<
"\n";
1006 std::vector<double> nonRand =
aSequence(500);
1010 for (
int i=0;
i<
n;
i++) r += e.
flat();
1011 std::ofstream os(
"anonymous.save");
1013 for (
int j=0;
j<25;
j++)
v.push_back(e.flat());
1015 output <<
"First four of v are: "
1016 <<
v[0] <<
", " <<
v[1] <<
", " <<
v[2] <<
", " <<
v[3] <<
"\n";
1024 std::vector<double>
k;
1025 std::ifstream
is(
"anonymous.save");
1028 for (
int j=0;
j<25;
j++)
k.push_back(
a->flat());
1031 output <<
"First four of k are: "
1032 <<
k[0] <<
", " <<
k[1] <<
", " <<
k[2] <<
", " <<
k[3] <<
"\n";
1034 for (
int m=0; m<25; m++) {
1035 if (
v[m] !=
k[m] ) {
1036 std::cout <<
"???? Incorrect restored value for anonymous engine"
1037 << E::engineName() <<
"\n";
1048 std::vector<double>
v;
1049 anonymousRestore1<E>(
n,
v);
1050 return anonymousRestore2<E>(
v);
1061 output <<
"\nRandomized, with theEngine = " << e->
name() <<
"\n";
1063 output <<
"Saved all static distributions\n";
1065 output <<
"Captured output of all static distributions\n";
1067 output <<
"Randomized all static distributions\n";
1069 output <<
"Restored all static distributions to saved state\n";
1071 output <<
"Captured output of all static distributions\n";
1072 for (
unsigned int iv=0; iv<c.size(); iv++) {
1073 if (c[iv] != d[iv]) {
1074 std::cout <<
"???? restoreStaticRandomStates failed at random "
1079 if (stat & 131072 == 0) {
1080 output <<
"All captured output agrees with earlier values\n";
1087 template <
class E1,
class E2>
1090 if ( E1::engineName() == E2::engineName() ) {
1091 return anonymousRestoreStatics1<E1>();
1096 output <<
"\nRandomized, with theEngine = " << e1->
name() <<
"\n";
1099 output <<
"Saved all static distributions\n";
1103 output <<
"Captured output of all static distributions\n";
1108 output <<
"Switched to theEngine = " << e2->
name() <<
"\n";
1110 { std::ofstream os(
"engine.save"); os << *e2; }
1111 double v1 = e2->
flat();
1112 double v2 = e2->
flat();
1113 { std::ifstream
is(
"engine.save");
is >> *e2; }
1115 output <<
"Saved the " << e2->
name() <<
" engine: \n"
1116 <<
"Next randoms to be " << v1 <<
" " << v2 <<
"\n"
1117 <<
"Restored the " << e2->
name() <<
" engine to that state\n";
1121 output <<
"Restored all static distributions to saved state\n"
1122 <<
"This changes the engine type back to " << E1::engineName() <<
"\n";
1126 output <<
"Captured output of all static distributions\n";
1128 for (
unsigned int iv=0; iv<c.size(); iv++) {
1129 if (c[iv] != d[iv]) {
1130 std::cout <<
"???? restoreStaticRandomStates failed at random "
1135 if (stat & 524288 == 0) {
1136 output <<
"All captured output agrees with earlier values\n";
1138 double k1 = e2->
flat();
1139 double k2 = e2->
flat();
1141 output <<
"The " << e2->
name() <<
" engine should not have been affected: \n"
1142 <<
"Next randoms are " << k1 <<
" " << k2 <<
"\n";
1145 std::cout <<
"???? Engine used as theEngine was affected by restoring \n"
1146 <<
" static distributions to use engine of a different type.\n";
1156 output <<
"Vector restore for " << E::engineName() <<
"\n";
1159 for (
int i=0;
i<
n;
i++) r += e.flat();
1160 std::vector<unsigned long>
state = e.put();
1161 for (
int j=0;
j<25;
j++)
v.push_back(e.flat());
1163 output <<
"First four of v are: "
1164 <<
v[0] <<
", " <<
v[1] <<
", " <<
v[2] <<
", " <<
v[3] <<
"\n";
1170 std::vector<unsigned long>
1175 std::vector<double> nonRand =
aSequence(500);
1179 for (
int i=0;
i<
n;
i++) r += e.
flat();
1180 std::vector<unsigned long>
state = e.
put();
1181 for (
int j=0;
j<25;
j++)
v.push_back(e.
flat());
1183 output <<
"First four of v are: "
1184 <<
v[0] <<
", " <<
v[1] <<
", " <<
v[2] <<
", " <<
v[3] <<
"\n";
1191 const std::vector<double> &
v) {
1193 std::vector<double>
k;
1197 std::cout <<
"???? could not restore engine state from vector for "
1198 << E::engineName() <<
"\n";
1202 if (
a->name() != E::engineName()) {
1203 std::cout <<
"???? restored engine state from vector for "
1204 << E::engineName() <<
"to different type of engine: "
1205 <<
a->name() <<
"\n"
1206 <<
"There is probably a clash in CRC hashes for these two names!\n";
1210 for (
int j=0;
j<25;
j++)
k.push_back(
a->flat());
1213 output <<
"First four of k are: "
1214 <<
k[0] <<
", " <<
k[1] <<
", " <<
k[2] <<
", " <<
k[3] <<
"\n";
1216 for (
int m=0; m<25; m++) {
1217 if (
v[m] !=
k[m] ) {
1218 std::cout <<
"???? Incorrect vector restored value for anonymous engine: "
1219 << E::engineName() <<
"\n";
1230 std::vector<double>
v;
1231 std::vector<unsigned long>
state = vectorRestore1<E>(
n,
v);
1232 return vectorRestore2<E>(
state,
v);
1245 #ifdef TEST_ORIGINAL_SAVE
1246 output <<
"=====================================\n";
1248 output <<
"Original tests of static save/restore\n";
1249 output <<
"=====================================\n\n";
1251 output <<
"Using old method or HepRandom::saveEngineStatus:\n";
1252 output <<
"All these tests should have a chance of failure.\n";
1262 output <<
"Using the class-specific RandGauss::saveEngineStatus:\n";
1263 output <<
"All these tests should work properly.\n";
1271 #ifdef TEST_MISSING_FILES
1272 output <<
"\n=======================================\n";
1274 output <<
"Test of behavior when a file is missing \n";
1275 output <<
"=======================================\n\n";
1277 output <<
"Testing restoreEngineStatus with missing file:\n";
1278 output <<
"Expect a number of <Failure to find or open> messages!\n";
1282 #ifdef CREATE_OLD_SAVES
1283 stat |= saveEngine<DRand48Engine, RandPoisson>(
"DRand48Engine.oldsav");
1284 stat |= saveEngine<DualRand, RandPoisson>(
"DualRand.oldsav");
1285 stat |= saveEngine<Hurd160Engine, RandPoisson>(
"Hurd160Engine.oldsav");
1286 stat |= saveEngine<Hurd288Engine, RandPoisson>(
"Hurd288Engine.oldsav");
1287 stat |= saveEngine<HepJamesRandom,RandPoisson>(
"HepJamesRandom.oldsav");
1288 stat |= saveEngine<MTwistEngine, RandPoisson>(
"MTwistEngine.oldsav");
1289 stat |= saveEngine<RanecuEngine, RandPoisson>(
"RanecuEngine.oldsav");
1290 stat |= saveEngine<Ranlux64Engine,RandPoisson>(
"Ranlux64Engine.oldsav");
1291 stat |= saveEngine<RanluxEngine, RandPoisson>(
"RanluxEngine.oldsav");
1292 stat |= saveEngine<RanshiEngine, RandPoisson>(
"RanshiEngine.oldsav");
1293 stat |= saveEngine<TripleRand, RandPoisson>(
"TripleRand.oldsav");
1296 #ifdef VERIFY_OLD_SAVES
1297 output <<
"\n==============================================\n";
1299 output <<
" Verification that changes wont invalidate \n";
1300 output <<
"invalidate engine saves from previous versions \n";
1301 output <<
"==============================================\n\n";
1303 stat |= checkSaveEngine<DRand48Engine, RandPoisson>(
"DRand48Engine.oldsav");
1304 stat |= checkSaveEngine<DualRand, RandPoisson>(
"DualRand.oldsav");
1305 stat |= checkSaveEngine<Hurd160Engine, RandPoisson>(
"Hurd160Engine.oldsav");
1306 stat |= checkSaveEngine<Hurd288Engine, RandPoisson>(
"Hurd288Engine.oldsav");
1307 stat |= checkSaveEngine<HepJamesRandom,RandPoisson>(
"HepJamesRandom.oldsav");
1308 stat |= checkSaveEngine<MTwistEngine, RandPoisson>(
"MTwistEngine.oldsav");
1309 stat |= checkSaveEngine<Ranlux64Engine,RandPoisson>(
"Ranlux64Engine.oldsav");
1310 stat |= checkSaveEngine<RanluxEngine, RandPoisson>(
"RanluxEngine.oldsav");
1311 stat |= checkSaveEngine<RanshiEngine, RandPoisson>(
"RanshiEngine.oldsav");
1312 stat |= checkSaveEngine<TripleRand, RandPoisson>(
"TripleRand.oldsav");
1313 stat |= checkSaveEngine<RanecuEngine, RandPoisson>(
"RanecuEngine.oldsav");
1316 #ifdef TEST_ENGINE_NAMES
1317 output <<
"\n=============================================\n";
1319 output <<
"Check all engine names were entered correctly \n";
1320 output <<
"=============================================\n\n";
1322 stat |= checkEngineName<DRand48Engine >(
"DRand48Engine");
1323 stat |= checkEngineName<DualRand >(
"DualRand");
1324 stat |= checkEngineName<Hurd160Engine >(
"Hurd160Engine");
1325 stat |= checkEngineName<Hurd288Engine >(
"Hurd288Engine");
1326 stat |= checkEngineName<HepJamesRandom>(
"HepJamesRandom");
1327 stat |= checkEngineName<MTwistEngine >(
"MTwistEngine");
1328 stat |= checkEngineName<RandEngine >(
"RandEngine");
1329 stat |= checkEngineName<RanecuEngine >(
"RanecuEngine");
1330 stat |= checkEngineName<Ranlux64Engine>(
"Ranlux64Engine");
1331 stat |= checkEngineName<RanluxEngine >(
"RanluxEngine");
1332 stat |= checkEngineName<RanshiEngine >(
"RanshiEngine");
1333 stat |= checkEngineName<TripleRand >(
"TripleRand");
1336 #ifdef TEST_INSTANCE_METHODS
1337 output <<
"===========================================\n\n";
1339 output <<
"Check instance methods for specific engines \n";
1340 output <<
" specific engines and distributions\n";
1341 output <<
"===========================================\n\n";
1355 {std::vector<double> nonRand =
aSequence(500);
1360 stat |= checkDistributions<DualRand>();
1361 stat |= checkDistributions<Hurd160Engine>();
1362 stat |= checkDistributions<Hurd288Engine>();
1363 stat |= checkDistributions<HepJamesRandom>();
1364 stat |= checkDistributions<MTwistEngine>();
1365 stat |= checkDistributions<Ranlux64Engine>();
1366 stat |= checkDistributions<RanluxEngine>();
1367 stat |= checkDistributions<RanshiEngine>();
1368 stat |= checkDistributions<TripleRand>();
1373 #ifdef TEST_SHARED_ENGINES
1374 output <<
"\n=============================================\n";
1376 output <<
"Check behavior when engines are shared \n";
1377 output <<
"=============================================\n\n";
1379 stat |= checkSharing<DualRand>();
1380 stat |= checkSharing<Hurd160Engine>();
1381 stat |= checkSharing<Hurd288Engine>();
1382 stat |= checkSharing<HepJamesRandom>();
1383 stat |= checkSharing<MTwistEngine>();
1384 stat |= checkSharing<Ranlux64Engine>();
1385 stat |= checkSharing<RanluxEngine>();
1386 stat |= checkSharing<RanshiEngine>();
1387 stat |= checkSharing<TripleRand>();
1390 #ifdef TEST_STATIC_SAVE
1391 output <<
"\n=========================================\n";
1393 output <<
"Static Save/restore to/from streams \n";
1394 output <<
"=========================================\n\n";
1396 stat |= staticSave <RandGauss>(7);
1397 stat |= staticSave <RandFlat>(7);
1398 stat |= staticSaveShootBit<RandFlat> (19);
1399 stat |= staticSaveShootBit<RandBit> (23);
1400 for (
int ibinom=0; ibinom<15; ibinom++) {
1401 stat |= staticSave <RandBinomial>(7+3*ibinom);
1403 stat |= staticSave <RandBreitWigner>(7);
1404 stat |= staticSave <RandChiSquare>(7);
1405 stat |= staticSave <RandExponential>(7);
1406 stat |= staticSave <RandGamma>(7);
1407 stat |= staticSave <RandGaussQ>(7);
1408 stat |= staticSave <RandGaussT>(7);
1409 stat |= staticSave <RandLandau>(7);
1410 stat |= staticSave <RandPoisson>(7);
1411 stat |= staticSave <RandPoissonQ>(7);
1412 stat |= staticSave <RandPoissonT>(7);
1413 stat |= staticSave <RandSkewNormal>(7);
1414 stat |= staticSave <RandStudentT>(7);
1417 #ifdef TEST_SAVE_STATIC_STATES
1418 output <<
"\n==============================================\n";
1420 output <<
"Save/restore all static states to/from streams \n";
1421 output <<
"==============================================\n\n";
1425 output <<
"Saved all static distributions\n";
1427 output <<
"Captured output of all static distributions\n";
1429 output <<
"Randomized all static distributions\n";
1431 output <<
"Restored all static distributions to saved state\n";
1433 output <<
"Captured output of all static distributions\n";
1434 for (
unsigned int iv=0; iv<c.size(); iv++) {
1435 if (c[iv] != d[iv]) {
1436 std::cout <<
"???? restoreStaticRandomStates failed at random "
1441 if (stat & 131072 == 0) {
1442 output <<
"All captured output agrees with earlier values\n";
1446 #ifdef TEST_ANONYMOUS_ENGINE_RESTORE
1447 output <<
"\n=================================\n";
1448 output <<
" Part VII \n";
1449 output <<
"Anonymous restore of engines \n";
1450 output <<
"=================================\n\n";
1452 stat |= anonymousRestore<DualRand>(13);
1453 stat |= anonymousRestore<DRand48Engine>(14);
1454 stat |= anonymousRestore<Hurd160Engine>(15);
1455 stat |= anonymousRestore<Hurd288Engine>(16);
1456 stat |= anonymousRestore<HepJamesRandom>(17);
1457 stat |= anonymousRestore<MTwistEngine>(18);
1458 stat |= anonymousRestore<RandEngine>(29);
1459 stat |= anonymousRestore<RanecuEngine>(39);
1460 stat |= anonymousRestore<Ranlux64Engine>(19);
1461 stat |= anonymousRestore<RanluxEngine>(20);
1462 stat |= anonymousRestore<RanshiEngine>(21);
1463 stat |= anonymousRestore<TripleRand>(22);
1464 stat |= anonymousRestore<NonRandomEngine>(22);
1467 #ifdef TEST_ANONYMOUS_RESTORE_STATICS
1468 output <<
"\n======================================\n";
1469 output <<
" Part VIII \n";
1470 output <<
"Anonymous restore static Distributions \n";
1471 output <<
"======================================\n\n";
1473 stat |= anonymousRestoreStatics<DualRand, Ranlux64Engine> ( );
1474 stat |= anonymousRestoreStatics<DRand48Engine, TripleRand> ( );
1475 stat |= anonymousRestoreStatics<RandEngine, Ranlux64Engine> ( );
1476 stat |= anonymousRestoreStatics<MTwistEngine, Hurd288Engine> ( );
1477 stat |= anonymousRestoreStatics<RanecuEngine, MTwistEngine> ( );
1478 stat |= anonymousRestoreStatics<HepJamesRandom, RanshiEngine> ( );
1479 stat |= anonymousRestoreStatics<RanecuEngine, RandEngine> ( );
1480 stat |= anonymousRestoreStatics<RanshiEngine, Hurd160Engine> ( );
1481 stat |= anonymousRestoreStatics<TripleRand, DualRand> ( );
1482 stat |= anonymousRestoreStatics<Hurd160Engine, HepJamesRandom> ( );
1483 stat |= anonymousRestoreStatics<Hurd288Engine, RanecuEngine> ( );
1484 stat |= anonymousRestoreStatics<HepJamesRandom, Ranlux64Engine> ( );
1485 stat |= anonymousRestoreStatics<TripleRand, TripleRand> ( );
1486 stat |= anonymousRestoreStatics<HepJamesRandom, HepJamesRandom> ( );
1489 #ifdef TEST_VECTOR_ENGINE_RESTORE
1490 output <<
"\n=================================\n";
1492 output <<
"Save/restore of engines to vectors\n";
1493 output <<
"=================================\n\n";
1495 stat |= vectorRestore<DualRand>(113);
1496 stat |= vectorRestore<DRand48Engine>(114);
1497 stat |= vectorRestore<Hurd160Engine>(115);
1498 stat |= vectorRestore<Hurd288Engine>(116);
1499 stat |= vectorRestore<HepJamesRandom>(117);
1500 stat |= vectorRestore<MTwistEngine>(118);
1501 stat |= vectorRestore<RanecuEngine>(139);
1502 stat |= vectorRestore<Ranlux64Engine>(119);
1503 stat |= vectorRestore<RanluxEngine>(120);
1504 stat |= vectorRestore<RanshiEngine>(121);
1505 stat |= vectorRestore<TripleRand>(122);
1506 stat |= vectorRestore<NonRandomEngine>(123);
1507 stat |= vectorRestore<RandEngine>(129);
1513 output <<
"\n=============================================\n\n";
1516 std::cout <<
"One or more problems detected: stat = " << stat <<
"\n";
1518 output <<
"ranRestoreTest passed with no problems detected.\n";