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

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

intro newnt et ntfrascci (partiel) cmv 30/9/99

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