| [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 | 
 | 
|---|
 | 17 | /* ------- SPECIFIQUE Mac Darwin OSX  <= 10.2 (gcc < 3.x) -------- */
 | 
|---|
 | 18 | #if defined(Darwin) &&  defined(__GNUC__) && (__GNUC__ < 3)
 | 
|---|
 | 19 | #include "osx_values.h"
 | 
|---|
 | 20 | /* Declaration de drand48 et srand48 etc , mis ds SysSpec, Reza 11/02/2003 */
 | 
|---|
 | 21 | #ifdef __cplusplus
 | 
|---|
 | 22 | extern "C" {
 | 
|---|
 | 23 | #endif
 | 
|---|
 | 24 | unsigned short int * seed48(unsigned short int seed16v[3]);
 | 
|---|
 | 25 | void srand48(long seedval);
 | 
|---|
 | 26 | #ifdef __cplusplus
 | 
|---|
 | 27 | }
 | 
|---|
 | 28 | #endif
 | 
|---|
 | 29 | #define drand48() ((double)(random())/LONG_MAX)
 | 
|---|
 | 30 | #endif
 | 
|---|
 | 31 | /* ------- FIN SPECIFIQUE Mac OSX / Darwin V <= 10.2 --------- */
 | 
|---|
 | 32 | 
 | 
|---|
 | 33 | 
 | 
|---|
| [3602] | 34 | namespace SOPHYA {
 | 
|---|
 | 35 | 
 | 
|---|
| [3604] | 36 | //! Implementation of the RandomGeneratorInterface class using drand48() functions 
 | 
|---|
| [3602] | 37 | class DR48RandGen : public RandomGeneratorInterface {
 | 
|---|
 | 38 | 
 | 
|---|
 | 39 |  public:
 | 
|---|
 | 40 |   DR48RandGen(long int seed=12345);
 | 
|---|
 | 41 |   virtual ~DR48RandGen();
 | 
|---|
 | 42 | 
 | 
|---|
 | 43 |   virtual void SetSeed(long int seed);
 | 
|---|
 | 44 |   virtual void SetSeed(uint_2 seed[3]);
 | 
|---|
 | 45 |   virtual void GetSeed(uint_2 seed[3]);
 | 
|---|
 | 46 |   virtual void AutoInit(int lp=0);
 | 
|---|
| [3615] | 47 |   virtual void ShowRandom();
 | 
|---|
| [3602] | 48 | 
 | 
|---|
 | 49 |   friend class ObjFileIO<DR48RandGen> ;
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 |  protected:
 | 
|---|
 | 52 |   virtual r_8 Next();
 | 
|---|
 | 53 | 
 | 
|---|
 | 54 | };
 | 
|---|
 | 55 | 
 | 
|---|
| [3612] | 56 | 
 | 
|---|
| [3602] | 57 | //--------------------------------------------------------------------------------
 | 
|---|
 | 58 | //--------------------------------------------------------------------------------
 | 
|---|
 | 59 | //--------------------------------------------------------------------------------
 | 
|---|
 | 60 | 
 | 
|---|
| [3604] | 61 | //! Version thread-safe de RandomGeneratorInterface avec drand48() functions 
 | 
|---|
| [3602] | 62 | class ThSDR48RandGen : public DR48RandGen {
 | 
|---|
 | 63 | 
 | 
|---|
 | 64 |  public:
 | 
|---|
 | 65 |   ThSDR48RandGen(size_t n=1024,bool tsafe=true);
 | 
|---|
 | 66 |   ThSDR48RandGen(ThSDR48RandGen const & rg);
 | 
|---|
 | 67 |   virtual ~ThSDR48RandGen();
 | 
|---|
 | 68 | 
 | 
|---|
 | 69 |   void SetBuffSize(size_t n);
 | 
|---|
 | 70 | 
 | 
|---|
 | 71 |   virtual void SetSeed(long int seed);
 | 
|---|
 | 72 |   virtual void SetSeed(uint_2 seed[3]);
 | 
|---|
 | 73 |   virtual void GetSeed(uint_2 seed[3]);
 | 
|---|
 | 74 |   virtual void AutoInit(int lp=0);
 | 
|---|
| [3615] | 75 |   virtual void ShowRandom();
 | 
|---|
| [3602] | 76 | 
 | 
|---|
 | 77 |   friend class ObjFileIO<ThSDR48RandGen> ;
 | 
|---|
 | 78 | 
 | 
|---|
 | 79 |  protected:
 | 
|---|
 | 80 |   // ---- protected data members
 | 
|---|
 | 81 |   NDataBlock<r_8>  rseq_;  
 | 
|---|
 | 82 |   size_t idx_;
 | 
|---|
 | 83 |   bool fg_nothrsafe;  // if true --> NOT thread-safe
 | 
|---|
 | 84 |   // ---- protected methods 
 | 
|---|
 | 85 |   void GenSeq();
 | 
|---|
| [3604] | 86 |   virtual r_8 Next();
 | 
|---|
 | 87 | 
 | 
|---|
| [3602] | 88 |   // Non thread-safe version of Init() and GetSeed()
 | 
|---|
 | 89 |   void SetSeed_P(uint_2 seed[3]);
 | 
|---|
 | 90 |   void GetSeed_P(uint_2 seed[3]);
 | 
|---|
 | 91 | 
 | 
|---|
 | 92 | };
 | 
|---|
 | 93 | 
 | 
|---|
 | 94 | // Classe pour la gestion de persistance PPF :  ObjFileIO<ThSDR48RandGen>
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 | /*! Writes the random generator object state in the POutPersist stream \b os */
 | 
|---|
 | 97 | inline POutPersist& operator << (POutPersist& os, ThSDR48RandGen & obj)
 | 
|---|
 | 98 | { ObjFileIO<ThSDR48RandGen> fio(&obj);  fio.Write(os);  return(os); }
 | 
|---|
 | 99 | /*! Reads the random generator object state from the PInPersist stream \b is */
 | 
|---|
 | 100 | inline PInPersist& operator >> (PInPersist& is, ThSDR48RandGen & obj)
 | 
|---|
 | 101 | { ObjFileIO<ThSDR48RandGen> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
 | 
|---|
 | 102 | 
 | 
|---|
 | 103 | // Classe pour la gestion de persistance PPF :  ObjFileIO<DR48RandGen>
 | 
|---|
 | 104 | 
 | 
|---|
 | 105 | /*! Writes the random generator object state in the POutPersist stream \b os */
 | 
|---|
 | 106 | inline POutPersist& operator << (POutPersist& os, DR48RandGen & obj)
 | 
|---|
 | 107 | { ObjFileIO<DR48RandGen> fio(&obj);  fio.Write(os);  return(os); }
 | 
|---|
 | 108 | /*! Reads the random generator object state from the PInPersist stream \b is */
 | 
|---|
 | 109 | inline PInPersist& operator >> (PInPersist& is, DR48RandGen & obj)
 | 
|---|
 | 110 | { ObjFileIO<DR48RandGen> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
 | 
|---|
 | 111 | 
 | 
|---|
 | 112 | } /* namespace SOPHYA */
 | 
|---|
 | 113 | 
 | 
|---|
 | 114 | #endif
 | 
|---|