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

Last change on this file since 3239 was 3228, checked in by ansari, 18 years ago

correction maj numero de version BaseTools, Reza 23/04/2007

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