Geant4 Cross Reference |
1 // -*- C++ -*- 1 // -*- C++ -*- 2 // 2 // 3 // ------------------------------------------- 3 // ----------------------------------------------------------------------- 4 // HEP Random 4 // HEP Random 5 // --- EngineFactory --- 5 // --- EngineFactory --- 6 // class implementation f 6 // class implementation file 7 // ------------------------------------------- 7 // ----------------------------------------------------------------------- 8 // 8 // 9 // =========================================== 9 // ======================================================================= 10 // Mark Fischler - Created: Dec. 21, 2004 10 // Mark Fischler - Created: Dec. 21, 2004 11 // =========================================== 11 // ======================================================================= 12 12 13 #include "CLHEP/Random/EngineFactory.h" 13 #include "CLHEP/Random/EngineFactory.h" 14 #include "CLHEP/Random/DualRand.h" 14 #include "CLHEP/Random/DualRand.h" 15 #include "CLHEP/Random/JamesRandom.h" 15 #include "CLHEP/Random/JamesRandom.h" 16 #include "CLHEP/Random/MixMaxRng.h" 16 #include "CLHEP/Random/MixMaxRng.h" 17 #include "CLHEP/Random/MTwistEngine.h" 17 #include "CLHEP/Random/MTwistEngine.h" 18 #include "CLHEP/Random/RanecuEngine.h" 18 #include "CLHEP/Random/RanecuEngine.h" 19 #include "CLHEP/Random/Ranlux64Engine.h" 19 #include "CLHEP/Random/Ranlux64Engine.h" 20 #include "CLHEP/Random/RanluxppEngine.h" 20 #include "CLHEP/Random/RanluxppEngine.h" 21 #include "CLHEP/Random/RanluxEngine.h" 21 #include "CLHEP/Random/RanluxEngine.h" 22 #include "CLHEP/Random/RanshiEngine.h" 22 #include "CLHEP/Random/RanshiEngine.h" 23 #include "CLHEP/Random/NonRandomEngine.h" 23 #include "CLHEP/Random/NonRandomEngine.h" 24 #include "CLHEP/Random/engineIDulong.h" 24 #include "CLHEP/Random/engineIDulong.h" 25 #include <iostream> 25 #include <iostream> 26 #include <string> 26 #include <string> 27 #include <vector> 27 #include <vector> 28 28 29 namespace CLHEP { 29 namespace CLHEP { 30 30 31 template<class E> 31 template<class E> 32 static HepRandomEngine* 32 static HepRandomEngine* 33 makeAnEngine (const std::string & tag, 33 makeAnEngine (const std::string & tag, 34 std::istream & is) { 34 std::istream & is) { 35 if ( tag != E::beginTag() ) return 0; 35 if ( tag != E::beginTag() ) return 0; 36 HepRandomEngine* eptr = new E; 36 HepRandomEngine* eptr = new E; 37 eptr->getState(is); 37 eptr->getState(is); 38 if (!is) return 0; 38 if (!is) return 0; 39 return eptr; 39 return eptr; 40 } 40 } 41 41 42 template<class E> 42 template<class E> 43 static HepRandomEngine* 43 static HepRandomEngine* 44 makeAnEngine (const std::vector<unsigned long> 44 makeAnEngine (const std::vector<unsigned long> & v) { 45 if ( (v[0] & 0xffffffffUL) != engineIDulong< 45 if ( (v[0] & 0xffffffffUL) != engineIDulong<E>() ) return 0; 46 HepRandomEngine* eptr = new E; 46 HepRandomEngine* eptr = new E; 47 bool success = eptr->getState(v); 47 bool success = eptr->getState(v); 48 if (!success) return 0; 48 if (!success) return 0; 49 // std::cerr << "makeAnEngine made " << E::e 49 // std::cerr << "makeAnEngine made " << E::engineName() << "\n"; 50 return eptr; 50 return eptr; 51 } 51 } 52 52 53 HepRandomEngine* EngineFactory::newEngine(std: 53 HepRandomEngine* EngineFactory::newEngine(std::istream& is) { 54 HepRandomEngine* eptr; 54 HepRandomEngine* eptr; 55 std::string tag; 55 std::string tag; 56 is >> tag; 56 is >> tag; 57 eptr = makeAnEngine <HepJamesRandom> (tag, 57 eptr = makeAnEngine <HepJamesRandom> (tag, is); if (eptr) return eptr; 58 eptr = makeAnEngine <RanecuEngine> (tag, 58 eptr = makeAnEngine <RanecuEngine> (tag, is); if (eptr) return eptr; 59 eptr = makeAnEngine <Ranlux64Engine> (tag, 59 eptr = makeAnEngine <Ranlux64Engine> (tag, is); if (eptr) return eptr; 60 eptr = makeAnEngine <RanluxppEngine> (tag, 60 eptr = makeAnEngine <RanluxppEngine> (tag, is); if (eptr) return eptr; 61 eptr = makeAnEngine <MixMaxRng> (tag, 61 eptr = makeAnEngine <MixMaxRng> (tag, is); if (eptr) return eptr; 62 eptr = makeAnEngine <MTwistEngine> (tag, 62 eptr = makeAnEngine <MTwistEngine> (tag, is); if (eptr) return eptr; 63 eptr = makeAnEngine <DualRand> (tag, 63 eptr = makeAnEngine <DualRand> (tag, is); if (eptr) return eptr; 64 eptr = makeAnEngine <RanluxEngine> (tag, 64 eptr = makeAnEngine <RanluxEngine> (tag, is); if (eptr) return eptr; 65 eptr = makeAnEngine <RanshiEngine> (tag, 65 eptr = makeAnEngine <RanshiEngine> (tag, is); if (eptr) return eptr; 66 eptr = makeAnEngine <NonRandomEngine> (tag, 66 eptr = makeAnEngine <NonRandomEngine> (tag, is); if (eptr) return eptr; 67 is.clear(std::ios::badbit | is.rdstate()); 67 is.clear(std::ios::badbit | is.rdstate()); 68 std::cerr << 68 std::cerr << 69 "Input mispositioned or bad in reading ano 69 "Input mispositioned or bad in reading anonymous engine\n" 70 << "\nBegin-tag read was: " << tag 70 << "\nBegin-tag read was: " << tag 71 << "\nInput stream is probably fouled up 71 << "\nInput stream is probably fouled up\n"; 72 return eptr; 72 return eptr; 73 } 73 } 74 74 75 HepRandomEngine* 75 HepRandomEngine* 76 EngineFactory::newEngine(std::vector<unsigned 76 EngineFactory::newEngine(std::vector<unsigned long> const & v) { 77 HepRandomEngine* eptr; 77 HepRandomEngine* eptr; 78 eptr = makeAnEngine <HepJamesRandom> (v); i 78 eptr = makeAnEngine <HepJamesRandom> (v); if (eptr) return eptr; 79 eptr = makeAnEngine <RanecuEngine> (v); i 79 eptr = makeAnEngine <RanecuEngine> (v); if (eptr) return eptr; 80 eptr = makeAnEngine <Ranlux64Engine> (v); i 80 eptr = makeAnEngine <Ranlux64Engine> (v); if (eptr) return eptr; 81 eptr = makeAnEngine <RanluxppEngine> (v); i 81 eptr = makeAnEngine <RanluxppEngine> (v); if (eptr) return eptr; 82 eptr = makeAnEngine <MixMaxRng> (v); i 82 eptr = makeAnEngine <MixMaxRng> (v); if (eptr) return eptr; 83 eptr = makeAnEngine <MTwistEngine> (v); i 83 eptr = makeAnEngine <MTwistEngine> (v); if (eptr) return eptr; 84 eptr = makeAnEngine <DualRand> (v); i 84 eptr = makeAnEngine <DualRand> (v); if (eptr) return eptr; 85 eptr = makeAnEngine <RanluxEngine> (v); i 85 eptr = makeAnEngine <RanluxEngine> (v); if (eptr) return eptr; 86 eptr = makeAnEngine <RanshiEngine> (v); i 86 eptr = makeAnEngine <RanshiEngine> (v); if (eptr) return eptr; 87 eptr = makeAnEngine <NonRandomEngine> (v); i 87 eptr = makeAnEngine <NonRandomEngine> (v); if (eptr) return eptr; 88 std::cerr << 88 std::cerr << 89 "Cannot correctly get anonymous engine fro 89 "Cannot correctly get anonymous engine from vector\n" 90 << "First unsigned long was: " << v[0] 90 << "First unsigned long was: " << v[0] 91 << " Vector size was: " << v.size() <<"\ 91 << " Vector size was: " << v.size() <<"\n"; 92 return eptr; 92 return eptr; 93 } 93 } 94 94 95 } // namespace CLHEP 95 } // namespace CLHEP 96 96 97 97