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