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

Last change on this file since 4071 was 4056, checked in by ansari, 13 years ago

Ajout fichiers pqnumber.h .cc et sunits.h .cc : classes PrimeNumbers , QNumber , Units , PhysQty - MAJ Makefile, sophyainit et numero de version SOPHYA a 2.222 V_Avr12, Reza 16/04/2012

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