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

Last change on this file since 2265 was 2180, checked in by cmv, 23 years ago

command eval dans spiapp cmv 13/8/02

File size: 39.7 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::ExpVal(string expval,string resultvarname)
316{
317 // Fill C-file to be executed
318 FILE *fip;
319 string func = "eval_pia_dl_func";
320 string fname = TmpDir + func; fname += ".c";
321 string cmd = "rm -f " + fname; system(cmd.c_str());
322 if((fip=fopen(fname.c_str(), "w"))==NULL) {
323 cout << "Services2NObjMgr/EvalExp_Error: fopen("<<fname<<")"<<endl;
324 return;
325 }
326 fprintf(fip,"#include <math.h>\n");
327 fprintf(fip,"double %s(double ___dummy_variable___) \n{\n",func.c_str());
328 // Add all variables already declared
329 DVList& varlist = mOmg->GetVarList();
330 DVList::ValList::const_iterator it;
331 for(it = varlist.Begin(); it != varlist.End(); it++) {
332#ifdef SANS_EVOLPLANCK
333 MuTyV mtv = (*it).second;
334 double value = (double)(mtv);
335#else
336 double value = (double)((*it).second.elval);
337#endif
338 string name_var = (*it).first;
339 fprintf(fip,"double %s = %.17f;\n",name_var.c_str(),value);
340 }
341 fprintf(fip,"return %s;\n}\n",expval.c_str());
342 fclose(fip);
343
344 // Dynamically link function
345 DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname,func);
346 if(!f) {
347 cout<<"Services2NObjMgr/EvalExp_Error: linking DlFunctionOfX"<<endl;
348 cout<<"...expval = "<<expval<<endl;
349 return;
350 }
351
352 // Evaluate function and close dynamic link
353 double result;
354 try {
355 result = f(0.);
356 CloseDLL();
357 } catch ( ... ) {
358 cout<<"Services2NObjMgr/EvalExp_Error: Arithmetic exception"<<endl;
359 CloseDLL();
360 return;
361 }
362
363 // Eventually store the result into variable or just print it
364 if(resultvarname.size()>0) {
365 if(mOmg->HasVar(resultvarname)) mOmg->DeleteVar(resultvarname);
366 char str[512];
367 if(result==0.) sprintf(str,"%f",result);
368 else {
369 double lr = log10(fabs(result));
370 if(lr>-17. && lr<17.) sprintf(str,"%17f",result);
371 else sprintf(str,"%.17e",result);
372 }
373 mOmg->SetVar(resultvarname,(string)str);
374 } else cout<<result<<" = "<<expval<<endl;
375
376}
377
378/* --Methode-- */
379void Services2NObjMgr::DisplayPoints2D(string& nom, string& expx, string& expy,
380 string& experrx, string& experry,
381 string& expcut, string dopt, string loop)
382{
383NObjMgrAdapter* obja=NULL;
384obja = mOmg->GetObjAdapter(nom);
385if (obja == NULL) {
386 cout << "Services2NObjMgr::DisplayPoints2D() Error , No such object " << nom << endl;
387 return;
388 }
389if (!mImgapp) return;
390
391// Creation NTuple
392char* ntn[4] = {"expx","expy","expex","expey",};
393NTuple* nt = NULL;
394bool haserr = false;
395
396if ( (experrx.length() > 0 ) && (experry.length() > 0 ) ) { haserr = true; nt = new NTuple(4, ntn); }
397else { haserr = false; experrx = experry = "0."; nt = new NTuple(2, ntn); }
398
399ComputeExpressions(obja, expx, expy, experrx, experry, expcut, loop, nt, NULL, NULL);
400
401if (nt->NEntry() < 1) {
402 cout << "Services2NObjMgr::DisplayPoints2D() Warning Zero points satisfy cut !" << endl;
403 delete nt;
404 return;
405 }
406
407// nt->Show();
408// nt->Print(0,10);
409PINTuple* pin = new PINTuple(nt, true);
410pin->SelectXY(ntn[0], ntn[1]);
411if ( haserr ) pin->SelectErrBar(ntn[2], ntn[3]);
412
413dopt = "defline " + dopt;
414string titre = nom + ":" + expy + "%" + expx;
415mImgapp->DispScDrawer( (PIDrawer*)pin, titre, dopt);
416return;
417}
418
419/* --Methode-- */
420void Services2NObjMgr::DisplayPoints3D(string& nom, string& expx, string& expy,
421 string& expz, string& expcut, string dopt, string loop)
422{
423NObjMgrAdapter* obja=NULL;
424obja = mOmg->GetObjAdapter(nom);
425if (obja == NULL) {
426 cout << "Services2NObjMgr::DisplayPoints3D() Error , No such object " << nom << endl;
427 return;
428 }
429if (!mImgapp) return;
430
431char* ntn[3] = {"expx","expy","expz"};
432NTuple* nt = new NTuple(3,ntn); // Creation NTuple
433
434string expwt = "1.";
435ComputeExpressions(obja, expx, expy, expz, expwt, expcut, loop, nt, NULL, NULL);
436
437if (nt->NEntry() < 1) {
438 cout << "Services2NObjMgr::DisplayPoints3D() Warning Zero points satisfy cut !" << endl;
439 delete nt;
440 return;
441 }
442nt->Show();
443nt->Print(0,10);
444PINTuple3D* pin = new PINTuple3D(nt, true);
445pin->SelectXYZ(ntn[0], ntn[1], ntn[2]);
446dopt = "defline " + dopt;
447
448// Pour plot a partir de DispScDrawer
449// string nomdisp = "_NT3D_";
450// mImgapp->DispScDrawer( (PIDrawer*)pin, nomdisp, opt);
451// Pour plot a partir de Disp3DDrawer
452string titre = nom + ":" + expy + "%" + expx;
453mImgapp->Disp3DDrawer(pin, titre, dopt);
454
455return;
456}
457
458/* --Methode-- */
459void Services2NObjMgr::DisplayPoints2DW(string& nom, string& expx, string& expy,
460 string& expwt, string& expcut, string dopt, string loop)
461{
462NObjMgrAdapter* obja=NULL;
463obja = mOmg->GetObjAdapter(nom);
464if (obja == NULL) {
465 cout << "Services2NObjMgr::DisplayPoints2DW() Error , No such object " << nom << endl;
466 return;
467 }
468if (!mImgapp) return;
469
470char* ntn[3] = {"expx","expy","expw"};
471NTuple* nt = new NTuple(3,ntn); // Creation NTuple
472
473string exp = "1.";
474ComputeExpressions(obja, expx, expy, expwt, exp, expcut, loop, nt, NULL, NULL);
475
476if (nt->NEntry() < 1) {
477 cout << "Services2NObjMgr::DisplayPoints2DW() Warning Zero points satisfy cut !" << endl;
478 delete nt;
479 return;
480 }
481
482PINTuple* pin = new PINTuple(nt, true);
483pin->SelectXY(ntn[0], ntn[1]);
484pin->SelectWt(ntn[2]);
485
486string titre = nom + ":" + expwt + "_" + expy + "%" + expx ;
487mImgapp->DispScDrawer( (PIDrawer*)pin, titre, dopt);
488return;
489}
490
491/* --Methode-- */
492void Services2NObjMgr::ProjectH1(string& nom, string& expx, string& expwt,
493 string& expcut, string& nomh1, string dopt, string loop)
494{
495NObjMgrAdapter* obja=NULL;
496obja = mOmg->GetObjAdapter(nom);
497if (obja == NULL) {
498 cout << "Services2NObjMgr::ProjectH1() Error , No such object " << nom << endl;
499 return;
500 }
501if (!mImgapp) return;
502
503Histo* h1 = NULL;
504NTuple* nt = NULL;
505AnyDataObj* oh = NULL;
506if (nomh1.length() > 0) oh=mOmg->GetObj(nomh1);
507else nomh1 = "/tmp/projh1d";
508if ( (oh != NULL) && (typeid(*oh) == typeid(Histo)) ) h1 = (Histo*)oh; // Pas de remise a zero ! h1->Zero();
509else {
510 char* ntn[2]= {"hxval", "hwt"};
511 nt = new NTuple(2,ntn); // Creation NTuple
512 }
513string expz = "0.";
514ComputeExpressions(obja, expx, expwt, expz, expwt, expcut, loop, nt, h1, NULL);
515
516if ((!h1) && (!nt)) return;
517if (!h1) {
518 if (nt->NEntry() < 1) {
519 cout << "Services2NObjMgr::ProjectH1() Warning Zero points satisfy cut !" << endl;
520 delete nt;
521 return;
522 }
523 double xmin, xmax;
524 nt->GetMinMax(0, xmin, xmax);
525 h1 = new Histo(xmin, xmax, 100);
526 int k;
527 float* xn;
528 for(k=0; k<nt->NEntry(); k++) {
529 xn = nt->GetVec(k);
530 h1->Add(xn[0], xn[1]);
531 }
532 delete nt;
533 mOmg->AddObj(h1, nomh1);
534 }
535
536mOmg->DisplayObj(nomh1, dopt);
537return;
538}
539
540/* --Methode-- */
541void Services2NObjMgr::ProjectH2(string& nom, string& expx, string& expy, string& expwt,
542 string& expcut, string& nomh2, string dopt, string loop)
543{
544NObjMgrAdapter* obja=NULL;
545obja = mOmg->GetObjAdapter(nom);
546if (obja == NULL) {
547 cout << "Services2NObjMgr::ProjectH2() Error , No such object " << nom << endl;
548 return;
549 }
550if (!mImgapp) return;
551
552Histo2D* h2 = NULL;
553NTuple* nt = NULL;
554AnyDataObj* oh = NULL;
555if (nomh2.length() > 0) oh=mOmg->GetObj(nomh2);
556else nomh2 = "/tmp/projh2d";
557if ( (oh != NULL) && (typeid(*oh) == typeid(Histo2D)) ) h2 = (Histo2D*)oh; // Pas de remise a zero ! h2->Zero();
558else {
559 char* ntn[3]= {"hxval", "hyval", "hwt"};
560 nt = new NTuple(3,ntn); // Creation NTuple
561 }
562string expz = "0.";
563ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, loop, nt, NULL, h2);
564
565if ((!h2) && (!nt)) return;
566if (!h2) {
567 if (nt->NEntry() < 1) {
568 cout << "Services2NObjMgr::ProjectH2() Warning Zero points satisfy cut !" << endl;
569 delete nt;
570 return;
571 }
572 double xmin, xmax, ymin, ymax;
573 nt->GetMinMax(0, xmin, xmax);
574 nt->GetMinMax(1, ymin, ymax);
575 h2 = new Histo2D(xmin, xmax, 50, ymin, ymax, 50);
576 int k;
577 float* xn;
578 for(k=0; k<nt->NEntry(); k++) {
579 xn = nt->GetVec(k);
580 h2->Add(xn[0], xn[1], xn[2]);
581 }
582 delete nt;
583 mOmg->AddObj(h2, nomh2);
584 }
585
586mOmg->DisplayObj(nomh2, dopt);
587return;
588
589}
590
591/* --Methode-- cmv 13/10/98 */
592void Services2NObjMgr::ProjectHProf(string& nom, string& expx, string& expy, string& expwt,
593 string& expcut, string& nomprof, string dopt, string loop)
594// Pour remplir un ``GeneralFitData'' a partir de divers objets:
595//| nom = nom de l'objet a projeter dans un HProf.
596//| expx = expression X de definition du bin.
597//| expy = expression Y a additionner dans le bin.
598//| expwt = expression W du poids a additionner.
599//| expcut = expression du test de selection.
600//| nomprof = nom du HProf engendre (optionnel). Si l'objet n'existe pas
601//| les limites Xmin,Xmax sont calculees automatiquement.
602//| sinon ce sont celles de l'objet preexistant.
603//| opt = options generales pour le display.
604{
605NObjMgrAdapter* obja=NULL;
606obja = mOmg->GetObjAdapter(nom);
607if (obja == NULL) {
608 cout << "Services2NObjMgr::ProjectHProf() Error , No such object " << nom << endl;
609 return;
610 }
611if (!mImgapp) return;
612
613HProf* hprof = NULL;
614NTuple* nt = NULL;
615AnyDataObj* oh = NULL;
616if (nomprof.length() > 0) oh=mOmg->GetObj(nomprof);
617else nomprof = "/tmp/projprof";
618if( (oh!=NULL) && (typeid(*oh) == typeid(HProf)) ) hprof = (HProf*)oh;
619else {
620 char* ntn[3]= {"hxval", "hyval", "hwt"};
621 nt = new NTuple(3,ntn); // Creation NTuple
622}
623string expz = "0.";
624ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, loop, nt, NULL, NULL, hprof);
625
626if((!hprof) && (!nt)) return;
627if(!hprof) {
628 if (nt->NEntry() < 1) {
629 cout << "Services2NObjMgr::ProjectHProf() Warning Zero points satisfy cut !" << endl;
630 delete nt;
631 return;
632 }
633 r_8 xmin, xmax;
634 nt->GetMinMax(0, xmin, xmax);
635 hprof = new HProf(xmin, xmax, 100);
636 int k;
637 float* xn;
638 for(k=0; k<nt->NEntry(); k++) {
639 xn = nt->GetVec(k);
640 hprof->Add(xn[0], xn[1], xn[2]);
641 }
642 delete nt;
643 mOmg->AddObj(hprof, nomprof);
644 }
645hprof->UpdateHisto();
646
647mOmg->DisplayObj(nomprof, dopt);
648return;
649}
650
651
652/* --Methode-- */
653void Services2NObjMgr::FillVect(string& nom, string& expx, string& expv,
654 string& expcut, string& nomvec, string dopt, string loop)
655{
656NObjMgrAdapter* obja=NULL;
657obja = mOmg->GetObjAdapter(nom);
658if (obja == NULL) {
659 cout << "Services2NObjMgr::FillVect() Error , No such object: " << nom << endl;
660 return;
661 }
662if (!mImgapp) return;
663
664Vector* v1 = NULL;
665AnyDataObj* ov = NULL;
666ov=mOmg->GetObj(nomvec);
667if (ov != NULL) v1 = dynamic_cast<Vector *>(ov);
668if (v1 == NULL) {
669 cout << "Services2NObjMgr::FillVect() Error , No such object or not a vector: " << nomvec << endl;
670 return;
671 }
672
673char* ntn[2]= {"vi", "vv"};
674NTuple* nt = new NTuple(2,ntn); // Creation NTuple
675
676string expz = "0.";
677ComputeExpressions(obja, expx, expv, expz, expz, expcut, loop, nt);
678
679if (!nt) return;
680if (nt->NEntry() < 1) {
681 cout << "Services2NObjMgr::FillVect() Warning Zero points satisfy cut !" << endl;
682 delete nt;
683 return;
684 }
685
686 int i,k;
687 double* xn;
688 for(k=0; k<nt->NEntry(); k++) {
689 xn = nt->GetLineD(k);
690 i = int(xn[0]+0.5);
691 if ( (i < 0) || i >= v1->NElts() ) continue;
692 (*v1)(i) = xn[1];
693 }
694 delete nt;
695
696
697mOmg->DisplayObj(nomvec, dopt);
698return;
699}
700
701/* --Methode-- */
702void Services2NObjMgr::FillMatx(string& nom, string& expx, string& expy, string& expv,
703 string& expcut, string& nommtx, string dopt, string loop)
704{
705NObjMgrAdapter* obja=NULL;
706obja = mOmg->GetObjAdapter(nom);
707if (obja == NULL) {
708 cout << "Services2NObjMgr::FillMatx() Error , No such objet " << nom << endl;
709 return;
710 }
711if (!mImgapp) return;
712
713Matrix* mtx = NULL;
714AnyDataObj* om = NULL;
715om=mOmg->GetObj(nommtx);
716if (om != NULL) mtx = dynamic_cast<Matrix *>(om);
717if (mtx == NULL) {
718 cout << "Services2NObjMgr::FillMatx() Error , No such object or not a matrix " << nommtx << endl;
719 return;
720 }
721
722char* ntn[3]= {"mi", "mj", "mv"};
723NTuple* nt = new NTuple(3,ntn); // Creation NTuple
724
725string expz = "0.";
726ComputeExpressions(obja, expx, expy, expv, expz, expcut, loop, nt);
727
728if (!nt) return;
729if (nt->NEntry() < 1) {
730 cout << "Services2NObjMgr::FillMatx() Warning Zero points satisfy cut !" << endl;
731 delete nt;
732 return;
733 }
734
735 int ic, jl, k;
736 double* xn;
737 for(k=0; k<nt->NEntry(); k++) {
738 xn = nt->GetLineD(k);
739 ic = int(xn[0]+0.5);
740 jl = int(xn[1]+0.5);
741 if ( (ic < 0) || ic >= mtx->NCol() ) continue;
742 if ( (jl < 0) || jl >= mtx->NRows() ) continue;
743 (*mtx)(jl, ic) = xn[2];
744 }
745 delete nt;
746
747
748mOmg->DisplayObj(nommtx, dopt);
749return;
750
751}
752
753/* --Methode-- */
754void Services2NObjMgr::ExpressionToVector(string& nom, string& expx, string& expcut,
755 string& nomvec, string dopt, string loop)
756{
757NObjMgrAdapter* obja=NULL;
758obja = mOmg->GetObjAdapter(nom);
759if (obja == NULL) {
760 cout << "Services2NObjMgr::ExpressionToVector() Error , No such object " << nom << endl;
761 return;
762 }
763if (!mImgapp) return;
764
765NTuple* nt = NULL;
766if (nomvec.length() < 1) nomvec = "/tmp/expvec";
767
768char* ntn[2]= {"vecval", "vecwt"};
769nt = new NTuple(1,ntn); // Creation NTuple
770
771string expwt = "1.";
772string expz = "0.";
773string dumexpcut = expcut; if(dumexpcut.size()<=0) dumexpcut = "1.";
774ComputeExpressions(obja,expx,expz,expz,expwt,dumexpcut,loop,nt,NULL,NULL);
775
776if (!nt) return;
777if (nt->NEntry() < 1) {
778 cout << "Services2NObjMgr::ExpressionToVector() Warning Zero points satisfy cut !" << endl;
779 delete nt;
780 return;
781 }
782
783Vector* vec = new Vector(nt->NEntry());
784int k;
785float* xn;
786for(k=0; k<nt->NEntry(); k++) {
787 xn = nt->GetVec(k);
788 (*vec)(k) = xn[0];
789 }
790delete nt;
791mOmg->AddObj(vec, nomvec);
792mOmg->DisplayObj(nomvec, dopt);
793return;
794}
795
796/* --Methode-- */
797void Services2NObjMgr::NtFromASCIIFile(string& nom,string& filename,double def_val)
798// Pour remplir un ntuple "nom" existant a partir du fichier
799// ASCII table "filename". Si il y a plus de variables dans le
800// ntuple que dans le fichier "filename",
801// les sur-numeraires sont mises a "def_val" par defaut.
802{
803AnyDataObj* mobj = mOmg->GetObj(nom);
804if(mobj == NULL)
805 {cout<<"NtFromASCIIFile() Error, object "<<nom<<" not existing"<<endl;
806 return;}
807if(typeid(*mobj) != typeid(NTuple))
808 {cout<<"NtFromASCIIFile() Error, object "<<nom<<" not an NTuple"<<endl;
809 return;}
810if (!mImgapp) return;
811
812NTuple* nt = (NTuple*) mobj;
813nt->FillFromASCIIFile(filename, def_val);
814return;
815}
816
817/* --Methode-- */
818void Services2NObjMgr::FillNT(string& nom, string& expx, string& expy, string& expz,
819 string& expt, string& expcut, string& nomnt, string loop)
820{
821NObjMgrAdapter* obja=NULL;
822obja = mOmg->GetObjAdapter(nom);
823if (obja == NULL) {
824 cout << "Services2NObjMgr::FillNT() Error , No such object " << nom << endl;
825 return;
826 }
827if (!mImgapp) return;
828
829bool fgnnt = false;
830NTuple* nt = NULL;
831AnyDataObj* oh = NULL;
832if (nomnt.length() > 0) oh=mOmg->GetObj(nomnt);
833else nomnt = "/tmp/fillnt";
834if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
835 nt = (NTuple*)oh;
836 if (nt->NVar() > 10) {
837 cout << "Services2NObjMgr::FillNT() Warning , Max 10 var in NTuple -> new NTuple" << endl;
838 nt = NULL;
839 }
840 }
841if (nt == NULL) {
842 char* ntn[4]= {"x", "y","z","t"};
843 nt = new NTuple(4,ntn); // Creation NTuple
844 fgnnt = true;
845 }
846
847ComputeExpressions(obja, expx, expy, expz, expt, expcut, loop, nt, NULL, NULL);
848
849if (fgnnt) mOmg->AddObj(nt, nomnt);
850return;
851
852}
853
854/* --Methode-- */
855void Services2NObjMgr::FillNTFrCFile(string & nom, string const & fname,
856 string const & funcname, string & nomnt, string loop)
857{
858if (!mImgapp) return;
859
860NObjMgrAdapter* obja=NULL;
861obja = mOmg->GetObjAdapter(nom);
862if (obja == NULL) {
863 cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) No such object" <<endl;
864 return;
865 }
866bool adel = true;
867NTupleInterface* objnt = obja->GetNTupleInterface(adel);
868if (objnt == NULL) {
869 cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) Not an NTupleInterface !" <<endl;
870 return;
871 }
872
873NTLoopExprFunc f = (NTLoopExprFunc)LinkFunctionFromFile(fname, funcname);
874if (!f) {
875 cerr << "Services2NObjMgr::FillNTFrCFile Error Creation NTLoopExprFunc" << endl;
876 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
877 return;
878 }
879
880bool fgnnt = false;
881NTuple* nt = NULL;
882if (nomnt.length() > 0) {
883 AnyDataObj* oh = NULL;
884 oh=mOmg->GetObj(nomnt);
885 if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
886 nt = (NTuple*)oh;
887 if (nt->NVar() > 10) {
888 cout << "Services2NObjMgr::FillNTFrCFile() Warning , Max 10 var in NTuple -> new NTuple" << endl;
889 nt = NULL;
890 }
891 }
892 if (nt == NULL) {
893 char* ntn[4]= {"x", "y","z","t"};
894 nt = new NTuple(4,ntn); // Creation NTuple
895 fgnnt = true;
896 }
897 }
898
899double xnt[10];
900float fxnt[10];
901
902int i,k;
903for(i=0; i<10; i++) fxnt[i] = xnt[i] = 0.;
904
905
906// $CHECK$ A virer des que possible - Pb blocage application quand trop d'impression
907// redirige - On redirige la sortie sur le terminal
908bool red = mImgapp->HasRedirectedStdOutErr();
909mImgapp->RedirectStdOutErr(false);
910
911int k1,k2,dk;
912k1 = 0; k2 = objnt->NbLines(); dk = 1;
913DecodeLoopParameters(loop, k1, k2, dk);
914if (k1 < 0) k1 = 0;
915if (k2 < 0) k2 = objnt->NbLines();
916if (k2 > (int_4)objnt->NbLines()) k2 = objnt->NbLines();
917if (dk <= 0) dk = 1;
918
919try {
920 double* xn;
921 int kmax = k2;
922 for(k=k1; k<kmax; k+=dk) {
923 xn = objnt->GetLineD(k);
924 if (f(xn, xnt, xnt+1, xnt+2, xnt+3, k, kmax) != 0) {
925 if (nt) {
926 for(i=0; i<4; i++) fxnt[i] = xnt[i];
927 nt->Fill(fxnt);
928 }
929 }
930 }
931 }
932#ifdef SANS_EVOLPLANCK
933CATCH(merr) {
934 fflush(stdout);
935 cout << endl;
936 cerr << endl;
937 string es = PeidaExc(merr);
938 cerr << "Services2NObjMgr::FillNTFrCFile() Exception :" << merr << es;
939 } ENDTRY;
940#else
941catch ( PException exc ) {
942 fflush(stdout);
943 cout << endl;
944 cerr << endl;
945 cerr << "Services2NObjMgr::FillNTFrCFile() Exception :" << exc.Msg() << endl;
946}
947#endif
948
949if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
950CloseDLL();
951
952// $CHECK$ A virer des que possible On redirige la sortie sur la fenetre PIConsole
953mImgapp->RedirectStdOutErr(red);
954
955if (fgnnt) mOmg->AddObj(nt, nomnt);
956return;
957}
958
959/* --Methode-- */
960void Services2NObjMgr::PrepareNTExpressionCFile(string & nom, string const & fname,
961 string const & funcname)
962{
963NObjMgrAdapter* obja=NULL;
964obja = mOmg->GetObjAdapter(nom);
965if (obja == NULL) {
966 cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom << "...) No such object" <<endl;
967 return;
968 }
969bool adel = true;
970NTupleInterface* objnt = obja->GetNTupleInterface(adel);
971if (objnt == NULL) {
972 cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom
973 << "...) No NTupleInterface !" <<endl;
974 return;
975 }
976string vardec = objnt->VarList_C("_xnti_");
977
978FILE *fip;
979if ((fip = fopen(fname.c_str(), "w")) == NULL) {
980 cout << "Services2NObjMgr::PrepareNTExpressionCFile()_Error: fopen " << fname << endl;
981 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
982 return;
983 }
984
985// constitution du fichier des decalarations des variables de l'interface NTuple
986fputs("#include <stdlib.h> \n", fip);
987fputs("#include <stdio.h> \n", fip);
988fputs("#include <math.h> \n\n", fip);
989
990fputs("/* ------ Compare bits on double --------- */ \n", fip);
991fputs("typedef long long int_8;\n", fip);
992fputs("int_8 BitCmp64(double v,int_8 flg)\n", fip);
993fputs("{return ((int_8)((v<0.) ? v-0.1 : v+0.1))&flg;}\n", fip);
994fputs("/* ------ Some random number generators --------- */ \n", fip);
995fputs("#if defined(__ppc__) && defined(__MACH__) \n",fip);
996fputs("#include <limits.h> \n", fip);
997fputs("#define drand48() ((double)(random())/LONG_MAX) \n",fip);
998fputs("#endif \n",fip);
999fputs("#define frand01() ( (float) drand48() ) \n", fip);
1000fputs("#define drand01() drand48() \n", fip);
1001fputs("#define rand01() drand48() \n", fip);
1002fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
1003fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
1004fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
1005fputs("double NorRand(void) \n", fip);
1006fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
1007fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
1008fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
1009fputs(" return(x); \n } \n", fip);
1010fputs("#define GauRand() NorRand() \n", fip);
1011fputs("#define gaurand() NorRand() \n\n", fip);
1012
1013fputs("/* NTupleInterface Variable declaration - Generated by piapp \n", fip);
1014fputs(" -- Services2NObjMgr::PrepareNTExpressionCFile() -- */ \n\n", fip);
1015fprintf(fip,"int %s(double* _xnti_, double* _rx_, double* _ry_, double* _rz_, \n",
1016 funcname.c_str());
1017fprintf(fip," double* _rt_, int _n_, int _nmax_) \n");
1018fprintf(fip, "{ \n %s \n", vardec.c_str());
1019fputs(" if (!1) { /* Cut Expression failed */ \n", fip);
1020fputs(" *_rx_ = *_ry_ = *_rz_ = *_rt_ = 0.; return(0);", fip);
1021fputs(" } \n /* Cut expression satisfied */ \n", fip);
1022fputs(" *_rx_ = 1.; \n *_ry_ = 1.; \n *_rz_ = 1.; \n *_rt_ = 1.; \n", fip);
1023fputs(" return(1); \n} \n", fip);
1024
1025fclose(fip);
1026
1027if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
1028return;
1029}
1030
1031/* --Methode-- cmv 13/10/98 */
1032void Services2NObjMgr::FillGFD(string& nom, string& expx, string& expy, string& expz,
1033 string& experr, string& expcut, string& nomgfd, string loop)
1034// Pour remplir un ``GeneralFitData'' a partir de divers objets:
1035//| nom = nom de l'objet a transcrire selon 1D: Z=f(X) ou 2D: Z=f(X,Y) .
1036//| Vector,Matrix,Histo,HProf,Histo2D,Image<T>,StarList,NTuple,GeneralFitData
1037//| expx = expression X du GeneralFitData (1er abscisse)
1038//| expy = expression Y du GeneralFitData (2sd abscisse si non "", Z=f(X,Y))
1039//| expz = expression Z du GeneralFitData (valeur de l'ordonnee)
1040//| experr = expression de l'erreur sur l'ordonnee Z
1041//| expcut = expression du test de selection
1042//| nomgfd = nom du GeneralFitData engendre (optionnel)
1043{
1044NObjMgrAdapter* obja=NULL;
1045obja = mOmg->GetObjAdapter(nom);
1046if (obja == NULL) {
1047 cout << "Services2NObjMgr::FillGFD() Error , No such object "<<nom<<endl;
1048 return;
1049 }
1050if(!mImgapp) return;
1051
1052// 2D ou 3D?
1053int nvar = 2;
1054if(expy.length()<=0) {nvar = 1; expy = "0.";}
1055
1056// Creation NTuple Buffer
1057char* ntn[4]= {"x","y","f","e"};
1058NTuple*nt = new NTuple(4,ntn);
1059
1060// Remplissage NTuple buffer
1061ComputeExpressions(obja, expx, expy, expz, experr, expcut, loop, nt, NULL, NULL);
1062if(nt->NEntry() < 1)
1063 {cout<<"Services2NObjMgr::FillGFD() Warning Zero points satisfy cut !"<<endl;
1064 delete nt; return;}
1065
1066//Remplissage de la structure GeneraFitData
1067if (nt->NEntry() <= 0) {
1068 cout<<"Services2NObjMgr::FillGFD() Warning - NData= " << nt->NEntry() << endl;
1069 delete nt;
1070 return;
1071 }
1072
1073GeneralFitData* gfd = new GeneralFitData(nvar,nt->NEntry(),0);
1074int k;
1075float* xn;
1076for(k=0; k<nt->NEntry(); k++) {
1077 xn = nt->GetVec(k);
1078 gfd->AddData(xn,xn[2],xn[3]);
1079}
1080
1081// Menage et table d'objets
1082delete nt;
1083mOmg->AddObj(gfd, nomgfd);
1084return;
1085}
1086
1087/* --Methode-- cmv 12/07/00 */
1088void Services2NObjMgr::FillGFDfrVec(string nomgfd,string namx,string namy,string namz,string name)
1089// Pour remplir un ``GeneralFitData'' a partir de vecteurs
1090//| gdfrvec nomgd X Y ! !
1091//| gdfrvec nomgd X Y ! EY
1092//| gdfrvec nomgd X Y Z !
1093//| gdfrvec nomgd X Y Z EZ
1094//| - nomgfd = nom du generaldata a remplir
1095//| - namx = nom du vecteur contenant les valeurs X
1096//| - namy = nom du vecteur contenant les valeurs Y
1097//| - namz = nom du vecteur contenant les valeurs Z (ou "!")
1098//| - name = nom du vecteur contenant les valeurs des erreurs EY ou EZ
1099{
1100// Decodage des noms des vecteurs pour le remplissage du generaldata
1101if(nomgfd=="!" || nomgfd.length()<1)
1102 {cout<<"FillGFDfrVec_Error: bad GenaralData name "<<nomgfd<<endl; return;}
1103if(namx=="!" || namx.length()<1)
1104 {cout<<"FillGFDfrVec_Error: bad X vector name "<<namx<<endl; return;}
1105if(namy=="!" || namy.length()<1)
1106 {cout<<"FillGFDfrVec_Error: bad Y vector name "<<namy<<endl; return;}
1107if(namz.length()<1) namz = "!";
1108if(name.length()<1) name = "!";
1109int nvar = 0;
1110if(namz=="!") nvar = 1; else nvar = 2;
1111
1112// Identify data
1113NamedObjMgr omg;
1114AnyDataObj* mobj = NULL;
1115Vector* v;
1116int nel = 0;
1117r_8 *x=NULL, *y=NULL, *z=NULL,* ez=NULL;
1118
1119if( (mobj=omg.GetObj(namx)) == NULL) {
1120 cout<<"FillGFDfrVec_Error: unknown X object "<<namx<<endl; return;
1121} else {
1122 v = (Vector*) mobj; x = v->Data(); nel=v->NElts();
1123}
1124
1125if( (mobj=omg.GetObj(namy)) == NULL) {
1126 cout<<"FillGFDfrVec_Error: unknown Y object "<<namy<<endl; return;
1127} else {
1128 v = (Vector*) mobj; y = z = v->Data(); if(v->NElts()<nel) nel=v->NElts();
1129}
1130
1131if( nvar==2 && (mobj=omg.GetObj(namz)) == NULL) {
1132 cout<<"FillGFDfrVec_Error: unknown Z object "<<namz<<endl; return;
1133} else {
1134 v = (Vector*) mobj; z = v->Data(); if(v->NElts()<nel) nel=v->NElts();
1135}
1136
1137if(name!="!") {
1138 if( (mobj=omg.GetObj(name)) == NULL) {
1139 cout<<"FillGFDfrVec_Error: unknown EZ object "<<name<<endl; return;
1140 } else {
1141 v = (Vector*) mobj; ez = v->Data(); if(v->NElts()<nel) nel=v->NElts();
1142 }
1143}
1144
1145if(nel<=0)
1146 {cout<<"FillGFDfrVec_Error: bad number of elements "<<nel<<endl; return;}
1147
1148// Create GeneralData and fill it with vectors
1149GeneralFitData* gfd = new GeneralFitData(nvar,nel+5,0);
1150if(nvar==1) gfd->SetData1(nel,x,z,ez); // On remplit Y=f(X)
1151else gfd->SetData2(nel,x,y,z,ez); // On remplit Z=f(X,y)
1152
1153// Menage et table d'objets
1154if( omg.GetObj(nomgfd) != NULL ) omg.DelObj(nomgfd);
1155mOmg->AddObj(gfd,nomgfd);
1156return;
1157}
1158
1159/* --Methode-- */
1160void Services2NObjMgr::ComputeExpressions(NObjMgrAdapter* obja, string& expx,
1161 string& expy, string& expz, string& expt, string& expcut, string& loop,
1162 NTuple* nt, Histo* h1, Histo2D* h2, HProf* hp)
1163{
1164if (obja == NULL) return;
1165bool adel = true;
1166NTupleInterface* objnt = obja->GetNTupleInterface(adel);
1167if (objnt == NULL) return;
1168string vardec = objnt->VarList_C("_zz6qi_");
1169
1170PlotExprFunc f = LinkExprFunc(vardec, expx, expy, expz, expt, expcut);
1171if (!f) {
1172 cerr << "Services2NObjMgr::::ComputeExpressions() Error Creation PlotExprFunc " << endl;
1173 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
1174 return;
1175 }
1176
1177double xnt[10];
1178float fxnt[10];
1179
1180int i,k;
1181for(i=0; i<10; i++) xnt[i] = 0.;
1182int k1,k2,dk;
1183k1 = 0; k2 = objnt->NbLines(); dk = 1;
1184DecodeLoopParameters(loop, k1, k2, dk);
1185if (k1 < 0) k1 = 0;
1186if (k2 < 0) k2 = objnt->NbLines();
1187if (k2 > (int_4)objnt->NbLines()) k2 = objnt->NbLines();
1188if (dk <= 0) dk = 1;
1189
1190try {
1191 double* xn;
1192 for(k=k1; k<k2; k += dk) {
1193 xn = objnt->GetLineD(k);
1194 if (f(xn, xnt, xnt+1, xnt+2, xnt+3) != 0) {
1195 if (nt) {
1196 for(i=0; i<4; i++) fxnt[i] = xnt[i];
1197 nt->Fill(fxnt);
1198 }
1199 if (h1) h1->Add(xnt[0], xnt[3]);
1200 if (h2) h2->Add(xnt[0], xnt[1], xnt[3]);
1201 if (hp) hp->Add(xnt[0], xnt[1], xnt[3]);
1202 }
1203 }
1204 }
1205#ifdef SANS_EVOLPLANCK
1206CATCH(merr) {
1207 fflush(stdout);
1208 cout << endl;
1209 cerr << endl;
1210 string es = PeidaExc(merr);
1211 cerr << "Services2NObjMgr::ComputeExpressions() Exception :" << merr << es;
1212 } ENDTRY;
1213#else
1214catch ( PException exc ) {
1215 fflush(stdout);
1216 cout << endl;
1217 cerr << endl;
1218 cerr << "Services2NObjMgr::ComputeExpressions() Exception :" << exc.Msg() << endl;
1219}
1220#endif
1221
1222if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
1223// Fermeture du fichier .so
1224CloseDLL();
1225return;
1226}
1227
1228
1229/* --Methode-- */
1230PlotExprFunc Services2NObjMgr::LinkExprFunc(string& vardec, string& expx, string& expy,
1231 string& expz, string& expt, string& cut)
1232{
1233FILE *fip;
1234string fname = TmpDir + "expf_pia_dl.c";
1235string cmd;
1236int rc;
1237
1238cmd = "rm -f " + fname;
1239rc = system(cmd.c_str());
1240//DBG printf("LinkExprFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
1241
1242if ((fip = fopen(fname.c_str(), "w")) == NULL) {
1243 string sn = fname;
1244 cout << "Services2NObjMgr/LinkExprFunc_Error: fopen( " << sn << endl;
1245 return(NULL);
1246 }
1247
1248// constitution du fichier a compiler
1249fputs("#include <stdlib.h> \n", fip);
1250fputs("#include <math.h> \n", fip);
1251
1252fputs("/* ------ Compare bits on double --------- */ \n", fip);
1253fputs("typedef long long int_8;\n", fip);
1254fputs("int_8 BitCmp64(double v,int_8 flg)\n", fip);
1255fputs("{return ((int_8)((v<0.) ? v-0.1 : v+0.1))&flg;}\n", fip);
1256fputs("/* ------ Some random number generators --------- */ \n", fip);
1257fputs("#if defined(__ppc__) && defined(__MACH__) \n",fip);
1258fputs("#include <limits.h> \n", fip);
1259fputs("#define drand48() ((double)(random())/LONG_MAX) \n",fip);
1260fputs("#endif \n",fip);
1261fputs("#define frand01() ( (float) drand48() ) \n", fip);
1262fputs("#define drand01() drand48() \n", fip);
1263fputs("#define rand01() drand48() \n", fip);
1264fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
1265fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
1266fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
1267fputs("double NorRand(void) \n", fip);
1268fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
1269fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
1270fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
1271fputs(" return(x); \n } \n", fip);
1272fputs("#define GauRand() NorRand() \n", fip);
1273fputs("#define gaurand() NorRand() \n\n", fip);
1274
1275fputs("int expf_pia_dl_func(double* _zz6qi_, double* _rx_6q_, double* _ry_6q_, double* _rz_6q_, double* _rt_6q_) \n{\n", fip);
1276fprintf(fip,"%s \n", vardec.c_str());
1277fprintf(fip, "if (!(%s)) { *_rx_6q_ = *_ry_6q_ = *_rz_6q_ = *_rt_6q_ = 0.; return(0); } \n", cut.c_str());
1278fprintf(fip, "*_rx_6q_ = %s ; \n", expx.c_str());
1279fprintf(fip, "*_ry_6q_ = %s ; \n", expy.c_str());
1280fprintf(fip, "*_rz_6q_ = %s ; \n", expz.c_str());
1281fprintf(fip, "*_rt_6q_ = %s ; \n", expt.c_str());
1282fputs("return(1); \n} \n", fip);
1283fclose(fip);
1284string func = "expf_pia_dl_func";
1285return((PlotExprFunc)LinkFunctionFromFile(fname, func));
1286}
1287
1288
1289/* --Methode-- */
1290DlFunction Services2NObjMgr::LinkFunctionFromFile(string const & fname, string const & funcname)
1291{
1292// Le link dynamique
1293CloseDLL();
1294dynlink = PDynLinkMgr::BuildFromCFile(fname);
1295if (dynlink == NULL) {
1296 cerr << "Services2NObjMgr/LinkFunctionFromFile_Erreur: Erreur creation/Ouverture SO " << endl;
1297 return(NULL);
1298 }
1299
1300DlFunction retfunc = dynlink->GetFunction(funcname);
1301if (retfunc == NULL) {
1302 string sn = funcname;
1303 cerr << "Services2NObjMgr/LinkExprFunc_Erreur: Erreur linking " << sn << endl;
1304 CloseDLL();
1305 return(NULL);
1306 }
1307else return(retfunc);
1308}
1309
1310/* --Methode-- */
1311void Services2NObjMgr::CloseDLL()
1312{
1313if (dynlink) delete dynlink; dynlink = NULL;
1314}
1315
1316/* --Methode-- */
1317int Services2NObjMgr::ExecuteCommand(string line)
1318{
1319 if (mImgapp == NULL) return(99);
1320 return(mImgapp->CmdInterpreter()->Interpret(line));
1321}
1322
1323// Fonction static
1324/* --Methode-- */
1325void Services2NObjMgr::DecodeLoopParameters(string& loop, int& i1, int& i2, int& di)
1326{
1327// Decode des paramatres de boucle for(int i=i1; i<i2; i+=di) specifies
1328// sous forme i1[:i2[:di]]
1329// cout << "LoopParam() " << loop << " I1=" << i1 << " I2=" << i2 << " DI=" << di;
1330size_t l = loop.length();
1331if (l < 1) return;
1332size_t p = loop.find(':');
1333if (p >= l) { i1 = atoi(loop.c_str()); return; }
1334i1 = atoi(loop.substr(0, p).c_str());
1335string aa = loop.substr(p+1);
1336p = aa.find(':');
1337if (p < aa.length() ) {
1338 i2 = atoi(aa.substr(0,p).c_str());
1339 di = atoi(aa.substr(p+1).c_str());
1340 }
1341else i2 = atoi(aa.c_str());
1342// cout << "-> I1= " << i1 << " I2= " << i2 << " DI= " << di << endl;
1343return;
1344}
1345
1346/* --Methode-- */
1347string Services2NObjMgr::FileName2Name(string const & fn)
1348{
1349
1350char fsep[2] = {FILESEP, '\0'};
1351char tsep[2] = {'.', '\0'};
1352size_t p = fn.find_last_of(fsep);
1353size_t l = fn.length();
1354if (p >= l) p = 0;
1355else p++;
1356size_t q = fn.find_first_of(tsep,p);
1357if (q < p) q = l;
1358return(fn.substr(p,q-p));
1359}
1360
1361
1362
1363
1364// SANS_EVOLPLANCK Attention !
1365#ifdef SANS_EVOLPLANCK
1366#include "pclassids.h"
1367
1368/* --Methode-- */
1369char* Services2NObjMgr::PClassIdToClassName(int cid)
1370{
1371switch (cid) {
1372 case ClassId_Poly1 :
1373 return("Poly1");
1374 case ClassId_Poly2 :
1375 return("Poly2");
1376 case ClassId_Matrix :
1377 return("Matrix");
1378 case ClassId_Vector :
1379 return("Vector");
1380
1381 case ClassId_DVList :
1382 return("DVList");
1383
1384 case ClassId_Histo1D :
1385 return("Histo1D");
1386 case ClassId_Histo2D :
1387 return("Histo2D");
1388 case ClassId_HProf :
1389 return("HProf");
1390 case ClassId_NTuple :
1391 return("NTuple");
1392 case ClassId_XNTuple :
1393 return("XNTuple");
1394 case ClassId_GeneralFitData :
1395 return("GeneralFitData");
1396
1397 case ClassId_Image :
1398 return("RzImage");
1399 case ClassId_Image + kuint_1 :
1400 return("ImageU1");
1401 case ClassId_Image + kint_1 :
1402 return("ImageI1");
1403 case ClassId_Image + kuint_2 :
1404 return("ImageU2");
1405 case ClassId_Image + kint_2 :
1406 return("ImageI2");
1407 case ClassId_Image + kuint_4 :
1408 return("ImageU4");
1409 case ClassId_Image + kint_4 :
1410 return("ImageI4");
1411 case ClassId_Image + kr_4 :
1412 return("ImageR4");
1413 case ClassId_Image + kr_8 :
1414 return("ImageR8");
1415 case ClassId_ZFidu :
1416 return("ZFidu");
1417
1418 case ClassId_StarList :
1419 return("StarList");
1420 case ClassId_Transfo :
1421 return("Transfo");
1422 case ClassId_PSF :
1423 return("PSF");
1424
1425
1426// - Ajout objet PPF
1427 default:
1428 return("AnyDataObj");
1429 }
1430}
1431
1432#else
1433char* Services2NObjMgr::PClassIdToClassName(int cid)
1434{
1435 return("AnyDataObj");
1436}
1437#endif
Note: See TracBrowser for help on using the repository browser.