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

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

Changement nom /func en /autoc
Nouvelles commandes PAW-like n/plot,...,reset,h/plot/2d etc..
Creation de helpfit pour commenatires fit,fitlin,fitw,crfitfun etc..

cmv 14/10/99

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