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

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

Ajout commande expmeansig pour TD/TP SurvEnv - Reza 27/3/2006

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