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

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

spiapp cmd "newdt" pour creer une DataTable
spiapp cmd "n/read" modifier pour remplir aussi des DataTable (option -dt)
NtFromASCIIFile modifier pour remplir aussi des DataTable

mais le decodage FillFromASCII de la classe DataTAble est encore a faire

cmv 01/06/2005

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