00001 /*************************************************************************** 00002 * 00003 * $Id: RandomEngine.h,v 1.4 2003/09/02 17:59:34 perev Exp $ 00004 * 00005 * Author: Gabriele Cosmo - Created: 5th September 1995 00006 * modified for SCL bl 00007 *************************************************************************** 00008 * 00009 * Description: 00010 * ----------------------------------------------------------------------- 00011 * HEP Random 00012 * --- HepRandomEngine --- 00013 * class header file 00014 * ----------------------------------------------------------------------- 00015 * This file is part of Geant4 (simulation toolkit for HEP). 00016 * 00017 * Is the abstract class defining the interface for each random engine. It 00018 * implements the getSeed() and getSeeds() methods which return the initial 00019 * seed value and the initial array of seeds respectively. It defines 7 00020 * pure virtual functions: flat(), flatArray(), setSeed(), setSeeds(), 00021 * saveStatus(), restoreStatus() and showStatus(), which are implemented by 00022 * the concrete random engines each one inheriting from this abstract class. 00023 * Many concrete random engines can be defined and added to the structure, 00024 * simply making them inheriting from HepRandomEngine and defining the six 00025 * functions flat(), flatArray(), setSeed(), setSeeds(), saveStatus(), 00026 * restoreStatus() and showStatus() in such a way that flat() and 00027 * flatArray() return double random values ranging between ]0,1[. 00028 * All the random engines have a default seed value already set but they 00029 * can be instantiated with a different seed value set up by the user. 00030 * The seed can be changed using a static method defined in HepRandom. 00031 * 00032 *************************************************************************** 00033 * 00034 * $Log: RandomEngine.h,v $ 00035 * Revision 1.4 2003/09/02 17:59:34 perev 00036 * gcc 3.2 updates + WarnOff 00037 * 00038 * Revision 1.3 1999/12/21 15:13:56 ullrich 00039 * Modified to cope with new compiler version on Sun (CC5.0). 00040 * 00041 * Revision 1.2 1999/03/07 15:02:50 wenaus 00042 * missing std 00043 * 00044 * Revision 1.1 1999/01/30 03:59:01 fisyak 00045 * Root Version of StarClassLibrary 00046 * 00047 * Revision 1.1 1999/01/23 00:27:41 ullrich 00048 * Initial Revision 00049 * 00050 **************************************************************************/ 00051 #ifndef HepRandomEngine_h 00052 #define HepRandomEngine_h 1 00053 00054 #include <Stiostream.h> 00055 #include "Stiostream.h" 00056 #include <math.h> 00057 #include <vector> 00058 #if !defined(ST_NO_NAMESPACES) 00059 using std::vector; 00060 #endif 00061 00062 #include "StGlobals.hh" 00063 00064 class HepRandomEngine { 00065 00066 public: 00067 00068 HepRandomEngine(); 00069 virtual ~HepRandomEngine(); 00070 // Constructor and destructor 00071 00072 inline HepBoolean operator==(const HepRandomEngine& engine); 00073 inline HepBoolean operator!=(const HepRandomEngine& engine); 00074 // Overloaded operators, ==, != 00075 00076 virtual HepDouble flat() = 0; 00077 // Should return a pseudo random number between 0 and 1 00078 // (excluding the end points) 00079 00080 virtual void flatArray(const HepInt size, HepDouble* vect) = 0; 00081 #ifndef ST_NO_TEMPLATE_DEF_ARGS 00082 virtual void flatArray(vector<HepDouble>&) = 0; 00083 #else 00084 virtual void flatArray(vector<HepDouble,allocator<HepDouble> >&) = 0; 00085 #endif 00086 // Fills an array "vect" of specified size with flat random values. 00087 00088 virtual void setSeed(long seed, HepInt) = 0; 00089 // Should initialise the status of the algorithm according to seed. 00090 00091 virtual void setSeeds(const long * seeds, HepInt) = 0; 00092 // Should initialise the status of the algorithm according to the zero terminated 00093 // array of seeds. It is allowed to ignore one or many seeds in this array. 00094 00095 virtual void saveStatus() const = 0; 00096 // Should save on a file specific to the instantiated engine in use 00097 // the current status. 00098 00099 virtual void restoreStatus() = 0; 00100 // Should read from a file (specific to the instantiated engine in use) 00101 // and restore the last saved engine configuration. 00102 00103 virtual void showStatus() const = 0; 00104 // Should dump the current engine status on the screen. 00105 00106 long getSeed() const { return theSeed; } 00107 // Gets the current seed. 00108 00109 const long* getSeeds() const { return theSeeds; } 00110 // Gets the current array of seeds. 00111 00112 void getTableSeeds(long* seeds, HepInt index) const; 00113 // Gets back seed values stored in the table, given the index. 00114 00115 protected: 00116 00117 long theSeed; 00118 const long* theSeeds; 00119 static const long seedTable[215][2]; 00120 }; 00121 00122 inline HepBoolean HepRandomEngine::operator==(const HepRandomEngine& engine) { 00123 return (this==&engine) ? true : false; 00124 } 00125 00126 inline HepBoolean HepRandomEngine::operator!=(const HepRandomEngine& engine) { 00127 return (this!=&engine) ? true : false; 00128 } 00129 00130 inline void HepRandomEngine::getTableSeeds(long* seeds, HepInt index) const 00131 { 00132 if ((index >= 0) && (index < 215)) { 00133 seeds[0] = seedTable[index][0]; 00134 seeds[1] = seedTable[index][1]; 00135 } 00136 else seeds = NULL; 00137 } 00138 00139 #endif
1.5.9