[3602] | 1 | #ifndef RANDR48_H_SEEN
|
---|
| 2 | #define RANDR48_H_SEEN
|
---|
| 3 |
|
---|
| 4 | // Classes DR48RandGen
|
---|
| 5 | // Generateur aleatoire utilisant l'aleatoire drand48()
|
---|
| 6 | //
|
---|
| 7 | // R. Ansari (C) UPS+LAL IN2P3/CNRS 2009
|
---|
| 8 | // C. Magneville (C) DAPNIA/SPP CEA 2009
|
---|
| 9 |
|
---|
| 10 |
|
---|
| 11 | #include "machdefs.h"
|
---|
| 12 | #include "objfio.h"
|
---|
| 13 | #include "ndatablock.h"
|
---|
| 14 | #include "randinterf.h"
|
---|
| 15 |
|
---|
| 16 | namespace SOPHYA {
|
---|
| 17 |
|
---|
[3604] | 18 | //! Implementation of the RandomGeneratorInterface class using drand48() functions
|
---|
[3602] | 19 | class DR48RandGen : public RandomGeneratorInterface {
|
---|
| 20 |
|
---|
| 21 | public:
|
---|
| 22 | DR48RandGen(long int seed=12345);
|
---|
| 23 | virtual ~DR48RandGen();
|
---|
| 24 |
|
---|
| 25 | virtual void SetSeed(long int seed);
|
---|
| 26 | virtual void SetSeed(uint_2 seed[3]);
|
---|
| 27 | virtual void GetSeed(uint_2 seed[3]);
|
---|
| 28 | virtual void AutoInit(int lp=0);
|
---|
| 29 |
|
---|
| 30 | friend class ObjFileIO<DR48RandGen> ;
|
---|
| 31 |
|
---|
| 32 | protected:
|
---|
| 33 | virtual r_8 Next();
|
---|
| 34 |
|
---|
| 35 | };
|
---|
| 36 |
|
---|
| 37 | //--------------------------------------------------------------------------------
|
---|
| 38 | //--------------------------------------------------------------------------------
|
---|
| 39 | //--------------------------------------------------------------------------------
|
---|
| 40 |
|
---|
[3604] | 41 | //! Version thread-safe de RandomGeneratorInterface avec drand48() functions
|
---|
[3602] | 42 | class ThSDR48RandGen : public DR48RandGen {
|
---|
| 43 |
|
---|
| 44 | public:
|
---|
| 45 | ThSDR48RandGen(size_t n=1024,bool tsafe=true);
|
---|
| 46 | ThSDR48RandGen(ThSDR48RandGen const & rg);
|
---|
| 47 | virtual ~ThSDR48RandGen();
|
---|
| 48 |
|
---|
| 49 | void SetBuffSize(size_t n);
|
---|
| 50 |
|
---|
| 51 | virtual void SetSeed(long int seed);
|
---|
| 52 | virtual void SetSeed(uint_2 seed[3]);
|
---|
| 53 | virtual void GetSeed(uint_2 seed[3]);
|
---|
| 54 | virtual void AutoInit(int lp=0);
|
---|
| 55 |
|
---|
| 56 | friend class ObjFileIO<ThSDR48RandGen> ;
|
---|
| 57 |
|
---|
| 58 | protected:
|
---|
| 59 | // ---- protected data members
|
---|
| 60 | NDataBlock<r_8> rseq_;
|
---|
| 61 | size_t idx_;
|
---|
| 62 | bool fg_nothrsafe; // if true --> NOT thread-safe
|
---|
| 63 | // ---- protected methods
|
---|
| 64 | void GenSeq();
|
---|
[3604] | 65 | virtual r_8 Next();
|
---|
| 66 |
|
---|
[3602] | 67 | // Non thread-safe version of Init() and GetSeed()
|
---|
| 68 | void SetSeed_P(uint_2 seed[3]);
|
---|
| 69 | void GetSeed_P(uint_2 seed[3]);
|
---|
| 70 |
|
---|
| 71 | };
|
---|
| 72 |
|
---|
| 73 | // Classe pour la gestion de persistance PPF : ObjFileIO<ThSDR48RandGen>
|
---|
| 74 |
|
---|
| 75 | /*! Writes the random generator object state in the POutPersist stream \b os */
|
---|
| 76 | inline POutPersist& operator << (POutPersist& os, ThSDR48RandGen & obj)
|
---|
| 77 | { ObjFileIO<ThSDR48RandGen> fio(&obj); fio.Write(os); return(os); }
|
---|
| 78 | /*! Reads the random generator object state from the PInPersist stream \b is */
|
---|
| 79 | inline PInPersist& operator >> (PInPersist& is, ThSDR48RandGen & obj)
|
---|
| 80 | { ObjFileIO<ThSDR48RandGen> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
|
---|
| 81 |
|
---|
| 82 | // Classe pour la gestion de persistance PPF : ObjFileIO<DR48RandGen>
|
---|
| 83 |
|
---|
| 84 | /*! Writes the random generator object state in the POutPersist stream \b os */
|
---|
| 85 | inline POutPersist& operator << (POutPersist& os, DR48RandGen & obj)
|
---|
| 86 | { ObjFileIO<DR48RandGen> fio(&obj); fio.Write(os); return(os); }
|
---|
| 87 | /*! Reads the random generator object state from the PInPersist stream \b is */
|
---|
| 88 | inline PInPersist& operator >> (PInPersist& is, DR48RandGen & obj)
|
---|
| 89 | { ObjFileIO<DR48RandGen> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
|
---|
| 90 |
|
---|
| 91 | } /* namespace SOPHYA */
|
---|
| 92 |
|
---|
| 93 | #endif
|
---|