CLHEP/Random/DRand48Engine.h

00001 // $Id: DRand48Engine.h,v 1.20 2002/04/12 15:02:44 evc 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 // =======================================================================
00039 
00040 #ifndef DRand48Engine_h
00041 #define DRand48Engine_h 1
00042 
00043 #include "CLHEP/Random/RandomEngine.h"
00044 
00049 class DRand48Engine : public HepRandomEngine {
00050 
00051 public:
00052 
00053   DRand48Engine(HepStd::istream& is);
00054   DRand48Engine();
00055   DRand48Engine(long seed);
00056   DRand48Engine(int rowIndex, int colIndex);
00057   virtual ~DRand48Engine();
00058   // Constructors and destructor
00059 
00060   double flat();
00061   // It returns a pseudo random number between 0 and 1,
00062   // according to the standard stdlib random function drand48()
00063   // but excluding the end points.
00064 
00065   void flatArray (const int size, double* vect);
00066   // Fills the array "vect" of specified size with flat random values.
00067 
00068   void setSeed(long seed, int dum=0);
00069   // Sets the state of the algorithm according to seed.
00070 
00071   void setSeeds(const long * seeds, int dum=0);
00072   // Sets the state of the algorithm according to the zero terminated
00073   // array of seeds. Only the first seed is used.
00074 
00075   void saveStatus( const char filename[] = "DRand48.conf" ) const;
00076   // Saves on file DRand48.conf the current engine status.
00077 
00078   void restoreStatus( const char filename[] = "DRand48.conf" );
00079   // Reads from file DRand48.conf the last saved engine status
00080   // and restores it.
00081 
00082   void showStatus() const;
00083   // Dumps the engine status on the screen.
00084 
00085   friend HepStd::ostream& operator<< (HepStd::ostream& os, const DRand48Engine& e);
00086   friend HepStd::istream& operator>> (HepStd::istream& is,       DRand48Engine& e);
00087 
00088 private:
00089 
00090   static int  numEngines;
00091   static int  maxIndex;
00092 
00093   DRand48Engine(const DRand48Engine &p);
00094   DRand48Engine & operator = (const DRand48Engine &p);
00095   // Private copy constructor and assignment operator.
00096 
00097 };
00098 
00099 #endif

Class Library for High Energy Physics (version 1.8)