CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
DRand48Engine.h
Go to the documentation of this file.
1// $Id: DRand48Engine.h,v 1.5 2010/06/16 17:24:53 garren Exp $
2// -*- C++ -*-
3//
4// -----------------------------------------------------------------------
5// HEP Random
6// --- DRand48Engine ---
7// class header file
8// -----------------------------------------------------------------------
9// This file is part of Geant4 (simulation toolkit for HEP).
10//
11// Random engine using drand48() and srand48() functions from C standard
12// library to implement the flat() basic distribution and for setting
13// seeds.
14// For Windows/NT platforms (WIN32), the code for drand48 has been
15// extracted from the GNU C Library 2.0.1 and adapted for the native
16// types.
17// Copy constructor and operator= are private for objects of this class.
18//
19// WARNING: drand48 is not thread safe. If you need to use multiple
20// engine objects on different threads concurrently, do not use DRand48Engine
21
22// =======================================================================
23// G.Cosmo - Created: 5th September 1995
24// - Minor corrections: 31st October 1996
25// - Added methods for engine status: 19th November 1996
26// - Added srand48(), seed48(), drand48() implementations
27// for Windows/NT: 6th March 1997
28// - setSeed(), setSeeds() now have default dummy argument
29// set to zero: 11th July 1997
30// E.Tcherniaev - Porting on KCC compiler: 2nd Feb 1998
31// G.Cosmo - Private copy constructor and operator=: 26th Feb 1998
32// J.Marraffino - Added stream operators and related constructor.
33// Added automatic seed selection from seed table and
34// engine counter: 16th Feb 1998
35// E.Tcherniaev - Removed #ifdef for prototypes for drand48(), srand48()
36// and seed48();
37// - More accurate code for drand48() on NT base on
38// a code extracted from GNU C Library 2.1.3: 8th Nov 2000
39// E.Tcherniaev - prototypes for drand48(), srand48() and seed48() have
40// been moved to DRand48Engine.cc: 21 Feb 2002
41// Mark Fischler - methods for distrib. instance save/restore 12/8/04
42// Mark Fischler - methods for anonymous save/restore 12/27/04
43// Mark Fischler - methods for vector save/restore 3/7/05
44// =======================================================================
45
46#ifndef DRand48Engine_h
47#define DRand48Engine_h 1
48
49#include "CLHEP/Random/defs.h"
50#include "CLHEP/Random/RandomEngine.h"
51#include "CLHEP/Utility/noncopyable.h"
52
53namespace CLHEP {
54
55/**
56 * @author <[email protected]>
57 * @ingroup random
58 */
60
61public:
62
63 DRand48Engine(std::istream& is);
65 DRand48Engine(long seed);
66 DRand48Engine(int rowIndex, int colIndex);
67 virtual ~DRand48Engine();
68 // Constructors and destructor
69
70 double flat();
71 // It returns a pseudo random number between 0 and 1,
72 // according to the standard stdlib random function drand48()
73 // but excluding the end points.
74
75 void flatArray (const int size, double* vect);
76 // Fills the array "vect" of specified size with flat random values.
77
78 void setSeed(long seed, int dum=0);
79 // Sets the state of the algorithm according to seed.
80
81 void setSeeds(const long * seeds, int dum=0);
82 // Sets the state of the algorithm according to the zero terminated
83 // array of seeds. Only the first seed is used.
84
85 void saveStatus( const char filename[] = "DRand48.conf" ) const;
86 // Saves on file DRand48.conf the current engine status.
87
88 void restoreStatus( const char filename[] = "DRand48.conf" );
89 // Reads from file DRand48.conf the last saved engine status
90 // and restores it.
91
92 void showStatus() const;
93 // Dumps the engine status on the screen.
94
95 virtual std::ostream & put (std::ostream & os) const;
96 virtual std::istream & get (std::istream & is);
97 static std::string beginTag ( );
98 virtual std::istream & getState ( std::istream & is );
99
100 std::string name() const;
101 static std::string engineName() {return "DRand48Engine";}
102
103 std::vector<unsigned long> put () const;
104 bool get (const std::vector<unsigned long> & v);
105 bool getState (const std::vector<unsigned long> & v);
106
107 static const unsigned int VECTOR_STATE_SIZE = 4;
108
109private:
110
111 static int numEngines;
112 static const int maxIndex;
113
114};
115
116} // namespace CLHEP
117
118#ifdef ENABLE_BACKWARDS_COMPATIBILITY
119// backwards compatibility will be enabled ONLY in CLHEP 1.9
120using namespace CLHEP;
121#endif
122
123#endif
virtual std::istream & getState(std::istream &is)
static std::string engineName()
void showStatus() const
static std::string beginTag()
void setSeed(long seed, int dum=0)
static const unsigned int VECTOR_STATE_SIZE
void setSeeds(const long *seeds, int dum=0)
virtual std::istream & get(std::istream &is)
void saveStatus(const char filename[]="DRand48.conf") const
std::vector< unsigned long > put() const
std::string name() const
void restoreStatus(const char filename[]="DRand48.conf")
void flatArray(const int size, double *vect)