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

Last change on this file since 2615 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

File size: 40.3 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];
902float fxnt[10];
903
904int i,k;
905for(i=0; i<10; i++) fxnt[i] = xnt[i] = 0.;
906
907
908// $CHECK$ A virer des que possible - Pb blocage application quand trop d'impression
909// redirige - On redirige la sortie sur le terminal
910bool red = mImgapp->HasRedirectedStdOutErr();
911mImgapp->RedirectStdOutErr(false);
912
913int_8 k1,k2,dk;
914k1 = 0; k2 = objnt->NbLines(); dk = 1;
915DecodeLoopParameters(loop, k1, k2, dk);
916if (k1 < 0) k1 = 0;
917if (k2 < 0) k2 = objnt->NbLines();
918if (k2 > (int_8)objnt->NbLines()) k2 = objnt->NbLines();
919if (dk <= 0) dk = 1;
920
921try {
922 double* xn;
923 int_8 kstart = k1, kend = k2;
924 for(k=kstart; k<kend; k+=dk) {
925 xn = objnt->GetLineD(k);
926 if (f((int_8_exprf)k, xn, xnt, xnt+1, xnt+2, xnt+3, (int_8_exprf)kstart,(int_8_exprf) kend) != 0) {
927 if (nt) {
928 for(int i=0; i<4; i++) fxnt[i] = xnt[i];
929 nt->Fill(fxnt);
930 }
931 }
932 }
933 }
934#ifdef SANS_EVOLPLANCK
935CATCH(merr) {
936 fflush(stdout);
937 cout << endl;
938 cerr << endl;
939 string es = PeidaExc(merr);
940 cerr << "Services2NObjMgr::FillNTFrCFile() Exception :" << merr << es;
941 } ENDTRY;
942#else
943catch ( PException exc ) {
944 fflush(stdout);
945 cout << endl;
946 cerr << endl;
947 cerr << "Services2NObjMgr::FillNTFrCFile() Exception :" << exc.Msg() << endl;
948}
949#endif
950
951if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
952CloseDLL();
953
954// $CHECK$ A virer des que possible On redirige la sortie sur la fenetre PIConsole
955mImgapp->RedirectStdOutErr(red);
956
957if (fgnnt) MyObjMgr()->AddObj(nt, nomnt);
958return;
959}
960
961/* --Methode-- */
962void Services2NObjMgr::PrepareNTExpressionCFile(string & nom, string const & fname,
963 string const & funcname)
964{
965NObjMgrAdapter* obja=NULL;
966obja = MyObjMgr()->GetObjAdapter(nom);
967if (obja == NULL) {
968 cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom << "...) No such object" <<endl;
969 return;
970 }
971bool adel = true;
972NTupleInterface* objnt = obja->GetNTupleInterface(adel);
973if (objnt == NULL) {
974 cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom
975 << "...) No NTupleInterface !" <<endl;
976 return;
977 }
978string vardec = objnt->VarList_C("_xnti_");
979
980FILE *fip;
981if ((fip = fopen(fname.c_str(), "w")) == NULL) {
982 cout << "Services2NObjMgr::PrepareNTExpressionCFile()_Error: fopen " << fname << endl;
983 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
984 return;
985 }
986
987// constitution du fichier des decalarations des variables de l'interface NTuple
988fputs("#include <stdlib.h> \n", fip);
989fputs("#include <stdio.h> \n", fip);
990fputs("#include <math.h> \n\n", fip);
991
992fputs("/* ------ Compare bits on double --------- */ \n", fip);
993fputs("typedef long long int_8_exprf;\n", fip);
994fputs("int_8_exprf BitCmp64(double v,int_8_exprf flg)\n", fip);
995fputs("{return ((int_8_exprf)((v<0.) ? v-0.1 : v+0.1))&flg;}\n", fip);
996fputs("/* ------ Some random number generators --------- */ \n", fip);
997fputs("#if defined(__ppc__) && defined(__MACH__) \n",fip);
998fputs("#include <limits.h> \n", fip);
999fputs("#define drand48() ((double)(random())/LONG_MAX) \n",fip);
1000fputs("#endif \n",fip);
1001fputs("#define frand01() ( (float) drand48() ) \n", fip);
1002fputs("#define drand01() drand48() \n", fip);
1003fputs("#define rand01() drand48() \n", fip);
1004fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
1005fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
1006fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
1007fputs("double NorRand(void) \n", fip);
1008fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
1009fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
1010fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
1011fputs(" return(x); \n } \n", fip);
1012fputs("#define GauRand() NorRand() \n", fip);
1013fputs("#define gaurand() NorRand() \n\n", fip);
1014
1015fputs("/* NTupleInterface Variable declaration - Generated by piapp */\n", fip);
1016fputs("/* -- Services2NObjMgr::PrepareNTExpressionCFile() -- */ \n", fip);
1017fputs("/* _nl line number or sequential index : _nstart <= _nl < _nend */ \n\n", fip);
1018fprintf(fip,"int %s(int_8_exprf _nl, double* _xnti_, double* _rx_, double* _ry_, double* _rz_, \n",
1019 funcname.c_str());
1020fprintf(fip," double* _rt_, int_8_exprf _nstart, int_8_exprf _nend) \n");
1021fprintf(fip, "{ \n %s \n", vardec.c_str());
1022fputs(" if (!1) { /* Cut Expression failed */ \n", fip);
1023fputs(" *_rx_ = *_ry_ = *_rz_ = *_rt_ = 0.; return(0);", fip);
1024fputs(" } \n /* Cut expression satisfied */ \n", fip);
1025fputs(" *_rx_ = 1.; \n *_ry_ = 1.; \n *_rz_ = 1.; \n *_rt_ = 1.; \n", fip);
1026fputs(" return(1); \n} \n", fip);
1027
1028fclose(fip);
1029
1030if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
1031return;
1032}
1033
1034/* --Methode-- cmv 13/10/98 */
1035void Services2NObjMgr::FillGFD(string& nom, string& expx, string& expy, string& expz,
1036 string& experr, string& expcut, string& nomgfd, string loop)
1037// Pour remplir un ``GeneralFitData'' a partir de divers objets:
1038//| nom = nom de l'objet a transcrire selon 1D: Z=f(X) ou 2D: Z=f(X,Y) .
1039//| Vector,Matrix,Histo,HProf,Histo2D,Image<T>,StarList,NTuple,GeneralFitData
1040//| expx = expression X du GeneralFitData (1er abscisse)
1041//| expy = expression Y du GeneralFitData (2sd abscisse si non "", Z=f(X,Y))
1042//| expz = expression Z du GeneralFitData (valeur de l'ordonnee)
1043//| experr = expression de l'erreur sur l'ordonnee Z
1044//| expcut = expression du test de selection
1045//| nomgfd = nom du GeneralFitData engendre (optionnel)
1046{
1047NObjMgrAdapter* obja=NULL;
1048obja = MyObjMgr()->GetObjAdapter(nom);
1049if (obja == NULL) {
1050 cout << "Services2NObjMgr::FillGFD() Error , No such object "<<nom<<endl;
1051 return;
1052 }
1053if(!mImgapp) return;
1054
1055// 2D ou 3D?
1056int nvar = 2;
1057if(expy.length()<=0) {nvar = 1; expy = "0.";}
1058
1059// Creation NTuple Buffer
1060char* ntn[4]= {"x","y","f","e"};
1061NTuple*nt = new NTuple(4,ntn);
1062
1063// Remplissage NTuple buffer
1064ComputeExpressions(obja, expx, expy, expz, experr, expcut, loop, nt, NULL, NULL);
1065if(nt->NEntry() < 1)
1066 {cout<<"Services2NObjMgr::FillGFD() Warning Zero points satisfy cut !"<<endl;
1067 delete nt; return;}
1068
1069//Remplissage de la structure GeneraFitData
1070if (nt->NEntry() <= 0) {
1071 cout<<"Services2NObjMgr::FillGFD() Warning - NData= " << nt->NEntry() << endl;
1072 delete nt;
1073 return;
1074 }
1075
1076GeneralFitData* gfd = new GeneralFitData(nvar,nt->NEntry(),0);
1077int k;
1078float* xn;
1079for(k=0; k<nt->NEntry(); k++) {
1080 xn = nt->GetVec(k);
1081 gfd->AddData(xn,xn[2],xn[3]);
1082}
1083
1084// Menage et table d'objets
1085delete nt;
1086MyObjMgr()->AddObj(gfd, nomgfd);
1087return;
1088}
1089
1090/* --Methode-- cmv 12/07/00 */
1091void Services2NObjMgr::FillGFDfrVec(string nomgfd,string namx,string namy,string namz,string name)
1092// Pour remplir un ``GeneralFitData'' a partir de vecteurs
1093//| gdfrvec nomgd X Y ! !
1094//| gdfrvec nomgd X Y ! EY
1095//| gdfrvec nomgd X Y Z !
1096//| gdfrvec nomgd X Y Z EZ
1097//| - nomgfd = nom du generaldata a remplir
1098//| - namx = nom du vecteur contenant les valeurs X
1099//| - namy = nom du vecteur contenant les valeurs Y
1100//| - namz = nom du vecteur contenant les valeurs Z (ou "!")
1101//| - name = nom du vecteur contenant les valeurs des erreurs EY ou EZ
1102{
1103// Decodage des noms des vecteurs pour le remplissage du generaldata
1104if(nomgfd=="!" || nomgfd.length()<1)
1105 {cout<<"FillGFDfrVec_Error: bad GenaralData name "<<nomgfd<<endl; return;}
1106if(namx=="!" || namx.length()<1)
1107 {cout<<"FillGFDfrVec_Error: bad X vector name "<<namx<<endl; return;}
1108if(namy=="!" || namy.length()<1)
1109 {cout<<"FillGFDfrVec_Error: bad Y vector name "<<namy<<endl; return;}
1110if(namz.length()<1) namz = "!";
1111if(name.length()<1) name = "!";
1112int nvar = 0;
1113if(namz=="!") nvar = 1; else nvar = 2;
1114
1115// Identify data
1116NamedObjMgr omg;
1117AnyDataObj* mobj = NULL;
1118Vector* v;
1119int nel = 0;
1120r_8 *x=NULL, *y=NULL, *z=NULL,* ez=NULL;
1121
1122if( (mobj=omg.GetObj(namx)) == NULL) {
1123 cout<<"FillGFDfrVec_Error: unknown X object "<<namx<<endl; return;
1124} else {
1125 v = (Vector*) mobj; x = v->Data(); nel=v->NElts();
1126}
1127
1128if( (mobj=omg.GetObj(namy)) == NULL) {
1129 cout<<"FillGFDfrVec_Error: unknown Y object "<<namy<<endl; return;
1130} else {
1131 v = (Vector*) mobj; y = z = v->Data(); if(v->NElts()<nel) nel=v->NElts();
1132}
1133
1134if( nvar==2 && (mobj=omg.GetObj(namz)) == NULL) {
1135 cout<<"FillGFDfrVec_Error: unknown Z object "<<namz<<endl; return;
1136} else {
1137 v = (Vector*) mobj; z = v->Data(); if(v->NElts()<nel) nel=v->NElts();
1138}
1139
1140if(name!="!") {
1141 if( (mobj=omg.GetObj(name)) == NULL) {
1142 cout<<"FillGFDfrVec_Error: unknown EZ object "<<name<<endl; return;
1143 } else {
1144 v = (Vector*) mobj; ez = v->Data(); if(v->NElts()<nel) nel=v->NElts();
1145 }
1146}
1147
1148if(nel<=0)
1149 {cout<<"FillGFDfrVec_Error: bad number of elements "<<nel<<endl; return;}
1150
1151// Create GeneralData and fill it with vectors
1152GeneralFitData* gfd = new GeneralFitData(nvar,nel+5,0);
1153if(nvar==1) gfd->SetData1(nel,x,z,ez); // On remplit Y=f(X)
1154else gfd->SetData2(nel,x,y,z,ez); // On remplit Z=f(X,y)
1155
1156// Menage et table d'objets
1157if( omg.GetObj(nomgfd) != NULL ) omg.DelObj(nomgfd);
1158MyObjMgr()->AddObj(gfd,nomgfd);
1159return;
1160}
1161
1162/* --Methode-- */
1163void Services2NObjMgr::ComputeExpressions(NObjMgrAdapter* obja, string& expx,
1164 string& expy, string& expz, string& expt, string& expcut, string& loop,
1165 NTuple* nt, Histo* h1, Histo2D* h2, HProf* hp)
1166{
1167if (obja == NULL) return;
1168bool adel = true;
1169NTupleInterface* objnt = obja->GetNTupleInterface(adel);
1170if (objnt == NULL) return;
1171string vardec = objnt->VarList_C("_zz6qi_");
1172
1173PlotExprFunc f = LinkExprFunc(vardec, expx, expy, expz, expt, expcut);
1174if (!f) {
1175 cerr << "Services2NObjMgr::::ComputeExpressions() Error Creation PlotExprFunc " << endl;
1176 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
1177 return;
1178 }
1179
1180double xnt[10];
1181float fxnt[10];
1182
1183int_8 k;
1184for(k=0; k<10; k++) xnt[k] = 0.;
1185int_8 k1,k2,dk;
1186k1 = 0; k2 = objnt->NbLines(); dk = 1;
1187DecodeLoopParameters(loop, k1, k2, dk);
1188if (k1 < 0) k1 = 0;
1189if (k2 < 0) k2 = objnt->NbLines();
1190if (k2 > (int_8)objnt->NbLines()) k2 = objnt->NbLines();
1191if (dk <= 0) dk = 1;
1192
1193try {
1194 double* xn;
1195 for(k=k1; k<k2; k += dk) {
1196 xn = objnt->GetLineD(k);
1197 if (f((int_8_exprf)k,xn, xnt, xnt+1, xnt+2, xnt+3) != 0) {
1198 if (nt) {
1199 for(int i=0; i<4; i++) fxnt[i] = xnt[i];
1200 nt->Fill(fxnt);
1201 }
1202 if (h1) h1->Add(xnt[0], xnt[3]);
1203 if (h2) h2->Add(xnt[0], xnt[1], xnt[3]);
1204 if (hp) hp->Add(xnt[0], xnt[1], xnt[3]);
1205 }
1206 }
1207 }
1208#ifdef SANS_EVOLPLANCK
1209CATCH(merr) {
1210 fflush(stdout);
1211 cout << endl;
1212 cerr << endl;
1213 string es = PeidaExc(merr);
1214 cerr << "Services2NObjMgr::ComputeExpressions() Exception :" << merr << es;
1215 } ENDTRY;
1216#else
1217catch ( PException exc ) {
1218 fflush(stdout);
1219 cout << endl;
1220 cerr << endl;
1221 cerr << "Services2NObjMgr::ComputeExpressions() Exception :" << exc.Msg() << endl;
1222}
1223#endif
1224
1225if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
1226// Fermeture du fichier .so
1227CloseDLL();
1228return;
1229}
1230
1231
1232/* --Methode-- */
1233PlotExprFunc Services2NObjMgr::LinkExprFunc(string& vardec, string& expx, string& expy,
1234 string& expz, string& expt, string& cut)
1235{
1236FILE *fip;
1237string fname = TmpDir + "expf_pia_dl.c";
1238string cmd;
1239int rc;
1240
1241cmd = "rm -f " + fname;
1242rc = system(cmd.c_str());
1243//DBG printf("LinkExprFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
1244
1245if ((fip = fopen(fname.c_str(), "w")) == NULL) {
1246 string sn = fname;
1247 cout << "Services2NObjMgr/LinkExprFunc_Error: fopen( " << sn << endl;
1248 return(NULL);
1249 }
1250
1251// constitution du fichier a compiler
1252fputs("#include <stdlib.h> \n", fip);
1253fputs("#include <math.h> \n", fip);
1254
1255fputs("/* ------ Compare bits on double --------- */ \n", fip);
1256fputs("typedef long long int_8_exprf;\n", fip);
1257fputs("int_8_exprf BitCmp64(double v,int_8_exprf flg)\n", fip);
1258fputs("{return ((int_8_exprf)((v<0.) ? v-0.1 : v+0.1))&flg;}\n", fip);
1259fputs("/* ------ Some random number generators --------- */ \n", fip);
1260fputs("#if defined(__ppc__) && defined(__MACH__) \n",fip);
1261fputs("#include <limits.h> \n", fip);
1262fputs("#define drand48() ((double)(random())/LONG_MAX) \n",fip);
1263fputs("#endif \n",fip);
1264fputs("#define frand01() ( (float) drand48() ) \n", fip);
1265fputs("#define drand01() drand48() \n", fip);
1266fputs("#define rand01() drand48() \n", fip);
1267fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
1268fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
1269fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
1270fputs("double NorRand(void) \n", fip);
1271fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
1272fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
1273fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
1274fputs(" return(x); \n } \n", fip);
1275fputs("#define GauRand() NorRand() \n", fip);
1276fputs("#define gaurand() NorRand() \n\n", fip);
1277
1278fputs("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);
1279fprintf(fip,"%s \n", vardec.c_str());
1280fprintf(fip, "if (!(%s)) { *_rx_6q_ = *_ry_6q_ = *_rz_6q_ = *_rt_6q_ = 0.; return(0); } \n", cut.c_str());
1281fprintf(fip, "*_rx_6q_ = %s ; \n", expx.c_str());
1282fprintf(fip, "*_ry_6q_ = %s ; \n", expy.c_str());
1283fprintf(fip, "*_rz_6q_ = %s ; \n", expz.c_str());
1284fprintf(fip, "*_rt_6q_ = %s ; \n", expt.c_str());
1285fputs("return(1); \n} \n", fip);
1286fclose(fip);
1287string func = "expf_pia_dl_func";
1288return((PlotExprFunc)LinkFunctionFromFile(fname, func));
1289}
1290
1291
1292/* --Methode-- */
1293DlFunction Services2NObjMgr::LinkFunctionFromFile(string const & fname, string const & funcname)
1294{
1295// Le link dynamique
1296CloseDLL();
1297dynlink = PDynLinkMgr::BuildFromCFile(fname);
1298if (dynlink == NULL) {
1299 cerr << "Services2NObjMgr/LinkFunctionFromFile_Erreur: Erreur creation/Ouverture SO " << endl;
1300 return(NULL);
1301 }
1302
1303DlFunction retfunc = dynlink->GetFunction(funcname);
1304if (retfunc == NULL) {
1305 string sn = funcname;
1306 cerr << "Services2NObjMgr/LinkExprFunc_Erreur: Erreur linking " << sn << endl;
1307 CloseDLL();
1308 return(NULL);
1309 }
1310else return(retfunc);
1311}
1312
1313/* --Methode-- */
1314void Services2NObjMgr::CloseDLL()
1315{
1316if (dynlink) delete dynlink; dynlink = NULL;
1317}
1318
1319/* --Methode-- */
1320int Services2NObjMgr::ExecuteCommand(string line)
1321{
1322 if (mImgapp == NULL) return(99);
1323 return(mImgapp->CmdInterpreter()->Interpret(line));
1324}
1325
1326// Fonction static
1327/* --Methode-- */
1328void Services2NObjMgr::DecodeLoopParameters(string& loop, int_8& i1, int_8& i2, int_8& di)
1329{
1330// Decode des paramatres de boucle for(int i=i1; i<i2; i+=di) specifies
1331// sous forme i1[:i2[:di]]
1332// cout << "LoopParam() " << loop << " I1=" << i1 << " I2=" << i2 << " DI=" << di;
1333size_t l = loop.length();
1334if (l < 1) return;
1335size_t p = loop.find(':');
1336if (p >= l) { i1 = atol(loop.c_str()); return; }
1337i1 = atol(loop.substr(0, p).c_str());
1338string aa = loop.substr(p+1);
1339p = aa.find(':');
1340if (p < aa.length() ) {
1341 i2 = atol(aa.substr(0,p).c_str());
1342 di = atol(aa.substr(p+1).c_str());
1343 }
1344else i2 = atol(aa.c_str());
1345// cout << "-> I1= " << i1 << " I2= " << i2 << " DI= " << di << endl;
1346return;
1347}
1348
1349/* --Methode-- */
1350string Services2NObjMgr::FileName2Name(string const & fn)
1351{
1352
1353char fsep[2] = {FILESEP, '\0'};
1354char tsep[2] = {'.', '\0'};
1355size_t p = fn.find_last_of(fsep);
1356size_t l = fn.length();
1357if (p >= l) p = 0;
1358else p++;
1359size_t q = fn.find_first_of(tsep,p);
1360if (q < p) q = l;
1361return(fn.substr(p,q-p));
1362}
1363
1364
1365
1366
1367// SANS_EVOLPLANCK Attention !
1368#ifdef SANS_EVOLPLANCK
1369#include "pclassids.h"
1370
1371/* --Methode-- */
1372char* Services2NObjMgr::PClassIdToClassName(int cid)
1373{
1374switch (cid) {
1375 case ClassId_Poly1 :
1376 return("Poly1");
1377 case ClassId_Poly2 :
1378 return("Poly2");
1379 case ClassId_Matrix :
1380 return("Matrix");
1381 case ClassId_Vector :
1382 return("Vector");
1383
1384 case ClassId_DVList :
1385 return("DVList");
1386
1387 case ClassId_Histo1D :
1388 return("Histo1D");
1389 case ClassId_Histo2D :
1390 return("Histo2D");
1391 case ClassId_HProf :
1392 return("HProf");
1393 case ClassId_HistoErr :
1394 return("HistoErr");
1395 case ClassId_NTuple :
1396 return("NTuple");
1397 case ClassId_XNTuple :
1398 return("XNTuple");
1399 case ClassId_GeneralFitData :
1400 return("GeneralFitData");
1401
1402 case ClassId_Image :
1403 return("RzImage");
1404 case ClassId_Image + kuint_1 :
1405 return("ImageU1");
1406 case ClassId_Image + kint_1 :
1407 return("ImageI1");
1408 case ClassId_Image + kuint_2 :
1409 return("ImageU2");
1410 case ClassId_Image + kint_2 :
1411 return("ImageI2");
1412 case ClassId_Image + kuint_4 :
1413 return("ImageU4");
1414 case ClassId_Image + kint_4 :
1415 return("ImageI4");
1416 case ClassId_Image + kr_4 :
1417 return("ImageR4");
1418 case ClassId_Image + kr_8 :
1419 return("ImageR8");
1420 case ClassId_ZFidu :
1421 return("ZFidu");
1422
1423 case ClassId_StarList :
1424 return("StarList");
1425 case ClassId_Transfo :
1426 return("Transfo");
1427 case ClassId_PSF :
1428 return("PSF");
1429
1430
1431// - Ajout objet PPF
1432 default:
1433 return("AnyDataObj");
1434 }
1435}
1436
1437#else
1438char* Services2NObjMgr::PClassIdToClassName(int cid)
1439{
1440 return("AnyDataObj");
1441}
1442#endif
Note: See TracBrowser for help on using the repository browser.