1 | #include <stdio.h>
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include "sopnamsp.h"
|
---|
4 | #include "math.h"
|
---|
5 | #include <iostream>
|
---|
6 | #include <string>
|
---|
7 |
|
---|
8 | // Pour le test
|
---|
9 | #include "histinit.h"
|
---|
10 | #include "histos.h"
|
---|
11 | #include "histos2.h"
|
---|
12 | #include "ntuple.h"
|
---|
13 |
|
---|
14 |
|
---|
15 | #include "fmath.h"
|
---|
16 | #include "srandgen.h"
|
---|
17 | #include "tarray.h"
|
---|
18 | #include "arrctcast.h"
|
---|
19 | #include "fioarr.h"
|
---|
20 | #include "timing.h"
|
---|
21 |
|
---|
22 | #include <typeinfo>
|
---|
23 | #include <datatype.h>
|
---|
24 |
|
---|
25 | /* ------------------------------------------------------------------
|
---|
26 | Programme de test des fonctionalites de persistance (PPF) de SOPHYA
|
---|
27 | (C) LAL/IN2P3-CNRS, Univ. Paris Sud, IRFU-CEA 1999-2010
|
---|
28 | SOPHYA::PPersist ....
|
---|
29 | Utilisation:
|
---|
30 | csh> tobjio --> mini help
|
---|
31 | csh> tobjio A
|
---|
32 | csh> tobjio B
|
---|
33 | */
|
---|
34 |
|
---|
35 | static int ppftstA();
|
---|
36 | static int ppftstB();
|
---|
37 |
|
---|
38 | /* -- Main program -- */
|
---|
39 | int main(int narg, char* arg[])
|
---|
40 | {
|
---|
41 |
|
---|
42 | int rc = 0;
|
---|
43 | if (narg < 2) {
|
---|
44 | cout << " Usage: tobjio A/B \n"
|
---|
45 | << " A : Create tobjio.ppf file containing Histo/NTuple/Array \n"
|
---|
46 | << " B : Check PPF I/O on TArray<T> \n" << endl;
|
---|
47 | return 1;
|
---|
48 | }
|
---|
49 | string opt = arg[1];
|
---|
50 | try {
|
---|
51 | SophyaInit();
|
---|
52 | InitTim();
|
---|
53 | cout << "Hash check, OMatrix : " << hex << PIOPersist::Hash("OMatrix") << dec << endl;
|
---|
54 | if (opt=="A") rc = ppftstA();
|
---|
55 | else rc = ppftstB();
|
---|
56 | }
|
---|
57 | catch (PThrowable & exc) {
|
---|
58 | cerr << " tobjio.cc: Catched Exception (PThrowable)" << (string)typeid(exc).name()
|
---|
59 | << " - Msg= " << exc.Msg() << endl;
|
---|
60 | rc = 99;
|
---|
61 | }
|
---|
62 | catch (std::exception & e) {
|
---|
63 | cerr << " tobjio.cc: Catched std::exception what()=" << e.what() << endl;
|
---|
64 | rc=98;
|
---|
65 | }
|
---|
66 | catch (...) {
|
---|
67 | cerr << " tobjio.cc: some other exception (...) was caught ! " << endl;
|
---|
68 | rc = 97;
|
---|
69 | }
|
---|
70 | PrtTim("End tobjio " );
|
---|
71 | cout << " ---- Programme tobjio.cc- FIN (Rc=" << rc << ") --- " << endl;
|
---|
72 | return rc;
|
---|
73 |
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|
77 |
|
---|
78 |
|
---|
79 | static sa_size_t NX = 15;
|
---|
80 | static sa_size_t NY = 20;
|
---|
81 |
|
---|
82 | /* --Fonction-- */
|
---|
83 | template <class T>
|
---|
84 | int ckppf_arr(T x)
|
---|
85 | {
|
---|
86 | int rc=0;
|
---|
87 | cout << " ---- ckppf_arr ----- T= " << typeid(x).name() << " , "
|
---|
88 | << DataTypeInfo<T>::getTypeName() << endl;
|
---|
89 | TArray<T> a(10,12);
|
---|
90 | a = RegularSequence();
|
---|
91 | {
|
---|
92 | POutPersist po("arrtobj.ppf");
|
---|
93 | po << a;
|
---|
94 | }
|
---|
95 | TArray<T> b;
|
---|
96 | {
|
---|
97 | PInPersist pin("arrtobj.ppf");
|
---|
98 | pin >> b;
|
---|
99 | }
|
---|
100 | TArray<T> d = a-b;
|
---|
101 | T min, max;
|
---|
102 | d.MinMax(min,max);
|
---|
103 | cout << " diff d=a-b, Min=" << min << " Max=" << max << endl;
|
---|
104 | if ((min != T(0))||(max != T(0))) rc=9;
|
---|
105 | if (rc==0)
|
---|
106 | cout << " ===>>> PPF I/O TArray< " << DataTypeInfo<T>::getTypeName() << " > OK " << endl;
|
---|
107 | else
|
---|
108 | cout << " ===>>> PPF I/O TArray< " << DataTypeInfo<T>::getTypeName() << " > ERROR !!!! " << endl;
|
---|
109 | return rc;
|
---|
110 | }
|
---|
111 |
|
---|
112 | /* --Fonction-- */
|
---|
113 | template <class T>
|
---|
114 | int ckppf_arrZ(T x)
|
---|
115 | {
|
---|
116 | int rc=0;
|
---|
117 | cout << " ---- ckppf_arrZ ----- complex< T= " << typeid(x).name() << " , "
|
---|
118 | << DataTypeInfo<T>::getTypeName() << " > " << endl;
|
---|
119 | TArray< complex<T> > a(10,12);
|
---|
120 | TArray<T> rea = SDRealPart(a);
|
---|
121 | TArray<T> ima = SDImagPart(a);
|
---|
122 |
|
---|
123 | rea = RegularSequence();
|
---|
124 | ima = RegularSequence(0.5,2.);
|
---|
125 | {
|
---|
126 | POutPersist po("arrtobj.ppf");
|
---|
127 | po << a;
|
---|
128 | }
|
---|
129 | TArray< complex<T> > b;
|
---|
130 | {
|
---|
131 | PInPersist pin("arrtobj.ppf");
|
---|
132 | pin >> b;
|
---|
133 | }
|
---|
134 | TArray< complex<T> > d = a-b;
|
---|
135 | T remin, remax;
|
---|
136 | SDRealPart(d).MinMax(remin, remax);
|
---|
137 | T immin, immax;
|
---|
138 | SDImagPart(d).MinMax(immin, immax);
|
---|
139 |
|
---|
140 | cout << " diff real[d=a-b], Min=" << remin << " Max=" << remax << endl;
|
---|
141 | cout << " diff imag[d=a-b], Min=" << immin << " Max=" << immax << endl;
|
---|
142 | if ((remin != T(0))||(remax != T(0)) ||
|
---|
143 | (immin != T(0))||(immax != T(0)) ) rc=9;
|
---|
144 | if (rc==0)
|
---|
145 | cout << " ===>>> PPF I/O TArray< complex<" << DataTypeInfo<T>::getTypeName() << " > > OK " << endl;
|
---|
146 | else
|
---|
147 | cout << " ===>>> PPF I/O TArray< complex< " << DataTypeInfo<T>::getTypeName() << " > > ERROR !!!! " << endl;
|
---|
148 | return rc;
|
---|
149 | }
|
---|
150 |
|
---|
151 | /* --Fonction-- */
|
---|
152 | int ppftstB()
|
---|
153 | {
|
---|
154 | int rcg=0;
|
---|
155 | int rc;
|
---|
156 | int_4 i=1;
|
---|
157 | int_8 l=1;
|
---|
158 | r_4 f=1.;
|
---|
159 | r_8 d=1.;
|
---|
160 | rc=ckppf_arr(i);
|
---|
161 | if (rc!=0) rcg+=10;
|
---|
162 | rc=ckppf_arr(l);
|
---|
163 | if (rc!=0) rcg+=10;
|
---|
164 | rc=ckppf_arr(f);
|
---|
165 | if (rc!=0) rcg+=10;
|
---|
166 | rc=ckppf_arr(d);
|
---|
167 | if (rc!=0) rcg+=10;
|
---|
168 | rc=ckppf_arrZ(f);
|
---|
169 | if (rc!=0) rcg+=10;
|
---|
170 | rc=ckppf_arrZ(d);
|
---|
171 | if (rc!=0) rcg+=10;
|
---|
172 | #ifdef SO_LDBLE128
|
---|
173 | r_16 ld=1.;
|
---|
174 | rc=ckppf_arr(ld);
|
---|
175 | if (rc!=0) rcg+=10;
|
---|
176 | rc=ckppf_arrZ(ld);
|
---|
177 | if (rc!=0) rcg+=10;
|
---|
178 | #endif
|
---|
179 | return rcg;
|
---|
180 | }
|
---|
181 |
|
---|
182 |
|
---|
183 | /* --Fonction-- */
|
---|
184 | int ppftstA()
|
---|
185 | {
|
---|
186 | cout << "Test Creation / PPersist Save NTuple, Histo, ..." << endl;
|
---|
187 |
|
---|
188 | POutPersist so("tobjio.ppf");
|
---|
189 |
|
---|
190 | NTuple *nt;
|
---|
191 | float xnt[4];
|
---|
192 | const char *ntn[4] = {"x","y","ex","ey"};
|
---|
193 | int nent,i;
|
---|
194 | nent = 1000;
|
---|
195 | nt = new NTuple(2,ntn); // Creation NTuple (AVEC new )
|
---|
196 | for(i=0; i<nent; i++) {
|
---|
197 | xnt[0] = i*50./nent; xnt[1] = 0.2*xnt[0]*xnt[0]+(NorRand()*xnt[0]/3.);
|
---|
198 | nt->Fill(xnt);
|
---|
199 | }
|
---|
200 |
|
---|
201 | string nom = "nt21";
|
---|
202 | ObjFileIO<NTuple> oiont(nt);
|
---|
203 | oiont.Write(so, nom);
|
---|
204 | cout << "Writing " << nom << endl;
|
---|
205 |
|
---|
206 | string nx, ny, nz;
|
---|
207 | string ex,ey,ez;
|
---|
208 | nx = "x"; ny = "y";
|
---|
209 | nent = 20;
|
---|
210 | nt = new NTuple(4,ntn); // Creation NTuple (AVEC new )
|
---|
211 | for(i=0; i<nent; i++) {
|
---|
212 | xnt[0] = i*50./nent; xnt[1] = 0.2*xnt[0]*xnt[0]+(NorRand()*xnt[0]/3.);
|
---|
213 | xnt[2] = sqrt((double) xnt[0]); xnt[3] = xnt[0]*2;
|
---|
214 | nt->Fill(xnt);
|
---|
215 | }
|
---|
216 | nom = "nt22";
|
---|
217 | ObjFileIO<NTuple> oiont2(nt);
|
---|
218 | oiont2.Write(so, nom);
|
---|
219 | cout << "Writing " << nom << endl;
|
---|
220 |
|
---|
221 | { // Objet Histo-2D
|
---|
222 | r_8 x,y,w;
|
---|
223 | int i,j;
|
---|
224 | Histo2D* h = new Histo2D(-10.,10.,25,-10.,10.,25);
|
---|
225 | for(i=0; i<25; i++) for(j=0; j<25; j++) {
|
---|
226 | h->BinCenter(i,j,x,y);
|
---|
227 | w = 100.*exp(-0.5*(x*x/9. + y*y/9.));
|
---|
228 | h->Add(x,y,w);
|
---|
229 | w = 50.*exp(-0.5*((x+10.)*(x+10.)/9. + (y+10.)*(y+10.)/9.));
|
---|
230 | h->Add(x,y,w);
|
---|
231 | }
|
---|
232 | nom = "h2d";
|
---|
233 | ObjFileIO<Histo2D> oioh(h);
|
---|
234 | oioh.Write(so, nom);
|
---|
235 | cout << "Writing " << nom << endl;
|
---|
236 | }
|
---|
237 |
|
---|
238 | {
|
---|
239 | Histo *h;
|
---|
240 | float x;
|
---|
241 |
|
---|
242 |
|
---|
243 | h = new Histo(0., 200., 100); // Creation histo (AVEC new )
|
---|
244 | for(i=0; i<100; i++) // Remplissage d'histo
|
---|
245 | { x = (2*i+1.); h->Add(x, x*(200.-x)); }
|
---|
246 | nom = "h1d";
|
---|
247 | ObjFileIO<Histo> oioh(h);
|
---|
248 | oioh.Write(so, nom);
|
---|
249 | cout << "Writing " << nom << endl;
|
---|
250 |
|
---|
251 | }
|
---|
252 |
|
---|
253 | { // Vecteurs
|
---|
254 | Vector* vpx, *vpy;
|
---|
255 | vpx = new Vector(20); vpy = new Vector(20);
|
---|
256 | int i; double x;
|
---|
257 | for(i=0; i<20; i++) { x = 8.*i/20; (*vpx)(i) = x; (*vpy)(i) = 3*cos(x)+2*sin(x); }
|
---|
258 | nom = "vx1";
|
---|
259 | FIO_TArray<double> oiov1(vpx);
|
---|
260 | oiov1.Write(so, nom);
|
---|
261 | cout << "Writing " << nom << endl;
|
---|
262 | nom = "vy1";
|
---|
263 | FIO_TArray<double> oiov2(vpy);
|
---|
264 | oiov2.Write(so, nom);
|
---|
265 | cout << "Writing " << nom << endl;
|
---|
266 | vpx = new Vector(30);
|
---|
267 | for(i=0; i<30; i++) { x = 8.*i/30+0.1; (*vpx)(i) = sin(2.*x)/(2.*x); }
|
---|
268 | nom = "vx2";
|
---|
269 | FIO_TArray<double> oiov3(vpx);
|
---|
270 | oiov3.Write(so, nom);
|
---|
271 | cout << "Writing " << nom << endl;
|
---|
272 | }
|
---|
273 |
|
---|
274 |
|
---|
275 | { // NTuple 3D
|
---|
276 | float xnt[6];
|
---|
277 | double ang;
|
---|
278 | const char *ntn[6] = {"x","y","z","ex","ey","ez"};
|
---|
279 | int nent,i;
|
---|
280 |
|
---|
281 | NTuple* nt = new NTuple(6,ntn); // Creation NTuple (AVEC new )
|
---|
282 | nent = 3000;
|
---|
283 | for(i=0; i<nent; i++) {
|
---|
284 | ang = 5.*6.28*(double)i/(double)nent;
|
---|
285 | xnt[0] = cos(ang)*1.5+NorRand()*0.1; xnt[1] = sin(ang)*1.5+NorRand()*0.1;
|
---|
286 | xnt[2] = ang/8.+NorRand()*0.05; xnt[3] = xnt[4] = xnt[5] = 0.;
|
---|
287 | nt->Fill(xnt);
|
---|
288 | }
|
---|
289 |
|
---|
290 | nom = "nt31";
|
---|
291 | ObjFileIO<NTuple> oiont(nt);
|
---|
292 | oiont.Write(so, nom);
|
---|
293 | cout << "Writing " << nom << endl;
|
---|
294 |
|
---|
295 | nt = new NTuple(6,ntn); // Creation NTuple (AVEC new )
|
---|
296 | nent = 100;
|
---|
297 | for(i=0; i<nent; i++) {
|
---|
298 | ang = 5.*6.28*(double)i/(double)nent;
|
---|
299 | xnt[0] = cos(-ang)*1+NorRand()*0.0; xnt[1] = sin(-ang)*1.+NorRand()*0.0;
|
---|
300 | xnt[2] = ang/8.+NorRand()*0.0; xnt[3] = 0.1; xnt[4] = 0.15; xnt[5] = 0.07;
|
---|
301 | nt->Fill(xnt);
|
---|
302 | }
|
---|
303 | nom = "nt32";
|
---|
304 | ObjFileIO<NTuple> oiont2(nt);
|
---|
305 | oiont2.Write(so, nom);
|
---|
306 | cout << "Writing " << nom << endl;
|
---|
307 | }
|
---|
308 |
|
---|
309 | { // Matrices
|
---|
310 | Matrix* mtx = new Matrix(50, 50);
|
---|
311 | int i,j;
|
---|
312 | double xp,yp,rp;
|
---|
313 | for(i=0; i<50; i++)
|
---|
314 | for(j=0; j<50; j++) {
|
---|
315 | xp = i-15; yp = j-25;
|
---|
316 | rp = (xp*xp)/16.+(yp*yp)/16.;
|
---|
317 | (*mtx)(j,i) = 11.*exp(-rp);
|
---|
318 | xp = i-35; yp = j-15;
|
---|
319 | rp = (xp*xp)/9.+(yp*yp)/9.;
|
---|
320 | (*mtx)(j,i) += 3.*exp(-rp);
|
---|
321 | xp = i-45; yp = j-40;
|
---|
322 | rp = (xp*xp)/10.+(yp*yp)/20.;
|
---|
323 | (*mtx)(j,i) += 6.*exp(-rp);
|
---|
324 | }
|
---|
325 | nom = "mtx1";
|
---|
326 | FIO_TArray<double> oiom(mtx);
|
---|
327 | oiom.Write(so, nom);
|
---|
328 | cout << "Writing " << nom << endl;
|
---|
329 | }
|
---|
330 | return 0;
|
---|
331 | }
|
---|
332 |
|
---|