Geant4 Cross Reference |
1 // -*- C++ -*- 1 2 // 3 // ------------------------------------------- 4 // HEP Random 5 // --- HepRandomEngine 6 // class header file 7 // ------------------------------------------- 8 // This file is part of Geant4 (simulation too 9 // 10 // Is the abstract class defining the interfac 11 // implements the getSeed() and getSeeds() met 12 // seed value and the initial array of seeds r 13 // pure virtual functions: flat(), flatArray() 14 // saveStatus(), restoreStatus() and showStatu 15 // the concrete random engines each one inheri 16 // Many concrete random engines can be defined 17 // simply making them inheriting from HepRando 18 // functions flat(), flatArray(), setSeed(), s 19 // restoreStatus() and showStatus() in such a 20 // flatArray() return double random values ran 21 // All the random engines have a default seed 22 // can be instantiated with a different seed v 23 24 // =========================================== 25 // Gabriele Cosmo - Created: 5th September 199 26 // - Minor corrections: 31st Oc 27 // - Added methods for engine s 28 // - Removed default values to 29 // setSeeds() pure virtual me 30 // - Moved seeds table to HepRa 31 // Ken Smith - Added conversion operators 32 // Mark Fischler - Added static twoToMinus_xx 33 // Mark Fischler - Removed getTableSeeds, whi 34 // in 1998. 10 Feb 2005. 35 // =========================================== 36 37 #ifndef HepRandomEngine_h 38 #define HepRandomEngine_h 1 39 40 #include <iostream> 41 #include <fstream> 42 #include <iomanip> 43 #include <string> 44 #include <sstream> 45 #include <vector> 46 47 namespace CLHEP { 48 49 /** 50 * @author <Gabriele.Cosmo@cern.ch> 51 * @ingroup random 52 */ 53 class HepRandomEngine { 54 55 public: 56 57 HepRandomEngine(); 58 virtual ~HepRandomEngine(); 59 // Constructor and destructor 60 61 inline bool operator==(const HepRandomEngine 62 inline bool operator!=(const HepRandomEngine 63 // Overloaded operators, ==, != 64 65 virtual double flat() = 0; 66 // Should return a pseudo random number betw 67 // (excluding the end points) 68 69 virtual void flatArray(const int size, doubl 70 // Fills an array "vect" of specified size w 71 72 virtual void setSeed(long seed, int) = 0; 73 // Should initialise the status of the algor 74 75 virtual void setSeeds(const long * seeds, in 76 // Should initialise the status of the algor 77 // array of seeds. It is allowed to ignore o 78 79 virtual void saveStatus( const char filename 80 // Should save on a file specific to the ins 81 // the current status. 82 83 virtual void restoreStatus( const char filen 84 // Should read from a file (specific to the 85 // and restore the last saved engine configu 86 87 virtual void showStatus() const = 0; 88 // Should dump the current engine status on 89 90 virtual std::string name() const = 0; 91 // Engine name. 92 93 virtual std::ostream & put (std::ostream & o 94 virtual std::istream & get (std::istream & i 95 // Save and restore to/from streams 96 97 static std::string beginTag ( ); 98 virtual std::istream & getState ( std::istre 99 // Helpers for EngineFactory which restores 100 101 static HepRandomEngine* newEngine(std::istre 102 // Instantiates on the heap a new engine of 103 104 static HepRandomEngine* newEngine(const std: 105 // Instantiates on the heap a new engine of 106 107 virtual std::vector<unsigned long> put () co 108 virtual bool get (const std::vector<unsigned 109 virtual bool getState (const std::vector<uns 110 // Save and restore to/from vectors 111 112 long getSeed() const { return theSeed; } 113 // Gets the current seed. 114 115 const long* getSeeds() const { return theSee 116 // Gets the current array of seeds. 117 118 virtual operator double(); // Returns 119 virtual operator float(); // less pr 120 virtual operator unsigned int(); // 32-b 121 122 // The above three conversion operators perm 123 // random number as either a double-precisio 124 // float, or a 32-bit unsigned integer. The 125 // of the respective engine class "e", is as 126 127 // Recommended: 128 // float x; 129 // x = float( e ); 130 131 // Reasonable: 132 // x = e; 133 134 // Works, but bad practice: 135 // x = 1.5 + e; 136 137 // Won't compile: 138 // x = e + 1.5; 139 140 protected: 141 142 long theSeed; 143 const long* theSeeds; 144 145 static inline double exponent_bit_32(); 146 static inline double mantissa_bit_12(); 147 static inline double mantissa_bit_24(); 148 static inline double mantissa_bit_32(); 149 static inline double twoToMinus_32(); 150 static inline double twoToMinus_48(); 151 static inline double twoToMinus_49(); 152 static inline double twoToMinus_53(); 153 static inline double nearlyTwoToMinus_54(); 154 155 static bool checkFile (std::istream & file, 156 const std::string & filename, 157 const std::string & classname, 158 const std::string & methodname); 159 160 }; 161 162 std::ostream & operator<< (std::ostream & os, 163 std::istream & operator>> (std::istream & is, 164 165 template <class IS, class T> 166 bool possibleKeywordInput (IS & is, const std: 167 std::string firstWord; 168 is >> firstWord; 169 if (firstWord == key) return true; 170 std::istringstream reread(firstWord); 171 reread >> t; 172 return false; 173 } 174 175 } // namespace CLHEP 176 177 #include "CLHEP/Random/RandomEngine.icc" 178 179 #endif 180