Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:03:29

0001 // $Id: Hurd288Engine.h,v 1.5 2010/06/16 17:24:53 garren Exp $
0002 // -*- C++ -*-
0003 //
0004 // -----------------------------------------------------------------------
0005 //                           HEP Random
0006 //                     --- Hurd288Engine ---
0007 //                       class header file
0008 // -----------------------------------------------------------------------
0009 // The starting point for the Hurd Random algorithm is the paper in
0010 // IEEE Transactions on Computers c23, 2 Feb 1974. The algorithm is
0011 // essentially a series of 32 interconnected b-bit registers. The basic
0012 // property is that at each step, bit 1 becomes bit 0, bit 2 the new bit 1,
0013 // bit b the new bit b-1. This is modified so that the new bit b0 is the old
0014 // bit b1 XOR'd with some bit b-d from the previous bit register. The values
0015 // of d can be chosen so as to generate a primitive polynomial, a maximal
0016 // length sequence through all bit patterns except the zero pattern.
0017 //
0018 // This generator, Hurd288, use values based upon Table I of the afore-
0019 // mentioned paper, such that we have 288 total bits, representing 32
0020 // 9-bit registers (actually implemented as an array of 9 32-bit words)
0021 // =======================================================================
0022 //  07-23-98  KLS   Initial draft started
0023 // Ken Smith      - Added conversion operators:  6th Aug 1998
0024 // Mark Fischler  - methods for distrib. instacne save/restore 12/8/04    
0025 // Mark Fischler  - methods for anonymous save/restore 12/27/04    
0026 // =======================================================================
0027 
0028 #ifndef Hurd288Engine_h
0029 #define Hurd288Engine_h
0030 
0031 #include "CLHEP/Random/defs.h"
0032 #include "CLHEP/Random/RandomEngine.h"
0033 
0034 namespace CLHEP {
0035 
0036 /**
0037  * @author
0038  * @ingroup random
0039  */
0040 class Hurd288Engine: public HepRandomEngine {
0041  
0042 public:
0043 
0044   Hurd288Engine();
0045   Hurd288Engine( std::istream &is );
0046   Hurd288Engine( long seed );
0047   Hurd288Engine( int rowIndex, int colIndex );
0048   virtual ~Hurd288Engine();
0049   // Constructors and destructor.
0050 
0051   double flat();
0052   // Returns a pseudo random number between 0 and 1
0053 
0054   void flatArray( const int size, double* vect );
0055   // Fills the array "vect" of specified size with flat random values.
0056 
0057   void setSeed( long seed, int );
0058   // Sets the state of the algorithm according to seed.
0059 
0060   void setSeeds( const long* seeds, int );
0061   // Sets the state of the algorithm according to the zero-terminated
0062   // array of seeds. 
0063 
0064   void saveStatus( const char filename[] = "Hurd288Engine.conf" ) const;
0065   // Saves on named file the current engine status
0066 
0067   void restoreStatus( const char filename[] = "Hurd288Engine.conf" );
0068   // Reads from named file the last saved engine status
0069   // and restores it.
0070 
0071   void showStatus() const;
0072   // Dumps the engine status on the screen
0073 
0074   operator double();       // Returns same as flat()
0075   operator float();        // flat value, without worrying about filling bits
0076   operator unsigned int(); // 32-bit flat value, quickest of all
0077 
0078   virtual std::ostream & put (std::ostream & os) const;
0079   virtual std::istream & get (std::istream & is);
0080   static  std::string beginTag ( );
0081   virtual std::istream & getState ( std::istream & is );
0082 
0083   std::string name() const;
0084   static std::string engineName() {return "Hurd288Engine";}
0085 
0086   std::vector<unsigned long> put () const;
0087   bool get (const std::vector<unsigned long> & v);
0088   bool getState (const std::vector<unsigned long> & v);
0089 
0090   static const unsigned int VECTOR_STATE_SIZE = 11;
0091   
0092 private:
0093 
0094   void advance();
0095 
0096   long seeds_[2];
0097   int wordIndex;
0098   unsigned int words[9];
0099 
0100 }; // Hurd288Engine
0101 
0102 }  // namespace CLHEP
0103 
0104 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
0105 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
0106 using namespace CLHEP;
0107 #endif
0108 
0109 #endif // Hurd288Engine_h