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

Last change on this file since 3600 was 3585, checked in by ansari, 17 years ago

Ajout heritage exceptions SOPHYA de std::exception (+method what()) - nettoyage/suppression TRY/CATCH... , Reza 05/03/2009

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