Changeset 3612 in Sophya
- Timestamp:
- Apr 30, 2009, 7:06:50 PM (16 years ago)
- Location:
- trunk/SophyaLib/BaseTools
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/basetools.h
r3602 r3612 21 21 #include "perrors.h" 22 22 #include "srandgen.h" 23 #include "stsrand.h"24 23 #include "datatype.h" 24 #include "randr48.h" 25 25 #include "randfmt.h" 26 #include "randr48.h"27 26 28 27 #endif -
trunk/SophyaLib/BaseTools/randinterf.h
r3609 r3612 15 15 namespace SOPHYA { 16 16 17 //! enum definition for usual types of probability distributio finctions 18 enum RNDTypes { 19 C_RND_Flat = 0, 20 C_RND_Gaussian = 1, 21 C_RND_Poisson = 2, 22 C_RND_Exponential = 3 23 }; 24 17 25 //! enum definition for the type of algorithm used for Gaussian distribution generation 18 26 enum GaussianGenAlgo { -
trunk/SophyaLib/BaseTools/randr48.h
r3604 r3612 34 34 35 35 }; 36 36 37 37 38 //-------------------------------------------------------------------------------- -
trunk/SophyaLib/BaseTools/sophyainit.cc
r3611 r3612 15 15 #include "dvlist.h" 16 16 17 #include "stsrand.h"18 17 #include "randr48.h" 19 18 #include "randfmt.h" … … 23 22 24 23 #include "sversion.h" 25 26 #include "randr48.h"27 24 28 25 #include <iostream> … … 71 68 72 69 // --- Les generateurs aleatoires ... 73 DR48RandGen* grgp = new DR48RandGen;70 DR48RandGen* grgp = new ThSDR48RandGen; 74 71 RandomGeneratorInterface::SetGlobalRandGenP(grgp); 75 72 … … 109 106 110 107 // Enregistrement des handlers PPF pour les RandomGenerator 111 PPRegister(ObjFileIO<RandomGenerator>);112 DObjRegister(ObjFileIO<RandomGenerator>, RandomGenerator);113 108 PPRegister(ObjFileIO<DR48RandGen>); 114 109 DObjRegister(ObjFileIO<DR48RandGen>,DR48RandGen ); -
trunk/SophyaLib/BaseTools/stsrand.cc
r3599 r3612 9 9 10 10 /*! 11 \class RandomGenerator11 \class STSRandGen 12 12 \ingroup BaseTools 13 13 \brief Random number generator … … 17 17 random number generator used. 18 18 19 \sa SOPHYA::ObjFileIO< RandomGenerator>19 \sa SOPHYA::ObjFileIO<STSRandGen> 20 20 21 21 \sa frand01 drand01 frandpm1 drandpm1 … … 29 29 static ThSafeOp* ths_rand = NULL; 30 30 31 RandomGenerator::RandomGenerator(size_t n, bool tsafe)31 STSRandGen::STSRandGen(size_t n, bool tsafe) 32 32 { 33 33 if (ths_rand == NULL) ths_rand = new ThSafeOp; … … 44 44 } 45 45 46 RandomGenerator::RandomGenerator(RandomGeneratorconst & rg)46 STSRandGen::STSRandGen(STSRandGen const & rg) 47 47 { 48 48 if (ths_rand == NULL) ths_rand = new ThSafeOp; … … 59 59 60 60 61 RandomGenerator::~RandomGenerator(void)61 STSRandGen::~STSRandGen(void) 62 62 { 63 63 // rien a faire 64 64 } 65 65 66 void RandomGenerator::SetBuffSize(size_t n)66 void STSRandGen::SetBuffSize(size_t n) 67 67 // redimensionnement du buffer 68 68 { … … 73 73 } 74 74 75 void RandomGenerator::AutoInit(int lp)75 void STSRandGen::AutoInit(int lp) 76 76 // Initialisation automatique (pseudo) aleatoire du generateur. 77 77 // L'initialiseur est donne par un codage du nombre de millisecondes … … 133 133 } 134 134 } 135 if(lp>0) cout<<" RandomGenerator::AutoInit: "<<seed_16v[0]<<" "<<seed_16v[1]<<" "<<seed_16v[2]<<endl;135 if(lp>0) cout<<"STSRandGen::AutoInit: "<<seed_16v[0]<<" "<<seed_16v[1]<<" "<<seed_16v[2]<<endl; 136 136 137 137 // Initialise drand48() … … 139 139 } 140 140 141 void RandomGenerator::Init(long seed_val, int lp)142 { 143 if (ths_rand == NULL) ths_rand = new ThSafeOp; 144 if(lp) cout << " RandomGenerator::Init(long seed=" << seed_val << ")" << endl;141 void STSRandGen::Init(long seed_val, int lp) 142 { 143 if (ths_rand == NULL) ths_rand = new ThSafeOp; 144 if(lp) cout << "STSRandGen::Init(long seed=" << seed_val << ")" << endl; 145 145 ths_rand->lock(); 146 146 srand48(seed_val); … … 149 149 } 150 150 151 void RandomGenerator::Init(unsigned short seed_16v[3], int lp)152 { 153 if (ths_rand == NULL) ths_rand = new ThSafeOp; 154 if(lp) cout << " RandomGenerator::Init(u_short seed_16v[3]=" << seed_16v[0]151 void STSRandGen::Init(unsigned short seed_16v[3], int lp) 152 { 153 if (ths_rand == NULL) ths_rand = new ThSafeOp; 154 if(lp) cout << "STSRandGen::Init(u_short seed_16v[3]=" << seed_16v[0] 155 155 << "," << seed_16v[1] << "," << seed_16v[2] << ")" << endl; 156 156 ths_rand->lock(); … … 159 159 } 160 160 161 void RandomGenerator::GetSeed(unsigned short seed_16v[3], int lp)161 void STSRandGen::GetSeed(unsigned short seed_16v[3], int lp) 162 162 { 163 163 if (ths_rand == NULL) ths_rand = new ThSafeOp; … … 165 165 GetSeed_P(seed_16v); 166 166 ths_rand->unlock(); 167 if(lp) cout << " RandomGenerator::GetSeed(u_short seed_16v[3]=" << seed_16v[0]167 if(lp) cout << "STSRandGen::GetSeed(u_short seed_16v[3]=" << seed_16v[0] 168 168 << "," << seed_16v[1] << "," << seed_16v[2] << ")" << endl; 169 169 return; 170 170 } 171 171 172 void RandomGenerator::Init_P(unsigned short seed_16v[3])172 void STSRandGen::Init_P(unsigned short seed_16v[3]) 173 173 { 174 174 seed48(seed_16v); 175 175 } 176 176 177 void RandomGenerator::GetSeed_P(unsigned short seed_16v[3])177 void STSRandGen::GetSeed_P(unsigned short seed_16v[3]) 178 178 { 179 179 unsigned short seed[3] = {0,0,0}; … … 186 186 } 187 187 188 r_8 RandomGenerator::Gaussian()188 r_8 STSRandGen::Gaussian() 189 189 { 190 190 r_8 A=Next(); … … 194 194 195 195 196 uint_8 RandomGenerator::Poisson(double mu,double mumax)196 uint_8 STSRandGen::Poisson(double mu,double mumax) 197 197 { 198 198 double pp,ppi,x; … … 218 218 } 219 219 220 void RandomGenerator::GenSeq(void)220 void STSRandGen::GenSeq(void) 221 221 { 222 222 ths_rand->lock(); … … 228 228 //---------------------------------------------------------- 229 229 // Classe pour la gestion de persistance 230 // ObjFileIO< RandomGenerator>230 // ObjFileIO<STSRandGen> 231 231 //---------------------------------------------------------- 232 232 233 233 /* --Methode-- */ 234 234 DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ 235 void ObjFileIO< RandomGenerator>::WriteSelf(POutPersist& s) const235 void ObjFileIO<STSRandGen>::WriteSelf(POutPersist& s) const 236 236 { 237 237 if (dobj == NULL) 238 throw NullPtrError("ObjFileIO< RandomGenerator>::WriteSelf() dobj=NULL");238 throw NullPtrError("ObjFileIO<STSRandGen>::WriteSelf() dobj=NULL"); 239 239 ths_rand->lock(); // thread-safety 240 240 uint_4 itab[6]; … … 259 259 /* --Methode-- */ 260 260 DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */ 261 void ObjFileIO< RandomGenerator>::ReadSelf(PInPersist& s)261 void ObjFileIO<STSRandGen>::ReadSelf(PInPersist& s) 262 262 { 263 263 uint_4 itab[6]; … … 268 268 s.Get(ix); // Taille du tableau intermediaire 269 269 270 if (dobj == NULL) dobj = new RandomGenerator(sz, (sz>0)?true:false);270 if (dobj == NULL) dobj = new STSRandGen(sz, (sz>0)?true:false); 271 271 dobj->idx_ = ix; 272 272 if (sz > 0) { … … 288 288 // --------------------------------------------------------- 289 289 #ifdef __CXX_PRAGMA_TEMPLATES__ 290 #pragma define_template ObjFileIO< RandomGenerator>290 #pragma define_template ObjFileIO<STSRandGen> 291 291 #endif 292 292 293 293 #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) 294 template class ObjFileIO< RandomGenerator>;294 template class ObjFileIO<STSRandGen>; 295 295 #endif 296 296 // --------------------------------------------------------- -
trunk/SophyaLib/BaseTools/stsrand.h
r3599 r3612 16 16 namespace SOPHYA { 17 17 18 class RandomGenerator: public AnyDataObj {18 class STSRandGen : public AnyDataObj { 19 19 20 20 public: 21 RandomGenerator(size_t n = 1024, bool tsafe=true);22 RandomGenerator(RandomGeneratorconst & rg);21 STSRandGen(size_t n = 1024, bool tsafe=true); 22 STSRandGen(STSRandGen const & rg); 23 23 24 24 void SetBuffSize(size_t n); 25 25 26 virtual ~ RandomGenerator();26 virtual ~STSRandGen(); 27 27 28 28 /*! \brief Automatic initialization using the current time */ … … 72 72 73 73 // Pour la gestion de persistance PPF 74 friend class ObjFileIO< RandomGenerator> ;74 friend class ObjFileIO<STSRandGen> ; 75 75 76 76 protected: … … 93 93 static void GetSeed_P(unsigned short seed_16v[3]); 94 94 95 }; // Fin de la classe RandomGenerator95 }; // Fin de la classe STSRandGen 96 96 97 // Classe pour la gestion de persistance PPF : ObjFileIO< RandomGenerator>97 // Classe pour la gestion de persistance PPF : ObjFileIO<STSRandGen> 98 98 99 99 /*! Writes the random generator object state in the POutPersist stream \b os */ 100 inline POutPersist& operator << (POutPersist& os, RandomGenerator& obj)101 { ObjFileIO< RandomGenerator> fio(&obj); fio.Write(os); return(os); }100 inline POutPersist& operator << (POutPersist& os, STSRandGen & obj) 101 { ObjFileIO<STSRandGen> fio(&obj); fio.Write(os); return(os); } 102 102 /*! Reads the random generator object state from the PInPersist stream \b is */ 103 inline PInPersist& operator >> (PInPersist& is, RandomGenerator& obj)104 { ObjFileIO< RandomGenerator> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }103 inline PInPersist& operator >> (PInPersist& is, STSRandGen & obj) 104 { ObjFileIO<STSRandGen> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); } 105 105 106 106 } /* namespace SOPHYA */
Note:
See TracChangeset
for help on using the changeset viewer.