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

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

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

File size: 9.5 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"
[3602]18#include "randr48.h"
19#include "randfmt.h"
[3393]20
[2660]21#include "fiosegdb.h"
22#include "ppfwrapstlv.h"
23
[754]24#include "sversion.h"
25
[3016]26#include <iostream>
27#include <map>
28
[754]29// --- Classe d'initialisation de SOPHYA, (PPersistMgr en particulier)
30int SophyaInitiator::FgInit = 0;
[3016]31// Module version number - 2.0 , Jul 2006
[3172]32// Module version number - 2.02 , Fev07 Ajout NDataBlock::RenewObjId()
[3213]33// Module version number - 2.1 , Avr07
34// - Nettoyage machdefs_mkmf.h
35// - Ajout classe ThSafeOp ---> NDataBlock<T> Sw/SegDataBlock<T> ThreadSafe
[3532]36// Module version number - 2.15 , Oct08
37#define MOD_VERS 2.15
[754]38
[3016]39// Pour garder la liste des modules et leurs numeros de version
40map<string, double>* ModListP = NULL;
41
[913]42/*!
43 \namespace SOPHYA
44 \brief This is the namespace for the whole Sophya package
45*/
46
47/*!
48 \class SOPHYA::SophyaInitiator
[1607]49 \ingroup BaseTools
[913]50 Each Sophya module may contain an initialiser class which should
51 be a sub-class of SophyaInitiator.
52*/
53
[3016]54
[754]55SophyaInitiator::SophyaInitiator()
56{
[1900]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
[754]62 FgInit++;
63 if (FgInit > 1) return;
64
[3016]65 ModListP = new map<string, double>;
66
[754]67
[2660]68 // Initialisation des mecanismes PPF I/O
[754]69 PIOPersist::Initialize();
[2660]70 // Enregistrement des handlers PPF pour les NDataBlock<T>
[754]71 PPRegister(FIO_NDataBlock<uint_1>);
[802]72 DObjRegister(FIO_NDataBlock<uint_1>, NDataBlock<uint_1>);
[754]73 PPRegister(FIO_NDataBlock<uint_2>);
[802]74 DObjRegister(FIO_NDataBlock<uint_2>, NDataBlock<uint_2>);
[754]75 PPRegister(FIO_NDataBlock<int_2>);
[802]76 DObjRegister(FIO_NDataBlock<int_2>, NDataBlock<int_2>);
[754]77 PPRegister(FIO_NDataBlock<int_4>);
[802]78 DObjRegister(FIO_NDataBlock<int_4>, NDataBlock<int_4>);
[754]79 PPRegister(FIO_NDataBlock<int_8>);
[802]80 DObjRegister(FIO_NDataBlock<int_8>, NDataBlock<int_8>);
[754]81 PPRegister(FIO_NDataBlock<uint_4>);
[802]82 DObjRegister(FIO_NDataBlock<uint_4>, NDataBlock<uint_4>);
[754]83 PPRegister(FIO_NDataBlock<uint_8>);
[802]84 DObjRegister(FIO_NDataBlock<uint_8>, NDataBlock<uint_8>);
[754]85 PPRegister(FIO_NDataBlock<r_4>);
[802]86 DObjRegister(FIO_NDataBlock<r_4>, NDataBlock<r_4>);
[754]87 PPRegister(FIO_NDataBlock<r_8>);
[802]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> >);
[754]93
[2830]94 // Enregistrement des handlers PPF pour les TimeStamp
95 PPRegister(ObjFileIO<TimeStamp>);
96 DObjRegister(ObjFileIO<TimeStamp>, TimeStamp);
97
[2660]98 // Enregistrement des handlers PPF pour les DVList
[754]99 PPRegister(ObjFileIO<DVList>);
[802]100 DObjRegister(ObjFileIO<DVList>, DVList);
[754]101
[3393]102 // Enregistrement des handlers PPF pour les RandomGenerator
103 PPRegister(ObjFileIO<RandomGenerator>);
104 DObjRegister(ObjFileIO<RandomGenerator>, RandomGenerator);
[3602]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);
[3393]111
[2660]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>);
[754]135
[2660]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> >);
[2774]157 PPRegister(PPFWrapperSTLVector< string >);
158 DObjRegister(PPFWrapperSTLVector< string >, std::vector<string>);
[2660]159
[2830]160 PPRegister(PPFWrapperSTLVector< TimeStamp >);
161 DObjRegister(PPFWrapperSTLVector< TimeStamp >, std::vector<TimeStamp>);
[2660]162
[2830]163
[3203]164#if (!defined(__GNUG__) && !defined(HPUX))
[754]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
[3016]172 if(!getenv("SOPHYA_NOPRTVER")) PrintVersion(false);
[754]173
174 int pnice;
175 char* snice = getenv("SOPHYA_NICE");
176 if (!snice) pnice=8;
177 else pnice = atoi(snice);
178 nice(pnice);
179
[3016]180 SophyaInitiator::RegisterModule("BaseTools", MOD_VERS); // Module name and version number registration
[754]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
[3016]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)
[754]201{
[3572]202 const char* compiler = 0;
[754]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
[3016]215 #ifdef __IBMCPP__
[3203]216 #ifdef SO_ARCH64
[3213]217 compiler = const_cast<char *>("IBM-xlC (-q64)") ;
[3203]218 #else
[3213]219 compiler = const_cast<char *>("IBM-xlC") ;
[3016]220 #endif
[3203]221 #endif
[3016]222 #ifdef __INTEL_COMPILER
223 compiler = const_cast<char *>("Intel-icc ") ;
224 #endif
[754]225 #ifdef __SGICC__
[3203]226 #ifdef SO_ARCH64
[1249]227 compiler = const_cast<char *>("SGI-CC (-64) ") ;
228 #else
[754]229 compiler = const_cast<char *>("SGI-CC ") ;
230 #endif
[1249]231 #endif
[3016]232
233 char buff[512];
234 sprintf(buff,"SOPHYA Version %4.1f Revision %d (%s) -- %s %s %s",
[754]235 SOPHYA_VERSION, SOPHYA_REVISION, SOPHYA_TAG,
236 __DATE__, __TIME__, compiler);
[3016]237 svers = buff;
238
239 return(SOPHYA_VERSION + (SOPHYA_REVISION/1000.));
[754]240}
[3016]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);
[754]249}
[1157]250
[3016]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
[1157]276double SOPHYA::SophyaVersion()
277{
278return(SOPHYA_VERSION + (SOPHYA_REVISION/1000.));
279}
[754]280
281// On met un objet initiator en statique, pour les loaders qui savent
282// appeler le constructeur des objets statiques Reza 08/98
[2430]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
[3016]285// Suppression de #if !defined(Darwin) en Juil 2006
[754]286static SophyaInitiator psophyainit;
[3016]287
Note: See TracBrowser for help on using the repository browser.