| [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 |  | 
|---|
| [3615] | 16 |  | 
|---|
| [3602] | 17 | namespace SOPHYA { | 
|---|
|  | 18 |  | 
|---|
| [3838] | 19 | // Implementation de RandomGeneratorInterface avec drand48() | 
|---|
| [3602] | 20 | class DR48RandGen : public RandomGeneratorInterface { | 
|---|
|  | 21 |  | 
|---|
|  | 22 | public: | 
|---|
| [3739] | 23 | DR48RandGen(); | 
|---|
|  | 24 | DR48RandGen(long int seed); | 
|---|
| [3602] | 25 | virtual ~DR48RandGen(); | 
|---|
|  | 26 |  | 
|---|
|  | 27 | virtual void SetSeed(long int seed); | 
|---|
|  | 28 | virtual void SetSeed(uint_2 seed[3]); | 
|---|
|  | 29 | virtual void GetSeed(uint_2 seed[3]); | 
|---|
|  | 30 | virtual void AutoInit(int lp=0); | 
|---|
| [3615] | 31 | virtual void ShowRandom(); | 
|---|
| [3602] | 32 |  | 
|---|
|  | 33 | friend class ObjFileIO<DR48RandGen> ; | 
|---|
|  | 34 |  | 
|---|
|  | 35 | protected: | 
|---|
|  | 36 | virtual r_8 Next(); | 
|---|
|  | 37 |  | 
|---|
|  | 38 | }; | 
|---|
|  | 39 |  | 
|---|
| [3612] | 40 |  | 
|---|
| [3602] | 41 | //-------------------------------------------------------------------------------- | 
|---|
|  | 42 | //-------------------------------------------------------------------------------- | 
|---|
|  | 43 | //-------------------------------------------------------------------------------- | 
|---|
|  | 44 |  | 
|---|
| [3838] | 45 | // Version thread-safe de  DR48RandGen | 
|---|
| [3602] | 46 | class ThSDR48RandGen : public DR48RandGen { | 
|---|
|  | 47 |  | 
|---|
|  | 48 | public: | 
|---|
|  | 49 | ThSDR48RandGen(size_t n=1024,bool tsafe=true); | 
|---|
|  | 50 | ThSDR48RandGen(ThSDR48RandGen const & rg); | 
|---|
|  | 51 | virtual ~ThSDR48RandGen(); | 
|---|
|  | 52 |  | 
|---|
|  | 53 | void SetBuffSize(size_t n); | 
|---|
|  | 54 |  | 
|---|
|  | 55 | virtual void SetSeed(long int seed); | 
|---|
|  | 56 | virtual void SetSeed(uint_2 seed[3]); | 
|---|
|  | 57 | virtual void GetSeed(uint_2 seed[3]); | 
|---|
|  | 58 | virtual void AutoInit(int lp=0); | 
|---|
| [3615] | 59 | virtual void ShowRandom(); | 
|---|
| [3602] | 60 |  | 
|---|
|  | 61 | friend class ObjFileIO<ThSDR48RandGen> ; | 
|---|
|  | 62 |  | 
|---|
|  | 63 | protected: | 
|---|
|  | 64 | // ---- protected data members | 
|---|
|  | 65 | NDataBlock<r_8>  rseq_; | 
|---|
|  | 66 | size_t idx_; | 
|---|
|  | 67 | bool fg_nothrsafe;  // if true --> NOT thread-safe | 
|---|
|  | 68 | // ---- protected methods | 
|---|
|  | 69 | void GenSeq(); | 
|---|
| [3604] | 70 | virtual r_8 Next(); | 
|---|
|  | 71 |  | 
|---|
| [3890] | 72 | //! For PPF handler use | 
|---|
|  | 73 | inline void GetSeed_P(uint_2 seed[3]) | 
|---|
|  | 74 | { return DR48RandGen::GetSeed(seed); } | 
|---|
|  | 75 | //! For PPF handler use | 
|---|
|  | 76 | inline void SetSeed_P(uint_2 seed[3]) | 
|---|
|  | 77 | { return DR48RandGen::SetSeed(seed); } | 
|---|
| [3602] | 78 | }; | 
|---|
|  | 79 |  | 
|---|
|  | 80 | // Classe pour la gestion de persistance PPF :  ObjFileIO<ThSDR48RandGen> | 
|---|
|  | 81 |  | 
|---|
|  | 82 | /*! Writes the random generator object state in the POutPersist stream \b os */ | 
|---|
|  | 83 | inline POutPersist& operator << (POutPersist& os, ThSDR48RandGen & obj) | 
|---|
|  | 84 | { ObjFileIO<ThSDR48RandGen> fio(&obj);  fio.Write(os);  return(os); } | 
|---|
|  | 85 | /*! Reads the random generator object state from the PInPersist stream \b is */ | 
|---|
|  | 86 | inline PInPersist& operator >> (PInPersist& is, ThSDR48RandGen & obj) | 
|---|
|  | 87 | { ObjFileIO<ThSDR48RandGen> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); } | 
|---|
|  | 88 |  | 
|---|
|  | 89 | // Classe pour la gestion de persistance PPF :  ObjFileIO<DR48RandGen> | 
|---|
|  | 90 |  | 
|---|
|  | 91 | /*! Writes the random generator object state in the POutPersist stream \b os */ | 
|---|
|  | 92 | inline POutPersist& operator << (POutPersist& os, DR48RandGen & obj) | 
|---|
|  | 93 | { ObjFileIO<DR48RandGen> fio(&obj);  fio.Write(os);  return(os); } | 
|---|
|  | 94 | /*! Reads the random generator object state from the PInPersist stream \b is */ | 
|---|
|  | 95 | inline PInPersist& operator >> (PInPersist& is, DR48RandGen & obj) | 
|---|
|  | 96 | { ObjFileIO<DR48RandGen> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); } | 
|---|
|  | 97 |  | 
|---|
|  | 98 | } /* namespace SOPHYA */ | 
|---|
|  | 99 |  | 
|---|
|  | 100 | #endif | 
|---|