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

Last change on this file since 3600 was 3585, checked in by ansari, 17 years ago

Ajout heritage exceptions SOPHYA de std::exception (+method what()) - nettoyage/suppression TRY/CATCH... , Reza 05/03/2009

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