// -*- C++ -*- // $Id: testEngineCopy.cc,v 1.2 2010/06/16 17:24:53 garren Exp $ // ---------------------------------------------------------------------- #include "CLHEP/Random/Randomize.h" #include "CLHEP/Random/NonRandomEngine.h" #include "CLHEP/Random/defs.h" #include #include #include #define CLEAN_OUTPUT #ifdef CLEAN_OUTPUT std::ofstream output("testEngineCopy.cout"); #else std::ostream & output = std::cout; #endif // Normally on for routine validation: #ifdef TURNOFF #endif #define TEST_ENGINE_COPY #define VERBOSER #define VERBOSER2 using namespace CLHEP; // Absolutely Safe Equals Without Registers Screwing Us Up bool equals01(const std::vector &ab) { return ab[1]==ab[0]; } bool equals(double a, double b) { std::vector ab(2); ab[0]=a; ab[1]=b; return (equals01(ab)); } std::vector aSequence(int n) { std::vector v; DualRand e(13542); RandFlat f(e); for (int i=0; i int vectorTest64(int n) { output << "Copy 64bit test for " << E::engineName() << "\n"; E e; double x = 0; for (int i=0; i int vectorTest64(int n) { output << "Copy 64bit test for " << NonRandomEngine::engineName() << "\n"; std::vector nonRand = aSequence(500); NonRandomEngine e; e.setRandomSequence(&nonRand[0], nonRand.size()); double x = 0; for (int i=0; i v = e.put(); NonRandomEngine f(e); x = e.flat(); output << "x = " << x << std::endl; double y = f.flat(); output << "y = " << y << std::endl; if( x != y ) return n; for( int i=0; i<300; ++i ) { if( e.flat() != f.flat() ) { output << "i = " << i << " vectorTest64 for NonRandomEngine problem: e != f \n"; return n+i; } } return 0; } template E vectorRestore1(int n, std::vector & v) { output << "Copy for " << E::engineName() << "\n"; E e(97538466); double r=0; for (int i=0; i NonRandomEngine vectorRestore1 (int n, std::vector & v) { #ifdef VERBOSER2 output << "Copy for " << NonRandomEngine::engineName() << "\n"; #endif std::vector nonRand = aSequence(500); NonRandomEngine e; e.setRandomSequence(&nonRand[0], nonRand.size()); double r=0; for (int i=0; i int vectorRestore2(E & f, const std::vector & v) { int stat = 0; std::vector k; for (int j=0; j<25; j++) k.push_back(f.flat()); #ifdef VERBOSER2 output << "First four of k are: " << k[0] << ", " << k[1] << ", " << k[2] << ", " << k[3] << "\n"; #endif for (int m=0; m<25; m++) { if ( v[m] != k[m] ) { std::cout << "???? Incorrect copy restored value for engine: " << E::engineName() << "\n"; #ifdef CLEAN_OUTPUT output << "???? Incorrect copy restored value for engine: " << E::engineName() << "\n"; #endif stat |= 1048576; return stat; } } return stat; } template int vectorRestore(int n) { std::vector v; int status1 = vectorTest64(n); E f = vectorRestore1(n,v); int status2 = vectorRestore2(f, v); return (status1 | status2); } // --------------------------------------------- // --------------------------------------------- // --------------------------------------------- int main() { int stat = 0; #ifdef TEST_ENGINE_COPY output << "\n=================================\n"; output << " Part IX \n"; output << " Copy test of engines\n"; output << "=================================\n\n"; stat |= vectorRestore(113); // copies of DRand48Engine are not allowed //stat |= vectorRestore(114); stat |= vectorRestore(115); stat |= vectorRestore(116); stat |= vectorRestore(117); stat |= vectorRestore(118); stat |= vectorRestore(139); stat |= vectorRestore(119); stat |= vectorRestore(120); stat |= vectorRestore(121); stat |= vectorRestore(122); stat |= vectorRestore(123); // anonymous engines are not copyable //stat |= vectorRestore(129); #endif output << "\n=============================================\n\n"; if (stat != 0) { std::cout << "One or more problems detected: stat = " << stat << "\n"; output << "One or more problems detected: stat = " << stat << "\n"; } else { output << "ranRestoreTest passed with no problems detected.\n"; } if (stat == 0) return 0; if (stat > 0) return -(stat|1); return stat|1; }