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

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

1/ Correction bug trace des lignes ds PINTuple
2/ Ajout methode IsThreadable() (declaration conformite thread separe pour certaines commandes) ds baseexecut.h .cc (plot2d plot3d ...) , ds pawexecut.cc (n/plot ...) et ds cxxexecutor.h .cc (c++exec c++execfrf ...)
3/ Ajout de ZMutex (et ZSync) pour la gestion des commandes threadable - ds les
executeurs et ds servnobjm.h .cc
4/ bug d'execution en thread identifie et corrige ds nobjmgr.h .cc (ajout des
methodes GetObj_P() GetObjAdapter_P() et ReadObj_P()
5/ Ajout de l'appel a ZSync::NOp() pour eviter les warnings 'unused variable zs ...'

Reza 23 Mai 2005

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