Geant4  10.02.p02
G4MTHepRandom.hh
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id:$
28 //
29 // Class G4MTHepRandom
30 //
31 // Modified version with MT extensions
32 // of corresponding CLHEP class HepRandom
33 
34 // --------------------------------------------------------------------
35 #ifndef G4MTHepRandom_h
36 #define G4MTHepRandom_h 1
37 
38 #include <CLHEP/Random/RandomEngine.h>
39 #include <CLHEP/Random/RandExponential.h>
40 #include <CLHEP/Random/RandFlat.h>
41 #include <CLHEP/Random/RandBit.h>
42 #include <CLHEP/Random/RandGamma.h>
43 #include <CLHEP/Random/RandGaussQ.h>
44 #include <CLHEP/Random/RandGeneral.h>
45 
46 #include "tls.hh"
47 #include "G4Types.hh"
48 
50 {
51 
52 public:
53 
54  G4MTHepRandom();
55  G4MTHepRandom(G4long seed);
56  // Contructors with and without a seed using the default engine
57  // (JamesRandom).
58 
59  G4MTHepRandom(CLHEP::HepRandomEngine & algorithm);
60  G4MTHepRandom(CLHEP::HepRandomEngine * algorithm);
61  // Constructor taking an alternative engine as argument. If a pointer is
62  // given the corresponding object will be deleted by the HepRandom
63  // destructor.
64 
65  virtual ~G4MTHepRandom();
66  // Destructor
67 
68  G4double flat();
69  // Returns the flat value ( interval ]0...1[ ).
70 
71  void flatArray(const G4int size, G4double* vect);
72  // Fills "vect" array of flat random values, given the size.
73 
74  inline G4double flat (CLHEP::HepRandomEngine* theNewEngine);
75  // Returns a flat value, given a defined Random Engine.
76 
77  inline void flatArray(CLHEP::HepRandomEngine* theNewEngine,
78  const G4int size, G4double* vect);
79  // Fills "vect" array of flat random values, given the size
80  // and a defined Random Engine.
81 
82  virtual G4double operator()();
83  // To get a flat random number using the operator ().
84 
85  virtual std::ostream & put ( std::ostream & os ) const;
86  virtual std::istream & get ( std::istream & is );
87  // Save and restore to/from streams
88 
89  // --------------------------------------------------
90  // Static member functions using the static generator
91  // --------------------------------------------------
92 
93  static void setTheSeed(G4long seed, G4int lux=3);
94  // (Re)Initializes the generator with a seed.
95 
96  static G4long getTheSeed();
97  // Gets the current seed of the current generator.
98 
99  static void setTheSeeds(const G4long* seeds, G4int aux=-1);
100  // (Re)Initializes the generator with a zero terminated list of seeds.
101 
102  static const G4long* getTheSeeds();
103  // Gets the current array of seeds of the current generator.
104 
105  static void getTheTableSeeds (G4long* seeds, G4int index);
106  // Gets the array of seeds in the static seedTable at "index" position.
107 
108  static G4MTHepRandom * getTheGenerator();
109  // Return the current static generator.
110 
111  static void setTheEngine (CLHEP::HepRandomEngine* theNewEngine);
112  // To set the underlying algorithm object.
113 
114  static CLHEP::HepRandomEngine * getTheEngine();
115  // Returns a pointer to the underlying algorithm object.
116 
117  static void saveEngineStatus( const char filename[] = "Config.conf" );
118  // Saves to file the current status of the current engine.
119 
120  static void restoreEngineStatus( const char filename[] = "Config.conf" );
121  // Restores a saved status (if any) for the current engine.
122 
123  static std::ostream& saveFullState ( std::ostream & os );
124  // Saves to stream the state of the engine and cached data.
125 
126  static std::istream& restoreFullState ( std::istream & is );
127  // Restores from stream the state of the engine and cached data.
128 
129  static std::ostream& saveDistState ( std::ostream & os ) {return os;}
130  // Saves to stream the state of the cached data.
131 
132  static std::istream& restoreDistState ( std::istream & is ) {return is;}
133  // Restores from stream the state of the cached data.
134 
135  static std::ostream& saveStaticRandomStates ( std::ostream & os );
136  // Saves to stream the engine and cached data for all distributions.
137 
138  static std::istream& restoreStaticRandomStates ( std::istream & is );
139  // Restores from stream the engine and cached data for all distributions.
140 
141  static void showEngineStatus();
142  // Dumps the current engine status on screen.
143 
144  static G4int createInstance();
145  // used to initialise HepRandom::isActive and instantiate singleton
146 
147  static G4int createInstanceOnce();
148  // used to initialise HepRandom::isActive and instantiate singleton
149 
150 private: // -------- Data members ---------
151 
152  static G4ThreadLocal CLHEP::HepRandomEngine * theEngine;
153  // The corresponding algorithm.
154 
156  // The common shared static generator
157 
159  // Flag notifying singleton instance
160 
162  // True if the engine should be deleted on destruction.
163 };
164 
165 std::ostream & operator<< (std::ostream & os, const G4MTHepRandom & dist);
166 std::istream & operator>> (std::istream & is, G4MTHepRandom & dist);
167 
168 #include "G4MTHepRandom.icc"
169 
170 #endif
static G4long getTheSeed()
static CLHEP::HepRandomEngine * getTheEngine()
static std::ostream & saveDistState(std::ostream &os)
static const double lux
Definition: G4SIunits.hh:324
virtual ~G4MTHepRandom()
static G4MTHepRandom * getTheGenerator()
static G4ThreadLocal G4MTHepRandom * theGenerator
std::istream & operator>>(std::istream &is, G4MTHepRandom &dist)
static G4int createInstance()
static void setTheSeeds(const G4long *seeds, G4int aux=-1)
static void setTheEngine(CLHEP::HepRandomEngine *theNewEngine)
long G4long
Definition: G4Types.hh:80
static void getTheTableSeeds(G4long *seeds, G4int index)
static void saveEngineStatus(const char filename[]="Config.conf")
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
static void setTheSeed(G4long seed, G4int lux=3)
static std::istream & restoreDistState(std::istream &is)
static std::istream & restoreFullState(std::istream &is)
static std::ostream & saveStaticRandomStates(std::ostream &os)
bool G4bool
Definition: G4Types.hh:79
static std::istream & restoreStaticRandomStates(std::istream &is)
static G4int createInstanceOnce()
static void showEngineStatus()
static std::ostream & saveFullState(std::ostream &os)
static G4ThreadLocal G4int isActive
G4double flat()
virtual std::ostream & put(std::ostream &os) const
static void restoreEngineStatus(const char filename[]="Config.conf")
std::ostream & operator<<(std::ostream &os, const G4MTHepRandom &dist)
static const G4long * getTheSeeds()
virtual G4double operator()()
double G4double
Definition: G4Types.hh:76
void flatArray(const G4int size, G4double *vect)
static G4ThreadLocal CLHEP::HepRandomEngine * theEngine