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

Last change on this file since 3572 was 3572, checked in by cmv, 17 years ago

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