StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
RandomEngine.h
1 /***************************************************************************
2  *
3  * $Id: RandomEngine.h,v 1.4 2003/09/02 17:59:34 perev Exp $
4  *
5  * Author: Gabriele Cosmo - Created: 5th September 1995
6  * modified for SCL bl
7  ***************************************************************************
8  *
9  * Description:
10  * -----------------------------------------------------------------------
11  * HEP Random
12  * --- HepRandomEngine ---
13  * class header file
14  * -----------------------------------------------------------------------
15  * This file is part of Geant4 (simulation toolkit for HEP).
16  *
17  * Is the abstract class defining the interface for each random engine. It
18  * implements the getSeed() and getSeeds() methods which return the initial
19  * seed value and the initial array of seeds respectively. It defines 7
20  * pure virtual functions: flat(), flatArray(), setSeed(), setSeeds(),
21  * saveStatus(), restoreStatus() and showStatus(), which are implemented by
22  * the concrete random engines each one inheriting from this abstract class.
23  * Many concrete random engines can be defined and added to the structure,
24  * simply making them inheriting from HepRandomEngine and defining the six
25  * functions flat(), flatArray(), setSeed(), setSeeds(), saveStatus(),
26  * restoreStatus() and showStatus() in such a way that flat() and
27  * flatArray() return double random values ranging between ]0,1[.
28  * All the random engines have a default seed value already set but they
29  * can be instantiated with a different seed value set up by the user.
30  * The seed can be changed using a static method defined in HepRandom.
31  *
32  ***************************************************************************
33  *
34  * $Log: RandomEngine.h,v $
35  * Revision 1.4 2003/09/02 17:59:34 perev
36  * gcc 3.2 updates + WarnOff
37  *
38  * Revision 1.3 1999/12/21 15:13:56 ullrich
39  * Modified to cope with new compiler version on Sun (CC5.0).
40  *
41  * Revision 1.2 1999/03/07 15:02:50 wenaus
42  * missing std
43  *
44  * Revision 1.1 1999/01/30 03:59:01 fisyak
45  * Root Version of StarClassLibrary
46  *
47  * Revision 1.1 1999/01/23 00:27:41 ullrich
48  * Initial Revision
49  *
50  **************************************************************************/
51 #ifndef HepRandomEngine_h
52 #define HepRandomEngine_h 1
53 
54 #include <Stiostream.h>
55 #include "Stiostream.h"
56 #include <math.h>
57 #include <vector>
58 #if !defined(ST_NO_NAMESPACES)
59 using std::vector;
60 #endif
61 
62 #include "StGlobals.hh"
63 
65 
66 public:
67 
69  virtual ~HepRandomEngine();
70  // Constructor and destructor
71 
72  inline HepBoolean operator==(const HepRandomEngine& engine);
73  inline HepBoolean operator!=(const HepRandomEngine& engine);
74  // Overloaded operators, ==, !=
75 
76  virtual HepDouble flat() = 0;
77  // Should return a pseudo random number between 0 and 1
78  // (excluding the end points)
79 
80  virtual void flatArray(const HepInt size, HepDouble* vect) = 0;
81 #ifndef ST_NO_TEMPLATE_DEF_ARGS
82  virtual void flatArray(vector<HepDouble>&) = 0;
83 #else
84  virtual void flatArray(vector<HepDouble,allocator<HepDouble> >&) = 0;
85 #endif
86  // Fills an array "vect" of specified size with flat random values.
87 
88  virtual void setSeed(long seed, HepInt) = 0;
89  // Should initialise the status of the algorithm according to seed.
90 
91  virtual void setSeeds(const long * seeds, HepInt) = 0;
92  // Should initialise the status of the algorithm according to the zero terminated
93  // array of seeds. It is allowed to ignore one or many seeds in this array.
94 
95  virtual void saveStatus() const = 0;
96  // Should save on a file specific to the instantiated engine in use
97  // the current status.
98 
99  virtual void restoreStatus() = 0;
100  // Should read from a file (specific to the instantiated engine in use)
101  // and restore the last saved engine configuration.
102 
103  virtual void showStatus() const = 0;
104  // Should dump the current engine status on the screen.
105 
106  long getSeed() const { return theSeed; }
107  // Gets the current seed.
108 
109  const long* getSeeds() const { return theSeeds; }
110  // Gets the current array of seeds.
111 
112  void getTableSeeds(long* seeds, HepInt index) const;
113  // Gets back seed values stored in the table, given the index.
114 
115 protected:
116 
117  long theSeed;
118  const long* theSeeds;
119  static const long seedTable[215][2];
120 };
121 
122 inline HepBoolean HepRandomEngine::operator==(const HepRandomEngine& engine) {
123  return (this==&engine) ? true : false;
124 }
125 
126 inline HepBoolean HepRandomEngine::operator!=(const HepRandomEngine& engine) {
127  return (this!=&engine) ? true : false;
128 }
129 
130 inline void HepRandomEngine::getTableSeeds(long* seeds, HepInt index) const
131 {
132  if ((index >= 0) && (index < 215)) {
133  seeds[0] = seedTable[index][0];
134  seeds[1] = seedTable[index][1];
135  }
136  else seeds = NULL;
137 }
138 
139 #endif