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

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

Petite modif/adaptation a BaseDataTable::FillFromASCIIFile() - Reza 8 Nov 2005

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