CLHEP 2.0.4.7 Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // $Id: RandomEngine.cc,v 1.4.4.1 2005/03/18 22:26:48 garren Exp $ 00002 // -*- C++ -*- 00003 // 00004 // ------------------------------------------------------------------------ 00005 // HEP Random 00006 // --- HepRandomEngine --- 00007 // class implementation file 00008 // ------------------------------------------------------------------------ 00009 // This file is part of Geant4 (simulation toolkit for HEP). 00010 00011 // ======================================================================== 00012 // Gabriele Cosmo - Created: 5th September 1995 00013 // - Minor corrections: 31st October 1996 00014 // - Moved table of seeds to HepRandom: 19th March 1998 00015 // Ken Smith - Added conversion operators: 6th Aug 1998 00016 // ======================================================================= 00017 00018 #include "CLHEP/Random/defs.h" 00019 #include "CLHEP/Random/RandomEngine.h" 00020 #include "CLHEP/Random/EngineFactory.h" 00021 #include <cmath> // for pow() 00022 00023 //------------------------- HepRandomEngine ------------------------------ 00024 00025 namespace CLHEP { 00026 00027 HepRandomEngine::HepRandomEngine() 00028 : theSeeds(&theSeed), 00029 exponent_bit_32( pow(2.,32.) ) 00030 { 00031 theSeed = 19780503L; 00032 } 00033 00034 HepRandomEngine::~HepRandomEngine() {} 00035 00036 HepRandomEngine::operator double() { 00037 return flat(); 00038 } 00039 00040 HepRandomEngine::operator float() { 00041 return float( flat() ); 00042 } 00043 00044 HepRandomEngine::operator unsigned int() { 00045 return (unsigned int)( flat() * exponent_bit_32 ); 00046 } 00047 00048 bool 00049 HepRandomEngine::checkFile (std::istream & file, 00050 const std::string & filename, 00051 const std::string & classname, 00052 const std::string & methodname) { 00053 if (!file) { 00054 std::cerr << "Failure to find or open file " << filename << 00055 " in " << classname << "::" << methodname << "()\n"; 00056 return false; 00057 } 00058 return true; 00059 } 00060 00061 std::ostream & HepRandomEngine::put (std::ostream & os) const { 00062 std::cerr << "HepRandomEngine::put called -- no effect!\n"; 00063 return os; 00064 } 00065 std::istream & HepRandomEngine::get (std::istream & is) { 00066 std::cerr << "HepRandomEngine::get called -- no effect!\n"; 00067 return is; 00068 } 00069 00070 std::string HepRandomEngine::beginTag ( ) { 00071 return "HepRandomEngine-begin"; 00072 } 00073 00074 std::istream & HepRandomEngine::getState ( std::istream & is ) { 00075 std::cerr << "HepRandomEngine::getState called -- no effect!\n"; 00076 return is; 00077 } 00078 00079 std::vector<unsigned long> HepRandomEngine::put () const { 00080 std::cerr << "v=HepRandomEngine::put() called -- no data!\n"; 00081 std::vector<unsigned long> v; 00082 return v; 00083 } 00084 bool HepRandomEngine::get (const std::vector<unsigned long> & v) { 00085 std::cerr << "HepRandomEngine::get(v) called -- no effect!\n"; 00086 return false; 00087 } 00088 bool HepRandomEngine::getState (const std::vector<unsigned long> & v) { 00089 std::cerr << "HepRandomEngine::getState(v) called -- no effect!\n"; 00090 return false; 00091 } 00092 00093 HepRandomEngine* HepRandomEngine::newEngine(std::istream& is) { 00094 return EngineFactory::newEngine(is); 00095 } 00096 00097 HepRandomEngine* 00098 HepRandomEngine::newEngine(const std::vector<unsigned long> & v) { 00099 return EngineFactory::newEngine(v); 00100 } 00101 00102 std::ostream & operator<< (std::ostream & os, const HepRandomEngine & e) { 00103 return e.put(os); 00104 } 00105 00106 std::istream & operator>> (std::istream & is, HepRandomEngine & e) { 00107 return e.get(is); 00108 } 00109 00110 00111 } // namespace CLHEP