CLHEP 2.0.4.7 Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // $Id: DRand48Engine.h,v 1.3.4.2 2005/04/15 16:32:52 garren Exp $ 00002 // -*- C++ -*- 00003 // 00004 // ----------------------------------------------------------------------- 00005 // HEP Random 00006 // --- DRand48Engine --- 00007 // class header file 00008 // ----------------------------------------------------------------------- 00009 // This file is part of Geant4 (simulation toolkit for HEP). 00010 // 00011 // Random engine using drand48() and srand48() functions from C standard 00012 // library to implement the flat() basic distribution and for setting 00013 // seeds. 00014 // For Windows/NT platforms (WIN32), the code for drand48 has been 00015 // extracted from the GNU C Library 2.0.1 and adapted for the native 00016 // types. 00017 // Copy constructor and operator= are private for objects of this class. 00018 00019 // ======================================================================= 00020 // G.Cosmo - Created: 5th September 1995 00021 // - Minor corrections: 31st October 1996 00022 // - Added methods for engine status: 19th November 1996 00023 // - Added srand48(), seed48(), drand48() implementations 00024 // for Windows/NT: 6th March 1997 00025 // - setSeed(), setSeeds() now have default dummy argument 00026 // set to zero: 11th July 1997 00027 // E.Tcherniaev - Porting on KCC compiler: 2nd Feb 1998 00028 // G.Cosmo - Private copy constructor and operator=: 26th Feb 1998 00029 // J.Marraffino - Added stream operators and related constructor. 00030 // Added automatic seed selection from seed table and 00031 // engine counter: 16th Feb 1998 00032 // E.Tcherniaev - Removed #ifdef for prototypes for drand48(), srand48() 00033 // and seed48(); 00034 // - More accurate code for drand48() on NT base on 00035 // a code extracted from GNU C Library 2.1.3: 8th Nov 2000 00036 // E.Tcherniaev - prototypes for drand48(), srand48() and seed48() have 00037 // been moved to DRand48Engine.cc: 21 Feb 2002 00038 // Mark Fischler - methods for distrib. instance save/restore 12/8/04 00039 // Mark Fischler - methods for anonymous save/restore 12/27/04 00040 // Mark Fischler - methods for vector save/restore 3/7/05 00041 // ======================================================================= 00042 00043 #ifndef DRand48Engine_h 00044 #define DRand48Engine_h 1 00045 00046 #include "CLHEP/Random/defs.h" 00047 #include "CLHEP/Random/RandomEngine.h" 00048 00049 namespace CLHEP { 00050 00055 class DRand48Engine : public HepRandomEngine { 00056 00057 public: 00058 00059 DRand48Engine(std::istream& is); 00060 DRand48Engine(); 00061 DRand48Engine(long seed); 00062 DRand48Engine(int rowIndex, int colIndex); 00063 virtual ~DRand48Engine(); 00064 // Constructors and destructor 00065 00066 double flat(); 00067 // It returns a pseudo random number between 0 and 1, 00068 // according to the standard stdlib random function drand48() 00069 // but excluding the end points. 00070 00071 void flatArray (const int size, double* vect); 00072 // Fills the array "vect" of specified size with flat random values. 00073 00074 void setSeed(long seed, int dum=0); 00075 // Sets the state of the algorithm according to seed. 00076 00077 void setSeeds(const long * seeds, int dum=0); 00078 // Sets the state of the algorithm according to the zero terminated 00079 // array of seeds. Only the first seed is used. 00080 00081 void saveStatus( const char filename[] = "DRand48.conf" ) const; 00082 // Saves on file DRand48.conf the current engine status. 00083 00084 void restoreStatus( const char filename[] = "DRand48.conf" ); 00085 // Reads from file DRand48.conf the last saved engine status 00086 // and restores it. 00087 00088 void showStatus() const; 00089 // Dumps the engine status on the screen. 00090 00091 virtual std::ostream & put (std::ostream & os) const; 00092 virtual std::istream & get (std::istream & is); 00093 static std::string beginTag ( ); 00094 virtual std::istream & getState ( std::istream & is ); 00095 00096 std::string name() const; 00097 static std::string engineName() {return "DRand48Engine";} 00098 00099 std::vector<unsigned long> put () const; 00100 bool get (const std::vector<unsigned long> & v); 00101 bool getState (const std::vector<unsigned long> & v); 00102 00103 static const unsigned int VECTOR_STATE_SIZE = 4; 00104 00105 private: 00106 00107 static int numEngines; 00108 static int maxIndex; 00109 00110 DRand48Engine(const DRand48Engine &p); 00111 DRand48Engine & operator = (const DRand48Engine &p); 00112 // Private copy constructor and assignment operator. 00113 00114 }; 00115 00116 } // namespace CLHEP 00117 00118 #ifdef ENABLE_BACKWARDS_COMPATIBILITY 00119 // backwards compatibility will be enabled ONLY in CLHEP 1.9 00120 using namespace CLHEP; 00121 #endif 00122 00123 #endif