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

Last change on this file since 2419 was 2419, checked in by cmv, 22 years ago
  • introduction notion de numero de ligne dans expression ntuple modif prototype PlotExprFunc NTLoopExprFunc (add _nl _nstart _nend) modif int_4 -> int_8_exprf (long long) pour _nl (DecodeLoopParameters,

PrepareNTExpressionCFile, LinkExprFunc,...)

  • doc pour _nl _nstart _nend et arragement repartition RegisterHelp/RegisterCommand

(rz + cmv 21/7/2003)

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