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