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