CLHEP/Random/Random.h

00001 // $Id: Random.h,v 1.19 2002/04/12 15:02:45 evc 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/RandomEngine.h"
00042 
00047 class HepRandom {
00048 
00049 public:
00050 
00051   HepRandom();
00052   HepRandom(long seed);
00053   // Contructors with and without a seed using the default engine
00054   // (JamesRandom).
00055  
00056   HepRandom(HepRandomEngine & algorithm);
00057   HepRandom(HepRandomEngine * algorithm);
00058   // Constructor taking an alternative engine as argument. If a pointer is
00059   // given the corresponding object will be deleted by the HepRandom
00060   // destructor.
00061   
00062   virtual ~HepRandom();
00063   // Destructor
00064 
00065   double flat();
00066   // Returns the flat value ( interval ]0.1[ ).
00067 
00068   void flatArray(const int size, double* vect);
00069   // Fills "vect" array of flat random values, given the size.
00070 
00071   inline double flat (HepRandomEngine* theNewEngine);
00072   // Returns a flat value, given a defined Random Engine.
00073 
00074   inline void flatArray(HepRandomEngine* theNewEngine, 
00075                         const int size, double* vect);
00076   // Fills "vect" array of flat random values, given the size
00077   // and a defined Random Engine.
00078 
00079   virtual double operator()();
00080   // To get a flat random number using the operator ().
00081 
00082   // --------------------------------------------------
00083   // Static member functions using the static generator
00084   // --------------------------------------------------
00085 
00086   static void setTheSeed(long seed, int lux=3);
00087   // (Re)Initializes the generator with a seed.
00088 
00089   static long getTheSeed();
00090   // Gets the current seed of the current generator.
00091 
00092   static void setTheSeeds(const long* seeds, int aux=-1);
00093   // (Re)Initializes the generator with a zero terminated list of seeds.
00094 
00095   static const long* getTheSeeds();
00096   // Gets the current array of seeds of the current generator.
00097 
00098   static void getTheTableSeeds (long* seeds, int index);
00099   // Gets the array of seeds in the static seedTable at "index" position.
00100 
00101   static HepRandom * getTheGenerator();
00102   // Return the current static generator.
00103 
00104   static void setTheEngine (HepRandomEngine* theNewEngine);
00105   // To set the underlying algorithm object.
00106 
00107   static HepRandomEngine * getTheEngine();
00108   // Returns a pointer to the underlying algorithm object.
00109 
00110   static void saveEngineStatus( const char filename[] = "Config.conf" );
00111   // Saves to file the current status of the current engine.
00112 
00113   static void restoreEngineStatus( const char filename[] = "Config.conf" );
00114   // Restores a saved status (if any) for the current engine.
00115 
00116   static void showEngineStatus();
00117   // Dumps the current engine status on screen.
00118 
00119   static int createInstance();
00120   // used to initialise HepRandom::isActive and instantiate singleton
00121      
00122 protected:     // -------- Data members ---------
00123 
00124   static const long seedTable[215][2];
00125   // Table of seeds
00126 
00127 private:       // -------- Data members ---------
00128 
00129   static HepRandomEngine * theEngine;
00130   // The corresponding algorithm.
00131 
00132   static HepRandom * theGenerator;
00133   // The common shared static generator
00134   
00135   static int isActive;
00136   // Flag notifying singleton instance
00137   
00138   bool deleteEngine;
00139   // True if the engine should be deleted on destruction.
00140 
00141 };
00142 
00143 #include "CLHEP/Random/Random.icc"
00144 
00145 #endif

Class Library for High Energy Physics (version 1.8)