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

Last change on this file since 3172 was 3172, checked in by ansari, 19 years ago

Correction bug ds swsegdb.h (non ecriture buffer avec 1 seul buffer-relu) + ajout methode NDataBlock::RenewObjId() pour re-ecriture PPF , Reza 05/02/2007

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