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

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

Ajout register PPFHandlet NDataBlock<int_1> et passage numero version SOPHYA 2.142 - Reza 24/10/2009

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