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

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

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

Reza 23 Mai 2005

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