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

Last change on this file since 2668 was 2668, checked in by ansari, 20 years ago

Passage remplissage NTuple en double dans Serv2NameObjMgr::ComputeExpression() - Reza 15/4/2005

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