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
Line 
1#include "sopnamsp.h"
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"
14#include "fiondblock.h"
15#include "dvlist.h"
16
17#include "stsrand.h"
18#include "randr48.h"
19#include "randfmt.h"
20
21#include "fiosegdb.h"
22#include "ppfwrapstlv.h"
23
24#include "sversion.h"
25
26#include "randr48.h"
27
28#include <iostream>
29#include <map>
30
31// --- Classe d'initialisation de SOPHYA, (PPersistMgr en particulier)
32int SophyaInitiator::FgInit = 0;
33// Module version number - 2.0 , Jul 2006
34// Module version number - 2.02 , Fev07 Ajout NDataBlock::RenewObjId()
35// Module version number - 2.1 , Avr07
36// - Nettoyage machdefs_mkmf.h
37// - Ajout classe ThSafeOp ---> NDataBlock<T> Sw/SegDataBlock<T> ThreadSafe
38// Module version number - 2.15 , Oct08
39// - Exceptions sophya heritent de std::exception (mars 09)
40// - Extension / ajout de classes generateur aleatoires (Mersenne-Twister ...avril 09)
41// Module version number - 2.20 , Avr09
42#define MOD_VERS 2.20
43
44// Pour garder la liste des modules et leurs numeros de version
45map<string, double>* ModListP = NULL;
46
47/*!
48 \namespace SOPHYA
49 \brief This is the namespace for the whole Sophya package
50*/
51
52/*!
53 \class SOPHYA::SophyaInitiator
54 \ingroup BaseTools
55 Each Sophya module may contain an initialiser class which should
56 be a sub-class of SophyaInitiator.
57*/
58
59
60SophyaInitiator::SophyaInitiator()
61{
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
67 FgInit++;
68 if (FgInit > 1) return;
69
70 ModListP = new map<string, double>;
71
72 // --- Les generateurs aleatoires ...
73 DR48RandGen* grgp = new DR48RandGen;
74 RandomGeneratorInterface::SetGlobalRandGenP(grgp);
75
76 // Initialisation des mecanismes PPF I/O
77 PIOPersist::Initialize();
78 // Enregistrement des handlers PPF pour les NDataBlock<T>
79 PPRegister(FIO_NDataBlock<uint_1>);
80 DObjRegister(FIO_NDataBlock<uint_1>, NDataBlock<uint_1>);
81 PPRegister(FIO_NDataBlock<uint_2>);
82 DObjRegister(FIO_NDataBlock<uint_2>, NDataBlock<uint_2>);
83 PPRegister(FIO_NDataBlock<int_2>);
84 DObjRegister(FIO_NDataBlock<int_2>, NDataBlock<int_2>);
85 PPRegister(FIO_NDataBlock<int_4>);
86 DObjRegister(FIO_NDataBlock<int_4>, NDataBlock<int_4>);
87 PPRegister(FIO_NDataBlock<int_8>);
88 DObjRegister(FIO_NDataBlock<int_8>, NDataBlock<int_8>);
89 PPRegister(FIO_NDataBlock<uint_4>);
90 DObjRegister(FIO_NDataBlock<uint_4>, NDataBlock<uint_4>);
91 PPRegister(FIO_NDataBlock<uint_8>);
92 DObjRegister(FIO_NDataBlock<uint_8>, NDataBlock<uint_8>);
93 PPRegister(FIO_NDataBlock<r_4>);
94 DObjRegister(FIO_NDataBlock<r_4>, NDataBlock<r_4>);
95 PPRegister(FIO_NDataBlock<r_8>);
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> >);
101
102 // Enregistrement des handlers PPF pour les TimeStamp
103 PPRegister(ObjFileIO<TimeStamp>);
104 DObjRegister(ObjFileIO<TimeStamp>, TimeStamp);
105
106 // Enregistrement des handlers PPF pour les DVList
107 PPRegister(ObjFileIO<DVList>);
108 DObjRegister(ObjFileIO<DVList>, DVList);
109
110 // Enregistrement des handlers PPF pour les RandomGenerator
111 PPRegister(ObjFileIO<RandomGenerator>);
112 DObjRegister(ObjFileIO<RandomGenerator>, RandomGenerator);
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);
119
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>);
143
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> >);
165 PPRegister(PPFWrapperSTLVector< string >);
166 DObjRegister(PPFWrapperSTLVector< string >, std::vector<string>);
167
168 PPRegister(PPFWrapperSTLVector< TimeStamp >);
169 DObjRegister(PPFWrapperSTLVector< TimeStamp >, std::vector<TimeStamp>);
170
171
172#if (!defined(__GNUG__) && !defined(HPUX))
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
180 if(!getenv("SOPHYA_NOPRTVER")) PrintVersion(false);
181
182 int pnice;
183 char* snice = getenv("SOPHYA_NICE");
184 if (!snice) pnice=8;
185 else pnice = atoi(snice);
186 nice(pnice);
187
188 SophyaInitiator::RegisterModule("BaseTools", MOD_VERS); // Module name and version number registration
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
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)
209{
210 const char* compiler = 0;
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
223 #ifdef __IBMCPP__
224 #ifdef SO_ARCH64
225 compiler = const_cast<char *>("IBM-xlC (-q64)") ;
226 #else
227 compiler = const_cast<char *>("IBM-xlC") ;
228 #endif
229 #endif
230 #ifdef __INTEL_COMPILER
231 compiler = const_cast<char *>("Intel-icc ") ;
232 #endif
233 #ifdef __SGICC__
234 #ifdef SO_ARCH64
235 compiler = const_cast<char *>("SGI-CC (-64) ") ;
236 #else
237 compiler = const_cast<char *>("SGI-CC ") ;
238 #endif
239 #endif
240
241 char buff[512];
242 sprintf(buff,"SOPHYA Version %4.1f Revision %d (%s) -- %s %s %s",
243 SOPHYA_VERSION, SOPHYA_REVISION, SOPHYA_TAG,
244 __DATE__, __TIME__, compiler);
245 svers = buff;
246
247 return(SOPHYA_VERSION + (SOPHYA_REVISION/1000.));
248}
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);
257}
258
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
284double SOPHYA::SophyaVersion()
285{
286return(SOPHYA_VERSION + (SOPHYA_REVISION/1000.));
287}
288
289// On met un objet initiator en statique, pour les loaders qui savent
290// appeler le constructeur des objets statiques Reza 08/98
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
293// Suppression de #if !defined(Darwin) en Juil 2006
294static SophyaInitiator psophyainit;
295
Note: See TracBrowser for help on using the repository browser.