source: Sophya/trunk/SophyaLib/BaseTools/sophyainit.cc@ 3753

Last change on this file since 3753 was 3750, checked in by ansari, 16 years ago

Prise en charge de float 128 bits (r_16, complex<r_16>) par les NDataBlock<T> et PPersist, controlee par le flag de compilation SO_LDBLE128 defini ds machdefs.h , Reza 03/03/2010

File size: 10.2 KB
RevLine 
[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)
29int 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)
[3750]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
[754]44
[3016]45// Pour garder la liste des modules et leurs numeros de version
46map<string, double>* ModListP = NULL;
47
[913]48/*!
49 \namespace SOPHYA
50 \brief This is the namespace for the whole Sophya package
51*/
52
53/*!
54 \class SOPHYA::SophyaInitiator
[1607]55 \ingroup BaseTools
[913]56 Each Sophya module may contain an initialiser class which should
57 be a sub-class of SophyaInitiator.
58*/
59
[3016]60
[754]61SophyaInitiator::SophyaInitiator()
62{
[1900]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
[754]68 FgInit++;
69 if (FgInit > 1) return;
70
[3016]71 ModListP = new map<string, double>;
[754]72
[3604]73 // --- Les generateurs aleatoires ...
[3612]74 DR48RandGen* grgp = new ThSDR48RandGen;
[3604]75 RandomGeneratorInterface::SetGlobalRandGenP(grgp);
76
[2660]77 // Initialisation des mecanismes PPF I/O
[754]78 PIOPersist::Initialize();
[2660]79 // Enregistrement des handlers PPF pour les NDataBlock<T>
[754]80 PPRegister(FIO_NDataBlock<uint_1>);
[802]81 DObjRegister(FIO_NDataBlock<uint_1>, NDataBlock<uint_1>);
[3663]82 PPRegister(FIO_NDataBlock<int_1>);
83 DObjRegister(FIO_NDataBlock<int_1>, NDataBlock<int_1>);
[754]84 PPRegister(FIO_NDataBlock<uint_2>);
[802]85 DObjRegister(FIO_NDataBlock<uint_2>, NDataBlock<uint_2>);
[754]86 PPRegister(FIO_NDataBlock<int_2>);
[802]87 DObjRegister(FIO_NDataBlock<int_2>, NDataBlock<int_2>);
[754]88 PPRegister(FIO_NDataBlock<int_4>);
[802]89 DObjRegister(FIO_NDataBlock<int_4>, NDataBlock<int_4>);
[754]90 PPRegister(FIO_NDataBlock<int_8>);
[802]91 DObjRegister(FIO_NDataBlock<int_8>, NDataBlock<int_8>);
[754]92 PPRegister(FIO_NDataBlock<uint_4>);
[802]93 DObjRegister(FIO_NDataBlock<uint_4>, NDataBlock<uint_4>);
[754]94 PPRegister(FIO_NDataBlock<uint_8>);
[802]95 DObjRegister(FIO_NDataBlock<uint_8>, NDataBlock<uint_8>);
[754]96 PPRegister(FIO_NDataBlock<r_4>);
[802]97 DObjRegister(FIO_NDataBlock<r_4>, NDataBlock<r_4>);
[754]98 PPRegister(FIO_NDataBlock<r_8>);
[802]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> >);
[3750]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
[2830]110 // Enregistrement des handlers PPF pour les TimeStamp
111 PPRegister(ObjFileIO<TimeStamp>);
112 DObjRegister(ObjFileIO<TimeStamp>, TimeStamp);
113
[2660]114 // Enregistrement des handlers PPF pour les DVList
[754]115 PPRegister(ObjFileIO<DVList>);
[802]116 DObjRegister(ObjFileIO<DVList>, DVList);
[754]117
[3393]118 // Enregistrement des handlers PPF pour les RandomGenerator
[3602]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);
[3393]125
[2660]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>);
[754]149
[2660]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> >);
[2774]171 PPRegister(PPFWrapperSTLVector< string >);
172 DObjRegister(PPFWrapperSTLVector< string >, std::vector<string>);
[2660]173
[2830]174 PPRegister(PPFWrapperSTLVector< TimeStamp >);
175 DObjRegister(PPFWrapperSTLVector< TimeStamp >, std::vector<TimeStamp>);
[2660]176
[2830]177
[3203]178#if (!defined(__GNUG__) && !defined(HPUX))
[754]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
[3016]186 if(!getenv("SOPHYA_NOPRTVER")) PrintVersion(false);
[754]187
188 int pnice;
189 char* snice = getenv("SOPHYA_NICE");
190 if (!snice) pnice=8;
191 else pnice = atoi(snice);
192 nice(pnice);
193
[3016]194 SophyaInitiator::RegisterModule("BaseTools", MOD_VERS); // Module name and version number registration
[754]195}
196
197SophyaInitiator::~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
[3016]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*/
214double SophyaInitiator::GetVersion(string& svers)
[754]215{
[3572]216 const char* compiler = 0;
[754]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
[3016]229 #ifdef __IBMCPP__
[3203]230 #ifdef SO_ARCH64
[3213]231 compiler = const_cast<char *>("IBM-xlC (-q64)") ;
[3203]232 #else
[3213]233 compiler = const_cast<char *>("IBM-xlC") ;
[3016]234 #endif
[3203]235 #endif
[3016]236 #ifdef __INTEL_COMPILER
237 compiler = const_cast<char *>("Intel-icc ") ;
238 #endif
[754]239 #ifdef __SGICC__
[3203]240 #ifdef SO_ARCH64
[1249]241 compiler = const_cast<char *>("SGI-CC (-64) ") ;
242 #else
[754]243 compiler = const_cast<char *>("SGI-CC ") ;
244 #endif
[1249]245 #endif
[3016]246
247 char buff[512];
248 sprintf(buff,"SOPHYA Version %4.1f Revision %d (%s) -- %s %s %s",
[754]249 SOPHYA_VERSION, SOPHYA_REVISION, SOPHYA_TAG,
250 __DATE__, __TIME__, compiler);
[3016]251 svers = buff;
252
253 return(SOPHYA_VERSION + (SOPHYA_REVISION/1000.));
[754]254}
[3016]255
256//! Print the SOPHYA version string and optionaly the list of registered modules
257void SophyaInitiator::PrintVersion(bool fglist)
258{
259 string svers;
260 GetVersion(svers);
261 cout << svers << endl;
262 if (fglist) ListModules(cout);
[754]263}
[1157]264
[3016]265//! Should be called by sub-classes to register module name and version
266int 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
276int 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
[1157]290double SOPHYA::SophyaVersion()
291{
292return(SOPHYA_VERSION + (SOPHYA_REVISION/1000.));
293}
[754]294
295// On met un objet initiator en statique, pour les loaders qui savent
296// appeler le constructeur des objets statiques Reza 08/98
[2430]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
[3016]299// Suppression de #if !defined(Darwin) en Juil 2006
[754]300static SophyaInitiator psophyainit;
[3016]301
Note: See TracBrowser for help on using the repository browser.