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

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

Modifs pour echelle Log - Reza 25/10/99

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