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

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

1-/ pour n/proj pas de display si histo existe ET pas d'option graphiques donnees
2-/ gestion correcte de la superposition d'histo 1D dans n/plot nt.x

L'histo pour le 2ieme display est dimensionne comme le premier.

(ajout de l'option graphique keepbin)

cmv 20/04/2005

File size: 40.4 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"
36#include "ntuple.h"
37#include "hisprof.h"
38
[1905]39#include "piyfxdrw.h"
[326]40#include "pisurfdr.h"
[333]41
42#include "pintuple.h"
43#include "pintup3d.h"
44
[326]45#include "pipodrw.h"
[165]46
47
[326]48
[165]49/* --Methode-- */
[2491]50Services2NObjMgr::Services2NObjMgr(string& tmpdir)
[165]51{
[1276]52SetTmpDir(tmpdir);
[333]53mImgapp = NULL;
[2491]54mOmg = NULL;
[171]55dynlink = NULL;
[165]56}
57
58/* --Methode-- */
59Services2NObjMgr::~Services2NObjMgr()
60{
61CloseDLL();
[2491]62if (mOmg) delete mOmg;
[165]63}
64
65/* --Methode-- */
[295]66void Services2NObjMgr::RegisterClass(AnyDataObj* o, NObjMgrAdapter* oa)
[165]67{
[295]68ObjAdaptList::iterator it;
69for(it = objadaplist.begin(); it != objadaplist.end(); it++)
[495]70#ifdef SANS_EVOLPLANCK
[295]71 if (typeid(*o) == typeid(*((*it).obj))) THROW(dupIdErr);
[495]72#else
73 if (typeid(*o) == typeid(*((*it).obj)))
74 throw(DuplicateIdExc("Services2NObjMgr::RegisterClass() - Duplicate class"));
75#endif
[295]76dataobj_adapter oba;
77oba.obj = o;
78oba.obja = oa;
79objadaplist.push_back(oba);
80}
[165]81
[295]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}
[165]90
[295]91/* --Methode-- */
[1276]92void Services2NObjMgr::SetTmpDir(string const & tmpdir)
93{
94TmpDir = tmpdir;
95PDynLinkMgr::SetTmpDir(tmpdir);
96return;
97}
98
99/* --Methode-- */
[333]100void Services2NObjMgr::PlotFunc(string const & expfunc, string & nom, double xmin, double xmax, int np, string dopt)
[295]101{
[165]102FILE *fip;
[326]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;
[449]115 cout << "Services2NObjMgr/PlotFunc_Error: fopen( " << sn << endl;
[326]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;
[333]128PlotFunc(f, nom, xmin, xmax, np, dopt);
[326]129CloseDLL();
130return;
131}
132
133/* --Methode-- */
[333]134void Services2NObjMgr::PlotFunc2D(string const & expfunc, string & nom, double xmin, double xmax,
135 double ymin, double ymax, int npx, int npy, string dopt)
[326]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;
[449]150 cout << "Services2NObjMgr/PlotFunc2D_Error: fopen( " << sn << endl;
[326]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;
[333]163PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt);
[326]164CloseDLL();
165return;
166}
167
168/* --Methode-- */
[333]169void Services2NObjMgr::PlotFuncFrCFile(string const & fname, string const & func, string & nom,
170 double xmin, double xmax, int np, string dopt)
[326]171{
172DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);
173if (!f) return;
[333]174PlotFunc(f, nom, xmin, xmax, np, dopt);
[326]175CloseDLL();
176return;
177}
178
179/* --Methode-- */
[333]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)
[326]182{
183DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);
184if (!f) return;
[333]185PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt);
[326]186CloseDLL();
187return;
188}
189
190/* --Methode-- */
[333]191void Services2NObjMgr::PlotFunc(DlFunctionOfX f, string & nom, double xmin, double xmax, int np, string dopt)
[326]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;
[500]202
203try {
204 for(k=0; k<np; k++) { xx = xmin+dx*k; (*vpy)(k) = f(xx); }
205}
[495]206#ifdef SANS_EVOLPLANCK
[500]207CATCH(merr) {
[326]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;
[495]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
[326]226
227if (vpy) {
[344]228 string titre;
229 if (nom.length() < 1) {
230 titre = "Function f(x)";
[466]231 nom = "/autoc/f_x";
[344]232 }
233 else titre = nom;
234
235 P1DArrayAdapter* vya = new POVectorAdapter(vpy, false);
[326]236 vya->DefineXCoordinate(xmin, (xmax-xmin)/np);
237 PIYfXDrawer* dr = new PIYfXDrawer(vya, NULL, true) ;
[1971]238 dopt = "thinline " + dopt;
239 int rsid = mImgapp->DispScDrawer(dr, titre, dopt);
[333]240 if (nom.length() > 0) {
[2491]241 MyObjMgr()->AddObj(vpy, nom);
242 MyObjMgr()->AddWRsId(nom, rsid);
[333]243 }
[326]244 }
245return;
246}
247
248/* --Methode-- */
[333]249void Services2NObjMgr::PlotFunc2D(DlFunctionOfXY f, string & nom, double xmin, double xmax, double ymin, double ymax,
[326]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);
[500]268try {
[326]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 }
[500]276}
277#ifdef SANS_EVOLPLANCK
278CATCH(merr) {
[326]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;
[495]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
[326]295
296if (mtx) {
[344]297 string titre;
298 if (nom.length() < 1) {
299 titre = "Function f(x,y)";
[466]300 nom = "/autoc/f2d_xy";
[344]301 }
302 else titre = nom;
303 P2DArrayAdapter* arr = new POMatrixAdapter(mtx, false);
[326]304 arr->DefineXYCoordinates(xmin, ymin, dx, dy);
305 PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
[1971]306 int rsid = mImgapp->Disp3DDrawer(sdr, titre, dopt);
[333]307 if (nom.length() > 0) {
[2491]308 MyObjMgr()->AddObj(mtx, nom);
309 MyObjMgr()->AddWRsId(nom, rsid);
[333]310 }
[326]311 }
312
313return;
314}
315
316/* --Methode-- */
[2180]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
[2491]331 DVList& varlist = MyObjMgr()->GetVarList();
[2180]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) {
[2491]367 if(MyObjMgr()->HasVar(resultvarname)) MyObjMgr()->DeleteVar(resultvarname);
[2180]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 }
[2491]375 MyObjMgr()->SetVar(resultvarname,(string)str);
[2180]376 } else cout<<result<<" = "<<expval<<endl;
377
378}
379
380/* --Methode-- */
[333]381void Services2NObjMgr::DisplayPoints2D(string& nom, string& expx, string& expy,
382 string& experrx, string& experry,
[357]383 string& expcut, string dopt, string loop)
[333]384{
385NObjMgrAdapter* obja=NULL;
[2491]386obja = MyObjMgr()->GetObjAdapter(nom);
[333]387if (obja == NULL) {
[449]388 cout << "Services2NObjMgr::DisplayPoints2D() Error , No such object " << nom << endl;
[333]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
[357]401ComputeExpressions(obja, expx, expy, experrx, experry, expcut, loop, nt, NULL, NULL);
[333]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
[1971]415dopt = "defline " + dopt;
[333]416string titre = nom + ":" + expy + "%" + expx;
[1971]417mImgapp->DispScDrawer( (PIDrawer*)pin, titre, dopt);
[333]418return;
419}
420
421/* --Methode-- */
422void Services2NObjMgr::DisplayPoints3D(string& nom, string& expx, string& expy,
[357]423 string& expz, string& expcut, string dopt, string loop)
[333]424{
425NObjMgrAdapter* obja=NULL;
[2491]426obja = MyObjMgr()->GetObjAdapter(nom);
[333]427if (obja == NULL) {
[449]428 cout << "Services2NObjMgr::DisplayPoints3D() Error , No such object " << nom << endl;
[333]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.";
[357]437ComputeExpressions(obja, expx, expy, expz, expwt, expcut, loop, nt, NULL, NULL);
[333]438
439if (nt->NEntry() < 1) {
440 cout << "Services2NObjMgr::DisplayPoints3D() Warning Zero points satisfy cut !" << endl;
441 delete nt;
442 return;
443 }
[2494]444//DBG nt->Show();
445//DBG nt->Print(0,10);
[333]446PINTuple3D* pin = new PINTuple3D(nt, true);
447pin->SelectXYZ(ntn[0], ntn[1], ntn[2]);
[1971]448dopt = "defline " + dopt;
[333]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;
[1971]455mImgapp->Disp3DDrawer(pin, titre, dopt);
[333]456
457return;
458}
459
460/* --Methode-- */
461void Services2NObjMgr::DisplayPoints2DW(string& nom, string& expx, string& expy,
[357]462 string& expwt, string& expcut, string dopt, string loop)
[333]463{
464NObjMgrAdapter* obja=NULL;
[2491]465obja = MyObjMgr()->GetObjAdapter(nom);
[333]466if (obja == NULL) {
[449]467 cout << "Services2NObjMgr::DisplayPoints2DW() Error , No such object " << nom << endl;
[333]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.";
[357]476ComputeExpressions(obja, expx, expy, expwt, exp, expcut, loop, nt, NULL, NULL);
[333]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 ;
[1971]489mImgapp->DispScDrawer( (PIDrawer*)pin, titre, dopt);
[333]490return;
491}
492
493/* --Methode-- */
494void Services2NObjMgr::ProjectH1(string& nom, string& expx, string& expwt,
[357]495 string& expcut, string& nomh1, string dopt, string loop)
[333]496{
497NObjMgrAdapter* obja=NULL;
[2491]498obja = MyObjMgr()->GetObjAdapter(nom);
[333]499if (obja == NULL) {
[449]500 cout << "Services2NObjMgr::ProjectH1() Error , No such object " << nom << endl;
[333]501 return;
[2681]502}
[333]503if (!mImgapp) return;
504
505Histo* h1 = NULL;
506NTuple* nt = NULL;
507AnyDataObj* oh = NULL;
[2679]508bool h1_already_exist = false;
[2491]509if (nomh1.length() > 0) oh=MyObjMgr()->GetObj(nomh1);
[333]510else nomh1 = "/tmp/projh1d";
[2679]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 {
[333]516 char* ntn[2]= {"hxval", "hwt"};
517 nt = new NTuple(2,ntn); // Creation NTuple
[2681]518}
[333]519string expz = "0.";
[357]520ComputeExpressions(obja, expx, expwt, expz, expwt, expcut, loop, nt, h1, NULL);
[333]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;
[2681]528 }
[333]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]);
[2681]537 }
[333]538 delete nt;
[2491]539 MyObjMgr()->AddObj(h1, nomh1);
[2681]540}
[333]541
[2681]542if(!h1_already_exist || dopt.size()>0) MyObjMgr()->DisplayObj(nomh1, dopt);
[333]543return;
544}
545
546/* --Methode-- */
547void Services2NObjMgr::ProjectH2(string& nom, string& expx, string& expy, string& expwt,
[357]548 string& expcut, string& nomh2, string dopt, string loop)
[333]549{
550NObjMgrAdapter* obja=NULL;
[2491]551obja = MyObjMgr()->GetObjAdapter(nom);
[333]552if (obja == NULL) {
[449]553 cout << "Services2NObjMgr::ProjectH2() Error , No such object " << nom << endl;
[333]554 return;
[2681]555}
[333]556if (!mImgapp) return;
557
558Histo2D* h2 = NULL;
559NTuple* nt = NULL;
560AnyDataObj* oh = NULL;
[2679]561bool h2_already_exist = false;
[2491]562if (nomh2.length() > 0) oh=MyObjMgr()->GetObj(nomh2);
[333]563else nomh2 = "/tmp/projh2d";
[2679]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 {
[333]569 char* ntn[3]= {"hxval", "hyval", "hwt"};
570 nt = new NTuple(3,ntn); // Creation NTuple
[2681]571}
[333]572string expz = "0.";
[357]573ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, loop, nt, NULL, h2);
[333]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;
[2681]581 }
[333]582 double xmin, xmax, ymin, ymax;
583 nt->GetMinMax(0, xmin, xmax);
[466]584 nt->GetMinMax(1, ymin, ymax);
[333]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]);
[2681]591 }
[333]592 delete nt;
[2491]593 MyObjMgr()->AddObj(h2, nomh2);
[2681]594}
[333]595
[2681]596if(!h2_already_exist || dopt.size()>0) MyObjMgr()->DisplayObj(nomh2, dopt);
[333]597return;
598
599}
600
601/* --Methode-- cmv 13/10/98 */
602void Services2NObjMgr::ProjectHProf(string& nom, string& expx, string& expy, string& expwt,
[357]603 string& expcut, string& nomprof, string dopt, string loop)
604// Pour remplir un ``GeneralFitData'' a partir de divers objets:
[333]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;
[2491]616obja = MyObjMgr()->GetObjAdapter(nom);
[333]617if (obja == NULL) {
[449]618 cout << "Services2NObjMgr::ProjectHProf() Error , No such object " << nom << endl;
[333]619 return;
[2681]620}
[333]621if (!mImgapp) return;
622
623HProf* hprof = NULL;
624NTuple* nt = NULL;
625AnyDataObj* oh = NULL;
[2679]626bool hp_already_exist = false;
[2491]627if (nomprof.length() > 0) oh=MyObjMgr()->GetObj(nomprof);
[333]628else nomprof = "/tmp/projprof";
[2679]629if( (oh!=NULL) && (typeid(*oh) == typeid(HProf)) ) {
630 hprof = (HProf*)oh;
631 hp_already_exist = true;
632} else {
[333]633 char* ntn[3]= {"hxval", "hyval", "hwt"};
634 nt = new NTuple(3,ntn); // Creation NTuple
635}
636string expz = "0.";
[357]637ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, loop, nt, NULL, NULL, hprof);
[333]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 }
[1091]646 r_8 xmin, xmax;
[333]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]);
[2681]654 }
[333]655 delete nt;
[2491]656 MyObjMgr()->AddObj(hprof, nomprof);
[2681]657}
[1090]658hprof->UpdateHisto();
[333]659
[2681]660if(!hp_already_exist || dopt.size()>0) MyObjMgr()->DisplayObj(nomprof, dopt);
[333]661return;
662}
663
[357]664
[333]665/* --Methode-- */
[357]666void Services2NObjMgr::FillVect(string& nom, string& expx, string& expv,
667 string& expcut, string& nomvec, string dopt, string loop)
[333]668{
669NObjMgrAdapter* obja=NULL;
[2491]670obja = MyObjMgr()->GetObjAdapter(nom);
[333]671if (obja == NULL) {
[357]672 cout << "Services2NObjMgr::FillVect() Error , No such object: " << nom << endl;
[333]673 return;
674 }
675if (!mImgapp) return;
676
[357]677Vector* v1 = NULL;
678AnyDataObj* ov = NULL;
[2491]679ov=MyObjMgr()->GetObj(nomvec);
[357]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);
[2180]703 i = int(xn[0]+0.5);
[357]704 if ( (i < 0) || i >= v1->NElts() ) continue;
705 (*v1)(i) = xn[1];
706 }
707 delete nt;
708
709
[2491]710MyObjMgr()->DisplayObj(nomvec, dopt);
[357]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;
[2491]719obja = MyObjMgr()->GetObjAdapter(nom);
[357]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;
[2491]728om=MyObjMgr()->GetObj(nommtx);
[357]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);
[2180]752 ic = int(xn[0]+0.5);
753 jl = int(xn[1]+0.5);
[357]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
[2491]761MyObjMgr()->DisplayObj(nommtx, dopt);
[357]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;
[2491]771obja = MyObjMgr()->GetObjAdapter(nom);
[357]772if (obja == NULL) {
[449]773 cout << "Services2NObjMgr::ExpressionToVector() Error , No such object " << nom << endl;
[357]774 return;
775 }
776if (!mImgapp) return;
777
[333]778NTuple* nt = NULL;
[357]779if (nomvec.length() < 1) nomvec = "/tmp/expvec";
[333]780
781char* ntn[2]= {"vecval", "vecwt"};
782nt = new NTuple(1,ntn); // Creation NTuple
783
784string expwt = "1.";
[1486]785string expz = "0.";
786string dumexpcut = expcut; if(dumexpcut.size()<=0) dumexpcut = "1.";
787ComputeExpressions(obja,expx,expz,expz,expwt,dumexpcut,loop,nt,NULL,NULL);
[333]788
789if (!nt) return;
790if (nt->NEntry() < 1) {
[357]791 cout << "Services2NObjMgr::ExpressionToVector() Warning Zero points satisfy cut !" << endl;
[333]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;
[2491]804MyObjMgr()->AddObj(vec, nomvec);
805MyObjMgr()->DisplayObj(nomvec, dopt);
[333]806return;
807}
808
809/* --Methode-- */
[447]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{
[2491]816AnyDataObj* mobj = MyObjMgr()->GetObj(nom);
[447]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;
[449]826nt->FillFromASCIIFile(filename, def_val);
[447]827return;
828}
829
830/* --Methode-- */
[333]831void Services2NObjMgr::FillNT(string& nom, string& expx, string& expy, string& expz,
[357]832 string& expt, string& expcut, string& nomnt, string loop)
[333]833{
834NObjMgrAdapter* obja=NULL;
[2491]835obja = MyObjMgr()->GetObjAdapter(nom);
[333]836if (obja == NULL) {
[449]837 cout << "Services2NObjMgr::FillNT() Error , No such object " << nom << endl;
[333]838 return;
839 }
840if (!mImgapp) return;
841
842bool fgnnt = false;
843NTuple* nt = NULL;
844AnyDataObj* oh = NULL;
[2491]845if (nomnt.length() > 0) oh=MyObjMgr()->GetObj(nomnt);
[333]846else nomnt = "/tmp/fillnt";
847if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
848 nt = (NTuple*)oh;
849 if (nt->NVar() > 10) {
[449]850 cout << "Services2NObjMgr::FillNT() Warning , Max 10 var in NTuple -> new NTuple" << endl;
[333]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
[357]860ComputeExpressions(obja, expx, expy, expz, expt, expcut, loop, nt, NULL, NULL);
[333]861
[2491]862if (fgnnt) MyObjMgr()->AddObj(nt, nomnt);
[333]863return;
864
865}
866
867/* --Methode-- */
868void Services2NObjMgr::FillNTFrCFile(string & nom, string const & fname,
[357]869 string const & funcname, string & nomnt, string loop)
[333]870{
871if (!mImgapp) return;
872
873NObjMgrAdapter* obja=NULL;
[2491]874obja = MyObjMgr()->GetObjAdapter(nom);
[333]875if (obja == NULL) {
876 cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) No such object" <<endl;
877 return;
878 }
[344]879bool adel = true;
880NTupleInterface* objnt = obja->GetNTupleInterface(adel);
[333]881if (objnt == NULL) {
[449]882 cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) Not an NTupleInterface !" <<endl;
[333]883 return;
884 }
885
886NTLoopExprFunc f = (NTLoopExprFunc)LinkFunctionFromFile(fname, funcname);
887if (!f) {
888 cerr << "Services2NObjMgr::FillNTFrCFile Error Creation NTLoopExprFunc" << endl;
[344]889 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
[333]890 return;
891 }
892
893bool fgnnt = false;
894NTuple* nt = NULL;
895if (nomnt.length() > 0) {
896 AnyDataObj* oh = NULL;
[2491]897 oh=MyObjMgr()->GetObj(nomnt);
[333]898 if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
899 nt = (NTuple*)oh;
900 if (nt->NVar() > 10) {
[449]901 cout << "Services2NObjMgr::FillNTFrCFile() Warning , Max 10 var in NTuple -> new NTuple" << endl;
[333]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;
[2668]915for(i=0; i<10; i++) xnt[i] = 0.;
[333]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
[2419]923int_8 k1,k2,dk;
[357]924k1 = 0; k2 = objnt->NbLines(); dk = 1;
925DecodeLoopParameters(loop, k1, k2, dk);
926if (k1 < 0) k1 = 0;
927if (k2 < 0) k2 = objnt->NbLines();
[2419]928if (k2 > (int_8)objnt->NbLines()) k2 = objnt->NbLines();
[357]929if (dk <= 0) dk = 1;
930
[500]931try {
[333]932 double* xn;
[2419]933 int_8 kstart = k1, kend = k2;
934 for(k=kstart; k<kend; k+=dk) {
[333]935 xn = objnt->GetLineD(k);
[2419]936 if (f((int_8_exprf)k, xn, xnt, xnt+1, xnt+2, xnt+3, (int_8_exprf)kstart,(int_8_exprf) kend) != 0) {
[2668]937 if (nt) nt->Fill(xnt);
[333]938 }
939 }
940 }
[500]941#ifdef SANS_EVOLPLANCK
[333]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;
[500]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
[344]957
958if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
[333]959CloseDLL();
960
961// $CHECK$ A virer des que possible On redirige la sortie sur la fenetre PIConsole
962mImgapp->RedirectStdOutErr(red);
963
[2491]964if (fgnnt) MyObjMgr()->AddObj(nt, nomnt);
[333]965return;
966}
967
968/* --Methode-- */
969void Services2NObjMgr::PrepareNTExpressionCFile(string & nom, string const & fname,
970 string const & funcname)
971{
972NObjMgrAdapter* obja=NULL;
[2491]973obja = MyObjMgr()->GetObjAdapter(nom);
[333]974if (obja == NULL) {
975 cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom << "...) No such object" <<endl;
976 return;
977 }
[344]978bool adel = true;
979NTupleInterface* objnt = obja->GetNTupleInterface(adel);
[333]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;
[344]990 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
[333]991 return;
992 }
[344]993
[333]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);
[344]998
[1469]999fputs("/* ------ Compare bits on double --------- */ \n", fip);
[2419]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);
[344]1003fputs("/* ------ Some random number generators --------- */ \n", fip);
[1931]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);
[344]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);
[345]1017fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
[344]1018fputs(" return(x); \n } \n", fip);
1019fputs("#define GauRand() NorRand() \n", fip);
1020fputs("#define gaurand() NorRand() \n\n", fip);
1021
[2419]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",
[333]1026 funcname.c_str());
[2419]1027fprintf(fip," double* _rt_, int_8_exprf _nstart, int_8_exprf _nend) \n");
[333]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);
[344]1036
1037if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
[333]1038return;
1039}
1040
1041/* --Methode-- cmv 13/10/98 */
1042void Services2NObjMgr::FillGFD(string& nom, string& expx, string& expy, string& expz,
[357]1043 string& experr, string& expcut, string& nomgfd, string loop)
[333]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;
[2491]1055obja = MyObjMgr()->GetObjAdapter(nom);
[333]1056if (obja == NULL) {
[449]1057 cout << "Services2NObjMgr::FillGFD() Error , No such object "<<nom<<endl;
[333]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
[357]1071ComputeExpressions(obja, expx, expy, expz, experr, expcut, loop, nt, NULL, NULL);
[333]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;
[2491]1093MyObjMgr()->AddObj(gfd, nomgfd);
[333]1094return;
1095}
1096
[1067]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;
[333]1121
[1067]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);
[2491]1165MyObjMgr()->AddObj(gfd,nomgfd);
[1067]1166return;
1167}
1168
[333]1169/* --Methode-- */
1170void Services2NObjMgr::ComputeExpressions(NObjMgrAdapter* obja, string& expx,
[357]1171 string& expy, string& expz, string& expt, string& expcut, string& loop,
[333]1172 NTuple* nt, Histo* h1, Histo2D* h2, HProf* hp)
1173{
1174if (obja == NULL) return;
[344]1175bool adel = true;
1176NTupleInterface* objnt = obja->GetNTupleInterface(adel);
[333]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;
[344]1183 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
[333]1184 return;
1185 }
1186
1187double xnt[10];
1188
[2419]1189int_8 k;
1190for(k=0; k<10; k++) xnt[k] = 0.;
1191int_8 k1,k2,dk;
[357]1192k1 = 0; k2 = objnt->NbLines(); dk = 1;
1193DecodeLoopParameters(loop, k1, k2, dk);
1194if (k1 < 0) k1 = 0;
1195if (k2 < 0) k2 = objnt->NbLines();
[2419]1196if (k2 > (int_8)objnt->NbLines()) k2 = objnt->NbLines();
[357]1197if (dk <= 0) dk = 1;
[500]1198
1199try {
[333]1200 double* xn;
[357]1201 for(k=k1; k<k2; k += dk) {
[333]1202 xn = objnt->GetLineD(k);
[2419]1203 if (f((int_8_exprf)k,xn, xnt, xnt+1, xnt+2, xnt+3) != 0) {
[2668]1204 if (nt) nt->Fill(xnt);
[333]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 }
[500]1211#ifdef SANS_EVOLPLANCK
[333]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;
[500]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
[333]1227
[344]1228if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
[333]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;
[449]1250 cout << "Services2NObjMgr/LinkExprFunc_Error: fopen( " << sn << endl;
[333]1251 return(NULL);
1252 }
1253
1254// constitution du fichier a compiler
1255fputs("#include <stdlib.h> \n", fip);
1256fputs("#include <math.h> \n", fip);
[344]1257
[1469]1258fputs("/* ------ Compare bits on double --------- */ \n", fip);
[2419]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);
[344]1262fputs("/* ------ Some random number generators --------- */ \n", fip);
[1931]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);
[344]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);
[345]1276fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
[344]1277fputs(" return(x); \n } \n", fip);
1278fputs("#define GauRand() NorRand() \n", fip);
1279fputs("#define gaurand() NorRand() \n\n", fip);
1280
[2419]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);
[333]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
[1319]1322/* --Methode-- */
1323int Services2NObjMgr::ExecuteCommand(string line)
1324{
1325 if (mImgapp == NULL) return(99);
1326 return(mImgapp->CmdInterpreter()->Interpret(line));
1327}
1328
[357]1329// Fonction static
1330/* --Methode-- */
[2419]1331void Services2NObjMgr::DecodeLoopParameters(string& loop, int_8& i1, int_8& i2, int_8& di)
[357]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(':');
[2419]1339if (p >= l) { i1 = atol(loop.c_str()); return; }
1340i1 = atol(loop.substr(0, p).c_str());
[357]1341string aa = loop.substr(p+1);
1342p = aa.find(':');
1343if (p < aa.length() ) {
[2419]1344 i2 = atol(aa.substr(0,p).c_str());
1345 di = atol(aa.substr(p+1).c_str());
[357]1346 }
[2419]1347else i2 = atol(aa.c_str());
[357]1348// cout << "-> I1= " << i1 << " I2= " << i2 << " DI= " << di << endl;
1349return;
1350}
[333]1351
1352/* --Methode-- */
[165]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);
[194]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;
[165]1364return(fn.substr(p,q-p));
1365}
1366
1367
[546]1368
[165]1369
[333]1370// SANS_EVOLPLANCK Attention !
[1105]1371#ifdef SANS_EVOLPLANCK
[333]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");
[2605]1396 case ClassId_HistoErr :
1397 return("HistoErr");
[333]1398 case ClassId_NTuple :
1399 return("NTuple");
[361]1400 case ClassId_XNTuple :
1401 return("XNTuple");
[333]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
[1105]1440#else
1441char* Services2NObjMgr::PClassIdToClassName(int cid)
1442{
1443 return("AnyDataObj");
1444}
1445#endif
Note: See TracBrowser for help on using the repository browser.