ATLAS Offline Software
Loading...
Searching...
No Matches
dSFMTEngine.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5// dSFMTEngine.h
6// base source code copied from CLHEP 1.9.4.7 version of MTwistEngine, than
7// adopted to use dSFMT
8// author Michael Duehrssen
9
10#ifndef dSFMTEngine_h
11#define dSFMTEngine_h
12
13#include <stdexcept>
14#include <atomic>
15#include "CLHEP/Random/defs.h"
16#include "CLHEP/Random/RandomEngine.h"
17
18#include <stdint.h>
19// forward declare the base data struct of the dSFMT method
20// dSFMT internally uses dsfmt_t, which is
21// typedef struct DSFMT_T dsfmt_t;
22// unfortunately, typedefs can't be forward declared
23struct DSFMT_T;
24
25namespace CLHEP {
26
31class dSFMTEngine : public HepRandomEngine {
32
33public:
35 dSFMTEngine( long seed );
36 dSFMTEngine( const long * seeds );
37 virtual ~dSFMTEngine();
38 // Constructors and destructor.
39
40 dSFMTEngine( const dSFMTEngine & p );
41 dSFMTEngine & operator=( const dSFMTEngine & p );
42 // Copy constructor and operator=.
43
44 virtual double flat() override;
45 // Returns a pseudo random number between 0 and 1 (excluding the end points).
46
47 virtual void flatArray(const int size, double* vect) override;
48 // Fills an array "vect" of specified size with flat random values.
49
50 virtual void setSeed(long seed, int k=0) override;
51 // Sets the state of the algorithm according to seed.
52
53 void setSeeds(const uint32_t * seeds, int k=0);
54 // Sets the state of the algorithm according to the zero terminated
55 // array of seeds. It is allowed to ignore one or many seeds in this array.
56
57 virtual void setSeeds(const long * seeds, int k=0) override;
58 // Sets the state of the algorithm according to the zero terminated
59 // array of seeds. It is allowed to ignore one or many seeds in this array.
60
61 virtual void saveStatus( const char filename[] = "MTwist.conf") const override;
62 // Saves the current engine status in the named file
63
64 virtual void restoreStatus( const char filename[] = "MTwist.conf" ) override;
65 // Reads from named file the the last saved engine status and restores it.
66
67 virtual void showStatus() const override;
68 // Dumps the current engine status on the screen.
69
70 using HepRandomEngine::operator double;
71 virtual operator float() override; // returns flat, without worrying about filling bits
72 virtual operator unsigned int() override; // 32-bit flat, quickest of all
73
74 virtual std::ostream & put (std::ostream & os) const override;
75 virtual std::istream & get (std::istream & is) override;
76 static std::string beginTag ( );
77 virtual std::istream & getState ( std::istream & is ) override;
78
79 virtual std::string name() const override;
80 static std::string engineName() {return "MTwistEngine";}
81
82 virtual std::vector<unsigned long> put () const override;
83 virtual bool get (const std::vector<unsigned long> & v) override;
84 virtual bool getState (const std::vector<unsigned long> & v) override;
85
86private:
87 DSFMT_T* m_dsfmt;
88 void init_dsfmt();
89
90 static std::atomic<int> numEngines;
91 static constexpr int maxIndex = 215;
92}; // dSFMTEngine
93
94} // namespace CLHEP
95
96#ifdef ENABLE_BACKWARDS_COMPATIBILITY
97// backwards compatibility will be enabled ONLY in CLHEP 1.9
98using namespace CLHEP;
99#endif
100
101#endif // dSFMTEngine_h
virtual std::string name() const override
virtual std::istream & get(std::istream &is) override
static std::atomic< int > numEngines
Definition dSFMTEngine.h:90
void setSeeds(const uint32_t *seeds, int k=0)
static std::string engineName()
Definition dSFMTEngine.h:80
static constexpr int maxIndex
Definition dSFMTEngine.h:91
static std::string beginTag()
virtual void setSeed(long seed, int k=0) override
virtual void showStatus() const override
dSFMTEngine & operator=(const dSFMTEngine &p)
virtual void saveStatus(const char filename[]="MTwist.conf") const override
virtual void flatArray(const int size, double *vect) override
virtual double flat() override
virtual std::vector< unsigned long > put() const override
virtual std::istream & getState(std::istream &is) override
virtual void restoreStatus(const char filename[]="MTwist.conf") override