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

Last change on this file since 1971 was 1971, checked in by ansari, 23 years ago

1/ Basculement de decodage des options de display aux methodes
PIDrawer/PIWdg::DecodeOptionString()
2/ Possibilite de Show/Hide de la partie Zoom/ColorMap/Stat du MainWindow

Reza 30/4/2002

File size: 37.8 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <ctype.h>
4
5#include <typeinfo>
6#include <iostream.h>
7#include <string>
8#include <list>
9#include <map>
10
11#include "strutil.h"
12
13#include "nobjmgr.h"
14#include "servnobjm.h"
15#include "nomgadapter.h"
16#include "pistdimgapp.h"
17
18#include "fct1dfit.h"
19#include "fct2dfit.h"
20
21#ifdef SANS_EVOLPLANCK
22#include "matrix.h"
23#include "cvector.h"
24#else
25#include "tmatrix.h"
26#include "tvector.h"
27#include "pitvmaad.h"
28#endif
29
30#include "ntuple.h"
31#include "cimage.h"
32
33#include "histos.h"
34#include "histos2.h"
35#include "ntuple.h"
36#include "hisprof.h"
37
38#include "piyfxdrw.h"
39#include "pisurfdr.h"
40
41#include "pintuple.h"
42#include "pintup3d.h"
43
44#include "pipodrw.h"
45
46
47
48/* --Methode-- */
49Services2NObjMgr::Services2NObjMgr(NamedObjMgr* omg, string& tmpdir)
50{
51SetTmpDir(tmpdir);
52mImgapp = NULL;
53mOmg = omg;
54dynlink = NULL;
55}
56
57/* --Methode-- */
58Services2NObjMgr::~Services2NObjMgr()
59{
60CloseDLL();
61}
62
63/* --Methode-- */
64void Services2NObjMgr::RegisterClass(AnyDataObj* o, NObjMgrAdapter* oa)
65{
66ObjAdaptList::iterator it;
67for(it = objadaplist.begin(); it != objadaplist.end(); it++)
68#ifdef SANS_EVOLPLANCK
69 if (typeid(*o) == typeid(*((*it).obj))) THROW(dupIdErr);
70#else
71 if (typeid(*o) == typeid(*((*it).obj)))
72 throw(DuplicateIdExc("Services2NObjMgr::RegisterClass() - Duplicate class"));
73#endif
74dataobj_adapter oba;
75oba.obj = o;
76oba.obja = oa;
77objadaplist.push_back(oba);
78}
79
80/* --Methode-- */
81NObjMgrAdapter* Services2NObjMgr::GetAdapter(AnyDataObj* o)
82{
83ObjAdaptList::iterator it;
84for(it = objadaplist.begin(); it != objadaplist.end(); it++)
85 if (typeid(*o) == typeid(*((*it).obj))) return((*it).obja->Clone(o));
86return(new NObjMgrAdapter(o));
87}
88
89/* --Methode-- */
90void Services2NObjMgr::SetTmpDir(string const & tmpdir)
91{
92TmpDir = tmpdir;
93PDynLinkMgr::SetTmpDir(tmpdir);
94return;
95}
96
97/* --Methode-- */
98void Services2NObjMgr::PlotFunc(string const & expfunc, string & nom, double xmin, double xmax, int np, string dopt)
99{
100FILE *fip;
101string fname = TmpDir + "func1_pia_dl.c";
102string cmd;
103int rc;
104
105if (!mImgapp) return;
106
107cmd = "rm -f " + fname;
108rc = system(cmd.c_str());
109// printf("PlotFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
110
111if ((fip = fopen(fname.c_str(), "w")) == NULL) {
112 string sn = fname;
113 cout << "Services2NObjMgr/PlotFunc_Error: fopen( " << sn << endl;
114 return;
115 }
116
117// constitution du fichier a compiler
118fputs("#include <math.h> \n", fip);
119fputs("double func1_pia_dl_func(double x) \n{\n", fip);
120fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
121fclose(fip);
122
123string func = "func1_pia_dl_func";
124DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);
125if (!f) return;
126PlotFunc(f, nom, xmin, xmax, np, dopt);
127CloseDLL();
128return;
129}
130
131/* --Methode-- */
132void Services2NObjMgr::PlotFunc2D(string const & expfunc, string & nom, double xmin, double xmax,
133 double ymin, double ymax, int npx, int npy, string dopt)
134{
135FILE *fip;
136string fname = TmpDir + "func2_pia_dl.c";
137string cmd;
138int rc;
139
140if (!mImgapp) return;
141
142cmd = "rm " + fname;
143rc = system(cmd.c_str());
144// printf("PlotFunc2D_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
145
146if ((fip = fopen(fname.c_str(), "w")) == NULL) {
147 string sn = fname;
148 cout << "Services2NObjMgr/PlotFunc2D_Error: fopen( " << sn << endl;
149 return;
150 }
151
152// constitution du fichier a compiler
153fputs("#include <math.h> \n", fip);
154fputs("double func2_pia_dl_func(double x, double y) \n{\n", fip);
155fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
156fclose(fip);
157
158string func = "func2_pia_dl_func";
159DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);
160if (!f) return;
161PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt);
162CloseDLL();
163return;
164}
165
166/* --Methode-- */
167void Services2NObjMgr::PlotFuncFrCFile(string const & fname, string const & func, string & nom,
168 double xmin, double xmax, int np, string dopt)
169{
170DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);
171if (!f) return;
172PlotFunc(f, nom, xmin, xmax, np, dopt);
173CloseDLL();
174return;
175}
176
177/* --Methode-- */
178void Services2NObjMgr::PlotFunc2DFrCFile(string const & fname, string const & func, string & nom,
179 double xmin, double xmax, double ymin, double ymax, int npx, int npy, string dopt)
180{
181DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);
182if (!f) return;
183PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt);
184CloseDLL();
185return;
186}
187
188/* --Methode-- */
189void Services2NObjMgr::PlotFunc(DlFunctionOfX f, string & nom, double xmin, double xmax, int np, string dopt)
190{
191if (!mImgapp) return;
192
193int k;
194if (np < 1) np = 1;
195if (xmax <= xmin) xmax = xmin+1.;
196Vector* vpy = new Vector(np);
197
198double xx;
199double dx = (xmax-xmin)/np;
200
201try {
202 for(k=0; k<np; k++) { xx = xmin+dx*k; (*vpy)(k) = f(xx); }
203}
204#ifdef SANS_EVOLPLANCK
205CATCH(merr) {
206 fflush(stdout);
207 cout << endl;
208 cerr << endl;
209 string es = PeidaExc(merr);
210 cerr << "Services2NObjMgr::PlotFunc() Exception :" << merr << es;
211 delete vpy;
212 vpy = NULL;
213 } ENDTRY;
214#else
215catch ( PException exc ) {
216 fflush(stdout);
217 cout << endl;
218 cerr << endl;
219 cerr << "Services2NObjMgr::PlotFunc() Exception :" << exc.Msg() << endl;
220 delete vpy;
221 vpy = NULL;
222}
223#endif
224
225if (vpy) {
226 string titre;
227 if (nom.length() < 1) {
228 titre = "Function f(x)";
229 nom = "/autoc/f_x";
230 }
231 else titre = nom;
232
233 P1DArrayAdapter* vya = new POVectorAdapter(vpy, false);
234 vya->DefineXCoordinate(xmin, (xmax-xmin)/np);
235 PIYfXDrawer* dr = new PIYfXDrawer(vya, NULL, true) ;
236 dopt = "thinline " + dopt;
237 int rsid = mImgapp->DispScDrawer(dr, titre, dopt);
238 if (nom.length() > 0) {
239 mOmg->AddObj(vpy, nom);
240 mOmg->AddWRsId(nom, rsid);
241 }
242 }
243return;
244}
245
246/* --Methode-- */
247void Services2NObjMgr::PlotFunc2D(DlFunctionOfXY f, string & nom, double xmin, double xmax, double ymin, double ymax,
248 int npx, int npy, string dopt)
249{
250if (!mImgapp) return;
251
252if (npx < 3) npx = 3;
253if (npy < 3) npy = 3;
254if (npx > 250) npx = 250;
255if (npy > 250) npy = 250;
256if (xmax <= xmin) xmax = xmin+1.;
257if (ymax <= ymin) ymax = ymin+1.;
258
259Matrix* mtx = new Matrix(npy, npx);
260
261int i,j;
262double xx, yy;
263double dx = (xmax-xmin)/npx;
264double dy = (ymax-ymin)/npy;
265// printf(" -- DBG -- %d %d , %g %g , %g %g \n", npx, npy, xmin, xmax, ymin, ymax);
266try {
267 for(j=0; j<npy; j++) {
268 yy = ymin+dy*j;
269 for(i=0; i<npx; i++) {
270 xx = xmin+dx*i;
271 (*mtx)(j, i) = f(xx, yy);
272 }
273 }
274}
275#ifdef SANS_EVOLPLANCK
276CATCH(merr) {
277 fflush(stdout);
278 cout << endl;
279 cerr << endl;
280 string es = PeidaExc(merr);
281 cerr << "Services2NObjMgr::PlotFunc2D() Exception :" << merr << es;
282 delete mtx; mtx = NULL;
283 } ENDTRY;
284#else
285catch ( PException exc ) {
286 fflush(stdout);
287 cout << endl;
288 cerr << endl;
289 cerr << "Services2NObjMgr::PlotFunc2D() Exception :" << exc.Msg() << endl;
290 delete mtx; mtx = NULL;
291}
292#endif
293
294if (mtx) {
295 string titre;
296 if (nom.length() < 1) {
297 titre = "Function f(x,y)";
298 nom = "/autoc/f2d_xy";
299 }
300 else titre = nom;
301 P2DArrayAdapter* arr = new POMatrixAdapter(mtx, false);
302 arr->DefineXYCoordinates(xmin, ymin, dx, dy);
303 PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
304 int rsid = mImgapp->Disp3DDrawer(sdr, titre, dopt);
305 if (nom.length() > 0) {
306 mOmg->AddObj(mtx, nom);
307 mOmg->AddWRsId(nom, rsid);
308 }
309 }
310
311return;
312}
313
314/* --Methode-- */
315void Services2NObjMgr::DisplayPoints2D(string& nom, string& expx, string& expy,
316 string& experrx, string& experry,
317 string& expcut, string dopt, string loop)
318{
319NObjMgrAdapter* obja=NULL;
320obja = mOmg->GetObjAdapter(nom);
321if (obja == NULL) {
322 cout << "Services2NObjMgr::DisplayPoints2D() Error , No such object " << nom << endl;
323 return;
324 }
325if (!mImgapp) return;
326
327// Creation NTuple
328char* ntn[4] = {"expx","expy","expex","expey",};
329NTuple* nt = NULL;
330bool haserr = false;
331
332if ( (experrx.length() > 0 ) && (experry.length() > 0 ) ) { haserr = true; nt = new NTuple(4, ntn); }
333else { haserr = false; experrx = experry = "0."; nt = new NTuple(2, ntn); }
334
335ComputeExpressions(obja, expx, expy, experrx, experry, expcut, loop, nt, NULL, NULL);
336
337if (nt->NEntry() < 1) {
338 cout << "Services2NObjMgr::DisplayPoints2D() Warning Zero points satisfy cut !" << endl;
339 delete nt;
340 return;
341 }
342
343// nt->Show();
344// nt->Print(0,10);
345PINTuple* pin = new PINTuple(nt, true);
346pin->SelectXY(ntn[0], ntn[1]);
347if ( haserr ) pin->SelectErrBar(ntn[2], ntn[3]);
348
349dopt = "defline " + dopt;
350string titre = nom + ":" + expy + "%" + expx;
351mImgapp->DispScDrawer( (PIDrawer*)pin, titre, dopt);
352return;
353}
354
355/* --Methode-- */
356void Services2NObjMgr::DisplayPoints3D(string& nom, string& expx, string& expy,
357 string& expz, string& expcut, string dopt, string loop)
358{
359NObjMgrAdapter* obja=NULL;
360obja = mOmg->GetObjAdapter(nom);
361if (obja == NULL) {
362 cout << "Services2NObjMgr::DisplayPoints3D() Error , No such object " << nom << endl;
363 return;
364 }
365if (!mImgapp) return;
366
367char* ntn[3] = {"expx","expy","expz"};
368NTuple* nt = new NTuple(3,ntn); // Creation NTuple
369
370string expwt = "1.";
371ComputeExpressions(obja, expx, expy, expz, expwt, expcut, loop, nt, NULL, NULL);
372
373if (nt->NEntry() < 1) {
374 cout << "Services2NObjMgr::DisplayPoints3D() Warning Zero points satisfy cut !" << endl;
375 delete nt;
376 return;
377 }
378nt->Show();
379nt->Print(0,10);
380PINTuple3D* pin = new PINTuple3D(nt, true);
381pin->SelectXYZ(ntn[0], ntn[1], ntn[2]);
382dopt = "defline " + dopt;
383
384// Pour plot a partir de DispScDrawer
385// string nomdisp = "_NT3D_";
386// mImgapp->DispScDrawer( (PIDrawer*)pin, nomdisp, opt);
387// Pour plot a partir de Disp3DDrawer
388string titre = nom + ":" + expy + "%" + expx;
389mImgapp->Disp3DDrawer(pin, titre, dopt);
390
391return;
392}
393
394/* --Methode-- */
395void Services2NObjMgr::DisplayPoints2DW(string& nom, string& expx, string& expy,
396 string& expwt, string& expcut, string dopt, string loop)
397{
398NObjMgrAdapter* obja=NULL;
399obja = mOmg->GetObjAdapter(nom);
400if (obja == NULL) {
401 cout << "Services2NObjMgr::DisplayPoints2DW() Error , No such object " << nom << endl;
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.";
410ComputeExpressions(obja, expx, expy, expwt, exp, expcut, loop, nt, NULL, NULL);
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
422string titre = nom + ":" + expwt + "_" + expy + "%" + expx ;
423mImgapp->DispScDrawer( (PIDrawer*)pin, titre, dopt);
424return;
425}
426
427/* --Methode-- */
428void Services2NObjMgr::ProjectH1(string& nom, string& expx, string& expwt,
429 string& expcut, string& nomh1, string dopt, string loop)
430{
431NObjMgrAdapter* obja=NULL;
432obja = mOmg->GetObjAdapter(nom);
433if (obja == NULL) {
434 cout << "Services2NObjMgr::ProjectH1() Error , No such object " << nom << endl;
435 return;
436 }
437if (!mImgapp) return;
438
439Histo* h1 = NULL;
440NTuple* nt = NULL;
441AnyDataObj* oh = NULL;
442if (nomh1.length() > 0) oh=mOmg->GetObj(nomh1);
443else nomh1 = "/tmp/projh1d";
444if ( (oh != NULL) && (typeid(*oh) == typeid(Histo)) ) h1 = (Histo*)oh; // Pas de remise a zero ! h1->Zero();
445else {
446 char* ntn[2]= {"hxval", "hwt"};
447 nt = new NTuple(2,ntn); // Creation NTuple
448 }
449string expz = "0.";
450ComputeExpressions(obja, expx, expwt, expz, expwt, expcut, loop, nt, h1, NULL);
451
452if ((!h1) && (!nt)) return;
453if (!h1) {
454 if (nt->NEntry() < 1) {
455 cout << "Services2NObjMgr::ProjectH1() Warning Zero points satisfy cut !" << endl;
456 delete nt;
457 return;
458 }
459 double xmin, xmax;
460 nt->GetMinMax(0, xmin, xmax);
461 h1 = new Histo(xmin, xmax, 100);
462 int k;
463 float* xn;
464 for(k=0; k<nt->NEntry(); k++) {
465 xn = nt->GetVec(k);
466 h1->Add(xn[0], xn[1]);
467 }
468 delete nt;
469 mOmg->AddObj(h1, nomh1);
470 }
471
472mOmg->DisplayObj(nomh1, dopt);
473return;
474}
475
476/* --Methode-- */
477void Services2NObjMgr::ProjectH2(string& nom, string& expx, string& expy, string& expwt,
478 string& expcut, string& nomh2, string dopt, string loop)
479{
480NObjMgrAdapter* obja=NULL;
481obja = mOmg->GetObjAdapter(nom);
482if (obja == NULL) {
483 cout << "Services2NObjMgr::ProjectH2() Error , No such object " << nom << endl;
484 return;
485 }
486if (!mImgapp) return;
487
488Histo2D* h2 = NULL;
489NTuple* nt = NULL;
490AnyDataObj* oh = NULL;
491if (nomh2.length() > 0) oh=mOmg->GetObj(nomh2);
492else nomh2 = "/tmp/projh2d";
493if ( (oh != NULL) && (typeid(*oh) == typeid(Histo2D)) ) h2 = (Histo2D*)oh; // Pas de remise a zero ! h2->Zero();
494else {
495 char* ntn[3]= {"hxval", "hyval", "hwt"};
496 nt = new NTuple(3,ntn); // Creation NTuple
497 }
498string expz = "0.";
499ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, loop, nt, NULL, h2);
500
501if ((!h2) && (!nt)) return;
502if (!h2) {
503 if (nt->NEntry() < 1) {
504 cout << "Services2NObjMgr::ProjectH2() Warning Zero points satisfy cut !" << endl;
505 delete nt;
506 return;
507 }
508 double xmin, xmax, ymin, ymax;
509 nt->GetMinMax(0, xmin, xmax);
510 nt->GetMinMax(1, ymin, ymax);
511 h2 = new Histo2D(xmin, xmax, 50, ymin, ymax, 50);
512 int k;
513 float* xn;
514 for(k=0; k<nt->NEntry(); k++) {
515 xn = nt->GetVec(k);
516 h2->Add(xn[0], xn[1], xn[2]);
517 }
518 delete nt;
519 mOmg->AddObj(h2, nomh2);
520 }
521
522mOmg->DisplayObj(nomh2, dopt);
523return;
524
525}
526
527/* --Methode-- cmv 13/10/98 */
528void Services2NObjMgr::ProjectHProf(string& nom, string& expx, string& expy, string& expwt,
529 string& expcut, string& nomprof, string dopt, string loop)
530// Pour remplir un ``GeneralFitData'' a partir de divers objets:
531//| nom = nom de l'objet a projeter dans un HProf.
532//| expx = expression X de definition du bin.
533//| expy = expression Y a additionner dans le bin.
534//| expwt = expression W du poids a additionner.
535//| expcut = expression du test de selection.
536//| nomprof = nom du HProf engendre (optionnel). Si l'objet n'existe pas
537//| les limites Xmin,Xmax sont calculees automatiquement.
538//| sinon ce sont celles de l'objet preexistant.
539//| opt = options generales pour le display.
540{
541NObjMgrAdapter* obja=NULL;
542obja = mOmg->GetObjAdapter(nom);
543if (obja == NULL) {
544 cout << "Services2NObjMgr::ProjectHProf() Error , No such object " << nom << endl;
545 return;
546 }
547if (!mImgapp) return;
548
549HProf* hprof = NULL;
550NTuple* nt = NULL;
551AnyDataObj* oh = NULL;
552if (nomprof.length() > 0) oh=mOmg->GetObj(nomprof);
553else nomprof = "/tmp/projprof";
554if( (oh!=NULL) && (typeid(*oh) == typeid(HProf)) ) hprof = (HProf*)oh;
555else {
556 char* ntn[3]= {"hxval", "hyval", "hwt"};
557 nt = new NTuple(3,ntn); // Creation NTuple
558}
559string expz = "0.";
560ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, loop, nt, NULL, NULL, hprof);
561
562if((!hprof) && (!nt)) return;
563if(!hprof) {
564 if (nt->NEntry() < 1) {
565 cout << "Services2NObjMgr::ProjectHProf() Warning Zero points satisfy cut !" << endl;
566 delete nt;
567 return;
568 }
569 r_8 xmin, xmax;
570 nt->GetMinMax(0, xmin, xmax);
571 hprof = new HProf(xmin, xmax, 100);
572 int k;
573 float* xn;
574 for(k=0; k<nt->NEntry(); k++) {
575 xn = nt->GetVec(k);
576 hprof->Add(xn[0], xn[1], xn[2]);
577 }
578 delete nt;
579 mOmg->AddObj(hprof, nomprof);
580 }
581hprof->UpdateHisto();
582
583mOmg->DisplayObj(nomprof, dopt);
584return;
585}
586
587
588/* --Methode-- */
589void Services2NObjMgr::FillVect(string& nom, string& expx, string& expv,
590 string& expcut, string& nomvec, string dopt, string loop)
591{
592NObjMgrAdapter* obja=NULL;
593obja = mOmg->GetObjAdapter(nom);
594if (obja == NULL) {
595 cout << "Services2NObjMgr::FillVect() Error , No such object: " << nom << endl;
596 return;
597 }
598if (!mImgapp) return;
599
600Vector* v1 = NULL;
601AnyDataObj* ov = NULL;
602ov=mOmg->GetObj(nomvec);
603if (ov != NULL) v1 = dynamic_cast<Vector *>(ov);
604if (v1 == NULL) {
605 cout << "Services2NObjMgr::FillVect() Error , No such object or not a vector: " << nomvec << endl;
606 return;
607 }
608
609char* ntn[2]= {"vi", "vv"};
610NTuple* nt = new NTuple(2,ntn); // Creation NTuple
611
612string expz = "0.";
613ComputeExpressions(obja, expx, expv, expz, expz, expcut, loop, nt);
614
615if (!nt) return;
616if (nt->NEntry() < 1) {
617 cout << "Services2NObjMgr::FillVect() Warning Zero points satisfy cut !" << endl;
618 delete nt;
619 return;
620 }
621
622 int i,k;
623 double* xn;
624 for(k=0; k<nt->NEntry(); k++) {
625 xn = nt->GetLineD(k);
626 i = xn[0]+0.5;
627 if ( (i < 0) || i >= v1->NElts() ) continue;
628 (*v1)(i) = xn[1];
629 }
630 delete nt;
631
632
633mOmg->DisplayObj(nomvec, dopt);
634return;
635}
636
637/* --Methode-- */
638void Services2NObjMgr::FillMatx(string& nom, string& expx, string& expy, string& expv,
639 string& expcut, string& nommtx, string dopt, string loop)
640{
641NObjMgrAdapter* obja=NULL;
642obja = mOmg->GetObjAdapter(nom);
643if (obja == NULL) {
644 cout << "Services2NObjMgr::FillMatx() Error , No such objet " << nom << endl;
645 return;
646 }
647if (!mImgapp) return;
648
649Matrix* mtx = NULL;
650AnyDataObj* om = NULL;
651om=mOmg->GetObj(nommtx);
652if (om != NULL) mtx = dynamic_cast<Matrix *>(om);
653if (mtx == NULL) {
654 cout << "Services2NObjMgr::FillMatx() Error , No such object or not a matrix " << nommtx << endl;
655 return;
656 }
657
658char* ntn[3]= {"mi", "mj", "mv"};
659NTuple* nt = new NTuple(3,ntn); // Creation NTuple
660
661string expz = "0.";
662ComputeExpressions(obja, expx, expy, expv, expz, expcut, loop, nt);
663
664if (!nt) return;
665if (nt->NEntry() < 1) {
666 cout << "Services2NObjMgr::FillMatx() Warning Zero points satisfy cut !" << endl;
667 delete nt;
668 return;
669 }
670
671 int ic, jl, k;
672 double* xn;
673 for(k=0; k<nt->NEntry(); k++) {
674 xn = nt->GetLineD(k);
675 ic = xn[0]+0.5;
676 jl = xn[1]+0.5;
677 if ( (ic < 0) || ic >= mtx->NCol() ) continue;
678 if ( (jl < 0) || jl >= mtx->NRows() ) continue;
679 (*mtx)(jl, ic) = xn[2];
680 }
681 delete nt;
682
683
684mOmg->DisplayObj(nommtx, dopt);
685return;
686
687}
688
689/* --Methode-- */
690void Services2NObjMgr::ExpressionToVector(string& nom, string& expx, string& expcut,
691 string& nomvec, string dopt, string loop)
692{
693NObjMgrAdapter* obja=NULL;
694obja = mOmg->GetObjAdapter(nom);
695if (obja == NULL) {
696 cout << "Services2NObjMgr::ExpressionToVector() Error , No such object " << nom << endl;
697 return;
698 }
699if (!mImgapp) return;
700
701NTuple* nt = NULL;
702if (nomvec.length() < 1) nomvec = "/tmp/expvec";
703
704char* ntn[2]= {"vecval", "vecwt"};
705nt = new NTuple(1,ntn); // Creation NTuple
706
707string expwt = "1.";
708string expz = "0.";
709string dumexpcut = expcut; if(dumexpcut.size()<=0) dumexpcut = "1.";
710ComputeExpressions(obja,expx,expz,expz,expwt,dumexpcut,loop,nt,NULL,NULL);
711
712if (!nt) return;
713if (nt->NEntry() < 1) {
714 cout << "Services2NObjMgr::ExpressionToVector() Warning Zero points satisfy cut !" << endl;
715 delete nt;
716 return;
717 }
718
719Vector* vec = new Vector(nt->NEntry());
720int k;
721float* xn;
722for(k=0; k<nt->NEntry(); k++) {
723 xn = nt->GetVec(k);
724 (*vec)(k) = xn[0];
725 }
726delete nt;
727mOmg->AddObj(vec, nomvec);
728mOmg->DisplayObj(nomvec, dopt);
729return;
730}
731
732/* --Methode-- */
733void Services2NObjMgr::NtFromASCIIFile(string& nom,string& filename,double def_val)
734// Pour remplir un ntuple "nom" existant a partir du fichier
735// ASCII table "filename". Si il y a plus de variables dans le
736// ntuple que dans le fichier "filename",
737// les sur-numeraires sont mises a "def_val" par defaut.
738{
739AnyDataObj* mobj = mOmg->GetObj(nom);
740if(mobj == NULL)
741 {cout<<"NtFromASCIIFile() Error, object "<<nom<<" not existing"<<endl;
742 return;}
743if(typeid(*mobj) != typeid(NTuple))
744 {cout<<"NtFromASCIIFile() Error, object "<<nom<<" not an NTuple"<<endl;
745 return;}
746if (!mImgapp) return;
747
748NTuple* nt = (NTuple*) mobj;
749nt->FillFromASCIIFile(filename, def_val);
750return;
751}
752
753/* --Methode-- */
754void Services2NObjMgr::FillNT(string& nom, string& expx, string& expy, string& expz,
755 string& expt, string& expcut, string& nomnt, string loop)
756{
757NObjMgrAdapter* obja=NULL;
758obja = mOmg->GetObjAdapter(nom);
759if (obja == NULL) {
760 cout << "Services2NObjMgr::FillNT() Error , No such object " << nom << endl;
761 return;
762 }
763if (!mImgapp) return;
764
765bool fgnnt = false;
766NTuple* nt = NULL;
767AnyDataObj* oh = NULL;
768if (nomnt.length() > 0) oh=mOmg->GetObj(nomnt);
769else nomnt = "/tmp/fillnt";
770if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
771 nt = (NTuple*)oh;
772 if (nt->NVar() > 10) {
773 cout << "Services2NObjMgr::FillNT() Warning , Max 10 var in NTuple -> new NTuple" << endl;
774 nt = NULL;
775 }
776 }
777if (nt == NULL) {
778 char* ntn[4]= {"x", "y","z","t"};
779 nt = new NTuple(4,ntn); // Creation NTuple
780 fgnnt = true;
781 }
782
783ComputeExpressions(obja, expx, expy, expz, expt, expcut, loop, nt, NULL, NULL);
784
785if (fgnnt) mOmg->AddObj(nt, nomnt);
786return;
787
788}
789
790/* --Methode-- */
791void Services2NObjMgr::FillNTFrCFile(string & nom, string const & fname,
792 string const & funcname, string & nomnt, string loop)
793{
794if (!mImgapp) return;
795
796NObjMgrAdapter* obja=NULL;
797obja = mOmg->GetObjAdapter(nom);
798if (obja == NULL) {
799 cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) No such object" <<endl;
800 return;
801 }
802bool adel = true;
803NTupleInterface* objnt = obja->GetNTupleInterface(adel);
804if (objnt == NULL) {
805 cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) Not an NTupleInterface !" <<endl;
806 return;
807 }
808
809NTLoopExprFunc f = (NTLoopExprFunc)LinkFunctionFromFile(fname, funcname);
810if (!f) {
811 cerr << "Services2NObjMgr::FillNTFrCFile Error Creation NTLoopExprFunc" << endl;
812 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
813 return;
814 }
815
816bool fgnnt = false;
817NTuple* nt = NULL;
818if (nomnt.length() > 0) {
819 AnyDataObj* oh = NULL;
820 oh=mOmg->GetObj(nomnt);
821 if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
822 nt = (NTuple*)oh;
823 if (nt->NVar() > 10) {
824 cout << "Services2NObjMgr::FillNTFrCFile() Warning , Max 10 var in NTuple -> new NTuple" << endl;
825 nt = NULL;
826 }
827 }
828 if (nt == NULL) {
829 char* ntn[4]= {"x", "y","z","t"};
830 nt = new NTuple(4,ntn); // Creation NTuple
831 fgnnt = true;
832 }
833 }
834
835double xnt[10];
836float fxnt[10];
837
838int i,k;
839for(i=0; i<10; i++) fxnt[i] = xnt[i] = 0.;
840
841
842// $CHECK$ A virer des que possible - Pb blocage application quand trop d'impression
843// redirige - On redirige la sortie sur le terminal
844bool red = mImgapp->HasRedirectedStdOutErr();
845mImgapp->RedirectStdOutErr(false);
846
847int k1,k2,dk;
848k1 = 0; k2 = objnt->NbLines(); dk = 1;
849DecodeLoopParameters(loop, k1, k2, dk);
850if (k1 < 0) k1 = 0;
851if (k2 < 0) k2 = objnt->NbLines();
852if (k2 > objnt->NbLines()) k2 = objnt->NbLines();
853if (dk <= 0) dk = 1;
854
855try {
856 double* xn;
857 int kmax = k2;
858 for(k=k1; k<kmax; k+=dk) {
859 xn = objnt->GetLineD(k);
860 if (f(xn, xnt, xnt+1, xnt+2, xnt+3, k, kmax) != 0) {
861 if (nt) {
862 for(i=0; i<4; i++) fxnt[i] = xnt[i];
863 nt->Fill(fxnt);
864 }
865 }
866 }
867 }
868#ifdef SANS_EVOLPLANCK
869CATCH(merr) {
870 fflush(stdout);
871 cout << endl;
872 cerr << endl;
873 string es = PeidaExc(merr);
874 cerr << "Services2NObjMgr::FillNTFrCFile() Exception :" << merr << es;
875 } ENDTRY;
876#else
877catch ( PException exc ) {
878 fflush(stdout);
879 cout << endl;
880 cerr << endl;
881 cerr << "Services2NObjMgr::FillNTFrCFile() Exception :" << exc.Msg() << endl;
882}
883#endif
884
885if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
886CloseDLL();
887
888// $CHECK$ A virer des que possible On redirige la sortie sur la fenetre PIConsole
889mImgapp->RedirectStdOutErr(red);
890
891if (fgnnt) mOmg->AddObj(nt, nomnt);
892return;
893}
894
895/* --Methode-- */
896void Services2NObjMgr::PrepareNTExpressionCFile(string & nom, string const & fname,
897 string const & funcname)
898{
899NObjMgrAdapter* obja=NULL;
900obja = mOmg->GetObjAdapter(nom);
901if (obja == NULL) {
902 cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom << "...) No such object" <<endl;
903 return;
904 }
905bool adel = true;
906NTupleInterface* objnt = obja->GetNTupleInterface(adel);
907if (objnt == NULL) {
908 cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom
909 << "...) No NTupleInterface !" <<endl;
910 return;
911 }
912string vardec = objnt->VarList_C("_xnti_");
913
914FILE *fip;
915if ((fip = fopen(fname.c_str(), "w")) == NULL) {
916 cout << "Services2NObjMgr::PrepareNTExpressionCFile()_Error: fopen " << fname << endl;
917 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
918 return;
919 }
920
921// constitution du fichier des decalarations des variables de l'interface NTuple
922fputs("#include <stdlib.h> \n", fip);
923fputs("#include <stdio.h> \n", fip);
924fputs("#include <math.h> \n\n", fip);
925
926fputs("/* ------ Compare bits on double --------- */ \n", fip);
927fputs("typedef long long int_8;\n", fip);
928fputs("int_8 BitCmp64(double v,int_8 flg)\n", fip);
929fputs("{return ((int_8)((v<0.) ? v-0.1 : v+0.1))&flg;}\n", fip);
930fputs("/* ------ Some random number generators --------- */ \n", fip);
931fputs("#if defined(__ppc__) && defined(__MACH__) \n",fip);
932fputs("#include <limits.h> \n", fip);
933fputs("#define drand48() ((double)(random())/LONG_MAX) \n",fip);
934fputs("#endif \n",fip);
935fputs("#define frand01() ( (float) drand48() ) \n", fip);
936fputs("#define drand01() drand48() \n", fip);
937fputs("#define rand01() drand48() \n", fip);
938fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
939fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
940fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
941fputs("double NorRand(void) \n", fip);
942fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
943fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
944fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
945fputs(" return(x); \n } \n", fip);
946fputs("#define GauRand() NorRand() \n", fip);
947fputs("#define gaurand() NorRand() \n\n", fip);
948
949fputs("/* NTupleInterface Variable declaration - Generated by piapp \n", fip);
950fputs(" -- Services2NObjMgr::PrepareNTExpressionCFile() -- */ \n\n", fip);
951fprintf(fip,"int %s(double* _xnti_, double* _rx_, double* _ry_, double* _rz_, \n",
952 funcname.c_str());
953fprintf(fip," double* _rt_, int _n_, int _nmax_) \n");
954fprintf(fip, "{ \n %s \n", vardec.c_str());
955fputs(" if (!1) { /* Cut Expression failed */ \n", fip);
956fputs(" *_rx_ = *_ry_ = *_rz_ = *_rt_ = 0.; return(0);", fip);
957fputs(" } \n /* Cut expression satisfied */ \n", fip);
958fputs(" *_rx_ = 1.; \n *_ry_ = 1.; \n *_rz_ = 1.; \n *_rt_ = 1.; \n", fip);
959fputs(" return(1); \n} \n", fip);
960
961fclose(fip);
962
963if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
964return;
965}
966
967/* --Methode-- cmv 13/10/98 */
968void Services2NObjMgr::FillGFD(string& nom, string& expx, string& expy, string& expz,
969 string& experr, string& expcut, string& nomgfd, string loop)
970// Pour remplir un ``GeneralFitData'' a partir de divers objets:
971//| nom = nom de l'objet a transcrire selon 1D: Z=f(X) ou 2D: Z=f(X,Y) .
972//| Vector,Matrix,Histo,HProf,Histo2D,Image<T>,StarList,NTuple,GeneralFitData
973//| expx = expression X du GeneralFitData (1er abscisse)
974//| expy = expression Y du GeneralFitData (2sd abscisse si non "", Z=f(X,Y))
975//| expz = expression Z du GeneralFitData (valeur de l'ordonnee)
976//| experr = expression de l'erreur sur l'ordonnee Z
977//| expcut = expression du test de selection
978//| nomgfd = nom du GeneralFitData engendre (optionnel)
979{
980NObjMgrAdapter* obja=NULL;
981obja = mOmg->GetObjAdapter(nom);
982if (obja == NULL) {
983 cout << "Services2NObjMgr::FillGFD() Error , No such object "<<nom<<endl;
984 return;
985 }
986if(!mImgapp) return;
987
988// 2D ou 3D?
989int nvar = 2;
990if(expy.length()<=0) {nvar = 1; expy = "0.";}
991
992// Creation NTuple Buffer
993char* ntn[4]= {"x","y","f","e"};
994NTuple*nt = new NTuple(4,ntn);
995
996// Remplissage NTuple buffer
997ComputeExpressions(obja, expx, expy, expz, experr, expcut, loop, nt, NULL, NULL);
998if(nt->NEntry() < 1)
999 {cout<<"Services2NObjMgr::FillGFD() Warning Zero points satisfy cut !"<<endl;
1000 delete nt; return;}
1001
1002//Remplissage de la structure GeneraFitData
1003if (nt->NEntry() <= 0) {
1004 cout<<"Services2NObjMgr::FillGFD() Warning - NData= " << nt->NEntry() << endl;
1005 delete nt;
1006 return;
1007 }
1008
1009GeneralFitData* gfd = new GeneralFitData(nvar,nt->NEntry(),0);
1010int k;
1011float* xn;
1012for(k=0; k<nt->NEntry(); k++) {
1013 xn = nt->GetVec(k);
1014 gfd->AddData(xn,xn[2],xn[3]);
1015}
1016
1017// Menage et table d'objets
1018delete nt;
1019mOmg->AddObj(gfd, nomgfd);
1020return;
1021}
1022
1023/* --Methode-- cmv 12/07/00 */
1024void Services2NObjMgr::FillGFDfrVec(string nomgfd,string namx,string namy,string namz,string name)
1025// Pour remplir un ``GeneralFitData'' a partir de vecteurs
1026//| gdfrvec nomgd X Y ! !
1027//| gdfrvec nomgd X Y ! EY
1028//| gdfrvec nomgd X Y Z !
1029//| gdfrvec nomgd X Y Z EZ
1030//| - nomgfd = nom du generaldata a remplir
1031//| - namx = nom du vecteur contenant les valeurs X
1032//| - namy = nom du vecteur contenant les valeurs Y
1033//| - namz = nom du vecteur contenant les valeurs Z (ou "!")
1034//| - name = nom du vecteur contenant les valeurs des erreurs EY ou EZ
1035{
1036// Decodage des noms des vecteurs pour le remplissage du generaldata
1037if(nomgfd=="!" || nomgfd.length()<1)
1038 {cout<<"FillGFDfrVec_Error: bad GenaralData name "<<nomgfd<<endl; return;}
1039if(namx=="!" || namx.length()<1)
1040 {cout<<"FillGFDfrVec_Error: bad X vector name "<<namx<<endl; return;}
1041if(namy=="!" || namy.length()<1)
1042 {cout<<"FillGFDfrVec_Error: bad Y vector name "<<namy<<endl; return;}
1043if(namz.length()<1) namz = "!";
1044if(name.length()<1) name = "!";
1045int nvar = 0;
1046if(namz=="!") nvar = 1; else nvar = 2;
1047
1048// Identify data
1049NamedObjMgr omg;
1050AnyDataObj* mobj = NULL;
1051Vector* v;
1052int nel = 0;
1053r_8 *x=NULL, *y=NULL, *z=NULL,* ez=NULL;
1054
1055if( (mobj=omg.GetObj(namx)) == NULL) {
1056 cout<<"FillGFDfrVec_Error: unknown X object "<<namx<<endl; return;
1057} else {
1058 v = (Vector*) mobj; x = v->Data(); nel=v->NElts();
1059}
1060
1061if( (mobj=omg.GetObj(namy)) == NULL) {
1062 cout<<"FillGFDfrVec_Error: unknown Y object "<<namy<<endl; return;
1063} else {
1064 v = (Vector*) mobj; y = z = v->Data(); if(v->NElts()<nel) nel=v->NElts();
1065}
1066
1067if( nvar==2 && (mobj=omg.GetObj(namz)) == NULL) {
1068 cout<<"FillGFDfrVec_Error: unknown Z object "<<namz<<endl; return;
1069} else {
1070 v = (Vector*) mobj; z = v->Data(); if(v->NElts()<nel) nel=v->NElts();
1071}
1072
1073if(name!="!") {
1074 if( (mobj=omg.GetObj(name)) == NULL) {
1075 cout<<"FillGFDfrVec_Error: unknown EZ object "<<name<<endl; return;
1076 } else {
1077 v = (Vector*) mobj; ez = v->Data(); if(v->NElts()<nel) nel=v->NElts();
1078 }
1079}
1080
1081if(nel<=0)
1082 {cout<<"FillGFDfrVec_Error: bad number of elements "<<nel<<endl; return;}
1083
1084// Create GeneralData and fill it with vectors
1085GeneralFitData* gfd = new GeneralFitData(nvar,nel+5,0);
1086if(nvar==1) gfd->SetData1(nel,x,z,ez); // On remplit Y=f(X)
1087else gfd->SetData2(nel,x,y,z,ez); // On remplit Z=f(X,y)
1088
1089// Menage et table d'objets
1090if( omg.GetObj(nomgfd) != NULL ) omg.DelObj(nomgfd);
1091mOmg->AddObj(gfd,nomgfd);
1092return;
1093}
1094
1095/* --Methode-- */
1096void Services2NObjMgr::ComputeExpressions(NObjMgrAdapter* obja, string& expx,
1097 string& expy, string& expz, string& expt, string& expcut, string& loop,
1098 NTuple* nt, Histo* h1, Histo2D* h2, HProf* hp)
1099{
1100if (obja == NULL) return;
1101bool adel = true;
1102NTupleInterface* objnt = obja->GetNTupleInterface(adel);
1103if (objnt == NULL) return;
1104string vardec = objnt->VarList_C("_zz6qi_");
1105
1106PlotExprFunc f = LinkExprFunc(vardec, expx, expy, expz, expt, expcut);
1107if (!f) {
1108 cerr << "Services2NObjMgr::::ComputeExpressions() Error Creation PlotExprFunc " << endl;
1109 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
1110 return;
1111 }
1112
1113double xnt[10];
1114float fxnt[10];
1115
1116int i,k;
1117for(i=0; i<10; i++) xnt[i] = 0.;
1118int k1,k2,dk;
1119k1 = 0; k2 = objnt->NbLines(); dk = 1;
1120DecodeLoopParameters(loop, k1, k2, dk);
1121if (k1 < 0) k1 = 0;
1122if (k2 < 0) k2 = objnt->NbLines();
1123if (k2 > objnt->NbLines()) k2 = objnt->NbLines();
1124if (dk <= 0) dk = 1;
1125
1126try {
1127 double* xn;
1128 for(k=k1; k<k2; k += dk) {
1129 xn = objnt->GetLineD(k);
1130 if (f(xn, xnt, xnt+1, xnt+2, xnt+3) != 0) {
1131 if (nt) {
1132 for(i=0; i<4; i++) fxnt[i] = xnt[i];
1133 nt->Fill(fxnt);
1134 }
1135 if (h1) h1->Add(xnt[0], xnt[3]);
1136 if (h2) h2->Add(xnt[0], xnt[1], xnt[3]);
1137 if (hp) hp->Add(xnt[0], xnt[1], xnt[3]);
1138 }
1139 }
1140 }
1141#ifdef SANS_EVOLPLANCK
1142CATCH(merr) {
1143 fflush(stdout);
1144 cout << endl;
1145 cerr << endl;
1146 string es = PeidaExc(merr);
1147 cerr << "Services2NObjMgr::ComputeExpressions() Exception :" << merr << es;
1148 } ENDTRY;
1149#else
1150catch ( PException exc ) {
1151 fflush(stdout);
1152 cout << endl;
1153 cerr << endl;
1154 cerr << "Services2NObjMgr::ComputeExpressions() Exception :" << exc.Msg() << endl;
1155}
1156#endif
1157
1158if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
1159// Fermeture du fichier .so
1160CloseDLL();
1161return;
1162}
1163
1164
1165/* --Methode-- */
1166PlotExprFunc Services2NObjMgr::LinkExprFunc(string& vardec, string& expx, string& expy,
1167 string& expz, string& expt, string& cut)
1168{
1169FILE *fip;
1170string fname = TmpDir + "expf_pia_dl.c";
1171string cmd;
1172int rc;
1173
1174cmd = "rm -f " + fname;
1175rc = system(cmd.c_str());
1176//DBG printf("LinkExprFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
1177
1178if ((fip = fopen(fname.c_str(), "w")) == NULL) {
1179 string sn = fname;
1180 cout << "Services2NObjMgr/LinkExprFunc_Error: fopen( " << sn << endl;
1181 return(NULL);
1182 }
1183
1184// constitution du fichier a compiler
1185fputs("#include <stdlib.h> \n", fip);
1186fputs("#include <math.h> \n", fip);
1187
1188fputs("/* ------ Compare bits on double --------- */ \n", fip);
1189fputs("typedef long long int_8;\n", fip);
1190fputs("int_8 BitCmp64(double v,int_8 flg)\n", fip);
1191fputs("{return ((int_8)((v<0.) ? v-0.1 : v+0.1))&flg;}\n", fip);
1192fputs("/* ------ Some random number generators --------- */ \n", fip);
1193fputs("#if defined(__ppc__) && defined(__MACH__) \n",fip);
1194fputs("#include <limits.h> \n", fip);
1195fputs("#define drand48() ((double)(random())/LONG_MAX) \n",fip);
1196fputs("#endif \n",fip);
1197fputs("#define frand01() ( (float) drand48() ) \n", fip);
1198fputs("#define drand01() drand48() \n", fip);
1199fputs("#define rand01() drand48() \n", fip);
1200fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
1201fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
1202fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
1203fputs("double NorRand(void) \n", fip);
1204fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
1205fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
1206fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
1207fputs(" return(x); \n } \n", fip);
1208fputs("#define GauRand() NorRand() \n", fip);
1209fputs("#define gaurand() NorRand() \n\n", fip);
1210
1211fputs("int expf_pia_dl_func(double* _zz6qi_, double* _rx_6q_, double* _ry_6q_, double* _rz_6q_, double* _rt_6q_) \n{\n", fip);
1212fprintf(fip,"%s \n", vardec.c_str());
1213fprintf(fip, "if (!(%s)) { *_rx_6q_ = *_ry_6q_ = *_rz_6q_ = *_rt_6q_ = 0.; return(0); } \n", cut.c_str());
1214fprintf(fip, "*_rx_6q_ = %s ; \n", expx.c_str());
1215fprintf(fip, "*_ry_6q_ = %s ; \n", expy.c_str());
1216fprintf(fip, "*_rz_6q_ = %s ; \n", expz.c_str());
1217fprintf(fip, "*_rt_6q_ = %s ; \n", expt.c_str());
1218fputs("return(1); \n} \n", fip);
1219fclose(fip);
1220string func = "expf_pia_dl_func";
1221return((PlotExprFunc)LinkFunctionFromFile(fname, func));
1222}
1223
1224
1225/* --Methode-- */
1226DlFunction Services2NObjMgr::LinkFunctionFromFile(string const & fname, string const & funcname)
1227{
1228// Le link dynamique
1229CloseDLL();
1230dynlink = PDynLinkMgr::BuildFromCFile(fname);
1231if (dynlink == NULL) {
1232 cerr << "Services2NObjMgr/LinkFunctionFromFile_Erreur: Erreur creation/Ouverture SO " << endl;
1233 return(NULL);
1234 }
1235
1236DlFunction retfunc = dynlink->GetFunction(funcname);
1237if (retfunc == NULL) {
1238 string sn = funcname;
1239 cerr << "Services2NObjMgr/LinkExprFunc_Erreur: Erreur linking " << sn << endl;
1240 CloseDLL();
1241 return(NULL);
1242 }
1243else return(retfunc);
1244}
1245
1246/* --Methode-- */
1247void Services2NObjMgr::CloseDLL()
1248{
1249if (dynlink) delete dynlink; dynlink = NULL;
1250}
1251
1252/* --Methode-- */
1253int Services2NObjMgr::ExecuteCommand(string line)
1254{
1255 if (mImgapp == NULL) return(99);
1256 return(mImgapp->CmdInterpreter()->Interpret(line));
1257}
1258
1259// Fonction static
1260/* --Methode-- */
1261void Services2NObjMgr::DecodeLoopParameters(string& loop, int& i1, int& i2, int& di)
1262{
1263// Decode des paramatres de boucle for(int i=i1; i<i2; i+=di) specifies
1264// sous forme i1[:i2[:di]]
1265// cout << "LoopParam() " << loop << " I1=" << i1 << " I2=" << i2 << " DI=" << di;
1266size_t l = loop.length();
1267if (l < 1) return;
1268size_t p = loop.find(':');
1269if (p >= l) { i1 = atoi(loop.c_str()); return; }
1270i1 = atoi(loop.substr(0, p).c_str());
1271string aa = loop.substr(p+1);
1272p = aa.find(':');
1273if (p < aa.length() ) {
1274 i2 = atoi(aa.substr(0,p).c_str());
1275 di = atoi(aa.substr(p+1).c_str());
1276 }
1277else i2 = atoi(aa.c_str());
1278// cout << "-> I1= " << i1 << " I2= " << i2 << " DI= " << di << endl;
1279return;
1280}
1281
1282/* --Methode-- */
1283string Services2NObjMgr::FileName2Name(string const & fn)
1284{
1285
1286char fsep[2] = {FILESEP, '\0'};
1287char tsep[2] = {'.', '\0'};
1288size_t p = fn.find_last_of(fsep);
1289size_t l = fn.length();
1290if (p >= l) p = 0;
1291else p++;
1292size_t q = fn.find_first_of(tsep,p);
1293if (q < p) q = l;
1294return(fn.substr(p,q-p));
1295}
1296
1297
1298
1299
1300// SANS_EVOLPLANCK Attention !
1301#ifdef SANS_EVOLPLANCK
1302#include "pclassids.h"
1303
1304/* --Methode-- */
1305char* Services2NObjMgr::PClassIdToClassName(int cid)
1306{
1307switch (cid) {
1308 case ClassId_Poly1 :
1309 return("Poly1");
1310 case ClassId_Poly2 :
1311 return("Poly2");
1312 case ClassId_Matrix :
1313 return("Matrix");
1314 case ClassId_Vector :
1315 return("Vector");
1316
1317 case ClassId_DVList :
1318 return("DVList");
1319
1320 case ClassId_Histo1D :
1321 return("Histo1D");
1322 case ClassId_Histo2D :
1323 return("Histo2D");
1324 case ClassId_HProf :
1325 return("HProf");
1326 case ClassId_NTuple :
1327 return("NTuple");
1328 case ClassId_XNTuple :
1329 return("XNTuple");
1330 case ClassId_GeneralFitData :
1331 return("GeneralFitData");
1332
1333 case ClassId_Image :
1334 return("RzImage");
1335 case ClassId_Image + kuint_1 :
1336 return("ImageU1");
1337 case ClassId_Image + kint_1 :
1338 return("ImageI1");
1339 case ClassId_Image + kuint_2 :
1340 return("ImageU2");
1341 case ClassId_Image + kint_2 :
1342 return("ImageI2");
1343 case ClassId_Image + kuint_4 :
1344 return("ImageU4");
1345 case ClassId_Image + kint_4 :
1346 return("ImageI4");
1347 case ClassId_Image + kr_4 :
1348 return("ImageR4");
1349 case ClassId_Image + kr_8 :
1350 return("ImageR8");
1351 case ClassId_ZFidu :
1352 return("ZFidu");
1353
1354 case ClassId_StarList :
1355 return("StarList");
1356 case ClassId_Transfo :
1357 return("Transfo");
1358 case ClassId_PSF :
1359 return("PSF");
1360
1361
1362// - Ajout objet PPF
1363 default:
1364 return("AnyDataObj");
1365 }
1366}
1367
1368#else
1369char* Services2NObjMgr::PClassIdToClassName(int cid)
1370{
1371 return("AnyDataObj");
1372}
1373#endif
Note: See TracBrowser for help on using the repository browser.