Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Random.h
Go to the documentation of this file.
1 // $Id:$
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 // HEP Random
6 // --- HepRandom ---
7 // class header file
8 // -----------------------------------------------------------------------
9 // This file is part of Geant4 (simulation toolkit for HEP).
10 //
11 // It's a singleton instantiated by default within the HEP Random module.
12 // It uses an instantiated HepJamesRandom engine as default algorithm
13 // for pseudo-random number generation. HepRandom defines a static private
14 // data member theGenerator and a set of static inlined methods to manipulate
15 // it. By means of theGenerator the user can change the underlying engine
16 // algorithm, get and set the seeds and use any kind of defined random
17 // distribution.
18 // Distribution classes inherit from HepRandom and define both static and
19 // not-static interfaces.
20 // A static table of uncorrelated seeds is available in this class.
21 // A static method "getTheTableSeeds()" is defined to access a couple of
22 // seeds at a given index in the table.
23 
24 // =======================================================================
25 // Gabriele Cosmo - Created: 5th Sep 1995
26 // - Minor update: 17th May 1996
27 // - Poisson now operates on doubles : 31st Oct 1996
28 // - Added methods for engine status: 19th Nov 1996
29 // - Fixed default values to setTheSeed() and
30 // setTheSeeds() static methods: 16th Oct 1997
31 // - Modified HepRandom to act as a singleton, constructors
32 // are kept public for backward compatibility. Added table
33 // of seeds from HepRandomEngine: 19th Mar 1998
34 // - Relocated Poisson and Gauss data and simplified
35 // initialisation of static generator: 5th Jan 1999
36 // =======================================================================
37 
38 #ifndef HepRandom_h
39 #define HepRandom_h 1
40 
42 
43 namespace CLHEP {
44 
49 class HepRandom {
50 
51 public:
52 
53  HepRandom();
54  HepRandom(long seed);
55  // Contructors with and without a seed using the default engine
56  // (JamesRandom).
57 
58  HepRandom(HepRandomEngine & algorithm);
59  HepRandom(HepRandomEngine * algorithm);
60  // Constructor taking an alternative engine as argument. If a pointer is
61  // given the corresponding object will be deleted by the HepRandom
62  // destructor.
63 
64  virtual ~HepRandom();
65  // Destructor
66 
67  // implicitly allow compiler-generated copy functions
68 
69  double flat();
70  // Returns the flat value ( interval ]0...1[ ).
71 
72  void flatArray(const int size, double* vect);
73  // Fills "vect" array of flat random values, given the size.
74 
75  inline double flat (HepRandomEngine* theNewEngine);
76  // Returns a flat value, given a defined Random Engine.
77 
78  inline void flatArray(HepRandomEngine* theNewEngine,
79  const int size, double* vect);
80  // Fills "vect" array of flat random values, given the size
81  // and a defined Random Engine.
82 
83  virtual double operator()();
84  // To get a flat random number using the operator ().
85 
86  virtual std::string name() const;
87  virtual HepRandomEngine & engine();
88 
89 
90  virtual std::ostream & put ( std::ostream & os ) const;
91  virtual std::istream & get ( std::istream & is );
92  // Save and restore to/from streams
93 
94  // --------------------------------------------------
95  // Static member functions using the static generator
96  // --------------------------------------------------
97 
98  static void setTheSeed(long seed, int lux=3);
99  // (Re)Initializes the generator with a seed.
100 
101  static long getTheSeed();
102  // Gets the current seed of the current generator.
103 
104  static void setTheSeeds(const long* seeds, int aux=-1);
105  // (Re)Initializes the generator with a zero terminated list of seeds.
106 
107  static const long* getTheSeeds();
108  // Gets the current array of seeds of the current generator.
109 
110  static void getTheTableSeeds (long* seeds, int index);
111  // Gets the array of seeds in the static seedTable at "index" position.
112 
113  static HepRandom * getTheGenerator();
114  // Return the current static generator.
115 
116  static void setTheEngine (HepRandomEngine* theNewEngine);
117  // To set the underlying algorithm object.
118 
119  static HepRandomEngine * getTheEngine();
120  // Returns a pointer to the underlying algorithm object.
121 
122  static void saveEngineStatus( const char filename[] = "Config.conf" );
123  // Saves to file the current status of the current engine.
124 
125  static void restoreEngineStatus( const char filename[] = "Config.conf" );
126  // Restores a saved status (if any) for the current engine.
127 
128  static std::ostream& saveFullState ( std::ostream & os );
129  // Saves to stream the state of the engine and cached data.
130 
131  static std::istream& restoreFullState ( std::istream & is );
132  // Restores from stream the state of the engine and cached data.
133 
134  static std::ostream& saveDistState ( std::ostream & os ) {return os;}
135  // Saves to stream the state of the cached data.
136 
137  static std::istream& restoreDistState ( std::istream & is ) {return is;}
138  // Restores from stream the state of the cached data.
139 
140  static std::ostream& saveStaticRandomStates ( std::ostream & os );
141  // Saves to stream the engine and cached data for all distributions.
142 
143  static std::istream& restoreStaticRandomStates ( std::istream & is );
144  // Restores from stream the engine and cached data for all distributions.
145 
146  static void showEngineStatus();
147  // Dumps the current engine status on screen.
148 
149  static int createInstance();
150  // used to initialise the default engine
151 
152  static std::string distributionName() {return "HepRandomEngine";}
153  // Provides the name of this distribution class
154 
155 protected: // -------- Data members ---------
156 
157  static const long seedTable[215][2];
158  // Table of seeds
159 
160 };
161 
162 std::ostream & operator<< (std::ostream & os, const HepRandom & dist);
163 std::istream & operator>> (std::istream & is, HepRandom & dist);
164 
165 } // namespace CLHEP
166 
167 #include "CLHEP/Random/Random.icc"
168 
169 #endif
static const long * getTheSeeds()
Definition: Random.cc:246
static HepRandom * getTheGenerator()
Definition: Random.cc:260
static void restoreEngineStatus(const char filename[]="Config.conf")
Definition: Random.cc:280
static void setTheSeeds(const long *seeds, int aux=-1)
Definition: Random.cc:241
static const long seedTable[215][2]
Definition: Random.h:157
static std::ostream & saveDistState(std::ostream &os)
Definition: Random.h:134
void flatArray(const int size, double *vect)
Definition: Random.cc:201
static void setTheSeed(long seed, int lux=3)
Definition: Random.cc:231
static HepRandomEngine * getTheEngine()
Definition: Random.cc:265
virtual std::ostream & put(std::ostream &os) const
Definition: Random.cc:224
std::ostream & operator<<(std::ostream &os, const HepRandom &dist)
Definition: Random.cc:216
long seed
Definition: chem4.cc:68
virtual HepRandomEngine & engine()
Definition: Random.cc:211
static void showEngineStatus()
Definition: Random.cc:303
virtual ~HepRandom()
Definition: Random.cc:193
double flat()
Definition: Random.cc:196
static long getTheSeed()
Definition: Random.cc:236
static int createInstance()
Definition: Random.cc:308
static void saveEngineStatus(const char filename[]="Config.conf")
Definition: Random.cc:275
static std::istream & restoreDistState(std::istream &is)
Definition: Random.h:137
static constexpr double lux
static std::ostream & saveStaticRandomStates(std::ostream &os)
Definition: Random.cc:295
static void setTheEngine(HepRandomEngine *theNewEngine)
Definition: Random.cc:270
static std::ostream & saveFullState(std::ostream &os)
Definition: Random.cc:285
std::istream & operator>>(std::istream &is, HepRandom &dist)
Definition: Random.cc:220
virtual double operator()()
Definition: Random.cc:206
virtual std::string name() const
Definition: Random.cc:210
static std::istream & restoreFullState(std::istream &is)
Definition: Random.cc:290
static void getTheTableSeeds(long *seeds, int index)
Definition: Random.cc:251
static std::istream & restoreStaticRandomStates(std::istream &is)
Definition: Random.cc:299
static std::string distributionName()
Definition: Random.h:152