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

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

Modifs pour SOPHYA , TMatrix, PixelMap, ... Reza 17/11/99

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