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

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

1/ Separation de basexecut.cc en deux : commandes graphiques mises ds graphexecut.cc .h
2/ Finalisation commandes bargraph et textdrawer ds graphexecut.cc
3/ Adaptation piacmd.cc , suppression limite a 250 ds func2d et MAJ MAkefile et objlist.list

Reza 30 Mai 2005

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