Changeset 3612 in Sophya


Ignore:
Timestamp:
Apr 30, 2009, 7:06:50 PM (16 years ago)
Author:
ansari
Message:

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

Location:
trunk/SophyaLib/BaseTools
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/BaseTools/basetools.h

    r3602 r3612  
    2121#include "perrors.h"
    2222#include "srandgen.h"
    23 #include "stsrand.h"
    2423#include "datatype.h"
     24#include "randr48.h"
    2525#include "randfmt.h"
    26 #include "randr48.h"
    2726
    2827#endif
  • trunk/SophyaLib/BaseTools/randinterf.h

    r3609 r3612  
    1515namespace SOPHYA {
    1616
     17//! enum definition for usual types of probability distributio finctions
     18enum RNDTypes {
     19  C_RND_Flat = 0,
     20  C_RND_Gaussian = 1,
     21  C_RND_Poisson = 2,
     22  C_RND_Exponential = 3
     23};
     24 
    1725//! enum definition for the type of algorithm used for Gaussian distribution generation
    1826enum GaussianGenAlgo {
  • trunk/SophyaLib/BaseTools/randr48.h

    r3604 r3612  
    3434
    3535};
     36
    3637
    3738//--------------------------------------------------------------------------------
  • trunk/SophyaLib/BaseTools/sophyainit.cc

    r3611 r3612  
    1515#include "dvlist.h"
    1616
    17 #include "stsrand.h"
    1817#include "randr48.h"
    1918#include "randfmt.h"
     
    2322
    2423#include "sversion.h"
    25 
    26 #include "randr48.h"
    2724
    2825#include <iostream>
     
    7168
    7269  // --- Les generateurs aleatoires ...
    73   DR48RandGen* grgp = new  DR48RandGen;
     70  DR48RandGen* grgp = new  ThSDR48RandGen;
    7471  RandomGeneratorInterface::SetGlobalRandGenP(grgp);
    7572
     
    109106
    110107  // Enregistrement des handlers PPF pour les RandomGenerator
    111   PPRegister(ObjFileIO<RandomGenerator>);
    112   DObjRegister(ObjFileIO<RandomGenerator>, RandomGenerator);
    113108  PPRegister(ObjFileIO<DR48RandGen>);
    114109  DObjRegister(ObjFileIO<DR48RandGen>,DR48RandGen );
  • trunk/SophyaLib/BaseTools/stsrand.cc

    r3599 r3612  
    99
    1010/*!
    11    \class RandomGenerator
     11   \class STSRandGen
    1212   \ingroup BaseTools
    1313   \brief Random number generator
     
    1717   random number generator used.
    1818
    19    \sa SOPHYA::ObjFileIO<RandomGenerator>
     19   \sa SOPHYA::ObjFileIO<STSRandGen>
    2020
    2121   \sa frand01 drand01 frandpm1 drandpm1
     
    2929static ThSafeOp* ths_rand = NULL;
    3030
    31 RandomGenerator::RandomGenerator(size_t n, bool tsafe)
     31STSRandGen::STSRandGen(size_t n, bool tsafe)
    3232{
    3333  if (ths_rand == NULL)  ths_rand = new ThSafeOp;
     
    4444}
    4545
    46 RandomGenerator::RandomGenerator(RandomGenerator const & rg)
     46STSRandGen::STSRandGen(STSRandGen const & rg)
    4747{
    4848  if (ths_rand == NULL)  ths_rand = new ThSafeOp;
     
    5959
    6060
    61 RandomGenerator::~RandomGenerator(void)
     61STSRandGen::~STSRandGen(void)
    6262{
    6363  // rien a faire
    6464}
    6565
    66 void RandomGenerator::SetBuffSize(size_t n)
     66void STSRandGen::SetBuffSize(size_t n)
    6767// redimensionnement du buffer
    6868{
     
    7373}
    7474
    75 void RandomGenerator::AutoInit(int lp)
     75void STSRandGen::AutoInit(int lp)
    7676// Initialisation automatique (pseudo) aleatoire du generateur.
    7777// L'initialiseur est donne par un codage du nombre de millisecondes
     
    133133    }
    134134  }
    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;
    136136
    137137  // Initialise drand48()
     
    139139}
    140140
    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;
     141void 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;
    145145  ths_rand->lock();
    146146  srand48(seed_val);
     
    149149}
    150150
    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]
     151void 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]
    155155              << "," << seed_16v[1] << "," << seed_16v[2] << ")" << endl;
    156156  ths_rand->lock();
     
    159159}
    160160
    161 void RandomGenerator::GetSeed(unsigned short seed_16v[3], int lp)
     161void STSRandGen::GetSeed(unsigned short seed_16v[3], int lp)
    162162{
    163163  if (ths_rand == NULL)  ths_rand = new ThSafeOp;
     
    165165  GetSeed_P(seed_16v);
    166166  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]
    168168              << "," << seed_16v[1] << "," << seed_16v[2] << ")" << endl;
    169169  return;
    170170}
    171171
    172 void RandomGenerator::Init_P(unsigned short seed_16v[3])
     172void STSRandGen::Init_P(unsigned short seed_16v[3])
    173173{
    174174  seed48(seed_16v);
    175175}
    176176
    177 void RandomGenerator::GetSeed_P(unsigned short seed_16v[3])
     177void STSRandGen::GetSeed_P(unsigned short seed_16v[3])
    178178{
    179179  unsigned short seed[3] = {0,0,0};
     
    186186}
    187187
    188 r_8 RandomGenerator::Gaussian()
     188r_8 STSRandGen::Gaussian()
    189189{
    190190  r_8 A=Next();
     
    194194
    195195
    196 uint_8 RandomGenerator::Poisson(double mu,double mumax)
     196uint_8 STSRandGen::Poisson(double mu,double mumax)
    197197{
    198198  double pp,ppi,x;
     
    218218}
    219219
    220 void RandomGenerator::GenSeq(void)
     220void STSRandGen::GenSeq(void)
    221221{
    222222  ths_rand->lock();
     
    228228//----------------------------------------------------------
    229229// Classe pour la gestion de persistance
    230 // ObjFileIO<RandomGenerator>
     230// ObjFileIO<STSRandGen>
    231231//----------------------------------------------------------
    232232
    233233/* --Methode-- */
    234234DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */
    235 void        ObjFileIO<RandomGenerator>::WriteSelf(POutPersist& s) const
     235void        ObjFileIO<STSRandGen>::WriteSelf(POutPersist& s) const
    236236{
    237237  if (dobj == NULL)
    238     throw NullPtrError("ObjFileIO<RandomGenerator>::WriteSelf() dobj=NULL");
     238    throw NullPtrError("ObjFileIO<STSRandGen>::WriteSelf() dobj=NULL");
    239239  ths_rand->lock();  // thread-safety
    240240  uint_4 itab[6];
     
    259259/* --Methode-- */
    260260DECL_TEMP_SPEC  /* equivalent a template <> , pour SGI-CC en particulier */
    261 void        ObjFileIO<RandomGenerator>::ReadSelf(PInPersist& s)
     261void        ObjFileIO<STSRandGen>::ReadSelf(PInPersist& s)
    262262{
    263263  uint_4 itab[6];
     
    268268  s.Get(ix);  // Taille du tableau intermediaire
    269269
    270   if (dobj == NULL) dobj = new RandomGenerator(sz, (sz>0)?true:false);
     270  if (dobj == NULL) dobj = new STSRandGen(sz, (sz>0)?true:false);
    271271  dobj->idx_ = ix;
    272272  if (sz > 0) {
     
    288288// ---------------------------------------------------------
    289289#ifdef __CXX_PRAGMA_TEMPLATES__
    290 #pragma define_template ObjFileIO<RandomGenerator>
     290#pragma define_template ObjFileIO<STSRandGen>
    291291#endif
    292292
    293293#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
    294 template class ObjFileIO<RandomGenerator>;
     294template class ObjFileIO<STSRandGen>;
    295295#endif
    296296// ---------------------------------------------------------
  • trunk/SophyaLib/BaseTools/stsrand.h

    r3599 r3612  
    1616namespace SOPHYA {
    1717
    18 class RandomGenerator : public AnyDataObj {
     18class STSRandGen : public AnyDataObj {
    1919
    2020 public:
    21   RandomGenerator(size_t n = 1024, bool tsafe=true);
    22   RandomGenerator(RandomGenerator const & rg);
     21  STSRandGen(size_t n = 1024, bool tsafe=true);
     22  STSRandGen(STSRandGen const & rg);
    2323
    2424  void SetBuffSize(size_t n);
    2525
    26   virtual ~RandomGenerator();
     26  virtual ~STSRandGen();
    2727
    2828  /*! \brief Automatic initialization using the current time */
     
    7272 
    7373  //  Pour la gestion de persistance PPF
    74   friend class ObjFileIO<RandomGenerator> ;
     74  friend class ObjFileIO<STSRandGen> ;
    7575
    7676 protected:
     
    9393  static  void GetSeed_P(unsigned short seed_16v[3]);
    9494
    95 };  // Fin de la classe RandomGenerator
     95};  // Fin de la classe STSRandGen
    9696
    97 // Classe pour la gestion de persistance PPF :  ObjFileIO<RandomGenerator>
     97// Classe pour la gestion de persistance PPF :  ObjFileIO<STSRandGen>
    9898
    9999/*! 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); }
     100inline POutPersist& operator << (POutPersist& os, STSRandGen & obj)
     101{ ObjFileIO<STSRandGen> fio(&obj);  fio.Write(os);  return(os); }
    102102/*! 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); }
     103inline PInPersist& operator >> (PInPersist& is, STSRandGen & obj)
     104{ ObjFileIO<STSRandGen> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
    105105
    106106} /* namespace SOPHYA */
Note: See TracChangeset for help on using the changeset viewer.