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

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

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

Reza 30 Mai 2005

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