source: Sophya/trunk/SophyaLib/BaseTools/randr48.h@ 3612

Last change on this file since 3612 was 3612, checked in by ansari, 16 years ago

Suite modifs / adaptation avec l'introduction de la suite des classes RandomGeneratorInterface et Cie , Reza 30/04/2009

File size: 2.9 KB
Line 
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
16namespace SOPHYA {
17
18//! Implementation of the RandomGeneratorInterface class using drand48() functions
19class 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//--------------------------------------------------------------------------------
41
42//! Version thread-safe de RandomGeneratorInterface avec drand48() functions
43class ThSDR48RandGen : public DR48RandGen {
44
45 public:
46 ThSDR48RandGen(size_t n=1024,bool tsafe=true);
47 ThSDR48RandGen(ThSDR48RandGen const & rg);
48 virtual ~ThSDR48RandGen();
49
50 void SetBuffSize(size_t n);
51
52 virtual void SetSeed(long int seed);
53 virtual void SetSeed(uint_2 seed[3]);
54 virtual void GetSeed(uint_2 seed[3]);
55 virtual void AutoInit(int lp=0);
56
57 friend class ObjFileIO<ThSDR48RandGen> ;
58
59 protected:
60 // ---- protected data members
61 NDataBlock<r_8> rseq_;
62 size_t idx_;
63 bool fg_nothrsafe; // if true --> NOT thread-safe
64 // ---- protected methods
65 void GenSeq();
66 virtual r_8 Next();
67
68 // Non thread-safe version of Init() and GetSeed()
69 void SetSeed_P(uint_2 seed[3]);
70 void GetSeed_P(uint_2 seed[3]);
71
72};
73
74// Classe pour la gestion de persistance PPF : ObjFileIO<ThSDR48RandGen>
75
76/*! Writes the random generator object state in the POutPersist stream \b os */
77inline POutPersist& operator << (POutPersist& os, ThSDR48RandGen & obj)
78{ ObjFileIO<ThSDR48RandGen> fio(&obj); fio.Write(os); return(os); }
79/*! Reads the random generator object state from the PInPersist stream \b is */
80inline PInPersist& operator >> (PInPersist& is, ThSDR48RandGen & obj)
81{ ObjFileIO<ThSDR48RandGen> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
82
83// Classe pour la gestion de persistance PPF : ObjFileIO<DR48RandGen>
84
85/*! Writes the random generator object state in the POutPersist stream \b os */
86inline POutPersist& operator << (POutPersist& os, DR48RandGen & obj)
87{ ObjFileIO<DR48RandGen> fio(&obj); fio.Write(os); return(os); }
88/*! Reads the random generator object state from the PInPersist stream \b is */
89inline PInPersist& operator >> (PInPersist& is, DR48RandGen & obj)
90{ ObjFileIO<DR48RandGen> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
91
92} /* namespace SOPHYA */
93
94#endif
Note: See TracBrowser for help on using the repository browser.