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

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

Documentation + ameliorations DrawStats + vector->tvector pour Planck - Reza 3/11/99

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