Geant4 Cross Reference |
1 // -*- C++ -*- 2 // 3 // ------------------------------------------------------------------------ 4 // HEP Random 5 // --- HepRandomEngine --- 6 // class implementation file 7 // ------------------------------------------------------------------------ 8 // This file is part of Geant4 (simulation toolkit for HEP). 9 10 // ======================================================================== 11 // Gabriele Cosmo - Created: 5th September 1995 12 // - Minor corrections: 31st October 1996 13 // - Moved table of seeds to HepRandom: 19th March 1998 14 // Ken Smith - Added conversion operators: 6th Aug 1998 15 // ======================================================================= 16 17 #include "CLHEP/Random/RandomEngine.h" 18 #include "CLHEP/Random/EngineFactory.h" 19 20 #include <iostream> 21 #include <vector> 22 23 //------------------------- HepRandomEngine ------------------------------ 24 25 namespace CLHEP { 26 27 HepRandomEngine::HepRandomEngine() 28 : theSeed (19780503L) 29 , theSeeds(&theSeed) 30 { } 31 32 HepRandomEngine::~HepRandomEngine() {} 33 34 HepRandomEngine::operator double() { 35 return flat(); 36 } 37 38 HepRandomEngine::operator float() { 39 return float( flat() ); 40 } 41 42 HepRandomEngine::operator unsigned int() { 43 return (unsigned int)( flat() * exponent_bit_32() ); 44 } 45 46 bool 47 HepRandomEngine::checkFile (std::istream & file, 48 const std::string & filename, 49 const std::string & classname, 50 const std::string & methodname) { 51 if (!file) { 52 std::cerr << "Failure to find or open file " << filename << 53 " in " << classname << "::" << methodname << "()\n"; 54 return false; 55 } 56 return true; 57 } 58 59 std::ostream & HepRandomEngine::put (std::ostream & os) const { 60 std::cerr << "HepRandomEngine::put called -- no effect!\n"; 61 return os; 62 } 63 std::istream & HepRandomEngine::get (std::istream & is) { 64 std::cerr << "HepRandomEngine::get called -- no effect!\n"; 65 return is; 66 } 67 68 std::string HepRandomEngine::beginTag ( ) { 69 return "HepRandomEngine-begin"; 70 } 71 72 std::istream & HepRandomEngine::getState ( std::istream & is ) { 73 std::cerr << "HepRandomEngine::getState called -- no effect!\n"; 74 return is; 75 } 76 77 std::vector<unsigned long> HepRandomEngine::put () const { 78 std::cerr << "v=HepRandomEngine::put() called -- no data!\n"; 79 std::vector<unsigned long> v; 80 return v; 81 } 82 bool HepRandomEngine::get (const std::vector<unsigned long> & ) { 83 std::cerr << "HepRandomEngine::get(v) called -- no effect!\n"; 84 return false; 85 } 86 bool HepRandomEngine::getState (const std::vector<unsigned long> & ) { 87 std::cerr << "HepRandomEngine::getState(v) called -- no effect!\n"; 88 return false; 89 } 90 91 HepRandomEngine* HepRandomEngine::newEngine(std::istream& is) { 92 return EngineFactory::newEngine(is); 93 } 94 95 HepRandomEngine* 96 HepRandomEngine::newEngine(const std::vector<unsigned long> & v) { 97 return EngineFactory::newEngine(v); 98 } 99 100 std::ostream & operator<< (std::ostream & os, const HepRandomEngine & e) { 101 return e.put(os); 102 } 103 104 std::istream & operator>> (std::istream & is, HepRandomEngine & e) { 105 return e.get(is); 106 } 107 108 109 } // namespace CLHEP 110