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

Last change on this file since 3603 was 3602, checked in by cmv, 16 years ago

RandomGeneratorInterface + dSFMT etc..., cmv 28/04/2009

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