1 | #include <stdio.h>
|
---|
2 | #include <string.h>
|
---|
3 |
|
---|
4 | #include "strutil.h"
|
---|
5 | #include "perrors.h"
|
---|
6 | #include "ntuple.h"
|
---|
7 |
|
---|
8 |
|
---|
9 | #define BADVAL -1.e19
|
---|
10 | #define LENNAME 8
|
---|
11 | #define LENNAME1 (LENNAME+1)
|
---|
12 |
|
---|
13 | //++
|
---|
14 | // Class NTuple
|
---|
15 | // Lib Outils++
|
---|
16 | // include ntuple.h
|
---|
17 | //
|
---|
18 | // Classe de ntuples
|
---|
19 | //--
|
---|
20 | //++
|
---|
21 | // Links Parents
|
---|
22 | // PPersist
|
---|
23 | // NTupleInterface
|
---|
24 | //--
|
---|
25 |
|
---|
26 | /* --Methode-- */
|
---|
27 | //++
|
---|
28 | NTuple::NTuple()
|
---|
29 | //
|
---|
30 | // Createur par defaut
|
---|
31 | //--
|
---|
32 | {
|
---|
33 | mNVar = mNEnt = mBlk = mNBlk = 0;
|
---|
34 | mVar = NULL;
|
---|
35 | mVarD = NULL;
|
---|
36 | mNames = NULL;
|
---|
37 | mInfo = NULL;
|
---|
38 | }
|
---|
39 |
|
---|
40 |
|
---|
41 | //++
|
---|
42 | NTuple::NTuple(int nvar, char** noms, int blk)
|
---|
43 | //
|
---|
44 | // Createur d'un ntuple de `nvar' variables dont les
|
---|
45 | // noms sont dans le tableau de cahines de caracteres `noms'
|
---|
46 | // avec `blk' d'evenements par blocks.
|
---|
47 | //--
|
---|
48 | {
|
---|
49 | mNVar = mNEnt = mBlk = mNBlk = 0;
|
---|
50 | mVar = NULL;
|
---|
51 | mVarD = NULL;
|
---|
52 | mNames = NULL;
|
---|
53 | mInfo = NULL;
|
---|
54 | if (nvar <= 0) THROW(sizeMismatchErr);
|
---|
55 | mNVar = nvar;
|
---|
56 | mVar = new r_4[nvar];
|
---|
57 | mVarD = new r_8[nvar];
|
---|
58 | if (blk < 10) blk = 10;
|
---|
59 | mBlk = blk;
|
---|
60 | // On prend des noms de LENNAME char pour le moment
|
---|
61 | mNames = new char[nvar*LENNAME1];
|
---|
62 | r_4* pt = new r_4[nvar*blk];
|
---|
63 | mNBlk = 1;
|
---|
64 | mPtr.push_back(pt);
|
---|
65 | int i;
|
---|
66 | for(i=0; i<nvar; i++)
|
---|
67 | { strncpy(mNames+i*LENNAME1, noms[i], LENNAME);
|
---|
68 | mNames[i*LENNAME1+LENNAME] = '\0'; }
|
---|
69 | return;
|
---|
70 | }
|
---|
71 |
|
---|
72 | // cmv 8/10/99
|
---|
73 | //++
|
---|
74 | NTuple::NTuple(const NTuple& NT)
|
---|
75 | //
|
---|
76 | // Createur par copie (clone).
|
---|
77 | //--
|
---|
78 | : mNVar(0), mNEnt(0), mBlk(0), mNBlk(0)
|
---|
79 | , mVar(NULL), mVarD(NULL), mNames(NULL), mInfo(NULL)
|
---|
80 | {
|
---|
81 | if(NT.mNVar<=0) return; // cas ou NT est cree par defaut
|
---|
82 | mNVar = NT.mNVar;
|
---|
83 | mBlk = NT.mBlk;
|
---|
84 | mVar = new r_4[NT.mNVar];
|
---|
85 | mVarD = new r_8[NT.mNVar];
|
---|
86 | mNames = new char[NT.mNVar*LENNAME1];
|
---|
87 |
|
---|
88 | int i;
|
---|
89 | r_4* pt = new r_4[mNVar*mBlk];
|
---|
90 | mNBlk = 1; mPtr.push_back(pt);
|
---|
91 |
|
---|
92 | for(i=0;i<mNVar;i++) strcpy(mNames+i*LENNAME1,NT.NomIndex(i));
|
---|
93 |
|
---|
94 | if(NT.mInfo!=NULL) {mInfo = new DVList; *mInfo = *(NT.mInfo);}
|
---|
95 |
|
---|
96 | if(NT.mNEnt<=0) return;
|
---|
97 | for(i=0;i<NT.mNEnt;i++) {r_4* x=NT.GetVec(i,NULL); Fill(x);}
|
---|
98 |
|
---|
99 | return;
|
---|
100 | }
|
---|
101 |
|
---|
102 | /* --Methode-- */
|
---|
103 | //++
|
---|
104 | NTuple::NTuple(char *flnm)
|
---|
105 | //
|
---|
106 | // Createur lecture fichier ppersist.
|
---|
107 | //--
|
---|
108 | {
|
---|
109 | mNVar = mNEnt = mBlk = mNBlk = 0;
|
---|
110 | mVar = NULL;
|
---|
111 | mVarD = NULL;
|
---|
112 | mNames = NULL;
|
---|
113 | mInfo = NULL;
|
---|
114 | PInPersist s(flnm);
|
---|
115 | ObjFileIO<NTuple> fiont(this);
|
---|
116 | fiont.Read(s);
|
---|
117 | }
|
---|
118 |
|
---|
119 | /* --Methode-- */
|
---|
120 | NTuple::~NTuple()
|
---|
121 | {
|
---|
122 | Clean();
|
---|
123 | }
|
---|
124 |
|
---|
125 | /* --Methode-- */
|
---|
126 | void NTuple::Clean()
|
---|
127 | {
|
---|
128 | if (mVar) delete[] mVar;
|
---|
129 | if (mVarD) delete[] mVarD;
|
---|
130 | if (mNames) delete[] mNames;
|
---|
131 | if (mInfo) delete mInfo;
|
---|
132 | int i;
|
---|
133 | if(mNBlk>0) for(i=0; i<mNBlk; i++) delete[] mPtr[i];
|
---|
134 | mPtr.erase(mPtr.begin(), mPtr.end());
|
---|
135 | mNVar = mNEnt = mBlk = mNBlk = 0;
|
---|
136 | mVar = NULL;
|
---|
137 | mVarD = NULL;
|
---|
138 | mNames = NULL;
|
---|
139 | mInfo = NULL;
|
---|
140 | return;
|
---|
141 | }
|
---|
142 |
|
---|
143 | /* --Methode-- cmv 08/10/99 */
|
---|
144 | //++
|
---|
145 | NTuple& NTuple::operator = (const NTuple& NT)
|
---|
146 | //
|
---|
147 | // Operateur egal (clone).
|
---|
148 | //--
|
---|
149 | {
|
---|
150 | if(this == &NT) return *this;
|
---|
151 | Clean();
|
---|
152 | if(NT.mNVar<=0) return *this; // cas ou NT est cree par defaut
|
---|
153 | mNVar = NT.mNVar;
|
---|
154 | mBlk = NT.mBlk;
|
---|
155 | mVar = new r_4[NT.mNVar];
|
---|
156 | mVarD = new r_8[NT.mNVar];
|
---|
157 | mNames = new char[NT.mNVar*LENNAME1];
|
---|
158 |
|
---|
159 | int i;
|
---|
160 | r_4* pt = new r_4[mNVar*mBlk];
|
---|
161 | mNBlk = 1; mPtr.push_back(pt);
|
---|
162 |
|
---|
163 | for(i=0;i<mNVar;i++) strcpy(mNames+i*LENNAME1,NT.NomIndex(i));
|
---|
164 |
|
---|
165 | if(NT.mInfo!=NULL) {mInfo = new DVList; *mInfo = *(NT.mInfo);}
|
---|
166 |
|
---|
167 | if(NT.mNEnt<=0) return *this;
|
---|
168 | for(i=0;i<NT.mNEnt;i++) {r_4* x=NT.GetVec(i,NULL); Fill(x);}
|
---|
169 |
|
---|
170 | // En fait il faudrait un createur par copie qui partage les donnees
|
---|
171 | // quand l'objet est temporaire... trop complique A FAIRE ! cmv.
|
---|
172 | return *this;
|
---|
173 | }
|
---|
174 |
|
---|
175 | /* --Methode-- */
|
---|
176 | //++
|
---|
177 | void NTuple::Fill(r_4* x)
|
---|
178 | //
|
---|
179 | // Remplit le ntuple avec le tableau cd reels `x'.
|
---|
180 | //--
|
---|
181 | {
|
---|
182 | int numb = mNEnt/mBlk;
|
---|
183 | if (numb >= mNBlk) {
|
---|
184 | r_4* pt = new r_4[mNVar*mBlk];
|
---|
185 | mNBlk++;
|
---|
186 | mPtr.push_back(pt);
|
---|
187 | }
|
---|
188 | int offb = mNEnt-numb*mBlk;
|
---|
189 | memcpy((mPtr[numb]+offb*mNVar), x, mNVar*sizeof(r_4));
|
---|
190 | mNEnt++;
|
---|
191 | return;
|
---|
192 | }
|
---|
193 |
|
---|
194 |
|
---|
195 | /* --Methode-- */
|
---|
196 | //++
|
---|
197 | float NTuple::GetVal(int n, int k) const
|
---|
198 | //
|
---|
199 | // Retourne la valeur de la variable `k' de l'evenement `n'.
|
---|
200 | //--
|
---|
201 | {
|
---|
202 | if (n >= mNEnt) return(BADVAL);
|
---|
203 | if ( (k < 0) || (k >= mNVar) ) return(BADVAL);
|
---|
204 | int numb = n/mBlk;
|
---|
205 | int offb = n-numb*mBlk;
|
---|
206 | return(*(mPtr[numb]+offb*mNVar+k));
|
---|
207 | }
|
---|
208 |
|
---|
209 | /* --Methode-- */
|
---|
210 | //++
|
---|
211 | void NTuple::SetVal(int n, int k, float value)
|
---|
212 | //
|
---|
213 | // initialise la valeur de la variable `k' de l'evenement `n'.
|
---|
214 | //--
|
---|
215 | {
|
---|
216 | if (n >= mNEnt) return;
|
---|
217 | if ( (k < 0) || (k >= mNVar) ) return;
|
---|
218 | int numb = n/mBlk;
|
---|
219 | int offb = n-numb*mBlk;
|
---|
220 | *(mPtr[numb]+offb*mNVar+k) = value;
|
---|
221 | }
|
---|
222 |
|
---|
223 | /* --Methode-- */
|
---|
224 | //++
|
---|
225 | int NTuple::IndexNom(const char* nom) const
|
---|
226 | //
|
---|
227 | // Retourne le numero de la variable de nom `nom'.
|
---|
228 | //--
|
---|
229 | {
|
---|
230 | int i;
|
---|
231 | for(i=0; i<mNVar; i++)
|
---|
232 | if ( strcmp(nom, mNames+i*LENNAME1) == 0) return(i);
|
---|
233 | return(-1);
|
---|
234 | }
|
---|
235 |
|
---|
236 |
|
---|
237 | static char nomretour[2*LENNAME1];
|
---|
238 | /* --Methode-- */
|
---|
239 | //++
|
---|
240 | char* NTuple::NomIndex(int k) const
|
---|
241 | //
|
---|
242 | // Retourne le nom de la variable numero 'k'
|
---|
243 | //--
|
---|
244 | {
|
---|
245 | nomretour[0] = '\0';
|
---|
246 | if ((k >= 0) && (k < mNVar)) strcpy(nomretour, mNames+k*LENNAME1);
|
---|
247 | return(nomretour);
|
---|
248 | }
|
---|
249 |
|
---|
250 |
|
---|
251 | /* --Methode-- */
|
---|
252 | //++
|
---|
253 | r_4* NTuple::GetVec(int n, r_4* ret) const
|
---|
254 | //
|
---|
255 | // Retourne l'evenement `n' dans le vecteur `ret'.
|
---|
256 | //--
|
---|
257 | {
|
---|
258 | int i;
|
---|
259 | if (ret == NULL) ret = mVar;
|
---|
260 | if (n >= mNEnt) {
|
---|
261 | for(i=0; i<mNVar; i++) ret[i] = BADVAL;
|
---|
262 | return(ret);
|
---|
263 | }
|
---|
264 |
|
---|
265 | int numb = n/mBlk;
|
---|
266 | int offb = n-numb*mBlk;
|
---|
267 | memcpy(ret, (mPtr[numb]+offb*mNVar), mNVar*sizeof(r_4));
|
---|
268 | return(ret);
|
---|
269 | }
|
---|
270 |
|
---|
271 | /* --Methode-- */
|
---|
272 | //++
|
---|
273 | r_8* NTuple::GetVecD(int n, r_8* ret) const
|
---|
274 | //
|
---|
275 | // Retourne l'evenement `n' dans le vecteur `ret'.
|
---|
276 | //--
|
---|
277 | {
|
---|
278 | int i;
|
---|
279 | if (ret == NULL) ret = mVarD;
|
---|
280 | float * fr = GetVec(n);
|
---|
281 | for(i=0; i<mNVar; i++) ret[i] = fr[i];
|
---|
282 | return(ret);
|
---|
283 | }
|
---|
284 |
|
---|
285 |
|
---|
286 |
|
---|
287 | /* --Methode-- */
|
---|
288 | //++
|
---|
289 | DVList& NTuple::Info()
|
---|
290 | //
|
---|
291 | // Renvoie une référence sur l'objet DVList Associé
|
---|
292 | //--
|
---|
293 | {
|
---|
294 | if (mInfo == NULL) mInfo = new DVList;
|
---|
295 | return(*mInfo);
|
---|
296 | }
|
---|
297 |
|
---|
298 | /* --Methode-- */
|
---|
299 | //++
|
---|
300 | void NTuple::Print(int num, int nmax) const
|
---|
301 | //
|
---|
302 | // Imprime `nmax' evenements a partir du numero `num'.
|
---|
303 | //--
|
---|
304 | {
|
---|
305 | int i,j;
|
---|
306 |
|
---|
307 | printf("Num ");
|
---|
308 | for(i=0; i<mNVar; i++) printf("%8s ", mNames+i*LENNAME1);
|
---|
309 | putchar('\n');
|
---|
310 |
|
---|
311 | if (nmax <= 0) nmax = 1;
|
---|
312 | if (num < 0) num = 0;
|
---|
313 | nmax += num;
|
---|
314 | if (nmax > mNEnt) nmax = mNEnt;
|
---|
315 | for(i=num; i<nmax; i++) {
|
---|
316 | GetVec(i, NULL);
|
---|
317 | printf("%6d ", i);
|
---|
318 | for(j=0; j<mNVar; j++) printf("%8g ", (float)mVar[j]);
|
---|
319 | putchar('\n');
|
---|
320 | }
|
---|
321 | return;
|
---|
322 | }
|
---|
323 |
|
---|
324 | /* --Methode-- */
|
---|
325 | //++
|
---|
326 | void NTuple::Show(ostream& os) const
|
---|
327 | //
|
---|
328 | // Imprime l'information generale sur le ntuple.
|
---|
329 | //--
|
---|
330 | {
|
---|
331 | os << "NTuple: NVar= " << mNVar << " NEnt=" << mNEnt
|
---|
332 | << " (Blk Sz,Nb= " << mBlk << " ," << mNBlk << ")\n";
|
---|
333 | os << " Variables Min Max \n";
|
---|
334 | int i;
|
---|
335 | double min, max;
|
---|
336 | char buff[128];
|
---|
337 | for(i=0; i<mNVar; i++) {
|
---|
338 | GetMinMax(i, min, max);
|
---|
339 | sprintf(buff, "%3d %16s %10lg %10lg \n", i, mNames+i*LENNAME1, min, max);
|
---|
340 | os << (string)buff ;
|
---|
341 | }
|
---|
342 | os << endl;
|
---|
343 | }
|
---|
344 |
|
---|
345 |
|
---|
346 | /* --Methode-- */
|
---|
347 | //++
|
---|
348 | int NTuple::FillFromASCIIFile(string const& fn, float defval)
|
---|
349 | //
|
---|
350 | // Remplit le ntuple a partir d'un fichier ASCII.
|
---|
351 | // Renvoie le nombre de lignes ajoutees.
|
---|
352 | //--
|
---|
353 | {
|
---|
354 | if (NbColumns() < 1) {
|
---|
355 | cout << "NTuple::FillFromASCIIFile() Ntuple has " << NbColumns() << " columns" << endl;
|
---|
356 | return(-1);
|
---|
357 | }
|
---|
358 | FILE * fip = fopen(fn.c_str(), "r");
|
---|
359 | if (fip == NULL) {
|
---|
360 | cout << "NTuple::FillFromASCIIFile() Error opening file " << fn << endl;
|
---|
361 | return(-2);
|
---|
362 | }
|
---|
363 |
|
---|
364 | char lineb[4096];
|
---|
365 | char *line;
|
---|
366 | char* ccp;
|
---|
367 | int j,kk;
|
---|
368 | int postab, posb;
|
---|
369 | float* xv = new float[NbColumns()];
|
---|
370 |
|
---|
371 | int nlread = 0;
|
---|
372 | int nvar = NbColumns();
|
---|
373 | // On boucle sur toutes les lignes
|
---|
374 | while (fgets(lineb,4096,fip) != NULL) {
|
---|
375 | lineb[4095] = '\0';
|
---|
376 | j = 0; line = lineb;
|
---|
377 | // On enleve les espaces et tab de debut
|
---|
378 | while ( (line[j] != '\0') && ((line[j] == ' ') || (line[j] == '\t')) ) j++;
|
---|
379 | line = lineb+j;
|
---|
380 | // Il faut que le premier caractere non-espace soit un digit, ou + ou - ou .
|
---|
381 | if (!( isdigit(line[0]) || (line[0] == '+') || (line[0] == '-') || (line[0] == '.') )) continue;
|
---|
382 | ccp = line;
|
---|
383 | for(kk=0; kk<nvar; kk++) xv[kk] = defval;
|
---|
384 | for(kk=0; kk<nvar; kk++) {
|
---|
385 | // Les mots sont separes par des espaces ou des tab
|
---|
386 | postab = posc(ccp, '\t' );
|
---|
387 | posb = posc(ccp, ' ' );
|
---|
388 | if (postab >= 0) {
|
---|
389 | if (posb < 0) posb = postab;
|
---|
390 | else if (postab < posb) posb = postab;
|
---|
391 | }
|
---|
392 | if (posb >= 0) ccp[posb] = '\0';
|
---|
393 | if ( isdigit(line[0]) || (line[0] == '+') || (line[0] == '-') || (line[0] == '.') )
|
---|
394 | xv[kk] = atof(ccp);
|
---|
395 | if (posb < 0) break;
|
---|
396 | ccp += posb+1; j = 0;
|
---|
397 | while ( (ccp[j] != '\0') && ((ccp[j] == ' ') || (ccp[j] == '\t')) ) j++;
|
---|
398 | ccp += j;
|
---|
399 | }
|
---|
400 | Fill(xv);
|
---|
401 | nlread++;
|
---|
402 | }
|
---|
403 |
|
---|
404 | delete[] xv;
|
---|
405 | cout << "NTuple::FillFromASCIIFile( " << fn << ") " << nlread << " fill from file " << endl;
|
---|
406 | return(nlread);
|
---|
407 | }
|
---|
408 |
|
---|
409 |
|
---|
410 | // ------- Implementation de l interface NTuple ---------
|
---|
411 |
|
---|
412 | /* --Methode-- */
|
---|
413 | uint_4 NTuple::NbLines() const
|
---|
414 | {
|
---|
415 | return(NEntry());
|
---|
416 | }
|
---|
417 | /* --Methode-- */
|
---|
418 | uint_4 NTuple::NbColumns() const
|
---|
419 | {
|
---|
420 | return(NVar());
|
---|
421 | }
|
---|
422 |
|
---|
423 | /* --Methode-- */
|
---|
424 | r_8 * NTuple::GetLineD(int n) const
|
---|
425 | {
|
---|
426 | return(GetVecD(n));
|
---|
427 | }
|
---|
428 |
|
---|
429 | /* --Methode-- */
|
---|
430 | r_8 NTuple::GetCell(int n, int k) const
|
---|
431 | {
|
---|
432 | return(GetVal(n, k));
|
---|
433 | }
|
---|
434 |
|
---|
435 | /* --Methode-- */
|
---|
436 | r_8 NTuple::GetCell(int n, string const & nom) const
|
---|
437 | {
|
---|
438 | return(GetVal(n, nom.c_str()));
|
---|
439 | }
|
---|
440 |
|
---|
441 | /* --Methode-- */
|
---|
442 | //++
|
---|
443 | void NTuple::GetMinMax(int k, double& min, double& max) const
|
---|
444 | //
|
---|
445 | // Retourne le minimum et le maximum de la variable `k'.
|
---|
446 | //--
|
---|
447 | {
|
---|
448 | min = 9.e19; max = -9.e19;
|
---|
449 | if ( (k < 0) || (k >= mNVar) ) return;
|
---|
450 | int jb,ib,i;
|
---|
451 | double x;
|
---|
452 | i=0;
|
---|
453 | for(jb=0; jb< mNBlk; jb++)
|
---|
454 | for(ib=0; ib< mBlk; ib++) {
|
---|
455 | if (i >= mNEnt) break;
|
---|
456 | i++;
|
---|
457 | x = *(mPtr[jb]+ib*mNVar+k);
|
---|
458 | if(i==1) {min = x; max = x;}
|
---|
459 | if (x < min) min = x;
|
---|
460 | if (x > max) max = x;
|
---|
461 | }
|
---|
462 | return;
|
---|
463 | }
|
---|
464 |
|
---|
465 | /* --Methode-- */
|
---|
466 | void NTuple::GetMinMax(string const & nom, double& min, double& max) const
|
---|
467 | {
|
---|
468 | GetMinMax(IndexNom(nom.c_str()), min, max);
|
---|
469 | }
|
---|
470 |
|
---|
471 | /* --Methode-- */
|
---|
472 | int NTuple::ColumnIndex(string const & nom) const
|
---|
473 | {
|
---|
474 | return(IndexNom(nom.c_str()));
|
---|
475 | }
|
---|
476 |
|
---|
477 | /* --Methode-- */
|
---|
478 | string NTuple::ColumnName(int k) const
|
---|
479 | {
|
---|
480 | return(NomIndex(k));
|
---|
481 | }
|
---|
482 |
|
---|
483 | /* --Methode-- */
|
---|
484 | //++
|
---|
485 | string NTuple::VarList_C(const char* nomx) const
|
---|
486 | //
|
---|
487 | // Retourne une chaine de caracteres avec la declaration des noms de
|
---|
488 | // variables. si "nomx!=NULL" , des instructions d'affectation
|
---|
489 | // a partir d'un tableau "nomx[i]" sont ajoutees.
|
---|
490 | //--
|
---|
491 | {
|
---|
492 | string rets="";
|
---|
493 | int i;
|
---|
494 | for(i=0; i<mNVar; i++) {
|
---|
495 | if ( (i%5 == 0) && (i > 0) ) rets += ";";
|
---|
496 | if (i%5 == 0) rets += "\ndouble ";
|
---|
497 | else rets += ",";
|
---|
498 | rets += mNames+i*LENNAME1;
|
---|
499 | }
|
---|
500 | rets += "; \n";
|
---|
501 | if (nomx) {
|
---|
502 | char buff[256];
|
---|
503 | for(i=0; i<mNVar; i++) {
|
---|
504 | sprintf(buff,"%s=%s[%d]; ", mNames+i*LENNAME1, nomx, i);
|
---|
505 | rets += buff;
|
---|
506 | if ( (i%3 == 0) && (i > 0) ) rets += "\n";
|
---|
507 | }
|
---|
508 | }
|
---|
509 |
|
---|
510 | return(rets);
|
---|
511 | }
|
---|
512 |
|
---|
513 |
|
---|
514 | /* --Methode-- */
|
---|
515 | //++
|
---|
516 | string NTuple::LineHeaderToString() const
|
---|
517 | // Retourne une chaine de caracteres avec la liste des noms de
|
---|
518 | // variables, utilisables pour une impression
|
---|
519 | //--
|
---|
520 | {
|
---|
521 | char buff[32];
|
---|
522 | string rets=" Num ";
|
---|
523 | for(int i=0; i<mNVar; i++) {
|
---|
524 | sprintf(buff, "%8s ", mNames+i*LENNAME1);
|
---|
525 | rets += buff;
|
---|
526 | }
|
---|
527 | rets += '\n';
|
---|
528 | return(rets);
|
---|
529 | }
|
---|
530 |
|
---|
531 | /* --Methode-- */
|
---|
532 | //++
|
---|
533 | string NTuple::LineToString(int n) const
|
---|
534 | // Retourne une chaine de caracteres avec le contenu de la ligne "n"
|
---|
535 | // utilisable pour une impression
|
---|
536 | //--
|
---|
537 | {
|
---|
538 | char buff[32];
|
---|
539 | double* val;
|
---|
540 | val = GetLineD(n);
|
---|
541 | sprintf(buff,"%6d: ",n);
|
---|
542 | string rets=buff;
|
---|
543 | int i;
|
---|
544 | for(i=0; i<mNVar; i++) {
|
---|
545 | sprintf(buff, "%8.3g ", val[i]);
|
---|
546 | rets += buff;
|
---|
547 | }
|
---|
548 | rets += '\n';
|
---|
549 | return(rets);
|
---|
550 | }
|
---|
551 |
|
---|
552 |
|
---|
553 | /* --Methode-- */
|
---|
554 | //++
|
---|
555 | void ObjFileIO<NTuple>::WriteSelf(POutPersist& s) const
|
---|
556 | //
|
---|
557 | // Ecriture ppersist du ntuple.
|
---|
558 | //--
|
---|
559 | {
|
---|
560 | char strg[256];
|
---|
561 | if (dobj->mInfo) sprintf(strg, "NVar=%6d NEnt=%9d BlkSz=%6d NBlk=%6d HasInfo",
|
---|
562 | (int)dobj->mNVar, (int)dobj->mNEnt, (int)dobj->mBlk, (int)dobj->mNBlk);
|
---|
563 | else sprintf(strg, "NVar=%6d NEnt=%9d BlkSz=%6d NBlk=%6d ",
|
---|
564 | (int)dobj->mNVar, (int)dobj->mNEnt, (int)dobj->mBlk, (int)dobj->mNBlk);
|
---|
565 | s.PutLine(strg);
|
---|
566 | s.PutI4(dobj->mNVar);
|
---|
567 | s.PutBytes(dobj->mNames, dobj->mNVar*LENNAME1);
|
---|
568 | s.PutI4(dobj->mNEnt);
|
---|
569 | s.PutI4(dobj->mBlk);
|
---|
570 | s.PutI4(dobj->mNBlk);
|
---|
571 | if (dobj->mInfo) s << (*(dobj->mInfo));
|
---|
572 | int jb;
|
---|
573 | for(jb=0; jb<dobj->mNBlk; jb++)
|
---|
574 | s.PutR4s(dobj->mPtr[jb], dobj->mNVar*dobj->mBlk);
|
---|
575 | return;
|
---|
576 | }
|
---|
577 |
|
---|
578 | /* --Methode-- */
|
---|
579 | //++
|
---|
580 | void ObjFileIO<NTuple>::ReadSelf(PInPersist& s)
|
---|
581 | //
|
---|
582 | // Lecture ppersist du ntuple.
|
---|
583 | //--
|
---|
584 | {
|
---|
585 |
|
---|
586 | dobj->Clean();
|
---|
587 |
|
---|
588 | char strg[256];
|
---|
589 | s.GetLine(strg, 255);
|
---|
590 | // Pour savoir s'il y avait un DVList Info associe
|
---|
591 | bool hadinfo = false;
|
---|
592 | if (strncmp(strg+strlen(strg)-7, "HasInfo", 7) == 0) hadinfo = true;
|
---|
593 |
|
---|
594 | s.GetI4(dobj->mNVar);
|
---|
595 | dobj->mNames = new char[dobj->mNVar*LENNAME1];
|
---|
596 | dobj->mVar = new r_4[dobj->mNVar];
|
---|
597 | dobj->mVarD = new r_8[dobj->mNVar];
|
---|
598 | s.GetBytes(dobj->mNames, dobj->mNVar*LENNAME1);
|
---|
599 | s.GetI4(dobj->mNEnt);
|
---|
600 | s.GetI4(dobj->mBlk);
|
---|
601 | s.GetI4(dobj->mNBlk);
|
---|
602 |
|
---|
603 | if (hadinfo) { // Lecture eventuelle du DVList Info
|
---|
604 | if (dobj->mInfo == NULL) dobj->mInfo = new DVList;
|
---|
605 | s >> (*(dobj->mInfo));
|
---|
606 | }
|
---|
607 |
|
---|
608 | int jb;
|
---|
609 | for(jb=0; jb<dobj->mNBlk; jb++) {
|
---|
610 | r_4* pt = new r_4[dobj->mNVar*dobj->mBlk];
|
---|
611 | dobj->mPtr.push_back(pt);
|
---|
612 | s.GetR4s(dobj->mPtr[jb], dobj->mNVar*dobj->mBlk);
|
---|
613 | }
|
---|
614 |
|
---|
615 | }
|
---|
616 |
|
---|
617 |
|
---|
618 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
619 | #pragma define_template ObjFileIO<NTuple>
|
---|
620 | #endif
|
---|
621 |
|
---|
622 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
623 | template class ObjFileIO<NTuple>;
|
---|
624 | #endif
|
---|