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

Last change on this file since 3393 was 3393, checked in by ansari, 18 years ago

Ajout enregistrement handler PPF de RandomGenerator, Reza 23/11/2007

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