Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // $Id: RandEngine.h,v 1.6 2010/06/16 17:24:53 garren Exp $
0002 // -*- C++ -*-
0003 //
0004 // -----------------------------------------------------------------------
0005 //                             HEP Random
0006 //                         --- RandEngine ---
0007 //                          class header file
0008 // -----------------------------------------------------------------------
0009 // This file is part of Geant4 (simulation toolkit for HEP).
0010 //
0011 // Simple random engine using rand() and srand() functions from C standard
0012 // library to implement the flat() basic distribution and for setting
0013 // seeds.
0014 // Copy constructor and operator= are private for objects of this class.
0015 //
0016 // WARNING: rand is not thread safe. If you need to use multiple
0017 // engine objects on different threads concurrently, do not use RandEngine
0018 
0019 // =======================================================================
0020 // Gabriele Cosmo - Created: 5th September 1995
0021 //                - Minor corrections: 31st October 1996
0022 //                - Added methods for engine status: 19th November 1996
0023 //                - setSeed(), setSeeds() now have default dummy argument
0024 //                  set to zero: 11th July 1997
0025 //                - Private copy constructor and operator=: 26th Feb 1998
0026 // J.Marraffino   - Added stream operators and related constructor.
0027 //                  Added automatic seed selection from seed table and
0028 //                  engine counter: 15th Feb 1998
0029 // Ken Smith      - Added conversion operators:  6th Aug 1998
0030 //                  replace mx by mantissa_bit_32
0031 // M Fischler     - Inserted warnings about the fact that the quality of rand()
0032 //                  is quite poor.
0033 // Mark Fischler    Methods for distrib. instance save/restore 12/8/04    
0034 // Mark Fischler    methods for anonymous save/restore 12/27/04    
0035 // =======================================================================
0036 
0037 #ifndef RandEngine_h
0038 #define RandEngine_h 1
0039 
0040 #include "CLHEP/Random/defs.h"
0041 #include "CLHEP/Random/RandomEngine.h"
0042 
0043 namespace CLHEP {
0044 
0045 /**
0046  * @author <Gabriele.Cosmo@cern.ch>
0047  * @ingroup random
0048  */
0049 class RandEngine : public HepRandomEngine {
0050 
0051 public:
0052 
0053   RandEngine(std::istream& is);
0054   RandEngine();
0055   RandEngine(long seed);
0056   RandEngine(int rowIndex, int colIndex);
0057   virtual ~RandEngine();
0058   // Constructors and destructor
0059 
0060   double flat();
0061   // It returns a pseudo random number between 0 and 1,
0062   // according to the standard stdlib random function rand()
0063   // but excluding the end points.
0064   //
0065   // WARNING:  rand() is quite a weak generator on most systems,                    <
0066   // will not pass several randomness tests, and does not give a           <
0067   // reproducible sequence of numbers.                                                                        <
0068 
0069   void flatArray (const int size, double* vect);
0070   // Fills the array "vect" of specified size with flat random values.
0071 
0072   void setSeed(long seed, int dum=0);
0073   // Sets the state of the algorithm according to seed.
0074 
0075   void setSeeds(const long * seeds, int dum=0);
0076   // Sets the state of the algorithm according to the zero terminated
0077   // array of seeds. Only the first seed is used.
0078 
0079   void saveStatus( const char filename[] = "Rand.conf" ) const;
0080   // Saves on file Rand.conf the current engine status.
0081   // WARNING:  This is non-functional, as rand() on various systems will            <
0082   // not give reproducible streams.                                                 <
0083 
0084   void restoreStatus( const char filename[] = "Rand.conf" );
0085   // Reads from file Rand.conf the last saved engine status
0086   // and restores it.
0087   // WARNING:  This is non-functional, as rand() on various systems will            <
0088   // not give reproducible streams.                                                 <
0089 
0090   void showStatus() const;
0091   // Dumps the engine status on the screen.
0092  
0093   operator double();       // Returns same as flat()
0094   operator float();        // flat value, without worrying about filling bits
0095   operator unsigned int(); // 32-bit flat value, quickest of all.
0096 
0097   virtual std::ostream & put (std::ostream & os) const;
0098   virtual std::istream & get (std::istream & is);
0099   static  std::string beginTag ( );
0100   virtual std::istream & getState ( std::istream & is );
0101 
0102   std::string name() const;
0103   static std::string engineName() {return "RandEngine";}
0104 
0105   std::vector<unsigned long> put () const;
0106   bool get (const std::vector<unsigned long> & v);
0107   bool getState (const std::vector<unsigned long> & v);
0108   
0109   static const unsigned int VECTOR_STATE_SIZE = 3;
0110   
0111 private:
0112 
0113   RandEngine(const RandEngine &p);
0114   RandEngine & operator = (const RandEngine &p);
0115   // Private copy constructor and assignment operator.
0116 
0117 private:
0118 
0119   long seq;
0120   static int numEngines;
0121   static const int maxIndex;
0122 
0123 };
0124 
0125 }  // namespace CLHEP
0126 
0127 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
0128 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
0129 using namespace CLHEP;
0130 #endif
0131 
0132 #endif