Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:37

0001 // $Id: DRand48Engine.h,v 1.5 2010/06/16 17:24:53 garren Exp $
0002 // -*- C++ -*-
0003 //
0004 // -----------------------------------------------------------------------
0005 //                             HEP Random
0006 //                        --- DRand48Engine ---
0007 //                          class header file
0008 // -----------------------------------------------------------------------
0009 // This file is part of Geant4 (simulation toolkit for HEP).
0010 //
0011 // Random engine using drand48() and srand48() functions from C standard
0012 // library to implement the flat() basic distribution and for setting
0013 // seeds.
0014 // For Windows/NT platforms (WIN32), the code for drand48 has been
0015 // extracted from the GNU C Library 2.0.1 and adapted for the native
0016 // types.
0017 // Copy constructor and operator= are private for objects of this class.
0018 //
0019 // WARNING: drand48 is not thread safe. If you need to use multiple
0020 // engine objects on different threads concurrently, do not use DRand48Engine
0021 
0022 // =======================================================================
0023 // G.Cosmo        - Created: 5th September 1995
0024 //                - Minor corrections: 31st October 1996
0025 //                - Added methods for engine status: 19th November 1996
0026 //                - Added srand48(), seed48(), drand48() implementations
0027 //                  for Windows/NT: 6th March 1997
0028 //                - setSeed(), setSeeds() now have default dummy argument
0029 //                  set to zero: 11th July 1997
0030 // E.Tcherniaev   - Porting on KCC compiler: 2nd Feb 1998
0031 // G.Cosmo        - Private copy constructor and operator=: 26th Feb 1998
0032 // J.Marraffino   - Added stream operators and related constructor.
0033 //                  Added automatic seed selection from seed table and
0034 //                  engine counter: 16th Feb 1998
0035 // E.Tcherniaev   - Removed #ifdef for prototypes for drand48(), srand48()
0036 //                  and seed48();
0037 //                - More accurate code for drand48() on NT base on
0038 //                  a code extracted from GNU C Library 2.1.3: 8th Nov 2000
0039 // E.Tcherniaev   - prototypes for drand48(), srand48() and seed48() have
0040 //                  been moved to DRand48Engine.cc: 21 Feb 2002
0041 // Mark Fischler  - methods for distrib. instance save/restore 12/8/04    
0042 // Mark Fischler  - methods for anonymous save/restore 12/27/04 
0043 // Mark Fischler  - methods for vector save/restore 3/7/05    
0044 // =======================================================================
0045 
0046 #ifndef DRand48Engine_h
0047 #define DRand48Engine_h 1
0048 
0049 #include "CLHEP/Random/defs.h"
0050 #include "CLHEP/Random/RandomEngine.h"
0051 #include "CLHEP/Utility/noncopyable.h"
0052 
0053 namespace CLHEP {
0054 
0055 /**
0056  * @author <Gabriele.Cosmo@cern.ch>
0057  * @ingroup random
0058  */
0059 class DRand48Engine : public HepRandomEngine, public noncopyable {
0060 
0061 public:
0062 
0063   DRand48Engine(std::istream& is);
0064   DRand48Engine();
0065   DRand48Engine(long seed);
0066   DRand48Engine(int rowIndex, int colIndex);
0067   virtual ~DRand48Engine();
0068   // Constructors and destructor
0069 
0070   double flat();
0071   // It returns a pseudo random number between 0 and 1,
0072   // according to the standard stdlib random function drand48()
0073   // but excluding the end points.
0074 
0075   void flatArray (const int size, double* vect);
0076   // Fills the array "vect" of specified size with flat random values.
0077 
0078   void setSeed(long seed, int dum=0);
0079   // Sets the state of the algorithm according to seed.
0080 
0081   void setSeeds(const long * seeds, int dum=0);
0082   // Sets the state of the algorithm according to the zero terminated
0083   // array of seeds. Only the first seed is used.
0084 
0085   void saveStatus( const char filename[] = "DRand48.conf" ) const;
0086   // Saves on file DRand48.conf the current engine status.
0087 
0088   void restoreStatus( const char filename[] = "DRand48.conf" );
0089   // Reads from file DRand48.conf the last saved engine status
0090   // and restores it.
0091 
0092   void showStatus() const;
0093   // Dumps the engine status on the screen.
0094 
0095   virtual std::ostream & put (std::ostream & os) const;
0096   virtual std::istream & get (std::istream & is);
0097   static  std::string beginTag ( );
0098   virtual std::istream & getState ( std::istream & is );
0099 
0100   std::string name() const;
0101   static std::string engineName() {return "DRand48Engine";}
0102 
0103   std::vector<unsigned long> put () const;
0104   bool get (const std::vector<unsigned long> & v);
0105   bool getState (const std::vector<unsigned long> & v);
0106 
0107   static const unsigned int VECTOR_STATE_SIZE = 4;
0108   
0109 private:
0110 
0111   static int  numEngines;
0112   static const int  maxIndex;
0113 
0114 };
0115 
0116 }  // namespace CLHEP
0117 
0118 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
0119 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
0120 using namespace CLHEP;
0121 #endif
0122 
0123 #endif