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

Last change on this file since 2679 was 2679, checked in by cmv, 20 years ago

Pour que le n/proj ne dessine plus cmv 19/04/2005

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