source: Sophya/trunk/SophyaPI/PIext/servnobjm.cc@ 546

Last change on this file since 546 was 546, checked in by ercodmgr, 26 years ago

Gestion option Stats ds piapp - Reza 3/11/99

File size: 43.7 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <ctype.h>
4
5#include <typeinfo>
6#include <iostream.h>
7#include <string>
8#include <list>
9#include <map>
10
11#include "strutil.h"
12
13#include "nobjmgr.h"
14#include "servnobjm.h"
15#include "nomgadapter.h"
16#include "pistdimgapp.h"
17
18#include "fct1dfit.h"
19#include "fct2dfit.h"
20
21#ifdef SANS_EVOLPLANCK
22#include "matrix.h"
23#include "cvector.h"
24#else
25#include "tmatrix.h"
26#include "tvector.h"
27#endif
28
29#include "ntuple.h"
30#include "cimage.h"
31
32#include "histos.h"
33#include "histos2.h"
34#include "ntuple.h"
35#include "hisprof.h"
36
37#include "piscdrawwdg.h"
38#include "pisurfdr.h"
39
40#include "pintuple.h"
41#include "pintup3d.h"
42
43#include "pipodrw.h"
44
45
46
47/* --Methode-- */
48Services2NObjMgr::Services2NObjMgr(NamedObjMgr* omg, string& tmpdir)
49{
50TmpDir = tmpdir;
51PDynLinkMgr::SetTmpDir(tmpdir);
52mImgapp = NULL;
53mOmg = omg;
54dynlink = NULL;
55InitGrAttNames();
56}
57
58/* --Methode-- */
59Services2NObjMgr::~Services2NObjMgr()
60{
61CloseDLL();
62}
63
64/* --Methode-- */
65void Services2NObjMgr::RegisterClass(AnyDataObj* o, NObjMgrAdapter* oa)
66{
67ObjAdaptList::iterator it;
68for(it = objadaplist.begin(); it != objadaplist.end(); it++)
69#ifdef SANS_EVOLPLANCK
70 if (typeid(*o) == typeid(*((*it).obj))) THROW(dupIdErr);
71#else
72 if (typeid(*o) == typeid(*((*it).obj)))
73 throw(DuplicateIdExc("Services2NObjMgr::RegisterClass() - Duplicate class"));
74#endif
75dataobj_adapter oba;
76oba.obj = o;
77oba.obja = oa;
78objadaplist.push_back(oba);
79}
80
81/* --Methode-- */
82NObjMgrAdapter* Services2NObjMgr::GetAdapter(AnyDataObj* o)
83{
84ObjAdaptList::iterator it;
85for(it = objadaplist.begin(); it != objadaplist.end(); it++)
86 if (typeid(*o) == typeid(*((*it).obj))) return((*it).obja->Clone(o));
87return(new NObjMgrAdapter(o));
88}
89
90/* --Methode-- */
91void Services2NObjMgr::PlotFunc(string const & expfunc, string & nom, double xmin, double xmax, int np, string dopt)
92{
93FILE *fip;
94string fname = TmpDir + "func1_pia_dl.c";
95string cmd;
96int rc;
97
98if (!mImgapp) return;
99
100cmd = "rm -f " + fname;
101rc = system(cmd.c_str());
102// printf("PlotFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
103
104if ((fip = fopen(fname.c_str(), "w")) == NULL) {
105 string sn = fname;
106 cout << "Services2NObjMgr/PlotFunc_Error: fopen( " << sn << endl;
107 return;
108 }
109
110// constitution du fichier a compiler
111fputs("#include <math.h> \n", fip);
112fputs("double func1_pia_dl_func(double x) \n{\n", fip);
113fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
114fclose(fip);
115
116string func = "func1_pia_dl_func";
117DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);
118if (!f) return;
119PlotFunc(f, nom, xmin, xmax, np, dopt);
120CloseDLL();
121return;
122}
123
124/* --Methode-- */
125void Services2NObjMgr::PlotFunc2D(string const & expfunc, string & nom, double xmin, double xmax,
126 double ymin, double ymax, int npx, int npy, string dopt)
127{
128FILE *fip;
129string fname = TmpDir + "func2_pia_dl.c";
130string cmd;
131int rc;
132
133if (!mImgapp) return;
134
135cmd = "rm " + fname;
136rc = system(cmd.c_str());
137// printf("PlotFunc2D_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
138
139if ((fip = fopen(fname.c_str(), "w")) == NULL) {
140 string sn = fname;
141 cout << "Services2NObjMgr/PlotFunc2D_Error: fopen( " << sn << endl;
142 return;
143 }
144
145// constitution du fichier a compiler
146fputs("#include <math.h> \n", fip);
147fputs("double func2_pia_dl_func(double x, double y) \n{\n", fip);
148fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
149fclose(fip);
150
151string func = "func2_pia_dl_func";
152DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);
153if (!f) return;
154PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt);
155CloseDLL();
156return;
157}
158
159/* --Methode-- */
160void Services2NObjMgr::PlotFuncFrCFile(string const & fname, string const & func, string & nom,
161 double xmin, double xmax, int np, string dopt)
162{
163DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);
164if (!f) return;
165PlotFunc(f, nom, xmin, xmax, np, dopt);
166CloseDLL();
167return;
168}
169
170/* --Methode-- */
171void Services2NObjMgr::PlotFunc2DFrCFile(string const & fname, string const & func, string & nom,
172 double xmin, double xmax, double ymin, double ymax, int npx, int npy, string dopt)
173{
174DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);
175if (!f) return;
176PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt);
177CloseDLL();
178return;
179}
180
181/* --Methode-- */
182void Services2NObjMgr::PlotFunc(DlFunctionOfX f, string & nom, double xmin, double xmax, int np, string dopt)
183{
184if (!mImgapp) return;
185
186int k;
187if (np < 1) np = 1;
188if (xmax <= xmin) xmax = xmin+1.;
189Vector* vpy = new Vector(np);
190
191double xx;
192double dx = (xmax-xmin)/np;
193
194try {
195 for(k=0; k<np; k++) { xx = xmin+dx*k; (*vpy)(k) = f(xx); }
196}
197#ifdef SANS_EVOLPLANCK
198CATCH(merr) {
199 fflush(stdout);
200 cout << endl;
201 cerr << endl;
202 string es = PeidaExc(merr);
203 cerr << "Services2NObjMgr::PlotFunc() Exception :" << merr << es;
204 delete vpy;
205 vpy = NULL;
206 } ENDTRY;
207#else
208catch ( PException exc ) {
209 fflush(stdout);
210 cout << endl;
211 cerr << endl;
212 cerr << "Services2NObjMgr::PlotFunc() Exception :" << exc.Msg() << endl;
213 delete vpy;
214 vpy = NULL;
215}
216#endif
217
218if (vpy) {
219 string titre;
220 if (nom.length() < 1) {
221 titre = "Function f(x)";
222 nom = "/autoc/f_x";
223 }
224 else titre = nom;
225
226 P1DArrayAdapter* vya = new POVectorAdapter(vpy, false);
227 vya->DefineXCoordinate(xmin, (xmax-xmin)/np);
228 PIYfXDrawer* dr = new PIYfXDrawer(vya, NULL, true) ;
229 bool fgsr = true;
230 dopt = "thinline," + dopt;
231 int opt = DecodeDispOption(dopt, fgsr);
232 int rsid = mImgapp->DispScDrawer(dr, titre, opt);
233 if (fgsr) mImgapp->RestoreGraphicAtt();
234 if (nom.length() > 0) {
235 mOmg->AddObj(vpy, nom);
236 mOmg->AddWRsId(nom, rsid);
237 }
238 }
239
240return;
241}
242
243/* --Methode-- */
244void Services2NObjMgr::PlotFunc2D(DlFunctionOfXY f, string & nom, double xmin, double xmax, double ymin, double ymax,
245 int npx, int npy, string dopt)
246{
247if (!mImgapp) return;
248
249if (npx < 3) npx = 3;
250if (npy < 3) npy = 3;
251if (npx > 250) npx = 250;
252if (npy > 250) npy = 250;
253if (xmax <= xmin) xmax = xmin+1.;
254if (ymax <= ymin) ymax = ymin+1.;
255
256Matrix* mtx = new Matrix(npy, npx);
257
258int i,j;
259double xx, yy;
260double dx = (xmax-xmin)/npx;
261double dy = (ymax-ymin)/npy;
262// printf(" -- DBG -- %d %d , %g %g , %g %g \n", npx, npy, xmin, xmax, ymin, ymax);
263try {
264 for(j=0; j<npy; j++) {
265 yy = ymin+dy*j;
266 for(i=0; i<npx; i++) {
267 xx = xmin+dx*i;
268 (*mtx)(j, i) = f(xx, yy);
269 }
270 }
271}
272#ifdef SANS_EVOLPLANCK
273CATCH(merr) {
274 fflush(stdout);
275 cout << endl;
276 cerr << endl;
277 string es = PeidaExc(merr);
278 cerr << "Services2NObjMgr::PlotFunc2D() Exception :" << merr << es;
279 delete mtx; mtx = NULL;
280 } ENDTRY;
281#else
282catch ( PException exc ) {
283 fflush(stdout);
284 cout << endl;
285 cerr << endl;
286 cerr << "Services2NObjMgr::PlotFunc2D() Exception :" << exc.Msg() << endl;
287 delete mtx; mtx = NULL;
288}
289#endif
290
291if (mtx) {
292 string titre;
293 if (nom.length() < 1) {
294 titre = "Function f(x,y)";
295 nom = "/autoc/f2d_xy";
296 }
297 else titre = nom;
298 bool fgsr = true;
299 int opt = DecodeDispOption(dopt, fgsr);
300 P2DArrayAdapter* arr = new POMatrixAdapter(mtx, false);
301 arr->DefineXYCoordinates(xmin, ymin, dx, dy);
302 PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
303 int rsid = mImgapp->Disp3DDrawer(sdr, titre, opt);
304 if (fgsr) mImgapp->RestoreGraphicAtt();
305 if (nom.length() > 0) {
306 mOmg->AddObj(mtx, nom);
307 mOmg->AddWRsId(nom, rsid);
308 }
309 }
310
311return;
312}
313
314/* --Methode-- */
315void Services2NObjMgr::DisplayPoints2D(string& nom, string& expx, string& expy,
316 string& experrx, string& experry,
317 string& expcut, string dopt, string loop)
318{
319NObjMgrAdapter* obja=NULL;
320obja = mOmg->GetObjAdapter(nom);
321if (obja == NULL) {
322 cout << "Services2NObjMgr::DisplayPoints2D() Error , No such object " << nom << endl;
323 return;
324 }
325if (!mImgapp) return;
326
327// Creation NTuple
328char* ntn[4] = {"expx","expy","expex","expey",};
329NTuple* nt = NULL;
330bool haserr = false;
331
332if ( (experrx.length() > 0 ) && (experry.length() > 0 ) ) { haserr = true; nt = new NTuple(4, ntn); }
333else { haserr = false; experrx = experry = "0."; nt = new NTuple(2, ntn); }
334
335ComputeExpressions(obja, expx, expy, experrx, experry, expcut, loop, nt, NULL, NULL);
336
337if (nt->NEntry() < 1) {
338 cout << "Services2NObjMgr::DisplayPoints2D() Warning Zero points satisfy cut !" << endl;
339 delete nt;
340 return;
341 }
342
343// nt->Show();
344// nt->Print(0,10);
345PINTuple* pin = new PINTuple(nt, true);
346pin->SetStats(Services2NObjMgr::GetStatsOption(dopt));
347pin->SelectXY(ntn[0], ntn[1]);
348if ( haserr ) pin->SelectErrBar(ntn[2], ntn[3]);
349
350bool fgsr = true;
351dopt = "defline," + dopt;
352int opt = DecodeDispOption(dopt, fgsr);
353string titre = nom + ":" + expy + "%" + expx;
354mImgapp->DispScDrawer( (PIDrawer*)pin, titre, opt);
355if (fgsr) mImgapp->RestoreGraphicAtt();
356return;
357}
358
359/* --Methode-- */
360void Services2NObjMgr::DisplayPoints3D(string& nom, string& expx, string& expy,
361 string& expz, string& expcut, string dopt, string loop)
362{
363NObjMgrAdapter* obja=NULL;
364obja = mOmg->GetObjAdapter(nom);
365if (obja == NULL) {
366 cout << "Services2NObjMgr::DisplayPoints3D() Error , No such object " << nom << endl;
367 return;
368 }
369if (!mImgapp) return;
370
371char* ntn[3] = {"expx","expy","expz"};
372NTuple* nt = new NTuple(3,ntn); // Creation NTuple
373
374string expwt = "1.";
375ComputeExpressions(obja, expx, expy, expz, expwt, expcut, loop, nt, NULL, NULL);
376
377if (nt->NEntry() < 1) {
378 cout << "Services2NObjMgr::DisplayPoints3D() Warning Zero points satisfy cut !" << endl;
379 delete nt;
380 return;
381 }
382nt->Show();
383nt->Print(0,10);
384PINTuple3D* pin = new PINTuple3D(nt, true);
385pin->SelectXYZ(ntn[0], ntn[1], ntn[2]);
386bool fgsr = true;
387dopt = "defline," + dopt;
388int opt = DecodeDispOption(dopt, fgsr);
389
390// Pour plot a partir de DispScDrawer
391// string nomdisp = "_NT3D_";
392// mImgapp->DispScDrawer( (PIDrawer*)pin, nomdisp, opt);
393// Pour plot a partir de Disp3DDrawer
394string titre = nom + ":" + expy + "%" + expx;
395mImgapp->Disp3DDrawer(pin, titre, opt);
396
397if (fgsr) mImgapp->RestoreGraphicAtt();
398return;
399}
400
401/* --Methode-- */
402void Services2NObjMgr::DisplayPoints2DW(string& nom, string& expx, string& expy,
403 string& expwt, string& expcut, string dopt, string loop)
404{
405NObjMgrAdapter* obja=NULL;
406obja = mOmg->GetObjAdapter(nom);
407if (obja == NULL) {
408 cout << "Services2NObjMgr::DisplayPoints2DW() Error , No such object " << nom << endl;
409 return;
410 }
411if (!mImgapp) return;
412
413char* ntn[3] = {"expx","expy","expw"};
414NTuple* nt = new NTuple(3,ntn); // Creation NTuple
415
416string exp = "1.";
417ComputeExpressions(obja, expx, expy, expwt, exp, expcut, loop, nt, NULL, NULL);
418
419if (nt->NEntry() < 1) {
420 cout << "Services2NObjMgr::DisplayPoints2DW() Warning Zero points satisfy cut !" << endl;
421 delete nt;
422 return;
423 }
424
425PINTuple* pin = new PINTuple(nt, true);
426pin->SetStats(Services2NObjMgr::GetStatsOption(dopt));
427pin->SelectXY(ntn[0], ntn[1]);
428pin->SelectWt(ntn[2]);
429
430bool fgsr = true;
431int opt = DecodeDispOption(dopt, fgsr);
432string titre = nom + ":" + expwt + "_" + expy + "%" + expx ;
433mImgapp->DispScDrawer( (PIDrawer*)pin, titre, opt);
434if (fgsr) mImgapp->RestoreGraphicAtt();
435return;
436}
437
438/* --Methode-- */
439void Services2NObjMgr::ProjectH1(string& nom, string& expx, string& expwt,
440 string& expcut, string& nomh1, string dopt, string loop)
441{
442NObjMgrAdapter* obja=NULL;
443obja = mOmg->GetObjAdapter(nom);
444if (obja == NULL) {
445 cout << "Services2NObjMgr::ProjectH1() Error , No such object " << nom << endl;
446 return;
447 }
448if (!mImgapp) return;
449
450Histo* h1 = NULL;
451NTuple* nt = NULL;
452AnyDataObj* oh = NULL;
453if (nomh1.length() > 0) oh=mOmg->GetObj(nomh1);
454else nomh1 = "/tmp/projh1d";
455if ( (oh != NULL) && (typeid(*oh) == typeid(Histo)) ) h1 = (Histo*)oh; // Pas de remise a zero ! h1->Zero();
456else {
457 char* ntn[2]= {"hxval", "hwt"};
458 nt = new NTuple(2,ntn); // Creation NTuple
459 }
460string expz = "0.";
461ComputeExpressions(obja, expx, expwt, expz, expwt, expcut, loop, nt, h1, NULL);
462
463if ((!h1) && (!nt)) return;
464if (!h1) {
465 if (nt->NEntry() < 1) {
466 cout << "Services2NObjMgr::ProjectH1() Warning Zero points satisfy cut !" << endl;
467 delete nt;
468 return;
469 }
470 double xmin, xmax;
471 nt->GetMinMax(0, xmin, xmax);
472 h1 = new Histo(xmin, xmax, 100);
473 int k;
474 float* xn;
475 for(k=0; k<nt->NEntry(); k++) {
476 xn = nt->GetVec(k);
477 h1->Add(xn[0], xn[1]);
478 }
479 delete nt;
480 mOmg->AddObj(h1, nomh1);
481 }
482
483mOmg->DisplayObj(nomh1, dopt);
484return;
485}
486
487/* --Methode-- */
488void Services2NObjMgr::ProjectH2(string& nom, string& expx, string& expy, string& expwt,
489 string& expcut, string& nomh2, string dopt, string loop)
490{
491NObjMgrAdapter* obja=NULL;
492obja = mOmg->GetObjAdapter(nom);
493if (obja == NULL) {
494 cout << "Services2NObjMgr::ProjectH2() Error , No such object " << nom << endl;
495 return;
496 }
497if (!mImgapp) return;
498
499Histo2D* h2 = NULL;
500NTuple* nt = NULL;
501AnyDataObj* oh = NULL;
502if (nomh2.length() > 0) oh=mOmg->GetObj(nomh2);
503else nomh2 = "/tmp/projh2d";
504if ( (oh != NULL) && (typeid(*oh) == typeid(Histo2D)) ) h2 = (Histo2D*)oh; // Pas de remise a zero ! h2->Zero();
505else {
506 char* ntn[3]= {"hxval", "hyval", "hwt"};
507 nt = new NTuple(3,ntn); // Creation NTuple
508 }
509string expz = "0.";
510ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, loop, nt, NULL, h2);
511
512if ((!h2) && (!nt)) return;
513if (!h2) {
514 if (nt->NEntry() < 1) {
515 cout << "Services2NObjMgr::ProjectH2() Warning Zero points satisfy cut !" << endl;
516 delete nt;
517 return;
518 }
519 double xmin, xmax, ymin, ymax;
520 nt->GetMinMax(0, xmin, xmax);
521 nt->GetMinMax(1, ymin, ymax);
522 h2 = new Histo2D(xmin, xmax, 50, ymin, ymax, 50);
523 int k;
524 float* xn;
525 for(k=0; k<nt->NEntry(); k++) {
526 xn = nt->GetVec(k);
527 h2->Add(xn[0], xn[1], xn[2]);
528 }
529 delete nt;
530 mOmg->AddObj(h2, nomh2);
531 }
532
533mOmg->DisplayObj(nomh2, dopt);
534return;
535
536}
537
538/* --Methode-- cmv 13/10/98 */
539void Services2NObjMgr::ProjectHProf(string& nom, string& expx, string& expy, string& expwt,
540 string& expcut, string& nomprof, string dopt, string loop)
541// Pour remplir un ``GeneralFitData'' a partir de divers objets:
542//| nom = nom de l'objet a projeter dans un HProf.
543//| expx = expression X de definition du bin.
544//| expy = expression Y a additionner dans le bin.
545//| expwt = expression W du poids a additionner.
546//| expcut = expression du test de selection.
547//| nomprof = nom du HProf engendre (optionnel). Si l'objet n'existe pas
548//| les limites Xmin,Xmax sont calculees automatiquement.
549//| sinon ce sont celles de l'objet preexistant.
550//| opt = options generales pour le display.
551{
552NObjMgrAdapter* obja=NULL;
553obja = mOmg->GetObjAdapter(nom);
554if (obja == NULL) {
555 cout << "Services2NObjMgr::ProjectHProf() Error , No such object " << nom << endl;
556 return;
557 }
558if (!mImgapp) return;
559
560HProf* hprof = NULL;
561NTuple* nt = NULL;
562AnyDataObj* oh = NULL;
563if (nomprof.length() > 0) oh=mOmg->GetObj(nomprof);
564else nomprof = "/tmp/projprof";
565if( (oh!=NULL) && (typeid(*oh) == typeid(HProf)) ) hprof = (HProf*)oh;
566else {
567 char* ntn[3]= {"hxval", "hyval", "hwt"};
568 nt = new NTuple(3,ntn); // Creation NTuple
569}
570string expz = "0.";
571ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, loop, nt, NULL, NULL, hprof);
572
573if((!hprof) && (!nt)) return;
574if(!hprof) {
575 if (nt->NEntry() < 1) {
576 cout << "Services2NObjMgr::ProjectHProf() Warning Zero points satisfy cut !" << endl;
577 delete nt;
578 return;
579 }
580 double xmin, xmax;
581 nt->GetMinMax(0, xmin, xmax);
582 hprof = new HProf(xmin, xmax, 100);
583 int k;
584 float* xn;
585 for(k=0; k<nt->NEntry(); k++) {
586 xn = nt->GetVec(k);
587 hprof->Add(xn[0], xn[1], xn[2]);
588 }
589 delete nt;
590 mOmg->AddObj(hprof, nomprof);
591 }
592hprof->UpdateHisto();
593
594mOmg->DisplayObj(nomprof, dopt);
595return;
596}
597
598
599/* --Methode-- */
600void Services2NObjMgr::FillVect(string& nom, string& expx, string& expv,
601 string& expcut, string& nomvec, string dopt, string loop)
602{
603NObjMgrAdapter* obja=NULL;
604obja = mOmg->GetObjAdapter(nom);
605if (obja == NULL) {
606 cout << "Services2NObjMgr::FillVect() Error , No such object: " << nom << endl;
607 return;
608 }
609if (!mImgapp) return;
610
611Vector* v1 = NULL;
612AnyDataObj* ov = NULL;
613ov=mOmg->GetObj(nomvec);
614if (ov != NULL) v1 = dynamic_cast<Vector *>(ov);
615if (v1 == NULL) {
616 cout << "Services2NObjMgr::FillVect() Error , No such object or not a vector: " << nomvec << endl;
617 return;
618 }
619
620char* ntn[2]= {"vi", "vv"};
621NTuple* nt = new NTuple(2,ntn); // Creation NTuple
622
623string expz = "0.";
624ComputeExpressions(obja, expx, expv, expz, expz, expcut, loop, nt);
625
626if (!nt) return;
627if (nt->NEntry() < 1) {
628 cout << "Services2NObjMgr::FillVect() Warning Zero points satisfy cut !" << endl;
629 delete nt;
630 return;
631 }
632
633 int i,k;
634 double* xn;
635 for(k=0; k<nt->NEntry(); k++) {
636 xn = nt->GetLineD(k);
637 i = xn[0]+0.5;
638 if ( (i < 0) || i >= v1->NElts() ) continue;
639 (*v1)(i) = xn[1];
640 }
641 delete nt;
642
643
644mOmg->DisplayObj(nomvec, dopt);
645return;
646}
647
648/* --Methode-- */
649void Services2NObjMgr::FillMatx(string& nom, string& expx, string& expy, string& expv,
650 string& expcut, string& nommtx, string dopt, string loop)
651{
652NObjMgrAdapter* obja=NULL;
653obja = mOmg->GetObjAdapter(nom);
654if (obja == NULL) {
655 cout << "Services2NObjMgr::FillMatx() Error , No such objet " << nom << endl;
656 return;
657 }
658if (!mImgapp) return;
659
660Matrix* mtx = NULL;
661AnyDataObj* om = NULL;
662om=mOmg->GetObj(nommtx);
663if (om != NULL) mtx = dynamic_cast<Matrix *>(om);
664if (mtx == NULL) {
665 cout << "Services2NObjMgr::FillMatx() Error , No such object or not a matrix " << nommtx << endl;
666 return;
667 }
668
669char* ntn[3]= {"mi", "mj", "mv"};
670NTuple* nt = new NTuple(3,ntn); // Creation NTuple
671
672string expz = "0.";
673ComputeExpressions(obja, expx, expy, expv, expz, expcut, loop, nt);
674
675if (!nt) return;
676if (nt->NEntry() < 1) {
677 cout << "Services2NObjMgr::FillMatx() Warning Zero points satisfy cut !" << endl;
678 delete nt;
679 return;
680 }
681
682 int ic, jl, k;
683 double* xn;
684 for(k=0; k<nt->NEntry(); k++) {
685 xn = nt->GetLineD(k);
686 ic = xn[0]+0.5;
687 jl = xn[1]+0.5;
688 if ( (ic < 0) || ic >= mtx->NCol() ) continue;
689 if ( (jl < 0) || jl >= mtx->NRows() ) continue;
690 (*mtx)(jl, ic) = xn[2];
691 }
692 delete nt;
693
694
695mOmg->DisplayObj(nommtx, dopt);
696return;
697
698}
699
700/* --Methode-- */
701void Services2NObjMgr::ExpressionToVector(string& nom, string& expx, string& expcut,
702 string& nomvec, string dopt, string loop)
703{
704NObjMgrAdapter* obja=NULL;
705obja = mOmg->GetObjAdapter(nom);
706if (obja == NULL) {
707 cout << "Services2NObjMgr::ExpressionToVector() Error , No such object " << nom << endl;
708 return;
709 }
710if (!mImgapp) return;
711
712NTuple* nt = NULL;
713if (nomvec.length() < 1) nomvec = "/tmp/expvec";
714
715char* ntn[2]= {"vecval", "vecwt"};
716nt = new NTuple(1,ntn); // Creation NTuple
717
718string expwt = "1.";
719string expz = "0.";
720ComputeExpressions(obja, expx, expz, expz, expwt, expcut, loop, nt, NULL, NULL);
721
722if (!nt) return;
723if (nt->NEntry() < 1) {
724 cout << "Services2NObjMgr::ExpressionToVector() Warning Zero points satisfy cut !" << endl;
725 delete nt;
726 return;
727 }
728
729Vector* vec = new Vector(nt->NEntry());
730int k;
731float* xn;
732for(k=0; k<nt->NEntry(); k++) {
733 xn = nt->GetVec(k);
734 (*vec)(k) = xn[0];
735 }
736delete nt;
737mOmg->AddObj(vec, nomvec);
738mOmg->DisplayObj(nomvec, dopt);
739return;
740}
741
742/* --Methode-- */
743void Services2NObjMgr::NtFromASCIIFile(string& nom,string& filename,double def_val)
744// Pour remplir un ntuple "nom" existant a partir du fichier
745// ASCII table "filename". Si il y a plus de variables dans le
746// ntuple que dans le fichier "filename",
747// les sur-numeraires sont mises a "def_val" par defaut.
748{
749AnyDataObj* mobj = mOmg->GetObj(nom);
750if(mobj == NULL)
751 {cout<<"NtFromASCIIFile() Error, object "<<nom<<" not existing"<<endl;
752 return;}
753if(typeid(*mobj) != typeid(NTuple))
754 {cout<<"NtFromASCIIFile() Error, object "<<nom<<" not an NTuple"<<endl;
755 return;}
756if (!mImgapp) return;
757
758NTuple* nt = (NTuple*) mobj;
759nt->FillFromASCIIFile(filename, def_val);
760return;
761}
762
763/* --Methode-- */
764void Services2NObjMgr::FillNT(string& nom, string& expx, string& expy, string& expz,
765 string& expt, string& expcut, string& nomnt, string loop)
766{
767NObjMgrAdapter* obja=NULL;
768obja = mOmg->GetObjAdapter(nom);
769if (obja == NULL) {
770 cout << "Services2NObjMgr::FillNT() Error , No such object " << nom << endl;
771 return;
772 }
773if (!mImgapp) return;
774
775bool fgnnt = false;
776NTuple* nt = NULL;
777AnyDataObj* oh = NULL;
778if (nomnt.length() > 0) oh=mOmg->GetObj(nomnt);
779else nomnt = "/tmp/fillnt";
780if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
781 nt = (NTuple*)oh;
782 if (nt->NVar() > 10) {
783 cout << "Services2NObjMgr::FillNT() Warning , Max 10 var in NTuple -> new NTuple" << endl;
784 nt = NULL;
785 }
786 }
787if (nt == NULL) {
788 char* ntn[4]= {"x", "y","z","t"};
789 nt = new NTuple(4,ntn); // Creation NTuple
790 fgnnt = true;
791 }
792
793ComputeExpressions(obja, expx, expy, expz, expt, expcut, loop, nt, NULL, NULL);
794
795if (fgnnt) mOmg->AddObj(nt, nomnt);
796return;
797
798}
799
800/* --Methode-- */
801void Services2NObjMgr::FillNTFrCFile(string & nom, string const & fname,
802 string const & funcname, string & nomnt, string loop)
803{
804if (!mImgapp) return;
805
806NObjMgrAdapter* obja=NULL;
807obja = mOmg->GetObjAdapter(nom);
808if (obja == NULL) {
809 cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) No such object" <<endl;
810 return;
811 }
812bool adel = true;
813NTupleInterface* objnt = obja->GetNTupleInterface(adel);
814if (objnt == NULL) {
815 cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) Not an NTupleInterface !" <<endl;
816 return;
817 }
818
819NTLoopExprFunc f = (NTLoopExprFunc)LinkFunctionFromFile(fname, funcname);
820if (!f) {
821 cerr << "Services2NObjMgr::FillNTFrCFile Error Creation NTLoopExprFunc" << endl;
822 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
823 return;
824 }
825
826bool fgnnt = false;
827NTuple* nt = NULL;
828if (nomnt.length() > 0) {
829 AnyDataObj* oh = NULL;
830 oh=mOmg->GetObj(nomnt);
831 if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
832 nt = (NTuple*)oh;
833 if (nt->NVar() > 10) {
834 cout << "Services2NObjMgr::FillNTFrCFile() Warning , Max 10 var in NTuple -> new NTuple" << endl;
835 nt = NULL;
836 }
837 }
838 if (nt == NULL) {
839 char* ntn[4]= {"x", "y","z","t"};
840 nt = new NTuple(4,ntn); // Creation NTuple
841 fgnnt = true;
842 }
843 }
844
845double xnt[10];
846float fxnt[10];
847
848int i,k;
849for(i=0; i<10; i++) fxnt[i] = xnt[i] = 0.;
850
851
852// $CHECK$ A virer des que possible - Pb blocage application quand trop d'impression
853// redirige - On redirige la sortie sur le terminal
854bool red = mImgapp->HasRedirectedStdOutErr();
855mImgapp->RedirectStdOutErr(false);
856
857int k1,k2,dk;
858k1 = 0; k2 = objnt->NbLines(); dk = 1;
859DecodeLoopParameters(loop, k1, k2, dk);
860if (k1 < 0) k1 = 0;
861if (k2 < 0) k2 = objnt->NbLines();
862if (k2 > objnt->NbLines()) k2 = objnt->NbLines();
863if (dk <= 0) dk = 1;
864
865try {
866 double* xn;
867 int kmax = k2;
868 for(k=k1; k<kmax; k+=dk) {
869 xn = objnt->GetLineD(k);
870 if (f(xn, xnt, xnt+1, xnt+2, xnt+3, k, kmax) != 0) {
871 if (nt) {
872 for(i=0; i<4; i++) fxnt[i] = xnt[i];
873 nt->Fill(fxnt);
874 }
875 }
876 }
877 }
878#ifdef SANS_EVOLPLANCK
879CATCH(merr) {
880 fflush(stdout);
881 cout << endl;
882 cerr << endl;
883 string es = PeidaExc(merr);
884 cerr << "Services2NObjMgr::FillNTFrCFile() Exception :" << merr << es;
885 } ENDTRY;
886#else
887catch ( PException exc ) {
888 fflush(stdout);
889 cout << endl;
890 cerr << endl;
891 cerr << "Services2NObjMgr::FillNTFrCFile() Exception :" << exc.Msg() << endl;
892}
893#endif
894
895if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
896CloseDLL();
897
898// $CHECK$ A virer des que possible On redirige la sortie sur la fenetre PIConsole
899mImgapp->RedirectStdOutErr(red);
900
901if (fgnnt) mOmg->AddObj(nt, nomnt);
902return;
903}
904
905/* --Methode-- */
906void Services2NObjMgr::PrepareNTExpressionCFile(string & nom, string const & fname,
907 string const & funcname)
908{
909NObjMgrAdapter* obja=NULL;
910obja = mOmg->GetObjAdapter(nom);
911if (obja == NULL) {
912 cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom << "...) No such object" <<endl;
913 return;
914 }
915bool adel = true;
916NTupleInterface* objnt = obja->GetNTupleInterface(adel);
917if (objnt == NULL) {
918 cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom
919 << "...) No NTupleInterface !" <<endl;
920 return;
921 }
922string vardec = objnt->VarList_C("_xnti_");
923
924FILE *fip;
925if ((fip = fopen(fname.c_str(), "w")) == NULL) {
926 cout << "Services2NObjMgr::PrepareNTExpressionCFile()_Error: fopen " << fname << endl;
927 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
928 return;
929 }
930
931// constitution du fichier des decalarations des variables de l'interface NTuple
932fputs("#include <stdlib.h> \n", fip);
933fputs("#include <stdio.h> \n", fip);
934fputs("#include <math.h> \n\n", fip);
935
936fputs("/* ------ Some random number generators --------- */ \n", fip);
937fputs("#define frand01() ( (float) drand48() ) \n", fip);
938fputs("#define drand01() drand48() \n", fip);
939fputs("#define rand01() drand48() \n", fip);
940fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
941fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
942fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
943fputs("double NorRand(void) \n", fip);
944fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
945fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
946fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
947fputs(" return(x); \n } \n", fip);
948fputs("#define GauRand() NorRand() \n", fip);
949fputs("#define gaurand() NorRand() \n\n", fip);
950
951fputs("/* NTupleInterface Variable declaration - Generated by piapp \n", fip);
952fputs(" -- Services2NObjMgr::PrepareNTExpressionCFile() -- */ \n\n", fip);
953fprintf(fip,"int %s(double* _xnti_, double* _rx_, double* _ry_, double* _rz_, \n",
954 funcname.c_str());
955fprintf(fip," double* _rt_, int _n_, int _nmax_) \n");
956fprintf(fip, "{ \n %s \n", vardec.c_str());
957fputs(" if (!1) { /* Cut Expression failed */ \n", fip);
958fputs(" *_rx_ = *_ry_ = *_rz_ = *_rt_ = 0.; return(0);", fip);
959fputs(" } \n /* Cut expression satisfied */ \n", fip);
960fputs(" *_rx_ = 1.; \n *_ry_ = 1.; \n *_rz_ = 1.; \n *_rt_ = 1.; \n", fip);
961fputs(" return(1); \n} \n", fip);
962
963fclose(fip);
964
965if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
966return;
967}
968
969/* --Methode-- cmv 13/10/98 */
970void Services2NObjMgr::FillGFD(string& nom, string& expx, string& expy, string& expz,
971 string& experr, string& expcut, string& nomgfd, string loop)
972// Pour remplir un ``GeneralFitData'' a partir de divers objets:
973//| nom = nom de l'objet a transcrire selon 1D: Z=f(X) ou 2D: Z=f(X,Y) .
974//| Vector,Matrix,Histo,HProf,Histo2D,Image<T>,StarList,NTuple,GeneralFitData
975//| expx = expression X du GeneralFitData (1er abscisse)
976//| expy = expression Y du GeneralFitData (2sd abscisse si non "", Z=f(X,Y))
977//| expz = expression Z du GeneralFitData (valeur de l'ordonnee)
978//| experr = expression de l'erreur sur l'ordonnee Z
979//| expcut = expression du test de selection
980//| nomgfd = nom du GeneralFitData engendre (optionnel)
981{
982NObjMgrAdapter* obja=NULL;
983obja = mOmg->GetObjAdapter(nom);
984if (obja == NULL) {
985 cout << "Services2NObjMgr::FillGFD() Error , No such object "<<nom<<endl;
986 return;
987 }
988if(!mImgapp) return;
989
990// 2D ou 3D?
991int nvar = 2;
992if(expy.length()<=0) {nvar = 1; expy = "0.";}
993
994// Creation NTuple Buffer
995char* ntn[4]= {"x","y","f","e"};
996NTuple*nt = new NTuple(4,ntn);
997
998// Remplissage NTuple buffer
999ComputeExpressions(obja, expx, expy, expz, experr, expcut, loop, nt, NULL, NULL);
1000if(nt->NEntry() < 1)
1001 {cout<<"Services2NObjMgr::FillGFD() Warning Zero points satisfy cut !"<<endl;
1002 delete nt; return;}
1003
1004//Remplissage de la structure GeneraFitData
1005if (nt->NEntry() <= 0) {
1006 cout<<"Services2NObjMgr::FillGFD() Warning - NData= " << nt->NEntry() << endl;
1007 delete nt;
1008 return;
1009 }
1010
1011GeneralFitData* gfd = new GeneralFitData(nvar,nt->NEntry(),0);
1012int k;
1013float* xn;
1014for(k=0; k<nt->NEntry(); k++) {
1015 xn = nt->GetVec(k);
1016 gfd->AddData(xn,xn[2],xn[3]);
1017}
1018
1019// Menage et table d'objets
1020delete nt;
1021mOmg->AddObj(gfd, nomgfd);
1022return;
1023}
1024
1025
1026/* --Methode-- */
1027void Services2NObjMgr::ComputeExpressions(NObjMgrAdapter* obja, string& expx,
1028 string& expy, string& expz, string& expt, string& expcut, string& loop,
1029 NTuple* nt, Histo* h1, Histo2D* h2, HProf* hp)
1030{
1031if (obja == NULL) return;
1032bool adel = true;
1033NTupleInterface* objnt = obja->GetNTupleInterface(adel);
1034if (objnt == NULL) return;
1035string vardec = objnt->VarList_C("_zz6qi_");
1036
1037PlotExprFunc f = LinkExprFunc(vardec, expx, expy, expz, expt, expcut);
1038if (!f) {
1039 cerr << "Services2NObjMgr::::ComputeExpressions() Error Creation PlotExprFunc " << endl;
1040 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
1041 return;
1042 }
1043
1044double xnt[10];
1045float fxnt[10];
1046
1047int i,k;
1048for(i=0; i<10; i++) xnt[i] = 0.;
1049int k1,k2,dk;
1050k1 = 0; k2 = objnt->NbLines(); dk = 1;
1051DecodeLoopParameters(loop, k1, k2, dk);
1052if (k1 < 0) k1 = 0;
1053if (k2 < 0) k2 = objnt->NbLines();
1054if (k2 > objnt->NbLines()) k2 = objnt->NbLines();
1055if (dk <= 0) dk = 1;
1056
1057try {
1058 double* xn;
1059 for(k=k1; k<k2; k += dk) {
1060 xn = objnt->GetLineD(k);
1061 if (f(xn, xnt, xnt+1, xnt+2, xnt+3) != 0) {
1062 if (nt) {
1063 for(i=0; i<4; i++) fxnt[i] = xnt[i];
1064 nt->Fill(fxnt);
1065 }
1066 if (h1) h1->Add(xnt[0], xnt[3]);
1067 if (h2) h2->Add(xnt[0], xnt[1], xnt[3]);
1068 if (hp) hp->Add(xnt[0], xnt[1], xnt[3]);
1069 }
1070 }
1071 }
1072#ifdef SANS_EVOLPLANCK
1073CATCH(merr) {
1074 fflush(stdout);
1075 cout << endl;
1076 cerr << endl;
1077 string es = PeidaExc(merr);
1078 cerr << "Services2NObjMgr::ComputeExpressions() Exception :" << merr << es;
1079 } ENDTRY;
1080#else
1081catch ( PException exc ) {
1082 fflush(stdout);
1083 cout << endl;
1084 cerr << endl;
1085 cerr << "Services2NObjMgr::ComputeExpressions() Exception :" << exc.Msg() << endl;
1086}
1087#endif
1088
1089if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
1090// Fermeture du fichier .so
1091CloseDLL();
1092return;
1093}
1094
1095
1096/* --Methode-- */
1097PlotExprFunc Services2NObjMgr::LinkExprFunc(string& vardec, string& expx, string& expy,
1098 string& expz, string& expt, string& cut)
1099{
1100FILE *fip;
1101string fname = TmpDir + "expf_pia_dl.c";
1102string cmd;
1103int rc;
1104
1105cmd = "rm -f " + fname;
1106rc = system(cmd.c_str());
1107//DBG printf("LinkExprFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
1108
1109if ((fip = fopen(fname.c_str(), "w")) == NULL) {
1110 string sn = fname;
1111 cout << "Services2NObjMgr/LinkExprFunc_Error: fopen( " << sn << endl;
1112 return(NULL);
1113 }
1114
1115// constitution du fichier a compiler
1116fputs("#include <stdlib.h> \n", fip);
1117fputs("#include <math.h> \n", fip);
1118
1119fputs("/* ------ Some random number generators --------- */ \n", fip);
1120fputs("#define frand01() ( (float) drand48() ) \n", fip);
1121fputs("#define drand01() drand48() \n", fip);
1122fputs("#define rand01() drand48() \n", fip);
1123fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
1124fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
1125fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
1126fputs("double NorRand(void) \n", fip);
1127fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
1128fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
1129fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
1130fputs(" return(x); \n } \n", fip);
1131fputs("#define GauRand() NorRand() \n", fip);
1132fputs("#define gaurand() NorRand() \n\n", fip);
1133
1134fputs("int expf_pia_dl_func(double* _zz6qi_, double* _rx_6q_, double* _ry_6q_, double* _rz_6q_, double* _rt_6q_) \n{\n", fip);
1135fprintf(fip,"%s \n", vardec.c_str());
1136fprintf(fip, "if (!(%s)) { *_rx_6q_ = *_ry_6q_ = *_rz_6q_ = *_rt_6q_ = 0.; return(0); } \n", cut.c_str());
1137fprintf(fip, "*_rx_6q_ = %s ; \n", expx.c_str());
1138fprintf(fip, "*_ry_6q_ = %s ; \n", expy.c_str());
1139fprintf(fip, "*_rz_6q_ = %s ; \n", expz.c_str());
1140fprintf(fip, "*_rt_6q_ = %s ; \n", expt.c_str());
1141fputs("return(1); \n} \n", fip);
1142fclose(fip);
1143string func = "expf_pia_dl_func";
1144return((PlotExprFunc)LinkFunctionFromFile(fname, func));
1145}
1146
1147
1148/* --Methode-- */
1149DlFunction Services2NObjMgr::LinkFunctionFromFile(string const & fname, string const & funcname)
1150{
1151// Le link dynamique
1152CloseDLL();
1153dynlink = PDynLinkMgr::BuildFromCFile(fname);
1154if (dynlink == NULL) {
1155 cerr << "Services2NObjMgr/LinkFunctionFromFile_Erreur: Erreur creation/Ouverture SO " << endl;
1156 return(NULL);
1157 }
1158
1159DlFunction retfunc = dynlink->GetFunction(funcname);
1160if (retfunc == NULL) {
1161 string sn = funcname;
1162 cerr << "Services2NObjMgr/LinkExprFunc_Erreur: Erreur linking " << sn << endl;
1163 CloseDLL();
1164 return(NULL);
1165 }
1166else return(retfunc);
1167}
1168
1169/* --Methode-- */
1170void Services2NObjMgr::CloseDLL()
1171{
1172if (dynlink) delete dynlink; dynlink = NULL;
1173}
1174
1175// Fonction static
1176/* --Methode-- */
1177void Services2NObjMgr::DecodeLoopParameters(string& loop, int& i1, int& i2, int& di)
1178{
1179// Decode des paramatres de boucle for(int i=i1; i<i2; i+=di) specifies
1180// sous forme i1[:i2[:di]]
1181// cout << "LoopParam() " << loop << " I1=" << i1 << " I2=" << i2 << " DI=" << di;
1182size_t l = loop.length();
1183if (l < 1) return;
1184size_t p = loop.find(':');
1185if (p >= l) { i1 = atoi(loop.c_str()); return; }
1186i1 = atoi(loop.substr(0, p).c_str());
1187string aa = loop.substr(p+1);
1188p = aa.find(':');
1189if (p < aa.length() ) {
1190 i2 = atoi(aa.substr(0,p).c_str());
1191 di = atoi(aa.substr(p+1).c_str());
1192 }
1193else i2 = atoi(aa.c_str());
1194// cout << "-> I1= " << i1 << " I2= " << i2 << " DI= " << di << endl;
1195return;
1196}
1197
1198/* --Methode-- */
1199string Services2NObjMgr::FileName2Name(string const & fn)
1200{
1201
1202char fsep[2] = {FILESEP, '\0'};
1203char tsep[2] = {'.', '\0'};
1204size_t p = fn.find_last_of(fsep);
1205size_t l = fn.length();
1206if (p >= l) p = 0;
1207else p++;
1208size_t q = fn.find_first_of(tsep,p);
1209if (q < p) q = l;
1210return(fn.substr(p,q-p));
1211}
1212
1213
1214// Variable pour stocker l'option de stat des drawers
1215static bool stats_option = true;
1216/* --Methode-- */
1217void Services2NObjMgr::SetDefaultStatsOption(bool opt)
1218{
1219 stats_option = opt;
1220}
1221
1222typedef vector<string> GraTok;
1223
1224/* --Methode-- */
1225bool Services2NObjMgr::GetStatsOption(string& gratt)
1226{
1227int ropt = Disp_Next;
1228for(int i=0; i<gratt.length(); i++) gratt[i] = tolower(gratt[i]);
1229// On separe en mots separes par des virgules
1230gratt = ","+gratt;
1231size_t p = 0;
1232size_t q = 0;
1233size_t l = gratt.length();
1234string token;
1235
1236GraTok grt;
1237
1238while (q < l) {
1239 p = gratt.find_first_not_of(" ,",q+1); // au debut d'un token
1240 if (p>=l) break;
1241 q = gratt.find_first_of(" ,",p); // la fin du token;
1242 token = gratt.substr(p,q-p);
1243 grt.push_back(token);
1244 }
1245int k;
1246bool fgsame = false;
1247int option = 0;
1248for(k=0; k<grt.size(); k++) {
1249 if ( (grt[k] == "same") || (grt[k] == "s") ) option = 1;
1250 else if ( (grt[k] == "stat") || (grt[k] == "stats") ) option = 2;
1251 else if ( (grt[k] == "nostat") || (grt[k] == "nostats") ) option = 3;
1252}
1253
1254if (option == 0) return(stats_option);
1255else if ( (option == 1) || (option == 3) ) return(false);
1256else return(true);
1257}
1258
1259/* --Methode-- */
1260int Services2NObjMgr::DecodeDispOption(string& gratt, bool& fgsrgr)
1261{
1262int ropt = Disp_Next;
1263if (!mImgapp) return(ropt);
1264
1265for(int i=0; i<gratt.length(); i++) gratt[i] = tolower(gratt[i]);
1266
1267if (fgsrgr) mImgapp->SaveGraphicAtt();
1268
1269if ( (gratt == "def") || (gratt == "default") ) { // Remise aux valeurs par defaut = non defini
1270 mImgapp->SetColAtt();
1271 mImgapp->SetLineAtt();
1272 mImgapp->SetFontAtt();
1273 mImgapp->SetMarkerAtt();
1274 mImgapp->SetColMapId();
1275 mImgapp->SetZoomAtt();
1276 mImgapp->SetAxesAtt();
1277 mImgapp->SetXYLimits();
1278 mImgapp->UseXYLimits();
1279 mImgapp->SetXLogScale();
1280 mImgapp->SetYLogScale();
1281 stats_option = true;
1282 return(ropt);
1283 }
1284
1285// On separe en mots separes par des virgules
1286gratt = ","+gratt;
1287size_t p = 0;
1288size_t q = 0;
1289size_t l = gratt.length();
1290string token;
1291
1292GraTok grt;
1293
1294while (q < l) {
1295 p = gratt.find_first_not_of(" ,",q+1); // au debut d'un token
1296 if (p>=l) break;
1297 q = gratt.find_first_of(" ,",p); // la fin du token;
1298 token = gratt.substr(p,q-p);
1299 grt.push_back(token);
1300 }
1301
1302
1303static GrAttNames::iterator it;
1304
1305int k;
1306bool fgcont = true;
1307fgsrgr = false;
1308
1309for(k=0; k<grt.size(); k++) {
1310// cout << "--DBG--SetGraphicAttributes() " << grt[k] << endl;
1311
1312 // Decodage option affichage (win, next, etc
1313 fgcont = true;
1314 if ( (grt[k] == "win") || (grt[k] == "w") ) ropt = Disp_Win;
1315 else if ( (grt[k] == "same") || (grt[k] == "s") ) ropt = Disp_Same;
1316 else if ( (grt[k] == "stack") || (grt[k] == "st") ) ropt = Disp_Stack;
1317 else fgcont = false;
1318 if (fgcont) continue;
1319
1320 // Utilisation limites X-Y
1321 if ( grt[k] == "xylimits" ) { mImgapp->UseXYLimits(true); fgsrgr = true; continue; }
1322 // Echelle logarithmique d'axe
1323 if ( grt[k] == "logx" ) { mImgapp->SetXLogScale(true); fgsrgr = true; continue; }
1324 if ( grt[k] == "linx" ) { mImgapp->SetXLogScale(false); fgsrgr = true; continue; }
1325 if ( grt[k] == "logy" ) { mImgapp->SetYLogScale(true); fgsrgr = true; continue; }
1326 if ( grt[k] == "liny" ) { mImgapp->SetYLogScale(false); fgsrgr = true; continue; }
1327
1328 // Si c'est une couleur
1329 it = GrAcolors.find(grt[k]);
1330 if (it != GrAcolors.end()) { mImgapp->SetColAtt((PIColors)((*it).second.a1)); fgsrgr = true; continue; }
1331 // Si c'est un attribut de lignes
1332 it = GrAlines.find(grt[k]);
1333 if (it != GrAlines.end()) { mImgapp->SetLineAtt((PILineAtt)((*it).second.a1)); fgsrgr = true; continue; }
1334 // Si c'est un attribut de fontes
1335 it = GrAfonts.find(grt[k]);
1336 if (it != GrAfonts.end()) { mImgapp->SetFontAtt((PIFontSize)((*it).second.a2), (PIFontAtt)((*it).second.a1) );
1337 fgsrgr = true; continue; }
1338 // Si c'est un attribut de markers
1339 it = GrAmarkers.find(grt[k]);
1340 if (it != GrAmarkers.end()) { mImgapp->SetMarkerAtt((*it).second.a2, (PIMarker)((*it).second.a1) );
1341 fgsrgr = true; continue; }
1342 // Si c'est un colormap
1343 it = GrAcmap.find(grt[k]);
1344 if (it != GrAcmap.end()) { mImgapp->SetColMapId( (CMapId)((*it).second.a1) ); fgsrgr = true; continue; }
1345 // Si c'est un facteur de zoom
1346 it = GrAzoom.find(grt[k]);
1347 if (it != GrAzoom.end()) { mImgapp->SetZoomAtt( (*it).second.a1 ); fgsrgr = true; continue; }
1348 // Si c'est un attribut d'axe
1349 it = GrAaxes.find(grt[k]);
1350 if (it != GrAaxes.end()) { mImgapp->SetAxesAtt( (*it).second.a1 ); fgsrgr = true; continue; }
1351
1352 }
1353
1354return(ropt);
1355}
1356
1357
1358// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1359// Initialisation des chaines de caracteres designant les attributs graphiques
1360
1361/* --Methode-- */
1362void Services2NObjMgr::InitGrAttNames()
1363{
1364gratt_item gi;
1365// Les couleurs
1366gi.a2 = 0;
1367gi.a1 = PI_NotDefColor;
1368GrAcolors["defcol"] = gi;
1369gi.a1 = PI_Black;
1370GrAcolors["black"] = gi;
1371gi.a1 = PI_White;
1372GrAcolors["white"] = gi;
1373gi.a1 = PI_Grey;
1374GrAcolors["grey"] = gi;
1375gi.a1 = PI_Red;
1376GrAcolors["red"] = gi;
1377gi.a1 = PI_Blue;
1378GrAcolors["blue"] = gi;
1379gi.a1 = PI_Green;
1380GrAcolors["green"] = gi;
1381gi.a1 = PI_Yellow;
1382GrAcolors["yellow"] = gi;
1383gi.a1 = PI_Magenta;
1384GrAcolors["magenta"] = gi;
1385
1386gi.a1 = PI_Cyan;
1387GrAcolors["cyan"] = gi;
1388gi.a1 = PI_Turquoise;
1389GrAcolors["turquoise"] = gi;
1390gi.a1 = PI_NavyBlue;
1391GrAcolors["navyblue"] = gi;
1392gi.a1 = PI_Orange;
1393GrAcolors["orange"] = gi;
1394gi.a1 = PI_SiennaRed;
1395GrAcolors["siennared"] = gi;
1396gi.a1 = PI_Purple;
1397GrAcolors["purple"] = gi;
1398gi.a1 = PI_LimeGreen;
1399GrAcolors["limegreen"] = gi;
1400gi.a1 = PI_Gold;
1401GrAcolors["gold"] = gi;
1402
1403// Les attributs de lignes
1404gi.a2 = 0;
1405gi.a1 = PI_NotDefLineAtt;
1406GrAlines["defline"] = gi;
1407gi.a1 = PI_NormalLine;
1408GrAlines["normalline"] = gi;
1409gi.a1 = PI_ThinLine;
1410GrAlines["thinline"] = gi;
1411gi.a1 = PI_ThickLine;
1412GrAlines["thickline"] = gi;
1413gi.a1 = PI_DashedLine;
1414GrAlines["dashedline"] = gi;
1415gi.a1 = PI_ThinDashedLine;
1416GrAlines["thindashedline"] = gi;
1417gi.a1 = PI_ThickDashedLine;
1418GrAlines["thickdashedline"] = gi;
1419gi.a1 = PI_DottedLine;
1420GrAlines["dottedline"] = gi;
1421gi.a1 = PI_ThinDottedLine;
1422GrAlines["thindottedline"] = gi;
1423gi.a1 = PI_ThickDottedLine;
1424GrAlines["thickdottedline"] = gi;
1425
1426// Les fontes
1427gi.a2 = PI_NotDefFontSize;
1428gi.a1 = PI_NotDefFontAtt;
1429GrAfonts["deffont"] = gi;
1430
1431gi.a2 = PI_NormalSizeFont;
1432gi.a1 = PI_RomanFont;
1433GrAfonts["normalfont"] = gi;
1434gi.a1 = PI_BoldFont;
1435GrAfonts["boldfont"] = gi;
1436gi.a1 = PI_ItalicFont;
1437GrAfonts["italicfont"] = gi;
1438gi.a2 = PI_SmallSizeFont;
1439gi.a1 = PI_RomanFont;
1440GrAfonts["smallfont"] = gi;
1441gi.a1 = PI_BoldFont;
1442GrAfonts["smallboldfont"] = gi;
1443gi.a1 = PI_ItalicFont;
1444GrAfonts["smallitalicfont"] = gi;
1445gi.a2 = PI_BigSizeFont;
1446gi.a1 = PI_RomanFont;
1447GrAfonts["bigfont"] = gi;
1448gi.a1 = PI_BoldFont;
1449GrAfonts["bigboldfont"] = gi;
1450gi.a1 = PI_ItalicFont;
1451GrAfonts["bigitalicfont"] = gi;
1452gi.a2 = PI_HugeSizeFont;
1453gi.a1 = PI_RomanFont;
1454GrAfonts["hugefont"] = gi;
1455gi.a1 = PI_BoldFont;
1456GrAfonts["hugeboldfont"] = gi;
1457gi.a1 = PI_ItalicFont;
1458GrAfonts["hugeitalicfont"] = gi;
1459
1460
1461// Les markers
1462const char* mrkn[11] = { "dotmarker", "plusmarker", "crossmarker",
1463 "circlemarker", "fcirclemarker", "boxmarker", "fboxmarker",
1464 "trianglemarker", "ftrianglemarker", "starmarker", "fstarmarker"};
1465PIMarker mrk[11] = { PI_DotMarker, PI_PlusMarker, PI_CrossMarker,
1466 PI_CircleMarker, PI_FCircleMarker, PI_BoxMarker, PI_FBoxMarker,
1467 PI_TriangleMarker, PI_FTriangleMarker, PI_StarMarker, PI_FStarMarker};
1468
1469gi.a2 = 0;
1470gi.a1 = PI_NotDefMarker;
1471GrAmarkers["defmarker"] = gi;
1472
1473for(int j=0; j<11; j++) {
1474 string smrk;
1475 char buff[16];
1476 for(int m=1; m<10; m+=2) {
1477 sprintf(buff,"%d",m);
1478 smrk = (string)mrkn[j] + (string)buff;
1479 gi.a1 = mrk[j]; gi.a2 = m;
1480 GrAmarkers[smrk] = gi;
1481 }
1482 }
1483
1484// Les tables de couleurs
1485gi.a2 = 0;
1486gi.a1 = CMAP_OTHER;
1487GrAcmap["defcmap"] = gi;
1488gi.a1 = CMAP_GREY32;
1489GrAcmap["grey32"] = gi;
1490gi.a1 = CMAP_GREYINV32;
1491GrAcmap["greyinv32"] = gi;
1492gi.a1 = CMAP_COLRJ32;
1493GrAcmap["colrj32"] = gi;
1494gi.a1 = CMAP_COLBR32;
1495GrAcmap["colbr32"] = gi;
1496gi.a1 = CMAP_GREY128;
1497GrAcmap["grey128"] = gi;
1498gi.a1 = CMAP_GREYINV128;
1499GrAcmap["greyinv128"] = gi;
1500gi.a1 = CMAP_COLRJ128;
1501GrAcmap["colrj128"] = gi;
1502gi.a1 = CMAP_COLBR128;
1503GrAcmap["colbr128"] = gi;
1504
1505// La valeur de zoom
1506gi.a2 = 0;
1507gi.a1 = 0;
1508GrAzoom["defzoom"] = gi;
1509gi.a1 = 1;
1510GrAzoom["zoomx1"] = gi;
1511gi.a1 = 2;
1512GrAzoom["zoomx2"] = gi;
1513gi.a1 = 3;
1514GrAzoom["zoomx3"] = gi;
1515gi.a1 = 4;
1516GrAzoom["zoomx4"] = gi;
1517gi.a1 = 5;
1518GrAzoom["zoomx5"] = gi;
1519gi.a1 = -2;
1520GrAzoom["zoom/2"] = gi;
1521gi.a1 = -3;
1522GrAzoom["zoom/3"] = gi;
1523gi.a1 = -4;
1524GrAzoom["zoom/4"] = gi;
1525gi.a1 = -5;
1526GrAzoom["zoom/5"] = gi;
1527
1528// Attributs d'axes
1529gi.a2 = 0;
1530gi.a1 = (int)(kBoxAxes | kExtTicks | kLabels);
1531GrAaxes["stdaxes"] = gi;
1532GrAaxes["defaxes"] = gi;
1533GrAaxes["boxaxes"] = gi;
1534gi.a1 = (int)kAxesDflt;
1535GrAaxes["simpleaxes"] = gi;
1536gi.a1 = (int)(kBoxAxes | kExtTicks | kLabels | kGridOn);
1537GrAaxes["boxaxesgrid"] = gi;
1538
1539gi.a1 = (int)(kBoxAxes | kTicks | kLabels | kMinTicks | kMajTicks);
1540GrAaxes["fineaxes"] = gi;
1541 gi.a1 = (int)(kBoxAxes | kTicks | kLabels | kMinTicks | kMajTicks | kGridOn);
1542GrAaxes["grid"] = gi;
1543GrAaxes["fineaxesgrid"] = gi;
1544
1545}
1546
1547
1548// SANS_EVOLPLANCK Attention !
1549#include "pclassids.h"
1550
1551/* --Methode-- */
1552char* Services2NObjMgr::PClassIdToClassName(int cid)
1553{
1554switch (cid) {
1555 case ClassId_Poly1 :
1556 return("Poly1");
1557 case ClassId_Poly2 :
1558 return("Poly2");
1559 case ClassId_Matrix :
1560 return("Matrix");
1561 case ClassId_Vector :
1562 return("Vector");
1563
1564 case ClassId_DVList :
1565 return("DVList");
1566
1567 case ClassId_Histo1D :
1568 return("Histo1D");
1569 case ClassId_Histo2D :
1570 return("Histo2D");
1571 case ClassId_HProf :
1572 return("HProf");
1573 case ClassId_NTuple :
1574 return("NTuple");
1575 case ClassId_XNTuple :
1576 return("XNTuple");
1577 case ClassId_GeneralFitData :
1578 return("GeneralFitData");
1579
1580 case ClassId_Image :
1581 return("RzImage");
1582 case ClassId_Image + kuint_1 :
1583 return("ImageU1");
1584 case ClassId_Image + kint_1 :
1585 return("ImageI1");
1586 case ClassId_Image + kuint_2 :
1587 return("ImageU2");
1588 case ClassId_Image + kint_2 :
1589 return("ImageI2");
1590 case ClassId_Image + kuint_4 :
1591 return("ImageU4");
1592 case ClassId_Image + kint_4 :
1593 return("ImageI4");
1594 case ClassId_Image + kr_4 :
1595 return("ImageR4");
1596 case ClassId_Image + kr_8 :
1597 return("ImageR8");
1598
1599 case ClassId_ZFidu :
1600 return("ZFidu");
1601
1602 case ClassId_StarList :
1603 return("StarList");
1604 case ClassId_Transfo :
1605 return("Transfo");
1606 case ClassId_PSF :
1607 return("PSF");
1608
1609
1610// - Ajout objet PPF
1611 default:
1612 return("AnyDataObj");
1613 }
1614}
1615
Note: See TracBrowser for help on using the repository browser.