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

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

copy objects + NamedObjMgr de NTFromASCII cmv 8/10/99

File size: 43.6 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_Error: fopen( " << 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_Error: fopen( " << 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 , No such object " << 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 , No such object " << 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 , No such object " << 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 , No such object " << 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 , No such object " << 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 , No such object " << 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 , No such object " << 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{
714AnyDataObj* mobj = mOmg->GetObj(nom);
715if(mobj == NULL)
716 {cout<<"NtFromASCIIFile() Error, object "<<nom<<" not existing"<<endl;
717 return;}
718if(typeid(*mobj) != typeid(NTuple))
719 {cout<<"NtFromASCIIFile() Error, object "<<nom<<" not an NTuple"<<endl;
720 return;}
721if (!mImgapp) return;
722
723NTuple* nt = (NTuple*) mobj;
724nt->FillFromASCIIFile(filename, def_val);
725return;
726}
727
728/* --Methode-- */
729void Services2NObjMgr::FillNT(string& nom, string& expx, string& expy, string& expz,
730 string& expt, string& expcut, string& nomnt, string loop)
731{
732NObjMgrAdapter* obja=NULL;
733obja = mOmg->GetObjAdapter(nom);
734if (obja == NULL) {
735 cout << "Services2NObjMgr::FillNT() Error , No such object " << nom << endl;
736 return;
737 }
738if (!mImgapp) return;
739
740bool fgnnt = false;
741NTuple* nt = NULL;
742AnyDataObj* oh = NULL;
743if (nomnt.length() > 0) oh=mOmg->GetObj(nomnt);
744else nomnt = "/tmp/fillnt";
745if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
746 nt = (NTuple*)oh;
747 if (nt->NVar() > 10) {
748 cout << "Services2NObjMgr::FillNT() Warning , Max 10 var in NTuple -> new NTuple" << endl;
749 nt = NULL;
750 }
751 }
752if (nt == NULL) {
753 char* ntn[4]= {"x", "y","z","t"};
754 nt = new NTuple(4,ntn); // Creation NTuple
755 fgnnt = true;
756 }
757
758ComputeExpressions(obja, expx, expy, expz, expt, expcut, loop, nt, NULL, NULL);
759
760if (fgnnt) mOmg->AddObj(nt, nomnt);
761return;
762
763}
764
765/* --Methode-- */
766void Services2NObjMgr::FillNTFrCFile(string & nom, string const & fname,
767 string const & funcname, string & nomnt, string loop)
768{
769if (!mImgapp) return;
770
771NObjMgrAdapter* obja=NULL;
772obja = mOmg->GetObjAdapter(nom);
773if (obja == NULL) {
774 cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) No such object" <<endl;
775 return;
776 }
777bool adel = true;
778NTupleInterface* objnt = obja->GetNTupleInterface(adel);
779if (objnt == NULL) {
780 cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) Not an NTupleInterface !" <<endl;
781 return;
782 }
783
784NTLoopExprFunc f = (NTLoopExprFunc)LinkFunctionFromFile(fname, funcname);
785if (!f) {
786 cerr << "Services2NObjMgr::FillNTFrCFile Error Creation NTLoopExprFunc" << endl;
787 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
788 return;
789 }
790
791bool fgnnt = false;
792NTuple* nt = NULL;
793if (nomnt.length() > 0) {
794 AnyDataObj* oh = NULL;
795 oh=mOmg->GetObj(nomnt);
796 if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
797 nt = (NTuple*)oh;
798 if (nt->NVar() > 10) {
799 cout << "Services2NObjMgr::FillNTFrCFile() Warning , Max 10 var in NTuple -> new NTuple" << endl;
800 nt = NULL;
801 }
802 }
803 if (nt == NULL) {
804 char* ntn[4]= {"x", "y","z","t"};
805 nt = new NTuple(4,ntn); // Creation NTuple
806 fgnnt = true;
807 }
808 }
809
810double xnt[10];
811float fxnt[10];
812
813int i,k;
814for(i=0; i<10; i++) fxnt[i] = xnt[i] = 0.;
815
816
817// $CHECK$ A virer des que possible - Pb blocage application quand trop d'impression
818// redirige - On redirige la sortie sur le terminal
819bool red = mImgapp->HasRedirectedStdOutErr();
820mImgapp->RedirectStdOutErr(false);
821
822int k1,k2,dk;
823k1 = 0; k2 = objnt->NbLines(); dk = 1;
824DecodeLoopParameters(loop, k1, k2, dk);
825if (k1 < 0) k1 = 0;
826if (k2 < 0) k2 = objnt->NbLines();
827if (k2 > objnt->NbLines()) k2 = objnt->NbLines();
828if (dk <= 0) dk = 1;
829
830TRY {
831 double* xn;
832 int kmax = k2;
833 for(k=k1; k<kmax; k+=dk) {
834 xn = objnt->GetLineD(k);
835 if (f(xn, xnt, xnt+1, xnt+2, xnt+3, k, kmax) != 0) {
836 if (nt) {
837 for(i=0; i<4; i++) fxnt[i] = xnt[i];
838 nt->Fill(fxnt);
839 }
840 }
841 }
842 }
843CATCH(merr) {
844 fflush(stdout);
845 cout << endl;
846 cerr << endl;
847 string es = PeidaExc(merr);
848 cerr << "Services2NObjMgr::FillNTFrCFile() Exception :" << merr << es;
849 } ENDTRY;
850
851if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
852CloseDLL();
853
854// $CHECK$ A virer des que possible On redirige la sortie sur la fenetre PIConsole
855mImgapp->RedirectStdOutErr(red);
856
857if (fgnnt) mOmg->AddObj(nt, nomnt);
858return;
859}
860
861/* --Methode-- */
862void Services2NObjMgr::PrepareNTExpressionCFile(string & nom, string const & fname,
863 string const & funcname)
864{
865NObjMgrAdapter* obja=NULL;
866obja = mOmg->GetObjAdapter(nom);
867if (obja == NULL) {
868 cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom << "...) No such object" <<endl;
869 return;
870 }
871bool adel = true;
872NTupleInterface* objnt = obja->GetNTupleInterface(adel);
873if (objnt == NULL) {
874 cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom
875 << "...) No NTupleInterface !" <<endl;
876 return;
877 }
878string vardec = objnt->VarList_C("_xnti_");
879
880FILE *fip;
881if ((fip = fopen(fname.c_str(), "w")) == NULL) {
882 cout << "Services2NObjMgr::PrepareNTExpressionCFile()_Error: fopen " << fname << endl;
883 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
884 return;
885 }
886
887// constitution du fichier des decalarations des variables de l'interface NTuple
888fputs("#include <stdlib.h> \n", fip);
889fputs("#include <stdio.h> \n", fip);
890fputs("#include <math.h> \n\n", fip);
891
892fputs("/* ------ Some random number generators --------- */ \n", fip);
893fputs("#define frand01() ( (float) drand48() ) \n", fip);
894fputs("#define drand01() drand48() \n", fip);
895fputs("#define rand01() drand48() \n", fip);
896fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
897fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
898fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
899fputs("double NorRand(void) \n", fip);
900fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
901fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
902fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
903fputs(" return(x); \n } \n", fip);
904fputs("#define GauRand() NorRand() \n", fip);
905fputs("#define gaurand() NorRand() \n\n", fip);
906
907fputs("/* NTupleInterface Variable declaration - Generated by piapp \n", fip);
908fputs(" -- Services2NObjMgr::PrepareNTExpressionCFile() -- */ \n\n", fip);
909fprintf(fip,"int %s(double* _xnti_, double* _rx_, double* _ry_, double* _rz_, \n",
910 funcname.c_str());
911fprintf(fip," double* _rt_, int _n_, int _nmax_) \n");
912fprintf(fip, "{ \n %s \n", vardec.c_str());
913fputs(" if (!1) { /* Cut Expression failed */ \n", fip);
914fputs(" *_rx_ = *_ry_ = *_rz_ = *_rt_ = 0.; return(0);", fip);
915fputs(" } \n /* Cut expression satisfied */ \n", fip);
916fputs(" *_rx_ = 1.; \n *_ry_ = 1.; \n *_rz_ = 1.; \n *_rt_ = 1.; \n", fip);
917fputs(" return(1); \n} \n", fip);
918
919fclose(fip);
920
921if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
922return;
923}
924
925/* --Methode-- cmv 08/10/99 */
926void Services2NObjMgr::CopyObjects(string& namefrom, string& nameto)
927// Pour copier l'object "namefrom" dans l'objet "nameto".
928{
929AnyDataObj* mobj = mOmg->GetObj(namefrom);
930if(mobj == NULL) {
931 cout<<"CopyObjects() Error, object "<<namefrom<<" not existing"<<endl;
932 return;
933}
934if(nameto.length()<=0) {
935 cout<<"CopyObjects() Error, copied object name "<<nameto<<" not valid"<<endl;
936 return;
937}
938
939// Les histos
940if(typeid(*mobj) == typeid(Histo)) {
941 Histo* objfr = (Histo*) mobj;
942 Histo* objto = new Histo(*objfr);
943 mOmg->AddObj(objto,nameto);
944} else if (typeid(*mobj) == typeid(Histo2D)) {
945 Histo2D* objfr = (Histo2D*) mobj;
946 Histo2D* objto = new Histo2D(*objfr);
947 mOmg->AddObj(objto,nameto);
948} else if (typeid(*mobj) == typeid(HProf)) {
949 HProf* objfr = (HProf*) mobj;
950 HProf* objto = new HProf(*objfr);
951 mOmg->AddObj(objto,nameto);
952} else if (typeid(*mobj) == typeid(NTuple)) {
953 NTuple* objfr = (NTuple*) mobj;
954 NTuple* objto = new NTuple(*objfr);
955 mOmg->AddObj(objto,nameto);
956
957// Les vecteurs et matrices
958} else if (typeid(*mobj) == typeid(Vector)) {
959 Vector* objfr = (Vector*) mobj;
960 Vector* objto = new Vector(*objfr);
961 mOmg->AddObj(objto,nameto);
962} else if (typeid(*mobj) == typeid(Matrix)) {
963 Matrix* objfr = (Matrix*) mobj;
964 Matrix* objto = new Matrix(*objfr);
965 mOmg->AddObj(objto,nameto);
966
967// Les generalfitdata
968} else if (typeid(*mobj) == typeid(GeneralFitData)) {
969 GeneralFitData* objfr = (GeneralFitData*) mobj;
970 GeneralFitData* objto = new GeneralFitData(*objfr);
971 mOmg->AddObj(objto,nameto);
972
973// Les images
974} else if (typeid(*mobj) == typeid(RzImage)) {
975 RzImage* objfr = (RzImage*) mobj;
976 RzImage* objto = new RzImage(*objfr);
977 mOmg->AddObj(objto,nameto);
978} else if (typeid(*mobj) == typeid(ImageU1)) {
979 ImageU1* objfr = (ImageU1*) mobj;
980 ImageU1* objto = new ImageU1(*objfr);
981 mOmg->AddObj(objto,nameto);
982} else if (typeid(*mobj) == typeid(ImageU2)) {
983 ImageU2* objfr = (ImageU2*) mobj;
984 ImageU2* objto = new ImageU2(*objfr);
985 mOmg->AddObj(objto,nameto);
986} else if (typeid(*mobj) == typeid(ImageI2)) {
987 ImageI2* objfr = (ImageI2*) mobj;
988 ImageI2* objto = new ImageI2(*objfr);
989 mOmg->AddObj(objto,nameto);
990} else if (typeid(*mobj) == typeid(ImageI4)) {
991 ImageI4* objfr = (ImageI4*) mobj;
992 ImageI4* objto = new ImageI4(*objfr);
993 mOmg->AddObj(objto,nameto);
994} else if (typeid(*mobj) == typeid(ImageR4)) {
995 ImageR4* objfr = (ImageR4*) mobj;
996 ImageR4* objto = new ImageR4(*objfr);
997 mOmg->AddObj(objto,nameto);
998
999// Pas prevu
1000} else {
1001 cout<<"CopyObjects() Error, object "<<typeid(*mobj).name()
1002
1003 <<" could not be copied"<<endl;
1004 return;
1005}
1006
1007return;
1008}
1009
1010/* --Methode-- cmv 13/10/98 */
1011void Services2NObjMgr::FillGFD(string& nom, string& expx, string& expy, string& expz,
1012 string& experr, string& expcut, string& nomgfd, string loop)
1013// Pour remplir un ``GeneralFitData'' a partir de divers objets:
1014//| nom = nom de l'objet a transcrire selon 1D: Z=f(X) ou 2D: Z=f(X,Y) .
1015//| Vector,Matrix,Histo,HProf,Histo2D,Image<T>,StarList,NTuple,GeneralFitData
1016//| expx = expression X du GeneralFitData (1er abscisse)
1017//| expy = expression Y du GeneralFitData (2sd abscisse si non "", Z=f(X,Y))
1018//| expz = expression Z du GeneralFitData (valeur de l'ordonnee)
1019//| experr = expression de l'erreur sur l'ordonnee Z
1020//| expcut = expression du test de selection
1021//| nomgfd = nom du GeneralFitData engendre (optionnel)
1022{
1023NObjMgrAdapter* obja=NULL;
1024obja = mOmg->GetObjAdapter(nom);
1025if (obja == NULL) {
1026 cout << "Services2NObjMgr::FillGFD() Error , No such object "<<nom<<endl;
1027 return;
1028 }
1029if(!mImgapp) return;
1030
1031// 2D ou 3D?
1032int nvar = 2;
1033if(expy.length()<=0) {nvar = 1; expy = "0.";}
1034
1035// Creation NTuple Buffer
1036char* ntn[4]= {"x","y","f","e"};
1037NTuple*nt = new NTuple(4,ntn);
1038
1039// Remplissage NTuple buffer
1040ComputeExpressions(obja, expx, expy, expz, experr, expcut, loop, nt, NULL, NULL);
1041if(nt->NEntry() < 1)
1042 {cout<<"Services2NObjMgr::FillGFD() Warning Zero points satisfy cut !"<<endl;
1043 delete nt; return;}
1044
1045//Remplissage de la structure GeneraFitData
1046if (nt->NEntry() <= 0) {
1047 cout<<"Services2NObjMgr::FillGFD() Warning - NData= " << nt->NEntry() << endl;
1048 delete nt;
1049 return;
1050 }
1051
1052GeneralFitData* gfd = new GeneralFitData(nvar,nt->NEntry(),0);
1053int k;
1054float* xn;
1055for(k=0; k<nt->NEntry(); k++) {
1056 xn = nt->GetVec(k);
1057 gfd->AddData(xn,xn[2],xn[3]);
1058}
1059
1060// Menage et table d'objets
1061delete nt;
1062mOmg->AddObj(gfd, nomgfd);
1063return;
1064}
1065
1066
1067/* --Methode-- */
1068void Services2NObjMgr::ComputeExpressions(NObjMgrAdapter* obja, string& expx,
1069 string& expy, string& expz, string& expt, string& expcut, string& loop,
1070 NTuple* nt, Histo* h1, Histo2D* h2, HProf* hp)
1071{
1072if (obja == NULL) return;
1073bool adel = true;
1074NTupleInterface* objnt = obja->GetNTupleInterface(adel);
1075if (objnt == NULL) return;
1076string vardec = objnt->VarList_C("_zz6qi_");
1077
1078PlotExprFunc f = LinkExprFunc(vardec, expx, expy, expz, expt, expcut);
1079if (!f) {
1080 cerr << "Services2NObjMgr::::ComputeExpressions() Error Creation PlotExprFunc " << endl;
1081 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
1082 return;
1083 }
1084
1085double xnt[10];
1086float fxnt[10];
1087
1088int i,k;
1089for(i=0; i<10; i++) xnt[i] = 0.;
1090int k1,k2,dk;
1091k1 = 0; k2 = objnt->NbLines(); dk = 1;
1092DecodeLoopParameters(loop, k1, k2, dk);
1093if (k1 < 0) k1 = 0;
1094if (k2 < 0) k2 = objnt->NbLines();
1095if (k2 > objnt->NbLines()) k2 = objnt->NbLines();
1096if (dk <= 0) dk = 1;
1097TRY {
1098 double* xn;
1099 for(k=k1; k<k2; k += dk) {
1100 xn = objnt->GetLineD(k);
1101 if (f(xn, xnt, xnt+1, xnt+2, xnt+3) != 0) {
1102 if (nt) {
1103 for(i=0; i<4; i++) fxnt[i] = xnt[i];
1104 nt->Fill(fxnt);
1105 }
1106 if (h1) h1->Add(xnt[0], xnt[3]);
1107 if (h2) h2->Add(xnt[0], xnt[1], xnt[3]);
1108 if (hp) hp->Add(xnt[0], xnt[1], xnt[3]);
1109 }
1110 }
1111 }
1112CATCH(merr) {
1113 fflush(stdout);
1114 cout << endl;
1115 cerr << endl;
1116 string es = PeidaExc(merr);
1117 cerr << "Services2NObjMgr::ComputeExpressions() Exception :" << merr << es;
1118 } ENDTRY;
1119
1120
1121if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
1122// Fermeture du fichier .so
1123CloseDLL();
1124return;
1125}
1126
1127
1128/* --Methode-- */
1129PlotExprFunc Services2NObjMgr::LinkExprFunc(string& vardec, string& expx, string& expy,
1130 string& expz, string& expt, string& cut)
1131{
1132FILE *fip;
1133string fname = TmpDir + "expf_pia_dl.c";
1134string cmd;
1135int rc;
1136
1137cmd = "rm -f " + fname;
1138rc = system(cmd.c_str());
1139//DBG printf("LinkExprFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
1140
1141if ((fip = fopen(fname.c_str(), "w")) == NULL) {
1142 string sn = fname;
1143 cout << "Services2NObjMgr/LinkExprFunc_Error: fopen( " << sn << endl;
1144 return(NULL);
1145 }
1146
1147// constitution du fichier a compiler
1148fputs("#include <stdlib.h> \n", fip);
1149fputs("#include <math.h> \n", fip);
1150
1151fputs("/* ------ Some random number generators --------- */ \n", fip);
1152fputs("#define frand01() ( (float) drand48() ) \n", fip);
1153fputs("#define drand01() drand48() \n", fip);
1154fputs("#define rand01() drand48() \n", fip);
1155fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
1156fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
1157fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
1158fputs("double NorRand(void) \n", fip);
1159fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
1160fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
1161fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
1162fputs(" return(x); \n } \n", fip);
1163fputs("#define GauRand() NorRand() \n", fip);
1164fputs("#define gaurand() NorRand() \n\n", fip);
1165
1166fputs("int expf_pia_dl_func(double* _zz6qi_, double* _rx_6q_, double* _ry_6q_, double* _rz_6q_, double* _rt_6q_) \n{\n", fip);
1167fprintf(fip,"%s \n", vardec.c_str());
1168fprintf(fip, "if (!(%s)) { *_rx_6q_ = *_ry_6q_ = *_rz_6q_ = *_rt_6q_ = 0.; return(0); } \n", cut.c_str());
1169fprintf(fip, "*_rx_6q_ = %s ; \n", expx.c_str());
1170fprintf(fip, "*_ry_6q_ = %s ; \n", expy.c_str());
1171fprintf(fip, "*_rz_6q_ = %s ; \n", expz.c_str());
1172fprintf(fip, "*_rt_6q_ = %s ; \n", expt.c_str());
1173fputs("return(1); \n} \n", fip);
1174fclose(fip);
1175string func = "expf_pia_dl_func";
1176return((PlotExprFunc)LinkFunctionFromFile(fname, func));
1177}
1178
1179
1180/* --Methode-- */
1181DlFunction Services2NObjMgr::LinkFunctionFromFile(string const & fname, string const & funcname)
1182{
1183// Le link dynamique
1184CloseDLL();
1185dynlink = PDynLinkMgr::BuildFromCFile(fname);
1186if (dynlink == NULL) {
1187 cerr << "Services2NObjMgr/LinkFunctionFromFile_Erreur: Erreur creation/Ouverture SO " << endl;
1188 return(NULL);
1189 }
1190
1191DlFunction retfunc = dynlink->GetFunction(funcname);
1192if (retfunc == NULL) {
1193 string sn = funcname;
1194 cerr << "Services2NObjMgr/LinkExprFunc_Erreur: Erreur linking " << sn << endl;
1195 CloseDLL();
1196 return(NULL);
1197 }
1198else return(retfunc);
1199}
1200
1201/* --Methode-- */
1202void Services2NObjMgr::CloseDLL()
1203{
1204if (dynlink) delete dynlink; dynlink = NULL;
1205}
1206
1207// Fonction static
1208/* --Methode-- */
1209void Services2NObjMgr::DecodeLoopParameters(string& loop, int& i1, int& i2, int& di)
1210{
1211// Decode des paramatres de boucle for(int i=i1; i<i2; i+=di) specifies
1212// sous forme i1[:i2[:di]]
1213// cout << "LoopParam() " << loop << " I1=" << i1 << " I2=" << i2 << " DI=" << di;
1214size_t l = loop.length();
1215if (l < 1) return;
1216size_t p = loop.find(':');
1217if (p >= l) { i1 = atoi(loop.c_str()); return; }
1218i1 = atoi(loop.substr(0, p).c_str());
1219string aa = loop.substr(p+1);
1220p = aa.find(':');
1221if (p < aa.length() ) {
1222 i2 = atoi(aa.substr(0,p).c_str());
1223 di = atoi(aa.substr(p+1).c_str());
1224 }
1225else i2 = atoi(aa.c_str());
1226// cout << "-> I1= " << i1 << " I2= " << i2 << " DI= " << di << endl;
1227return;
1228}
1229
1230/* --Methode-- */
1231string Services2NObjMgr::FileName2Name(string const & fn)
1232{
1233
1234char fsep[2] = {FILESEP, '\0'};
1235char tsep[2] = {'.', '\0'};
1236size_t p = fn.find_last_of(fsep);
1237size_t l = fn.length();
1238if (p >= l) p = 0;
1239else p++;
1240size_t q = fn.find_first_of(tsep,p);
1241if (q < p) q = l;
1242return(fn.substr(p,q-p));
1243}
1244
1245
1246typedef vector<string> GraTok;
1247
1248/* --Methode-- */
1249int Services2NObjMgr::DecodeDispOption(string& gratt, bool& fgsrgr)
1250{
1251int ropt = Disp_Next;
1252if (!mImgapp) return(ropt);
1253
1254for(int i=0; i<gratt.length(); i++) gratt[i] = tolower(gratt[i]);
1255
1256if (fgsrgr) mImgapp->SaveGraphicAtt();
1257
1258if ( (gratt == "def") || (gratt == "default") ) { // Remise aux valeurs par defaut = non defini
1259 mImgapp->SetColAtt();
1260 mImgapp->SetLineAtt();
1261 mImgapp->SetFontAtt();
1262 mImgapp->SetMarkerAtt();
1263 mImgapp->SetColMapId();
1264 mImgapp->SetZoomAtt();
1265 mImgapp->SetAxesAtt();
1266 mImgapp->SetXYLimits();
1267 mImgapp->UseXYLimits();
1268 return(ropt);
1269 }
1270
1271// On separe en mots separes par des virgules
1272gratt = ","+gratt;
1273size_t p = 0;
1274size_t q = 0;
1275size_t l = gratt.length();
1276string token;
1277
1278GraTok grt;
1279
1280while (q < l) {
1281 p = gratt.find_first_not_of(" ,",q+1); // au debut d'un token
1282 if (p>=l) break;
1283 q = gratt.find_first_of(" ,",p); // la fin du token;
1284 token = gratt.substr(p,q-p);
1285 grt.push_back(token);
1286 }
1287
1288
1289static GrAttNames::iterator it;
1290
1291int k;
1292bool fgcont = true;
1293fgsrgr = false;
1294
1295for(k=0; k<grt.size(); k++) {
1296// cout << "--DBG--SetGraphicAttributes() " << grt[k] << endl;
1297
1298 // Decodage option affichage (win, next, etc
1299 fgcont = true;
1300 if ( (grt[k] == "win") || (grt[k] == "w") ) ropt = Disp_Win;
1301 else if ( (grt[k] == "same") || (grt[k] == "s") ) ropt = Disp_Same;
1302 else if ( (grt[k] == "stack") || (grt[k] == "st") ) ropt = Disp_Stack;
1303 else fgcont = false;
1304 if (fgcont) continue;
1305
1306 // Utilisation limites X-Y
1307 if ( grt[k] == "xylimits" ) { mImgapp->UseXYLimits(true); fgsrgr = true; continue; }
1308 // Si c'est une couleur
1309 it = GrAcolors.find(grt[k]);
1310 if (it != GrAcolors.end()) { mImgapp->SetColAtt((PIColors)((*it).second.a1)); fgsrgr = true; continue; }
1311 // Si c'est un attribut de lignes
1312 it = GrAlines.find(grt[k]);
1313 if (it != GrAlines.end()) { mImgapp->SetLineAtt((PILineAtt)((*it).second.a1)); fgsrgr = true; continue; }
1314 // Si c'est un attribut de fontes
1315 it = GrAfonts.find(grt[k]);
1316 if (it != GrAfonts.end()) { mImgapp->SetFontAtt((PIFontSize)((*it).second.a2), (PIFontAtt)((*it).second.a1) );
1317 fgsrgr = true; continue; }
1318 // Si c'est un attribut de markers
1319 it = GrAmarkers.find(grt[k]);
1320 if (it != GrAmarkers.end()) { mImgapp->SetMarkerAtt((*it).second.a2, (PIMarker)((*it).second.a1) );
1321 fgsrgr = true; continue; }
1322 // Si c'est un colormap
1323 it = GrAcmap.find(grt[k]);
1324 if (it != GrAcmap.end()) { mImgapp->SetColMapId( (CMapId)((*it).second.a1) ); fgsrgr = true; continue; }
1325 // Si c'est un facteur de zoom
1326 it = GrAzoom.find(grt[k]);
1327 if (it != GrAzoom.end()) { mImgapp->SetZoomAtt( (*it).second.a1 ); fgsrgr = true; continue; }
1328 // Si c'est un attribut d'axe
1329 it = GrAaxes.find(grt[k]);
1330 if (it != GrAaxes.end()) { mImgapp->SetAxesAtt( (*it).second.a1 ); fgsrgr = true; continue; }
1331
1332 }
1333
1334return(ropt);
1335}
1336
1337
1338
1339// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1340// Initialisation des chaines de caracteres designant les attributs graphiques
1341
1342/* --Methode-- */
1343void Services2NObjMgr::InitGrAttNames()
1344{
1345gratt_item gi;
1346// Les couleurs
1347gi.a2 = 0;
1348gi.a1 = PI_NotDefColor;
1349GrAcolors["defcol"] = gi;
1350gi.a1 = PI_Black;
1351GrAcolors["black"] = gi;
1352gi.a1 = PI_White;
1353GrAcolors["white"] = gi;
1354gi.a1 = PI_Grey;
1355GrAcolors["grey"] = gi;
1356gi.a1 = PI_Red;
1357GrAcolors["red"] = gi;
1358gi.a1 = PI_Blue;
1359GrAcolors["blue"] = gi;
1360gi.a1 = PI_Green;
1361GrAcolors["green"] = gi;
1362gi.a1 = PI_Yellow;
1363GrAcolors["yellow"] = gi;
1364gi.a1 = PI_Magenta;
1365GrAcolors["magenta"] = gi;
1366
1367gi.a1 = PI_Cyan;
1368GrAcolors["cyan"] = gi;
1369gi.a1 = PI_Turquoise;
1370GrAcolors["turquoise"] = gi;
1371gi.a1 = PI_NavyBlue;
1372GrAcolors["navyblue"] = gi;
1373gi.a1 = PI_Orange;
1374GrAcolors["orange"] = gi;
1375gi.a1 = PI_SiennaRed;
1376GrAcolors["siennared"] = gi;
1377gi.a1 = PI_Purple;
1378GrAcolors["purple"] = gi;
1379gi.a1 = PI_LimeGreen;
1380GrAcolors["limegreen"] = gi;
1381gi.a1 = PI_Gold;
1382GrAcolors["gold"] = gi;
1383
1384// Les attributs de lignes
1385gi.a2 = 0;
1386gi.a1 = PI_NotDefLineAtt;
1387GrAlines["defline"] = gi;
1388gi.a1 = PI_NormalLine;
1389GrAlines["normalline"] = gi;
1390gi.a1 = PI_ThinLine;
1391GrAlines["thinline"] = gi;
1392gi.a1 = PI_ThickLine;
1393GrAlines["thickline"] = gi;
1394gi.a1 = PI_DashedLine;
1395GrAlines["dashedline"] = gi;
1396gi.a1 = PI_ThinDashedLine;
1397GrAlines["thindashedline"] = gi;
1398gi.a1 = PI_ThickDashedLine;
1399GrAlines["thickdashedline"] = gi;
1400gi.a1 = PI_DottedLine;
1401GrAlines["dottedline"] = gi;
1402gi.a1 = PI_ThinDottedLine;
1403GrAlines["thindottedline"] = gi;
1404gi.a1 = PI_ThickDottedLine;
1405GrAlines["thickdottedline"] = gi;
1406
1407// Les fontes
1408gi.a2 = PI_NotDefFontSize;
1409gi.a1 = PI_NotDefFontAtt;
1410GrAfonts["deffont"] = gi;
1411
1412gi.a2 = PI_NormalSizeFont;
1413gi.a1 = PI_RomanFont;
1414GrAfonts["normalfont"] = gi;
1415gi.a1 = PI_BoldFont;
1416GrAfonts["boldfont"] = gi;
1417gi.a1 = PI_ItalicFont;
1418GrAfonts["italicfont"] = gi;
1419gi.a2 = PI_SmallSizeFont;
1420gi.a1 = PI_RomanFont;
1421GrAfonts["smallfont"] = gi;
1422gi.a1 = PI_BoldFont;
1423GrAfonts["smallboldfont"] = gi;
1424gi.a1 = PI_ItalicFont;
1425GrAfonts["smallitalicfont"] = gi;
1426gi.a2 = PI_BigSizeFont;
1427gi.a1 = PI_RomanFont;
1428GrAfonts["bigfont"] = gi;
1429gi.a1 = PI_BoldFont;
1430GrAfonts["bigboldfont"] = gi;
1431gi.a1 = PI_ItalicFont;
1432GrAfonts["bigitalicfont"] = gi;
1433gi.a2 = PI_HugeSizeFont;
1434gi.a1 = PI_RomanFont;
1435GrAfonts["hugefont"] = gi;
1436gi.a1 = PI_BoldFont;
1437GrAfonts["hugeboldfont"] = gi;
1438gi.a1 = PI_ItalicFont;
1439GrAfonts["hugeitalicfont"] = gi;
1440
1441
1442// Les markers
1443const char* mrkn[11] = { "dotmarker", "plusmarker", "crossmarker",
1444 "circlemarker", "fcirclemarker", "boxmarker", "fboxmarker",
1445 "trianglemarker", "ftrianglemarker", "starmarker", "fstarmarker"};
1446PIMarker mrk[11] = { PI_DotMarker, PI_PlusMarker, PI_CrossMarker,
1447 PI_CircleMarker, PI_FCircleMarker, PI_BoxMarker, PI_FBoxMarker,
1448 PI_TriangleMarker, PI_FTriangleMarker, PI_StarMarker, PI_FStarMarker};
1449
1450gi.a2 = 0;
1451gi.a1 = PI_NotDefMarker;
1452GrAmarkers["defmarker"] = gi;
1453
1454for(int j=0; j<11; j++) {
1455 string smrk;
1456 char buff[16];
1457 for(int m=1; m<10; m+=2) {
1458 sprintf(buff,"%d",m);
1459 smrk = (string)mrkn[j] + (string)buff;
1460 gi.a1 = mrk[j]; gi.a2 = m;
1461 GrAmarkers[smrk] = gi;
1462 }
1463 }
1464
1465// Les tables de couleurs
1466gi.a2 = 0;
1467gi.a1 = CMAP_OTHER;
1468GrAcmap["defcmap"] = gi;
1469gi.a1 = CMAP_GREY32;
1470GrAcmap["grey32"] = gi;
1471gi.a1 = CMAP_GREYINV32;
1472GrAcmap["greyinv32"] = gi;
1473gi.a1 = CMAP_COLRJ32;
1474GrAcmap["colrj32"] = gi;
1475gi.a1 = CMAP_COLBR32;
1476GrAcmap["colbr32"] = gi;
1477gi.a1 = CMAP_GREY128;
1478GrAcmap["grey128"] = gi;
1479gi.a1 = CMAP_GREYINV128;
1480GrAcmap["greyinv128"] = gi;
1481gi.a1 = CMAP_COLRJ128;
1482GrAcmap["colrj128"] = gi;
1483gi.a1 = CMAP_COLBR128;
1484GrAcmap["colbr128"] = gi;
1485
1486// La valeur de zoom
1487gi.a2 = 0;
1488gi.a1 = 0;
1489GrAzoom["defzoom"] = gi;
1490gi.a1 = 1;
1491GrAzoom["zoomx1"] = gi;
1492gi.a1 = 2;
1493GrAzoom["zoomx2"] = gi;
1494gi.a1 = 3;
1495GrAzoom["zoomx3"] = gi;
1496gi.a1 = 4;
1497GrAzoom["zoomx4"] = gi;
1498gi.a1 = 5;
1499GrAzoom["zoomx5"] = gi;
1500gi.a1 = -2;
1501GrAzoom["zoom/2"] = gi;
1502gi.a1 = -3;
1503GrAzoom["zoom/3"] = gi;
1504gi.a1 = -4;
1505GrAzoom["zoom/4"] = gi;
1506gi.a1 = -5;
1507GrAzoom["zoom/5"] = gi;
1508
1509// Attributs d'axes
1510gi.a2 = 0;
1511gi.a1 = (int)(kBoxAxes | kExtTicks | kLabels);
1512GrAaxes["stdaxes"] = gi;
1513GrAaxes["defaxes"] = gi;
1514GrAaxes["boxaxes"] = gi;
1515gi.a1 = (int)kAxesDflt;
1516GrAaxes["simpleaxes"] = gi;
1517gi.a1 = (int)(kBoxAxes | kExtTicks | kLabels | kGridOn);
1518GrAaxes["boxaxesgrid"] = gi;
1519
1520gi.a1 = (int)(kBoxAxes | kTicks | kLabels | kMinTicks | kMajTicks);
1521GrAaxes["fineaxes"] = gi;
1522 gi.a1 = (int)(kBoxAxes | kTicks | kLabels | kMinTicks | kMajTicks | kGridOn);
1523GrAaxes["grid"] = gi;
1524GrAaxes["fineaxesgrid"] = gi;
1525
1526}
1527
1528
1529// SANS_EVOLPLANCK Attention !
1530#include "pclassids.h"
1531
1532/* --Methode-- */
1533char* Services2NObjMgr::PClassIdToClassName(int cid)
1534{
1535switch (cid) {
1536 case ClassId_Poly1 :
1537 return("Poly1");
1538 case ClassId_Poly2 :
1539 return("Poly2");
1540 case ClassId_Matrix :
1541 return("Matrix");
1542 case ClassId_Vector :
1543 return("Vector");
1544
1545 case ClassId_DVList :
1546 return("DVList");
1547
1548 case ClassId_Histo1D :
1549 return("Histo1D");
1550 case ClassId_Histo2D :
1551 return("Histo2D");
1552 case ClassId_HProf :
1553 return("HProf");
1554 case ClassId_NTuple :
1555 return("NTuple");
1556 case ClassId_XNTuple :
1557 return("XNTuple");
1558 case ClassId_GeneralFitData :
1559 return("GeneralFitData");
1560
1561 case ClassId_Image :
1562 return("RzImage");
1563 case ClassId_Image + kuint_1 :
1564 return("ImageU1");
1565 case ClassId_Image + kint_1 :
1566 return("ImageI1");
1567 case ClassId_Image + kuint_2 :
1568 return("ImageU2");
1569 case ClassId_Image + kint_2 :
1570 return("ImageI2");
1571 case ClassId_Image + kuint_4 :
1572 return("ImageU4");
1573 case ClassId_Image + kint_4 :
1574 return("ImageI4");
1575 case ClassId_Image + kr_4 :
1576 return("ImageR4");
1577 case ClassId_Image + kr_8 :
1578 return("ImageR8");
1579
1580 case ClassId_ZFidu :
1581 return("ZFidu");
1582
1583 case ClassId_StarList :
1584 return("StarList");
1585 case ClassId_Transfo :
1586 return("Transfo");
1587 case ClassId_PSF :
1588 return("PSF");
1589
1590
1591// - Ajout objet PPF
1592 default:
1593 return("AnyDataObj");
1594 }
1595}
1596
Note: See TracBrowser for help on using the repository browser.