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