| 1 | #include "sopnamsp.h"
 | 
|---|
| 2 | #include "machdefs.h"
 | 
|---|
| 3 | 
 | 
|---|
| 4 | #include <unistd.h>
 | 
|---|
| 5 | #include <stdlib.h>
 | 
|---|
| 6 | #include <stdio.h>
 | 
|---|
| 7 | #include <complex>
 | 
|---|
| 8 | 
 | 
|---|
| 9 | #include "sophyainit.h"
 | 
|---|
| 10 | 
 | 
|---|
| 11 | #include "pexceptions.h"
 | 
|---|
| 12 | 
 | 
|---|
| 13 | #include "ppersist.h"
 | 
|---|
| 14 | #include "fiondblock.h"
 | 
|---|
| 15 | #include "dvlist.h"
 | 
|---|
| 16 | 
 | 
|---|
| 17 | #include "randr48.h"
 | 
|---|
| 18 | #include "randfmt.h"
 | 
|---|
| 19 | 
 | 
|---|
| 20 | #include "fiosegdb.h" 
 | 
|---|
| 21 | #include "ppfwrapstlv.h" 
 | 
|---|
| 22 | 
 | 
|---|
| 23 | #include "sversion.h"
 | 
|---|
| 24 | 
 | 
|---|
| 25 | #include <iostream>
 | 
|---|
| 26 | #include <map> 
 | 
|---|
| 27 | 
 | 
|---|
| 28 | // ---  Classe d'initialisation de SOPHYA, (PPersistMgr en particulier)
 | 
|---|
| 29 | int SophyaInitiator::FgInit = 0;
 | 
|---|
| 30 | // Module version number - 2.0 , Jul 2006
 | 
|---|
| 31 | // Module version number - 2.02 , Fev07 Ajout NDataBlock::RenewObjId()
 | 
|---|
| 32 | // Module version number - 2.1 ,  Avr07 
 | 
|---|
| 33 | //  - Nettoyage machdefs_mkmf.h 
 | 
|---|
| 34 | //  - Ajout classe ThSafeOp ---> NDataBlock<T> Sw/SegDataBlock<T> ThreadSafe
 | 
|---|
| 35 | // Module version number - 2.15 ,  Oct08
 | 
|---|
| 36 | //  - Exceptions sophya heritent de std::exception  (mars 09)
 | 
|---|
| 37 | //  - Extension / ajout de classes generateur aleatoires (Mersenne-Twister ...avril 09)      
 | 
|---|
| 38 | // Module version number - 2.20 ,  Avr09      
 | 
|---|
| 39 | #define MOD_VERS   2.20
 | 
|---|
| 40 | 
 | 
|---|
| 41 | // Pour garder la liste des modules et leurs numeros de version
 | 
|---|
| 42 | map<string, double>* ModListP = NULL;
 | 
|---|
| 43 | 
 | 
|---|
| 44 | /*!
 | 
|---|
| 45 |    \namespace SOPHYA
 | 
|---|
| 46 |    \brief This is the namespace for the whole Sophya package
 | 
|---|
| 47 | */
 | 
|---|
| 48 | 
 | 
|---|
| 49 | /*!
 | 
|---|
| 50 |   \class SOPHYA::SophyaInitiator
 | 
|---|
| 51 |   \ingroup BaseTools
 | 
|---|
| 52 |   Each Sophya module may contain an initialiser class which should
 | 
|---|
| 53 |   be a sub-class of SophyaInitiator.  
 | 
|---|
| 54 | */
 | 
|---|
| 55 | 
 | 
|---|
| 56 | 
 | 
|---|
| 57 | SophyaInitiator::SophyaInitiator()
 | 
|---|
| 58 | {
 | 
|---|
| 59 | #if defined(Darwin)
 | 
|---|
| 60 |   // Il semble y avoir un probleme sous MacOSX ...
 | 
|---|
| 61 |   if (FgInit == 0) 
 | 
|---|
| 62 |     cout << " SophyaInitiator::SophyaInitiator() BaseTools Init" << endl;
 | 
|---|
| 63 | #endif
 | 
|---|
| 64 |   FgInit++;
 | 
|---|
| 65 |   if (FgInit > 1)  return;
 | 
|---|
| 66 | 
 | 
|---|
| 67 |   ModListP = new map<string, double>;
 | 
|---|
| 68 | 
 | 
|---|
| 69 |   // --- Les generateurs aleatoires ...
 | 
|---|
| 70 |   DR48RandGen* grgp = new  ThSDR48RandGen;
 | 
|---|
| 71 |   RandomGeneratorInterface::SetGlobalRandGenP(grgp); 
 | 
|---|
| 72 | 
 | 
|---|
| 73 |   // Initialisation des mecanismes PPF I/O 
 | 
|---|
| 74 |   PIOPersist::Initialize();
 | 
|---|
| 75 |   // Enregistrement des handlers PPF pour les NDataBlock<T> 
 | 
|---|
| 76 |   PPRegister(FIO_NDataBlock<uint_1>);
 | 
|---|
| 77 |   DObjRegister(FIO_NDataBlock<uint_1>, NDataBlock<uint_1>);
 | 
|---|
| 78 |   PPRegister(FIO_NDataBlock<int_1>);
 | 
|---|
| 79 |   DObjRegister(FIO_NDataBlock<int_1>, NDataBlock<int_1>);
 | 
|---|
| 80 |   PPRegister(FIO_NDataBlock<uint_2>);
 | 
|---|
| 81 |   DObjRegister(FIO_NDataBlock<uint_2>, NDataBlock<uint_2>);
 | 
|---|
| 82 |   PPRegister(FIO_NDataBlock<int_2>);
 | 
|---|
| 83 |   DObjRegister(FIO_NDataBlock<int_2>, NDataBlock<int_2>);
 | 
|---|
| 84 |   PPRegister(FIO_NDataBlock<int_4>);
 | 
|---|
| 85 |   DObjRegister(FIO_NDataBlock<int_4>, NDataBlock<int_4>);
 | 
|---|
| 86 |   PPRegister(FIO_NDataBlock<int_8>);
 | 
|---|
| 87 |   DObjRegister(FIO_NDataBlock<int_8>, NDataBlock<int_8>);
 | 
|---|
| 88 |   PPRegister(FIO_NDataBlock<uint_4>);
 | 
|---|
| 89 |   DObjRegister(FIO_NDataBlock<uint_4>, NDataBlock<uint_4>);
 | 
|---|
| 90 |   PPRegister(FIO_NDataBlock<uint_8>);
 | 
|---|
| 91 |   DObjRegister(FIO_NDataBlock<uint_8>, NDataBlock<uint_8>);
 | 
|---|
| 92 |   PPRegister(FIO_NDataBlock<r_4>);
 | 
|---|
| 93 |   DObjRegister(FIO_NDataBlock<r_4>, NDataBlock<r_4>);
 | 
|---|
| 94 |   PPRegister(FIO_NDataBlock<r_8>);
 | 
|---|
| 95 |   DObjRegister(FIO_NDataBlock<r_8>, NDataBlock<r_8>);
 | 
|---|
| 96 |   PPRegister(FIO_NDataBlock< complex<r_4> >);
 | 
|---|
| 97 |   DObjRegister(FIO_NDataBlock< complex<r_4> >, NDataBlock< complex<r_4> >);
 | 
|---|
| 98 |   PPRegister(FIO_NDataBlock< complex<r_8> >);
 | 
|---|
| 99 |   DObjRegister(FIO_NDataBlock< complex<r_8> >, NDataBlock< complex<r_8> >);
 | 
|---|
| 100 | 
 | 
|---|
| 101 |   // Enregistrement des handlers PPF pour les TimeStamp
 | 
|---|
| 102 |   PPRegister(ObjFileIO<TimeStamp>);
 | 
|---|
| 103 |   DObjRegister(ObjFileIO<TimeStamp>, TimeStamp);
 | 
|---|
| 104 | 
 | 
|---|
| 105 |   // Enregistrement des handlers PPF pour les DVList
 | 
|---|
| 106 |   PPRegister(ObjFileIO<DVList>);
 | 
|---|
| 107 |   DObjRegister(ObjFileIO<DVList>, DVList);
 | 
|---|
| 108 | 
 | 
|---|
| 109 |   // Enregistrement des handlers PPF pour les RandomGenerator
 | 
|---|
| 110 |   PPRegister(ObjFileIO<DR48RandGen>);
 | 
|---|
| 111 |   DObjRegister(ObjFileIO<DR48RandGen>,DR48RandGen );
 | 
|---|
| 112 |   PPRegister(ObjFileIO<ThSDR48RandGen>);
 | 
|---|
| 113 |   DObjRegister(ObjFileIO<ThSDR48RandGen>, ThSDR48RandGen);
 | 
|---|
| 114 |   PPRegister(ObjFileIO<FMTRandGen>);
 | 
|---|
| 115 |   DObjRegister(ObjFileIO<FMTRandGen>, FMTRandGen);
 | 
|---|
| 116 | 
 | 
|---|
| 117 |   // Enregistrement des handlers PPF pour les SegDataBlock<T> 
 | 
|---|
| 118 |   PPRegister(FIO_SegDataBlock<uint_2>);
 | 
|---|
| 119 |   DObjRegister(FIO_SegDataBlock<uint_2>, SegDataBlock<uint_2>);
 | 
|---|
| 120 |   PPRegister(FIO_SegDataBlock<int_2>);
 | 
|---|
| 121 |   DObjRegister(FIO_SegDataBlock<int_2>, SegDataBlock<int_2>);
 | 
|---|
| 122 |   PPRegister(FIO_SegDataBlock<int_4>);
 | 
|---|
| 123 |   DObjRegister(FIO_SegDataBlock<int_4>, SegDataBlock<int_4>);
 | 
|---|
| 124 |   PPRegister(FIO_SegDataBlock<int_8>);
 | 
|---|
| 125 |   DObjRegister(FIO_SegDataBlock<int_8>, SegDataBlock<int_8>);
 | 
|---|
| 126 |   PPRegister(FIO_SegDataBlock<uint_4>);
 | 
|---|
| 127 |   DObjRegister(FIO_SegDataBlock<uint_4>, SegDataBlock<uint_4>);
 | 
|---|
| 128 |   PPRegister(FIO_SegDataBlock<uint_8>);
 | 
|---|
| 129 |   DObjRegister(FIO_SegDataBlock<uint_8>, SegDataBlock<uint_8>);
 | 
|---|
| 130 |   PPRegister(FIO_SegDataBlock<r_4>);
 | 
|---|
| 131 |   DObjRegister(FIO_SegDataBlock<r_4>, SegDataBlock<r_4>);
 | 
|---|
| 132 |   PPRegister(FIO_SegDataBlock<r_8>);
 | 
|---|
| 133 |   DObjRegister(FIO_SegDataBlock<r_8>, SegDataBlock<r_8>);
 | 
|---|
| 134 |   PPRegister(FIO_SegDataBlock< complex<r_4> >);
 | 
|---|
| 135 |   DObjRegister(FIO_SegDataBlock< complex<r_4> >, SegDataBlock< complex<r_4> >);
 | 
|---|
| 136 |   PPRegister(FIO_SegDataBlock< complex<r_8> >);
 | 
|---|
| 137 |   DObjRegister(FIO_SegDataBlock< complex<r_8> >, SegDataBlock< complex<r_8> >);
 | 
|---|
| 138 |   PPRegister(FIO_SegDataBlock<string>);
 | 
|---|
| 139 |   DObjRegister(FIO_SegDataBlock<string>, SegDataBlock<string>);
 | 
|---|
| 140 | 
 | 
|---|
| 141 |   // Enregistrement des handlers PPF pour les vecteurs de la STL
 | 
|---|
| 142 |   PPRegister(PPFWrapperSTLVector<uint_2>);
 | 
|---|
| 143 |   DObjRegister(PPFWrapperSTLVector<uint_2>, std::vector<uint_2>);
 | 
|---|
| 144 |   PPRegister(PPFWrapperSTLVector<int_2>);
 | 
|---|
| 145 |   DObjRegister(PPFWrapperSTLVector<int_2>, std::vector<int_2>);
 | 
|---|
| 146 |   PPRegister(PPFWrapperSTLVector<int_4>);
 | 
|---|
| 147 |   DObjRegister(PPFWrapperSTLVector<int_4>, std::vector<int_4>);
 | 
|---|
| 148 |   PPRegister(PPFWrapperSTLVector<int_8>);
 | 
|---|
| 149 |   DObjRegister(PPFWrapperSTLVector<int_8>, std::vector<int_8>);
 | 
|---|
| 150 |   PPRegister(PPFWrapperSTLVector<uint_4>);
 | 
|---|
| 151 |   DObjRegister(PPFWrapperSTLVector<uint_4>, std::vector<uint_4>);
 | 
|---|
| 152 |   PPRegister(PPFWrapperSTLVector<uint_8>);
 | 
|---|
| 153 |   DObjRegister(PPFWrapperSTLVector<uint_8>, std::vector<uint_8>);
 | 
|---|
| 154 |   PPRegister(PPFWrapperSTLVector<r_4>);
 | 
|---|
| 155 |   DObjRegister(PPFWrapperSTLVector<r_4>, std::vector<r_4>);
 | 
|---|
| 156 |   PPRegister(PPFWrapperSTLVector<r_8>);
 | 
|---|
| 157 |   DObjRegister(PPFWrapperSTLVector<r_8>, std::vector<r_8>);
 | 
|---|
| 158 |   PPRegister(PPFWrapperSTLVector< complex<r_4> >);
 | 
|---|
| 159 |   DObjRegister(PPFWrapperSTLVector< complex<r_4> >, std::vector< complex<r_4> >);
 | 
|---|
| 160 |   PPRegister(PPFWrapperSTLVector< complex<r_8> >);
 | 
|---|
| 161 |   DObjRegister(PPFWrapperSTLVector< complex<r_8> >, std::vector< complex<r_8> >);
 | 
|---|
| 162 |   PPRegister(PPFWrapperSTLVector< string >);
 | 
|---|
| 163 |   DObjRegister(PPFWrapperSTLVector< string >, std::vector<string>);
 | 
|---|
| 164 | 
 | 
|---|
| 165 |   PPRegister(PPFWrapperSTLVector< TimeStamp >);
 | 
|---|
| 166 |   DObjRegister(PPFWrapperSTLVector< TimeStamp >, std::vector<TimeStamp>);
 | 
|---|
| 167 | 
 | 
|---|
| 168 | 
 | 
|---|
| 169 | #if (!defined(__GNUG__) && !defined(HPUX))
 | 
|---|
| 170 |   // pas de bufferisation pour printf   cmv 18/3/97 selon E.A.
 | 
|---|
| 171 |   // setvbuf(stdout,NULL,_IOLBF,0); setvbuf(stderr,NULL,_IOLBF,0);
 | 
|---|
| 172 |   setlinebuf(stdout);
 | 
|---|
| 173 |   setlinebuf(stderr);
 | 
|---|
| 174 | #endif
 | 
|---|
| 175 | 
 | 
|---|
| 176 |   // si var env SOPHYA_NOPRTVER definie pas de print
 | 
|---|
| 177 |   if(!getenv("SOPHYA_NOPRTVER")) PrintVersion(false);
 | 
|---|
| 178 | 
 | 
|---|
| 179 |   int pnice;
 | 
|---|
| 180 |   char* snice = getenv("SOPHYA_NICE");
 | 
|---|
| 181 |   if (!snice) pnice=8;
 | 
|---|
| 182 |   else pnice = atoi(snice);
 | 
|---|
| 183 |   nice(pnice);
 | 
|---|
| 184 | 
 | 
|---|
| 185 |   SophyaInitiator::RegisterModule("BaseTools", MOD_VERS);  // Module name and version number registration  
 | 
|---|
| 186 | }
 | 
|---|
| 187 | 
 | 
|---|
| 188 | SophyaInitiator::~SophyaInitiator()
 | 
|---|
| 189 | {
 | 
|---|
| 190 |   FgInit--;
 | 
|---|
| 191 | /*
 | 
|---|
| 192 |   if (FgInit == 0)
 | 
|---|
| 193 |     {
 | 
|---|
| 194 |     delete PPersistMgr::classList; PPersistMgr::classList = NULL;
 | 
|---|
| 195 |     delete PShPersist::objList;    PShPersist::objList = NULL;
 | 
|---|
| 196 |     }
 | 
|---|
| 197 |     */
 | 
|---|
| 198 | }
 | 
|---|
| 199 | 
 | 
|---|
| 200 | /*! 
 | 
|---|
| 201 |   \brief Return the SOPHYA version number. 
 | 
|---|
| 202 |   \param svers contain the complete in addition the SOPHYA tag, the compiler name 
 | 
|---|
| 203 |   and the compilation date
 | 
|---|
| 204 | */
 | 
|---|
| 205 | double SophyaInitiator::GetVersion(string& svers)
 | 
|---|
| 206 | {
 | 
|---|
| 207 |   const char* compiler = 0;
 | 
|---|
| 208 |   #ifdef __GNUG__
 | 
|---|
| 209 |   compiler = "gcc " __VERSION__;
 | 
|---|
| 210 |   #endif
 | 
|---|
| 211 |   #ifdef __DECCXX
 | 
|---|
| 212 |   compiler = "cxx " ;
 | 
|---|
| 213 |   #endif
 | 
|---|
| 214 |   #ifdef __aCC__
 | 
|---|
| 215 |   compiler = const_cast<char *>("HP-aCC ") ;
 | 
|---|
| 216 |   #endif
 | 
|---|
| 217 |   #ifdef __KCC__
 | 
|---|
| 218 |   compiler = const_cast<char *>("KCC ") ;
 | 
|---|
| 219 |   #endif
 | 
|---|
| 220 |   #ifdef __IBMCPP__
 | 
|---|
| 221 |   #ifdef SO_ARCH64
 | 
|---|
| 222 |   compiler = const_cast<char *>("IBM-xlC (-q64)") ;
 | 
|---|
| 223 |   #else
 | 
|---|
| 224 |   compiler = const_cast<char *>("IBM-xlC") ;
 | 
|---|
| 225 |   #endif
 | 
|---|
| 226 |   #endif
 | 
|---|
| 227 |   #ifdef __INTEL_COMPILER
 | 
|---|
| 228 |   compiler = const_cast<char *>("Intel-icc ") ;
 | 
|---|
| 229 |   #endif
 | 
|---|
| 230 |   #ifdef __SGICC__
 | 
|---|
| 231 |   #ifdef SO_ARCH64
 | 
|---|
| 232 |   compiler = const_cast<char *>("SGI-CC (-64) ") ;
 | 
|---|
| 233 |   #else
 | 
|---|
| 234 |   compiler = const_cast<char *>("SGI-CC ") ;
 | 
|---|
| 235 |   #endif
 | 
|---|
| 236 |   #endif
 | 
|---|
| 237 | 
 | 
|---|
| 238 |   char buff[512];
 | 
|---|
| 239 |   sprintf(buff,"SOPHYA Version %4.1f Revision %d (%s) -- %s %s %s",
 | 
|---|
| 240 |           SOPHYA_VERSION, SOPHYA_REVISION, SOPHYA_TAG,
 | 
|---|
| 241 |           __DATE__, __TIME__, compiler);
 | 
|---|
| 242 |   svers = buff;
 | 
|---|
| 243 |   
 | 
|---|
| 244 |   return(SOPHYA_VERSION + (SOPHYA_REVISION/1000.));
 | 
|---|
| 245 | }
 | 
|---|
| 246 | 
 | 
|---|
| 247 | //! Print the SOPHYA version string and optionaly the list of registered modules
 | 
|---|
| 248 | void SophyaInitiator::PrintVersion(bool fglist)
 | 
|---|
| 249 | {
 | 
|---|
| 250 |   string svers;
 | 
|---|
| 251 |   GetVersion(svers);
 | 
|---|
| 252 |   cout << svers << endl;
 | 
|---|
| 253 |   if (fglist) ListModules(cout);   
 | 
|---|
| 254 | }
 | 
|---|
| 255 | 
 | 
|---|
| 256 | //! Should be called by sub-classes to register module name and version 
 | 
|---|
| 257 | int SophyaInitiator::RegisterModule(const char * name, double version)
 | 
|---|
| 258 | {
 | 
|---|
| 259 |   if (ModListP == NULL) 
 | 
|---|
| 260 |     throw NullPtrError("SophyaInitiator::RegisterModule() ModListP= NULL !");
 | 
|---|
| 261 |   map<string, double>& modlist = *ModListP;
 | 
|---|
| 262 |   modlist[string(name)] = version;
 | 
|---|
| 263 |   return modlist.size();
 | 
|---|
| 264 | }
 | 
|---|
| 265 | 
 | 
|---|
| 266 | //! List of registered module names and version number
 | 
|---|
| 267 | int SophyaInitiator::ListModules(ostream& os)
 | 
|---|
| 268 | {
 | 
|---|
| 269 |   if (ModListP == NULL) 
 | 
|---|
| 270 |     throw NullPtrError("SophyaInitiator::ListModules() ModListP= NULL !");
 | 
|---|
| 271 |   os << "--- SophyaInitiator::ListModules() Name / VersionNumber --- " << endl;
 | 
|---|
| 272 |   map<string, double>& modlist = *ModListP;
 | 
|---|
| 273 |   int k = 1;
 | 
|---|
| 274 |   for(map<string, double>::iterator it = modlist.begin(); it != modlist.end(); it++, k++) 
 | 
|---|
| 275 |     os << k << " : " << (*it).first << " V= " << (*it).second << endl; 
 | 
|---|
| 276 |   os << " ----------------------------------------------------------- " << endl;
 | 
|---|
| 277 |   return modlist.size();
 | 
|---|
| 278 | }
 | 
|---|
| 279 | 
 | 
|---|
| 280 | //! Return the SOPHYA version number: VERS + REV/1000
 | 
|---|
| 281 | double SOPHYA::SophyaVersion()
 | 
|---|
| 282 | {
 | 
|---|
| 283 | return(SOPHYA_VERSION + (SOPHYA_REVISION/1000.));
 | 
|---|
| 284 | }
 | 
|---|
| 285 |  
 | 
|---|
| 286 | // On met un objet initiator en statique, pour les loaders qui savent 
 | 
|---|
| 287 | // appeler le constructeur des objets statiques   Reza 08/98
 | 
|---|
| 288 | // La presence de l'objet statique psophyainit semble poserun probleme 
 | 
|---|
| 289 | // sur MacOSX 10.2 qui se plante a l'initialisation avec les shared-libs
 | 
|---|
| 290 | // Suppression de #if !defined(Darwin) en Juil 2006
 | 
|---|
| 291 | static SophyaInitiator psophyainit;
 | 
|---|
| 292 | 
 | 
|---|