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

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

Petite erreur de frappe corrigee suite compil OSF - Reza 30/04/2009

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