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

Last change on this file since 3604 was 3604, checked in by ansari, 16 years ago

Modifs,petites extensions + numero de version/initialisation de l'instance globale de RandomGenerator, Reza 29/04/2009

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