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