CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

Random.h

Go to the documentation of this file.
00001 // $Id: Random.h,v 1.5 2010/06/16 17:24:53 garren Exp $
00002 // -*- C++ -*-
00003 //
00004 // -----------------------------------------------------------------------
00005 //                             HEP Random
00006 //                          --- HepRandom ---
00007 //                          class header file
00008 // -----------------------------------------------------------------------
00009 // This file is part of Geant4 (simulation toolkit for HEP).
00010 //
00011 // It's a singleton instantiated by default within the HEP Random module.
00012 // It uses an instantiated HepJamesRandom engine as default algorithm
00013 // for pseudo-random number generation. HepRandom defines a static private
00014 // data member theGenerator and a set of static inlined methods to manipulate
00015 // it. By means of theGenerator the user can change the underlying engine
00016 // algorithm, get and set the seeds and use any kind of defined random
00017 // distribution.
00018 // Distribution classes inherit from HepRandom and define both static and
00019 // not-static interfaces.
00020 // A static table of uncorrelated seeds is available in this class.
00021 // A static method "getTheTableSeeds()" is defined to access a couple of
00022 // seeds at a given index in the table.
00023 
00024 // =======================================================================
00025 // Gabriele Cosmo - Created: 5th Sep 1995
00026 //                - Minor update: 17th May 1996
00027 //                - Poisson now operates on doubles : 31st Oct 1996
00028 //                - Added methods for engine status: 19th Nov 1996
00029 //                - Fixed default values to setTheSeed() and
00030 //                  setTheSeeds() static methods: 16th Oct 1997
00031 //                - Modified HepRandom to act as a singleton, constructors
00032 //                  are kept public for backward compatibility. Added table
00033 //                  of seeds from HepRandomEngine: 19th Mar 1998
00034 //                - Relocated Poisson and Gauss data and simplified
00035 //                  initialisation of static generator: 5th Jan 1999
00036 // =======================================================================
00037 
00038 #ifndef HepRandom_h
00039 #define HepRandom_h 1
00040 
00041 #include "CLHEP/Random/defs.h"
00042 #include "CLHEP/Random/RandomEngine.h"
00043 
00044 namespace CLHEP {
00045 
00050 class HepRandom {
00051 
00052 public:
00053 
00054   HepRandom();
00055   HepRandom(long seed);
00056   // Contructors with and without a seed using the default engine
00057   // (JamesRandom).
00058  
00059   HepRandom(HepRandomEngine & algorithm);
00060   HepRandom(HepRandomEngine * algorithm);
00061   // Constructor taking an alternative engine as argument. If a pointer is
00062   // given the corresponding object will be deleted by the HepRandom
00063   // destructor.
00064   
00065   virtual ~HepRandom();
00066   // Destructor
00067   
00068   // implicitly allow compiler-generated copy functions 
00069 
00070   double flat();
00071   // Returns the flat value ( interval ]0...1[ ).
00072 
00073   void flatArray(const int size, double* vect);
00074   // Fills "vect" array of flat random values, given the size.
00075 
00076   inline double flat (HepRandomEngine* theNewEngine);
00077   // Returns a flat value, given a defined Random Engine.
00078 
00079   inline void flatArray(HepRandomEngine* theNewEngine, 
00080                         const int size, double* vect);
00081   // Fills "vect" array of flat random values, given the size
00082   // and a defined Random Engine.
00083 
00084   virtual double operator()();
00085   // To get a flat random number using the operator ().
00086 
00087   virtual std::string name() const;
00088   virtual HepRandomEngine & engine();
00089     
00090   
00091   virtual std::ostream & put ( std::ostream & os ) const;
00092   virtual std::istream & get ( std::istream & is );
00093   // Save and restore to/from streams
00094 
00095   // --------------------------------------------------
00096   // Static member functions using the static generator
00097   // --------------------------------------------------
00098 
00099   static void setTheSeed(long seed, int lux=3);
00100   // (Re)Initializes the generator with a seed.
00101 
00102   static long getTheSeed();
00103   // Gets the current seed of the current generator.
00104 
00105   static void setTheSeeds(const long* seeds, int aux=-1);
00106   // (Re)Initializes the generator with a zero terminated list of seeds.
00107 
00108   static const long* getTheSeeds();
00109   // Gets the current array of seeds of the current generator.
00110 
00111   static void getTheTableSeeds (long* seeds, int index);
00112   // Gets the array of seeds in the static seedTable at "index" position.
00113 
00114   static HepRandom * getTheGenerator();
00115   // Return the current static generator.
00116 
00117   static void setTheEngine (HepRandomEngine* theNewEngine);
00118   // To set the underlying algorithm object.
00119 
00120   static HepRandomEngine * getTheEngine();
00121   // Returns a pointer to the underlying algorithm object.
00122 
00123   static void saveEngineStatus( const char filename[] = "Config.conf" );
00124   // Saves to file the current status of the current engine.
00125 
00126   static void restoreEngineStatus( const char filename[] = "Config.conf" );
00127   // Restores a saved status (if any) for the current engine.
00128 
00129   static std::ostream& saveFullState ( std::ostream & os );
00130   // Saves to stream the state of the engine and cached data.
00131 
00132   static std::istream& restoreFullState ( std::istream & is );
00133   // Restores from stream the state of the engine and cached data.
00134 
00135   static std::ostream& saveDistState ( std::ostream & os ) {return os;}
00136   // Saves to stream the state of the cached data.
00137 
00138   static std::istream& restoreDistState ( std::istream & is ) {return is;}
00139   // Restores from stream the state of the cached data.
00140 
00141   static std::ostream& saveStaticRandomStates ( std::ostream & os );
00142   // Saves to stream the engine and cached data for all distributions.
00143 
00144   static std::istream& restoreStaticRandomStates ( std::istream & is );
00145   // Restores from stream the engine and cached data for all distributions.
00146 
00147   static void showEngineStatus();
00148   // Dumps the current engine status on screen.
00149 
00150   static int createInstance();
00151   // used to initialise the default engine
00152 
00153   static std::string distributionName() {return "HepRandomEngine";}  
00154   // Provides the name of this distribution class
00155        
00156 protected:     // -------- Data members ---------
00157 
00158   static const long seedTable[215][2];
00159   // Table of seeds
00160 
00161 };
00162 
00163 std::ostream & operator<< (std::ostream & os, const HepRandom & dist);
00164 std::istream & operator>> (std::istream & is, HepRandom & dist);
00165 
00166 }  // namespace CLHEP
00167 
00168 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
00169 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
00170 using namespace CLHEP;
00171 #endif
00172 
00173 #include "CLHEP/Random/Random.icc"
00174 
00175 #endif

Generated on 15 Nov 2012 for CLHEP by  doxygen 1.4.7