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

Last change on this file since 1469 was 1469, checked in by cmv, 24 years ago

BitCmp64(double,long long) cmv 18/4/01

File size: 47.4 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <ctype.h>
4
5#include <typeinfo>
6#include <iostream.h>
7#include <string>
8#include <list>
9#include <map>
10
11#include "strutil.h"
12
13#include "nobjmgr.h"
14#include "servnobjm.h"
15#include "nomgadapter.h"
16#include "pistdimgapp.h"
17
18#include "fct1dfit.h"
19#include "fct2dfit.h"
20
21#ifdef SANS_EVOLPLANCK
22#include "matrix.h"
23#include "cvector.h"
24#else
25#include "tmatrix.h"
26#include "tvector.h"
27#include "pitvmaad.h"
28#endif
29
30#include "ntuple.h"
31#include "cimage.h"
32
33#include "histos.h"
34#include "histos2.h"
35#include "ntuple.h"
36#include "hisprof.h"
37
38#include "piscdrawwdg.h"
39#include "pisurfdr.h"
40
41#include "pintuple.h"
42#include "pintup3d.h"
43
44#include "pipodrw.h"
45
46
47
48/* --Methode-- */
49Services2NObjMgr::Services2NObjMgr(NamedObjMgr* omg, string& tmpdir)
50{
51SetTmpDir(tmpdir);
52mImgapp = NULL;
53mOmg = omg;
54dynlink = NULL;
55InitGrAttNames();
56}
57
58/* --Methode-- */
59Services2NObjMgr::~Services2NObjMgr()
60{
61CloseDLL();
62}
63
64/* --Methode-- */
65void Services2NObjMgr::RegisterClass(AnyDataObj* o, NObjMgrAdapter* oa)
66{
67ObjAdaptList::iterator it;
68for(it = objadaplist.begin(); it != objadaplist.end(); it++)
69#ifdef SANS_EVOLPLANCK
70 if (typeid(*o) == typeid(*((*it).obj))) THROW(dupIdErr);
71#else
72 if (typeid(*o) == typeid(*((*it).obj)))
73 throw(DuplicateIdExc("Services2NObjMgr::RegisterClass() - Duplicate class"));
74#endif
75dataobj_adapter oba;
76oba.obj = o;
77oba.obja = oa;
78objadaplist.push_back(oba);
79}
80
81/* --Methode-- */
82NObjMgrAdapter* Services2NObjMgr::GetAdapter(AnyDataObj* o)
83{
84ObjAdaptList::iterator it;
85for(it = objadaplist.begin(); it != objadaplist.end(); it++)
86 if (typeid(*o) == typeid(*((*it).obj))) return((*it).obja->Clone(o));
87return(new NObjMgrAdapter(o));
88}
89
90/* --Methode-- */
91void Services2NObjMgr::SetTmpDir(string const & tmpdir)
92{
93TmpDir = tmpdir;
94PDynLinkMgr::SetTmpDir(tmpdir);
95return;
96}
97
98/* --Methode-- */
99void Services2NObjMgr::PlotFunc(string const & expfunc, string & nom, double xmin, double xmax, int np, string dopt)
100{
101FILE *fip;
102string fname = TmpDir + "func1_pia_dl.c";
103string cmd;
104int rc;
105
106if (!mImgapp) return;
107
108cmd = "rm -f " + fname;
109rc = system(cmd.c_str());
110// printf("PlotFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
111
112if ((fip = fopen(fname.c_str(), "w")) == NULL) {
113 string sn = fname;
114 cout << "Services2NObjMgr/PlotFunc_Error: fopen( " << sn << endl;
115 return;
116 }
117
118// constitution du fichier a compiler
119fputs("#include <math.h> \n", fip);
120fputs("double func1_pia_dl_func(double x) \n{\n", fip);
121fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
122fclose(fip);
123
124string func = "func1_pia_dl_func";
125DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);
126if (!f) return;
127PlotFunc(f, nom, xmin, xmax, np, dopt);
128CloseDLL();
129return;
130}
131
132/* --Methode-- */
133void Services2NObjMgr::PlotFunc2D(string const & expfunc, string & nom, double xmin, double xmax,
134 double ymin, double ymax, int npx, int npy, string dopt)
135{
136FILE *fip;
137string fname = TmpDir + "func2_pia_dl.c";
138string cmd;
139int rc;
140
141if (!mImgapp) return;
142
143cmd = "rm " + fname;
144rc = system(cmd.c_str());
145// printf("PlotFunc2D_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
146
147if ((fip = fopen(fname.c_str(), "w")) == NULL) {
148 string sn = fname;
149 cout << "Services2NObjMgr/PlotFunc2D_Error: fopen( " << sn << endl;
150 return;
151 }
152
153// constitution du fichier a compiler
154fputs("#include <math.h> \n", fip);
155fputs("double func2_pia_dl_func(double x, double y) \n{\n", fip);
156fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
157fclose(fip);
158
159string func = "func2_pia_dl_func";
160DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);
161if (!f) return;
162PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt);
163CloseDLL();
164return;
165}
166
167/* --Methode-- */
168void Services2NObjMgr::PlotFuncFrCFile(string const & fname, string const & func, string & nom,
169 double xmin, double xmax, int np, string dopt)
170{
171DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);
172if (!f) return;
173PlotFunc(f, nom, xmin, xmax, np, dopt);
174CloseDLL();
175return;
176}
177
178/* --Methode-- */
179void Services2NObjMgr::PlotFunc2DFrCFile(string const & fname, string const & func, string & nom,
180 double xmin, double xmax, double ymin, double ymax, int npx, int npy, string dopt)
181{
182DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);
183if (!f) return;
184PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt);
185CloseDLL();
186return;
187}
188
189/* --Methode-- */
190void Services2NObjMgr::PlotFunc(DlFunctionOfX f, string & nom, double xmin, double xmax, int np, string dopt)
191{
192if (!mImgapp) return;
193
194int k;
195if (np < 1) np = 1;
196if (xmax <= xmin) xmax = xmin+1.;
197Vector* vpy = new Vector(np);
198
199double xx;
200double dx = (xmax-xmin)/np;
201
202try {
203 for(k=0; k<np; k++) { xx = xmin+dx*k; (*vpy)(k) = f(xx); }
204}
205#ifdef SANS_EVOLPLANCK
206CATCH(merr) {
207 fflush(stdout);
208 cout << endl;
209 cerr << endl;
210 string es = PeidaExc(merr);
211 cerr << "Services2NObjMgr::PlotFunc() Exception :" << merr << es;
212 delete vpy;
213 vpy = NULL;
214 } ENDTRY;
215#else
216catch ( PException exc ) {
217 fflush(stdout);
218 cout << endl;
219 cerr << endl;
220 cerr << "Services2NObjMgr::PlotFunc() Exception :" << exc.Msg() << endl;
221 delete vpy;
222 vpy = NULL;
223}
224#endif
225
226if (vpy) {
227 string titre;
228 if (nom.length() < 1) {
229 titre = "Function f(x)";
230 nom = "/autoc/f_x";
231 }
232 else titre = nom;
233
234 P1DArrayAdapter* vya = new POVectorAdapter(vpy, false);
235 vya->DefineXCoordinate(xmin, (xmax-xmin)/np);
236 PIYfXDrawer* dr = new PIYfXDrawer(vya, NULL, true) ;
237 bool fgsr = true;
238 dopt = "thinline," + dopt;
239 int opt = DecodeDispOption(dopt, fgsr);
240 int rsid = mImgapp->DispScDrawer(dr, titre, opt);
241 if (fgsr) mImgapp->RestoreGraphicAtt();
242 if (nom.length() > 0) {
243 mOmg->AddObj(vpy, nom);
244 mOmg->AddWRsId(nom, rsid);
245 }
246 }
247
248return;
249}
250
251/* --Methode-- */
252void Services2NObjMgr::PlotFunc2D(DlFunctionOfXY f, string & nom, double xmin, double xmax, double ymin, double ymax,
253 int npx, int npy, string dopt)
254{
255if (!mImgapp) return;
256
257if (npx < 3) npx = 3;
258if (npy < 3) npy = 3;
259if (npx > 250) npx = 250;
260if (npy > 250) npy = 250;
261if (xmax <= xmin) xmax = xmin+1.;
262if (ymax <= ymin) ymax = ymin+1.;
263
264Matrix* mtx = new Matrix(npy, npx);
265
266int i,j;
267double xx, yy;
268double dx = (xmax-xmin)/npx;
269double dy = (ymax-ymin)/npy;
270// printf(" -- DBG -- %d %d , %g %g , %g %g \n", npx, npy, xmin, xmax, ymin, ymax);
271try {
272 for(j=0; j<npy; j++) {
273 yy = ymin+dy*j;
274 for(i=0; i<npx; i++) {
275 xx = xmin+dx*i;
276 (*mtx)(j, i) = f(xx, yy);
277 }
278 }
279}
280#ifdef SANS_EVOLPLANCK
281CATCH(merr) {
282 fflush(stdout);
283 cout << endl;
284 cerr << endl;
285 string es = PeidaExc(merr);
286 cerr << "Services2NObjMgr::PlotFunc2D() Exception :" << merr << es;
287 delete mtx; mtx = NULL;
288 } ENDTRY;
289#else
290catch ( PException exc ) {
291 fflush(stdout);
292 cout << endl;
293 cerr << endl;
294 cerr << "Services2NObjMgr::PlotFunc2D() Exception :" << exc.Msg() << endl;
295 delete mtx; mtx = NULL;
296}
297#endif
298
299if (mtx) {
300 string titre;
301 if (nom.length() < 1) {
302 titre = "Function f(x,y)";
303 nom = "/autoc/f2d_xy";
304 }
305 else titre = nom;
306 bool fgsr = true;
307 int opt = DecodeDispOption(dopt, fgsr);
308 P2DArrayAdapter* arr = new POMatrixAdapter(mtx, false);
309 arr->DefineXYCoordinates(xmin, ymin, dx, dy);
310 PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
311 int rsid = mImgapp->Disp3DDrawer(sdr, titre, opt);
312 if (fgsr) mImgapp->RestoreGraphicAtt();
313 if (nom.length() > 0) {
314 mOmg->AddObj(mtx, nom);
315 mOmg->AddWRsId(nom, rsid);
316 }
317 }
318
319return;
320}
321
322/* --Methode-- */
323void Services2NObjMgr::DisplayPoints2D(string& nom, string& expx, string& expy,
324 string& experrx, string& experry,
325 string& expcut, string dopt, string loop)
326{
327NObjMgrAdapter* obja=NULL;
328obja = mOmg->GetObjAdapter(nom);
329if (obja == NULL) {
330 cout << "Services2NObjMgr::DisplayPoints2D() Error , No such object " << nom << endl;
331 return;
332 }
333if (!mImgapp) return;
334
335// Creation NTuple
336char* ntn[4] = {"expx","expy","expex","expey",};
337NTuple* nt = NULL;
338bool haserr = false;
339
340if ( (experrx.length() > 0 ) && (experry.length() > 0 ) ) { haserr = true; nt = new NTuple(4, ntn); }
341else { haserr = false; experrx = experry = "0."; nt = new NTuple(2, ntn); }
342
343ComputeExpressions(obja, expx, expy, experrx, experry, expcut, loop, nt, NULL, NULL);
344
345if (nt->NEntry() < 1) {
346 cout << "Services2NObjMgr::DisplayPoints2D() Warning Zero points satisfy cut !" << endl;
347 delete nt;
348 return;
349 }
350
351// nt->Show();
352// nt->Print(0,10);
353PINTuple* pin = new PINTuple(nt, true);
354pin->SetStats(Services2NObjMgr::GetStatsOption(dopt));
355pin->SelectXY(ntn[0], ntn[1]);
356if ( haserr ) pin->SelectErrBar(ntn[2], ntn[3]);
357
358bool fgsr = true;
359dopt = "defline," + dopt;
360int opt = DecodeDispOption(dopt, fgsr);
361string titre = nom + ":" + expy + "%" + expx;
362mImgapp->DispScDrawer( (PIDrawer*)pin, titre, opt);
363if (fgsr) mImgapp->RestoreGraphicAtt();
364return;
365}
366
367/* --Methode-- */
368void Services2NObjMgr::DisplayPoints3D(string& nom, string& expx, string& expy,
369 string& expz, string& expcut, string dopt, string loop)
370{
371NObjMgrAdapter* obja=NULL;
372obja = mOmg->GetObjAdapter(nom);
373if (obja == NULL) {
374 cout << "Services2NObjMgr::DisplayPoints3D() Error , No such object " << nom << endl;
375 return;
376 }
377if (!mImgapp) return;
378
379char* ntn[3] = {"expx","expy","expz"};
380NTuple* nt = new NTuple(3,ntn); // Creation NTuple
381
382string expwt = "1.";
383ComputeExpressions(obja, expx, expy, expz, expwt, expcut, loop, nt, NULL, NULL);
384
385if (nt->NEntry() < 1) {
386 cout << "Services2NObjMgr::DisplayPoints3D() Warning Zero points satisfy cut !" << endl;
387 delete nt;
388 return;
389 }
390nt->Show();
391nt->Print(0,10);
392PINTuple3D* pin = new PINTuple3D(nt, true);
393pin->SelectXYZ(ntn[0], ntn[1], ntn[2]);
394bool fgsr = true;
395dopt = "defline," + dopt;
396int opt = DecodeDispOption(dopt, fgsr);
397
398// Pour plot a partir de DispScDrawer
399// string nomdisp = "_NT3D_";
400// mImgapp->DispScDrawer( (PIDrawer*)pin, nomdisp, opt);
401// Pour plot a partir de Disp3DDrawer
402string titre = nom + ":" + expy + "%" + expx;
403mImgapp->Disp3DDrawer(pin, titre, opt);
404
405if (fgsr) mImgapp->RestoreGraphicAtt();
406return;
407}
408
409/* --Methode-- */
410void Services2NObjMgr::DisplayPoints2DW(string& nom, string& expx, string& expy,
411 string& expwt, string& expcut, string dopt, string loop)
412{
413NObjMgrAdapter* obja=NULL;
414obja = mOmg->GetObjAdapter(nom);
415if (obja == NULL) {
416 cout << "Services2NObjMgr::DisplayPoints2DW() Error , No such object " << nom << endl;
417 return;
418 }
419if (!mImgapp) return;
420
421char* ntn[3] = {"expx","expy","expw"};
422NTuple* nt = new NTuple(3,ntn); // Creation NTuple
423
424string exp = "1.";
425ComputeExpressions(obja, expx, expy, expwt, exp, expcut, loop, nt, NULL, NULL);
426
427if (nt->NEntry() < 1) {
428 cout << "Services2NObjMgr::DisplayPoints2DW() Warning Zero points satisfy cut !" << endl;
429 delete nt;
430 return;
431 }
432
433PINTuple* pin = new PINTuple(nt, true);
434pin->SetStats(Services2NObjMgr::GetStatsOption(dopt));
435pin->SelectXY(ntn[0], ntn[1]);
436pin->SelectWt(ntn[2]);
437
438bool fgsr = true;
439int opt = DecodeDispOption(dopt, fgsr);
440string titre = nom + ":" + expwt + "_" + expy + "%" + expx ;
441mImgapp->DispScDrawer( (PIDrawer*)pin, titre, opt);
442if (fgsr) mImgapp->RestoreGraphicAtt();
443return;
444}
445
446/* --Methode-- */
447void Services2NObjMgr::ProjectH1(string& nom, string& expx, string& expwt,
448 string& expcut, string& nomh1, string dopt, string loop)
449{
450NObjMgrAdapter* obja=NULL;
451obja = mOmg->GetObjAdapter(nom);
452if (obja == NULL) {
453 cout << "Services2NObjMgr::ProjectH1() Error , No such object " << nom << endl;
454 return;
455 }
456if (!mImgapp) return;
457
458Histo* h1 = NULL;
459NTuple* nt = NULL;
460AnyDataObj* oh = NULL;
461if (nomh1.length() > 0) oh=mOmg->GetObj(nomh1);
462else nomh1 = "/tmp/projh1d";
463if ( (oh != NULL) && (typeid(*oh) == typeid(Histo)) ) h1 = (Histo*)oh; // Pas de remise a zero ! h1->Zero();
464else {
465 char* ntn[2]= {"hxval", "hwt"};
466 nt = new NTuple(2,ntn); // Creation NTuple
467 }
468string expz = "0.";
469ComputeExpressions(obja, expx, expwt, expz, expwt, expcut, loop, nt, h1, NULL);
470
471if ((!h1) && (!nt)) return;
472if (!h1) {
473 if (nt->NEntry() < 1) {
474 cout << "Services2NObjMgr::ProjectH1() Warning Zero points satisfy cut !" << endl;
475 delete nt;
476 return;
477 }
478 double xmin, xmax;
479 nt->GetMinMax(0, xmin, xmax);
480 h1 = new Histo(xmin, xmax, 100);
481 int k;
482 float* xn;
483 for(k=0; k<nt->NEntry(); k++) {
484 xn = nt->GetVec(k);
485 h1->Add(xn[0], xn[1]);
486 }
487 delete nt;
488 mOmg->AddObj(h1, nomh1);
489 }
490
491mOmg->DisplayObj(nomh1, dopt);
492return;
493}
494
495/* --Methode-- */
496void Services2NObjMgr::ProjectH2(string& nom, string& expx, string& expy, string& expwt,
497 string& expcut, string& nomh2, string dopt, string loop)
498{
499NObjMgrAdapter* obja=NULL;
500obja = mOmg->GetObjAdapter(nom);
501if (obja == NULL) {
502 cout << "Services2NObjMgr::ProjectH2() Error , No such object " << nom << endl;
503 return;
504 }
505if (!mImgapp) return;
506
507Histo2D* h2 = NULL;
508NTuple* nt = NULL;
509AnyDataObj* oh = NULL;
510if (nomh2.length() > 0) oh=mOmg->GetObj(nomh2);
511else nomh2 = "/tmp/projh2d";
512if ( (oh != NULL) && (typeid(*oh) == typeid(Histo2D)) ) h2 = (Histo2D*)oh; // Pas de remise a zero ! h2->Zero();
513else {
514 char* ntn[3]= {"hxval", "hyval", "hwt"};
515 nt = new NTuple(3,ntn); // Creation NTuple
516 }
517string expz = "0.";
518ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, loop, nt, NULL, h2);
519
520if ((!h2) && (!nt)) return;
521if (!h2) {
522 if (nt->NEntry() < 1) {
523 cout << "Services2NObjMgr::ProjectH2() Warning Zero points satisfy cut !" << endl;
524 delete nt;
525 return;
526 }
527 double xmin, xmax, ymin, ymax;
528 nt->GetMinMax(0, xmin, xmax);
529 nt->GetMinMax(1, ymin, ymax);
530 h2 = new Histo2D(xmin, xmax, 50, ymin, ymax, 50);
531 int k;
532 float* xn;
533 for(k=0; k<nt->NEntry(); k++) {
534 xn = nt->GetVec(k);
535 h2->Add(xn[0], xn[1], xn[2]);
536 }
537 delete nt;
538 mOmg->AddObj(h2, nomh2);
539 }
540
541mOmg->DisplayObj(nomh2, dopt);
542return;
543
544}
545
546/* --Methode-- cmv 13/10/98 */
547void Services2NObjMgr::ProjectHProf(string& nom, string& expx, string& expy, string& expwt,
548 string& expcut, string& nomprof, string dopt, string loop)
549// Pour remplir un ``GeneralFitData'' a partir de divers objets:
550//| nom = nom de l'objet a projeter dans un HProf.
551//| expx = expression X de definition du bin.
552//| expy = expression Y a additionner dans le bin.
553//| expwt = expression W du poids a additionner.
554//| expcut = expression du test de selection.
555//| nomprof = nom du HProf engendre (optionnel). Si l'objet n'existe pas
556//| les limites Xmin,Xmax sont calculees automatiquement.
557//| sinon ce sont celles de l'objet preexistant.
558//| opt = options generales pour le display.
559{
560NObjMgrAdapter* obja=NULL;
561obja = mOmg->GetObjAdapter(nom);
562if (obja == NULL) {
563 cout << "Services2NObjMgr::ProjectHProf() Error , No such object " << nom << endl;
564 return;
565 }
566if (!mImgapp) return;
567
568HProf* hprof = NULL;
569NTuple* nt = NULL;
570AnyDataObj* oh = NULL;
571if (nomprof.length() > 0) oh=mOmg->GetObj(nomprof);
572else nomprof = "/tmp/projprof";
573if( (oh!=NULL) && (typeid(*oh) == typeid(HProf)) ) hprof = (HProf*)oh;
574else {
575 char* ntn[3]= {"hxval", "hyval", "hwt"};
576 nt = new NTuple(3,ntn); // Creation NTuple
577}
578string expz = "0.";
579ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, loop, nt, NULL, NULL, hprof);
580
581if((!hprof) && (!nt)) return;
582if(!hprof) {
583 if (nt->NEntry() < 1) {
584 cout << "Services2NObjMgr::ProjectHProf() Warning Zero points satisfy cut !" << endl;
585 delete nt;
586 return;
587 }
588 r_8 xmin, xmax;
589 nt->GetMinMax(0, xmin, xmax);
590 hprof = new HProf(xmin, xmax, 100);
591 int k;
592 float* xn;
593 for(k=0; k<nt->NEntry(); k++) {
594 xn = nt->GetVec(k);
595 hprof->Add(xn[0], xn[1], xn[2]);
596 }
597 delete nt;
598 mOmg->AddObj(hprof, nomprof);
599 }
600hprof->UpdateHisto();
601
602mOmg->DisplayObj(nomprof, dopt);
603return;
604}
605
606
607/* --Methode-- */
608void Services2NObjMgr::FillVect(string& nom, string& expx, string& expv,
609 string& expcut, string& nomvec, string dopt, string loop)
610{
611NObjMgrAdapter* obja=NULL;
612obja = mOmg->GetObjAdapter(nom);
613if (obja == NULL) {
614 cout << "Services2NObjMgr::FillVect() Error , No such object: " << nom << endl;
615 return;
616 }
617if (!mImgapp) return;
618
619Vector* v1 = NULL;
620AnyDataObj* ov = NULL;
621ov=mOmg->GetObj(nomvec);
622if (ov != NULL) v1 = dynamic_cast<Vector *>(ov);
623if (v1 == NULL) {
624 cout << "Services2NObjMgr::FillVect() Error , No such object or not a vector: " << nomvec << endl;
625 return;
626 }
627
628char* ntn[2]= {"vi", "vv"};
629NTuple* nt = new NTuple(2,ntn); // Creation NTuple
630
631string expz = "0.";
632ComputeExpressions(obja, expx, expv, expz, expz, expcut, loop, nt);
633
634if (!nt) return;
635if (nt->NEntry() < 1) {
636 cout << "Services2NObjMgr::FillVect() Warning Zero points satisfy cut !" << endl;
637 delete nt;
638 return;
639 }
640
641 int i,k;
642 double* xn;
643 for(k=0; k<nt->NEntry(); k++) {
644 xn = nt->GetLineD(k);
645 i = xn[0]+0.5;
646 if ( (i < 0) || i >= v1->NElts() ) continue;
647 (*v1)(i) = xn[1];
648 }
649 delete nt;
650
651
652mOmg->DisplayObj(nomvec, dopt);
653return;
654}
655
656/* --Methode-- */
657void Services2NObjMgr::FillMatx(string& nom, string& expx, string& expy, string& expv,
658 string& expcut, string& nommtx, string dopt, string loop)
659{
660NObjMgrAdapter* obja=NULL;
661obja = mOmg->GetObjAdapter(nom);
662if (obja == NULL) {
663 cout << "Services2NObjMgr::FillMatx() Error , No such objet " << nom << endl;
664 return;
665 }
666if (!mImgapp) return;
667
668Matrix* mtx = NULL;
669AnyDataObj* om = NULL;
670om=mOmg->GetObj(nommtx);
671if (om != NULL) mtx = dynamic_cast<Matrix *>(om);
672if (mtx == NULL) {
673 cout << "Services2NObjMgr::FillMatx() Error , No such object or not a matrix " << nommtx << endl;
674 return;
675 }
676
677char* ntn[3]= {"mi", "mj", "mv"};
678NTuple* nt = new NTuple(3,ntn); // Creation NTuple
679
680string expz = "0.";
681ComputeExpressions(obja, expx, expy, expv, expz, expcut, loop, nt);
682
683if (!nt) return;
684if (nt->NEntry() < 1) {
685 cout << "Services2NObjMgr::FillMatx() Warning Zero points satisfy cut !" << endl;
686 delete nt;
687 return;
688 }
689
690 int ic, jl, k;
691 double* xn;
692 for(k=0; k<nt->NEntry(); k++) {
693 xn = nt->GetLineD(k);
694 ic = xn[0]+0.5;
695 jl = xn[1]+0.5;
696 if ( (ic < 0) || ic >= mtx->NCol() ) continue;
697 if ( (jl < 0) || jl >= mtx->NRows() ) continue;
698 (*mtx)(jl, ic) = xn[2];
699 }
700 delete nt;
701
702
703mOmg->DisplayObj(nommtx, dopt);
704return;
705
706}
707
708/* --Methode-- */
709void Services2NObjMgr::ExpressionToVector(string& nom, string& expx, string& expcut,
710 string& nomvec, string dopt, string loop)
711{
712NObjMgrAdapter* obja=NULL;
713obja = mOmg->GetObjAdapter(nom);
714if (obja == NULL) {
715 cout << "Services2NObjMgr::ExpressionToVector() Error , No such object " << nom << endl;
716 return;
717 }
718if (!mImgapp) return;
719
720NTuple* nt = NULL;
721if (nomvec.length() < 1) nomvec = "/tmp/expvec";
722
723char* ntn[2]= {"vecval", "vecwt"};
724nt = new NTuple(1,ntn); // Creation NTuple
725
726string expwt = "1.";
727string expz = "0.";
728ComputeExpressions(obja, expx, expz, expz, expwt, expcut, loop, nt, NULL, NULL);
729
730if (!nt) return;
731if (nt->NEntry() < 1) {
732 cout << "Services2NObjMgr::ExpressionToVector() Warning Zero points satisfy cut !" << endl;
733 delete nt;
734 return;
735 }
736
737Vector* vec = new Vector(nt->NEntry());
738int k;
739float* xn;
740for(k=0; k<nt->NEntry(); k++) {
741 xn = nt->GetVec(k);
742 (*vec)(k) = xn[0];
743 }
744delete nt;
745mOmg->AddObj(vec, nomvec);
746mOmg->DisplayObj(nomvec, dopt);
747return;
748}
749
750/* --Methode-- */
751void Services2NObjMgr::NtFromASCIIFile(string& nom,string& filename,double def_val)
752// Pour remplir un ntuple "nom" existant a partir du fichier
753// ASCII table "filename". Si il y a plus de variables dans le
754// ntuple que dans le fichier "filename",
755// les sur-numeraires sont mises a "def_val" par defaut.
756{
757AnyDataObj* mobj = mOmg->GetObj(nom);
758if(mobj == NULL)
759 {cout<<"NtFromASCIIFile() Error, object "<<nom<<" not existing"<<endl;
760 return;}
761if(typeid(*mobj) != typeid(NTuple))
762 {cout<<"NtFromASCIIFile() Error, object "<<nom<<" not an NTuple"<<endl;
763 return;}
764if (!mImgapp) return;
765
766NTuple* nt = (NTuple*) mobj;
767nt->FillFromASCIIFile(filename, def_val);
768return;
769}
770
771/* --Methode-- */
772void Services2NObjMgr::FillNT(string& nom, string& expx, string& expy, string& expz,
773 string& expt, string& expcut, string& nomnt, string loop)
774{
775NObjMgrAdapter* obja=NULL;
776obja = mOmg->GetObjAdapter(nom);
777if (obja == NULL) {
778 cout << "Services2NObjMgr::FillNT() Error , No such object " << nom << endl;
779 return;
780 }
781if (!mImgapp) return;
782
783bool fgnnt = false;
784NTuple* nt = NULL;
785AnyDataObj* oh = NULL;
786if (nomnt.length() > 0) oh=mOmg->GetObj(nomnt);
787else nomnt = "/tmp/fillnt";
788if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
789 nt = (NTuple*)oh;
790 if (nt->NVar() > 10) {
791 cout << "Services2NObjMgr::FillNT() Warning , Max 10 var in NTuple -> new NTuple" << endl;
792 nt = NULL;
793 }
794 }
795if (nt == NULL) {
796 char* ntn[4]= {"x", "y","z","t"};
797 nt = new NTuple(4,ntn); // Creation NTuple
798 fgnnt = true;
799 }
800
801ComputeExpressions(obja, expx, expy, expz, expt, expcut, loop, nt, NULL, NULL);
802
803if (fgnnt) mOmg->AddObj(nt, nomnt);
804return;
805
806}
807
808/* --Methode-- */
809void Services2NObjMgr::FillNTFrCFile(string & nom, string const & fname,
810 string const & funcname, string & nomnt, string loop)
811{
812if (!mImgapp) return;
813
814NObjMgrAdapter* obja=NULL;
815obja = mOmg->GetObjAdapter(nom);
816if (obja == NULL) {
817 cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) No such object" <<endl;
818 return;
819 }
820bool adel = true;
821NTupleInterface* objnt = obja->GetNTupleInterface(adel);
822if (objnt == NULL) {
823 cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) Not an NTupleInterface !" <<endl;
824 return;
825 }
826
827NTLoopExprFunc f = (NTLoopExprFunc)LinkFunctionFromFile(fname, funcname);
828if (!f) {
829 cerr << "Services2NObjMgr::FillNTFrCFile Error Creation NTLoopExprFunc" << endl;
830 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
831 return;
832 }
833
834bool fgnnt = false;
835NTuple* nt = NULL;
836if (nomnt.length() > 0) {
837 AnyDataObj* oh = NULL;
838 oh=mOmg->GetObj(nomnt);
839 if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
840 nt = (NTuple*)oh;
841 if (nt->NVar() > 10) {
842 cout << "Services2NObjMgr::FillNTFrCFile() Warning , Max 10 var in NTuple -> new NTuple" << endl;
843 nt = NULL;
844 }
845 }
846 if (nt == NULL) {
847 char* ntn[4]= {"x", "y","z","t"};
848 nt = new NTuple(4,ntn); // Creation NTuple
849 fgnnt = true;
850 }
851 }
852
853double xnt[10];
854float fxnt[10];
855
856int i,k;
857for(i=0; i<10; i++) fxnt[i] = xnt[i] = 0.;
858
859
860// $CHECK$ A virer des que possible - Pb blocage application quand trop d'impression
861// redirige - On redirige la sortie sur le terminal
862bool red = mImgapp->HasRedirectedStdOutErr();
863mImgapp->RedirectStdOutErr(false);
864
865int k1,k2,dk;
866k1 = 0; k2 = objnt->NbLines(); dk = 1;
867DecodeLoopParameters(loop, k1, k2, dk);
868if (k1 < 0) k1 = 0;
869if (k2 < 0) k2 = objnt->NbLines();
870if (k2 > objnt->NbLines()) k2 = objnt->NbLines();
871if (dk <= 0) dk = 1;
872
873try {
874 double* xn;
875 int kmax = k2;
876 for(k=k1; k<kmax; k+=dk) {
877 xn = objnt->GetLineD(k);
878 if (f(xn, xnt, xnt+1, xnt+2, xnt+3, k, kmax) != 0) {
879 if (nt) {
880 for(i=0; i<4; i++) fxnt[i] = xnt[i];
881 nt->Fill(fxnt);
882 }
883 }
884 }
885 }
886#ifdef SANS_EVOLPLANCK
887CATCH(merr) {
888 fflush(stdout);
889 cout << endl;
890 cerr << endl;
891 string es = PeidaExc(merr);
892 cerr << "Services2NObjMgr::FillNTFrCFile() Exception :" << merr << es;
893 } ENDTRY;
894#else
895catch ( PException exc ) {
896 fflush(stdout);
897 cout << endl;
898 cerr << endl;
899 cerr << "Services2NObjMgr::FillNTFrCFile() Exception :" << exc.Msg() << endl;
900}
901#endif
902
903if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
904CloseDLL();
905
906// $CHECK$ A virer des que possible On redirige la sortie sur la fenetre PIConsole
907mImgapp->RedirectStdOutErr(red);
908
909if (fgnnt) mOmg->AddObj(nt, nomnt);
910return;
911}
912
913/* --Methode-- */
914void Services2NObjMgr::PrepareNTExpressionCFile(string & nom, string const & fname,
915 string const & funcname)
916{
917NObjMgrAdapter* obja=NULL;
918obja = mOmg->GetObjAdapter(nom);
919if (obja == NULL) {
920 cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom << "...) No such object" <<endl;
921 return;
922 }
923bool adel = true;
924NTupleInterface* objnt = obja->GetNTupleInterface(adel);
925if (objnt == NULL) {
926 cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom
927 << "...) No NTupleInterface !" <<endl;
928 return;
929 }
930string vardec = objnt->VarList_C("_xnti_");
931
932FILE *fip;
933if ((fip = fopen(fname.c_str(), "w")) == NULL) {
934 cout << "Services2NObjMgr::PrepareNTExpressionCFile()_Error: fopen " << fname << endl;
935 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
936 return;
937 }
938
939// constitution du fichier des decalarations des variables de l'interface NTuple
940fputs("#include <stdlib.h> \n", fip);
941fputs("#include <stdio.h> \n", fip);
942fputs("#include <math.h> \n\n", fip);
943
944fputs("/* ------ Compare bits on double --------- */ \n", fip);
945fputs("typedef long long int_8;\n", fip);
946fputs("int_8 BitCmp64(double v,int_8 flg)\n", fip);
947fputs("{return ((int_8)((v<0.) ? v-0.1 : v+0.1))&flg;}\n", fip);
948fputs("/* ------ Some random number generators --------- */ \n", fip);
949fputs("#define frand01() ( (float) drand48() ) \n", fip);
950fputs("#define drand01() drand48() \n", fip);
951fputs("#define rand01() drand48() \n", fip);
952fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
953fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
954fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
955fputs("double NorRand(void) \n", fip);
956fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
957fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
958fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
959fputs(" return(x); \n } \n", fip);
960fputs("#define GauRand() NorRand() \n", fip);
961fputs("#define gaurand() NorRand() \n\n", fip);
962
963fputs("/* NTupleInterface Variable declaration - Generated by piapp \n", fip);
964fputs(" -- Services2NObjMgr::PrepareNTExpressionCFile() -- */ \n\n", fip);
965fprintf(fip,"int %s(double* _xnti_, double* _rx_, double* _ry_, double* _rz_, \n",
966 funcname.c_str());
967fprintf(fip," double* _rt_, int _n_, int _nmax_) \n");
968fprintf(fip, "{ \n %s \n", vardec.c_str());
969fputs(" if (!1) { /* Cut Expression failed */ \n", fip);
970fputs(" *_rx_ = *_ry_ = *_rz_ = *_rt_ = 0.; return(0);", fip);
971fputs(" } \n /* Cut expression satisfied */ \n", fip);
972fputs(" *_rx_ = 1.; \n *_ry_ = 1.; \n *_rz_ = 1.; \n *_rt_ = 1.; \n", fip);
973fputs(" return(1); \n} \n", fip);
974
975fclose(fip);
976
977if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
978return;
979}
980
981/* --Methode-- cmv 13/10/98 */
982void Services2NObjMgr::FillGFD(string& nom, string& expx, string& expy, string& expz,
983 string& experr, string& expcut, string& nomgfd, string loop)
984// Pour remplir un ``GeneralFitData'' a partir de divers objets:
985//| nom = nom de l'objet a transcrire selon 1D: Z=f(X) ou 2D: Z=f(X,Y) .
986//| Vector,Matrix,Histo,HProf,Histo2D,Image<T>,StarList,NTuple,GeneralFitData
987//| expx = expression X du GeneralFitData (1er abscisse)
988//| expy = expression Y du GeneralFitData (2sd abscisse si non "", Z=f(X,Y))
989//| expz = expression Z du GeneralFitData (valeur de l'ordonnee)
990//| experr = expression de l'erreur sur l'ordonnee Z
991//| expcut = expression du test de selection
992//| nomgfd = nom du GeneralFitData engendre (optionnel)
993{
994NObjMgrAdapter* obja=NULL;
995obja = mOmg->GetObjAdapter(nom);
996if (obja == NULL) {
997 cout << "Services2NObjMgr::FillGFD() Error , No such object "<<nom<<endl;
998 return;
999 }
1000if(!mImgapp) return;
1001
1002// 2D ou 3D?
1003int nvar = 2;
1004if(expy.length()<=0) {nvar = 1; expy = "0.";}
1005
1006// Creation NTuple Buffer
1007char* ntn[4]= {"x","y","f","e"};
1008NTuple*nt = new NTuple(4,ntn);
1009
1010// Remplissage NTuple buffer
1011ComputeExpressions(obja, expx, expy, expz, experr, expcut, loop, nt, NULL, NULL);
1012if(nt->NEntry() < 1)
1013 {cout<<"Services2NObjMgr::FillGFD() Warning Zero points satisfy cut !"<<endl;
1014 delete nt; return;}
1015
1016//Remplissage de la structure GeneraFitData
1017if (nt->NEntry() <= 0) {
1018 cout<<"Services2NObjMgr::FillGFD() Warning - NData= " << nt->NEntry() << endl;
1019 delete nt;
1020 return;
1021 }
1022
1023GeneralFitData* gfd = new GeneralFitData(nvar,nt->NEntry(),0);
1024int k;
1025float* xn;
1026for(k=0; k<nt->NEntry(); k++) {
1027 xn = nt->GetVec(k);
1028 gfd->AddData(xn,xn[2],xn[3]);
1029}
1030
1031// Menage et table d'objets
1032delete nt;
1033mOmg->AddObj(gfd, nomgfd);
1034return;
1035}
1036
1037/* --Methode-- cmv 12/07/00 */
1038void Services2NObjMgr::FillGFDfrVec(string nomgfd,string namx,string namy,string namz,string name)
1039// Pour remplir un ``GeneralFitData'' a partir de vecteurs
1040//| gdfrvec nomgd X Y ! !
1041//| gdfrvec nomgd X Y ! EY
1042//| gdfrvec nomgd X Y Z !
1043//| gdfrvec nomgd X Y Z EZ
1044//| - nomgfd = nom du generaldata a remplir
1045//| - namx = nom du vecteur contenant les valeurs X
1046//| - namy = nom du vecteur contenant les valeurs Y
1047//| - namz = nom du vecteur contenant les valeurs Z (ou "!")
1048//| - name = nom du vecteur contenant les valeurs des erreurs EY ou EZ
1049{
1050// Decodage des noms des vecteurs pour le remplissage du generaldata
1051if(nomgfd=="!" || nomgfd.length()<1)
1052 {cout<<"FillGFDfrVec_Error: bad GenaralData name "<<nomgfd<<endl; return;}
1053if(namx=="!" || namx.length()<1)
1054 {cout<<"FillGFDfrVec_Error: bad X vector name "<<namx<<endl; return;}
1055if(namy=="!" || namy.length()<1)
1056 {cout<<"FillGFDfrVec_Error: bad Y vector name "<<namy<<endl; return;}
1057if(namz.length()<1) namz = "!";
1058if(name.length()<1) name = "!";
1059int nvar = 0;
1060if(namz=="!") nvar = 1; else nvar = 2;
1061
1062// Identify data
1063NamedObjMgr omg;
1064AnyDataObj* mobj = NULL;
1065Vector* v;
1066int nel = 0;
1067r_8 *x=NULL, *y=NULL, *z=NULL,* ez=NULL;
1068
1069if( (mobj=omg.GetObj(namx)) == NULL) {
1070 cout<<"FillGFDfrVec_Error: unknown X object "<<namx<<endl; return;
1071} else {
1072 v = (Vector*) mobj; x = v->Data(); nel=v->NElts();
1073}
1074
1075if( (mobj=omg.GetObj(namy)) == NULL) {
1076 cout<<"FillGFDfrVec_Error: unknown Y object "<<namy<<endl; return;
1077} else {
1078 v = (Vector*) mobj; y = z = v->Data(); if(v->NElts()<nel) nel=v->NElts();
1079}
1080
1081if( nvar==2 && (mobj=omg.GetObj(namz)) == NULL) {
1082 cout<<"FillGFDfrVec_Error: unknown Z object "<<namz<<endl; return;
1083} else {
1084 v = (Vector*) mobj; z = v->Data(); if(v->NElts()<nel) nel=v->NElts();
1085}
1086
1087if(name!="!") {
1088 if( (mobj=omg.GetObj(name)) == NULL) {
1089 cout<<"FillGFDfrVec_Error: unknown EZ object "<<name<<endl; return;
1090 } else {
1091 v = (Vector*) mobj; ez = v->Data(); if(v->NElts()<nel) nel=v->NElts();
1092 }
1093}
1094
1095if(nel<=0)
1096 {cout<<"FillGFDfrVec_Error: bad number of elements "<<nel<<endl; return;}
1097
1098// Create GeneralData and fill it with vectors
1099GeneralFitData* gfd = new GeneralFitData(nvar,nel+5,0);
1100if(nvar==1) gfd->SetData1(nel,x,z,ez); // On remplit Y=f(X)
1101else gfd->SetData2(nel,x,y,z,ez); // On remplit Z=f(X,y)
1102
1103// Menage et table d'objets
1104if( omg.GetObj(nomgfd) != NULL ) omg.DelObj(nomgfd);
1105mOmg->AddObj(gfd,nomgfd);
1106return;
1107}
1108
1109/* --Methode-- */
1110void Services2NObjMgr::ComputeExpressions(NObjMgrAdapter* obja, string& expx,
1111 string& expy, string& expz, string& expt, string& expcut, string& loop,
1112 NTuple* nt, Histo* h1, Histo2D* h2, HProf* hp)
1113{
1114if (obja == NULL) return;
1115bool adel = true;
1116NTupleInterface* objnt = obja->GetNTupleInterface(adel);
1117if (objnt == NULL) return;
1118string vardec = objnt->VarList_C("_zz6qi_");
1119
1120PlotExprFunc f = LinkExprFunc(vardec, expx, expy, expz, expt, expcut);
1121if (!f) {
1122 cerr << "Services2NObjMgr::::ComputeExpressions() Error Creation PlotExprFunc " << endl;
1123 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
1124 return;
1125 }
1126
1127double xnt[10];
1128float fxnt[10];
1129
1130int i,k;
1131for(i=0; i<10; i++) xnt[i] = 0.;
1132int k1,k2,dk;
1133k1 = 0; k2 = objnt->NbLines(); dk = 1;
1134DecodeLoopParameters(loop, k1, k2, dk);
1135if (k1 < 0) k1 = 0;
1136if (k2 < 0) k2 = objnt->NbLines();
1137if (k2 > objnt->NbLines()) k2 = objnt->NbLines();
1138if (dk <= 0) dk = 1;
1139
1140try {
1141 double* xn;
1142 for(k=k1; k<k2; k += dk) {
1143 xn = objnt->GetLineD(k);
1144 if (f(xn, xnt, xnt+1, xnt+2, xnt+3) != 0) {
1145 if (nt) {
1146 for(i=0; i<4; i++) fxnt[i] = xnt[i];
1147 nt->Fill(fxnt);
1148 }
1149 if (h1) h1->Add(xnt[0], xnt[3]);
1150 if (h2) h2->Add(xnt[0], xnt[1], xnt[3]);
1151 if (hp) hp->Add(xnt[0], xnt[1], xnt[3]);
1152 }
1153 }
1154 }
1155#ifdef SANS_EVOLPLANCK
1156CATCH(merr) {
1157 fflush(stdout);
1158 cout << endl;
1159 cerr << endl;
1160 string es = PeidaExc(merr);
1161 cerr << "Services2NObjMgr::ComputeExpressions() Exception :" << merr << es;
1162 } ENDTRY;
1163#else
1164catch ( PException exc ) {
1165 fflush(stdout);
1166 cout << endl;
1167 cerr << endl;
1168 cerr << "Services2NObjMgr::ComputeExpressions() Exception :" << exc.Msg() << endl;
1169}
1170#endif
1171
1172if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
1173// Fermeture du fichier .so
1174CloseDLL();
1175return;
1176}
1177
1178
1179/* --Methode-- */
1180PlotExprFunc Services2NObjMgr::LinkExprFunc(string& vardec, string& expx, string& expy,
1181 string& expz, string& expt, string& cut)
1182{
1183FILE *fip;
1184string fname = TmpDir + "expf_pia_dl.c";
1185string cmd;
1186int rc;
1187
1188cmd = "rm -f " + fname;
1189rc = system(cmd.c_str());
1190//DBG printf("LinkExprFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
1191
1192if ((fip = fopen(fname.c_str(), "w")) == NULL) {
1193 string sn = fname;
1194 cout << "Services2NObjMgr/LinkExprFunc_Error: fopen( " << sn << endl;
1195 return(NULL);
1196 }
1197
1198// constitution du fichier a compiler
1199fputs("#include <stdlib.h> \n", fip);
1200fputs("#include <math.h> \n", fip);
1201
1202fputs("/* ------ Compare bits on double --------- */ \n", fip);
1203fputs("typedef long long int_8;\n", fip);
1204fputs("int_8 BitCmp64(double v,int_8 flg)\n", fip);
1205fputs("{return ((int_8)((v<0.) ? v-0.1 : v+0.1))&flg;}\n", fip);
1206fputs("/* ------ Some random number generators --------- */ \n", fip);
1207fputs("#define frand01() ( (float) drand48() ) \n", fip);
1208fputs("#define drand01() drand48() \n", fip);
1209fputs("#define rand01() drand48() \n", fip);
1210fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
1211fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
1212fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
1213fputs("double NorRand(void) \n", fip);
1214fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
1215fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
1216fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
1217fputs(" return(x); \n } \n", fip);
1218fputs("#define GauRand() NorRand() \n", fip);
1219fputs("#define gaurand() NorRand() \n\n", fip);
1220
1221fputs("int expf_pia_dl_func(double* _zz6qi_, double* _rx_6q_, double* _ry_6q_, double* _rz_6q_, double* _rt_6q_) \n{\n", fip);
1222fprintf(fip,"%s \n", vardec.c_str());
1223fprintf(fip, "if (!(%s)) { *_rx_6q_ = *_ry_6q_ = *_rz_6q_ = *_rt_6q_ = 0.; return(0); } \n", cut.c_str());
1224fprintf(fip, "*_rx_6q_ = %s ; \n", expx.c_str());
1225fprintf(fip, "*_ry_6q_ = %s ; \n", expy.c_str());
1226fprintf(fip, "*_rz_6q_ = %s ; \n", expz.c_str());
1227fprintf(fip, "*_rt_6q_ = %s ; \n", expt.c_str());
1228fputs("return(1); \n} \n", fip);
1229fclose(fip);
1230string func = "expf_pia_dl_func";
1231return((PlotExprFunc)LinkFunctionFromFile(fname, func));
1232}
1233
1234
1235/* --Methode-- */
1236DlFunction Services2NObjMgr::LinkFunctionFromFile(string const & fname, string const & funcname)
1237{
1238// Le link dynamique
1239CloseDLL();
1240dynlink = PDynLinkMgr::BuildFromCFile(fname);
1241if (dynlink == NULL) {
1242 cerr << "Services2NObjMgr/LinkFunctionFromFile_Erreur: Erreur creation/Ouverture SO " << endl;
1243 return(NULL);
1244 }
1245
1246DlFunction retfunc = dynlink->GetFunction(funcname);
1247if (retfunc == NULL) {
1248 string sn = funcname;
1249 cerr << "Services2NObjMgr/LinkExprFunc_Erreur: Erreur linking " << sn << endl;
1250 CloseDLL();
1251 return(NULL);
1252 }
1253else return(retfunc);
1254}
1255
1256/* --Methode-- */
1257void Services2NObjMgr::CloseDLL()
1258{
1259if (dynlink) delete dynlink; dynlink = NULL;
1260}
1261
1262/* --Methode-- */
1263int Services2NObjMgr::ExecuteCommand(string line)
1264{
1265 if (mImgapp == NULL) return(99);
1266 return(mImgapp->CmdInterpreter()->Interpret(line));
1267}
1268
1269// Fonction static
1270/* --Methode-- */
1271void Services2NObjMgr::DecodeLoopParameters(string& loop, int& i1, int& i2, int& di)
1272{
1273// Decode des paramatres de boucle for(int i=i1; i<i2; i+=di) specifies
1274// sous forme i1[:i2[:di]]
1275// cout << "LoopParam() " << loop << " I1=" << i1 << " I2=" << i2 << " DI=" << di;
1276size_t l = loop.length();
1277if (l < 1) return;
1278size_t p = loop.find(':');
1279if (p >= l) { i1 = atoi(loop.c_str()); return; }
1280i1 = atoi(loop.substr(0, p).c_str());
1281string aa = loop.substr(p+1);
1282p = aa.find(':');
1283if (p < aa.length() ) {
1284 i2 = atoi(aa.substr(0,p).c_str());
1285 di = atoi(aa.substr(p+1).c_str());
1286 }
1287else i2 = atoi(aa.c_str());
1288// cout << "-> I1= " << i1 << " I2= " << i2 << " DI= " << di << endl;
1289return;
1290}
1291
1292/* --Methode-- */
1293string Services2NObjMgr::FileName2Name(string const & fn)
1294{
1295
1296char fsep[2] = {FILESEP, '\0'};
1297char tsep[2] = {'.', '\0'};
1298size_t p = fn.find_last_of(fsep);
1299size_t l = fn.length();
1300if (p >= l) p = 0;
1301else p++;
1302size_t q = fn.find_first_of(tsep,p);
1303if (q < p) q = l;
1304return(fn.substr(p,q-p));
1305}
1306
1307
1308// Variable pour stocker l'option de stat des drawers
1309static bool stats_option = true;
1310/* --Methode-- */
1311void Services2NObjMgr::SetDefaultStatsOption(bool opt)
1312{
1313 stats_option = opt;
1314}
1315
1316typedef vector<string> GraTok;
1317
1318/* --Methode-- */
1319bool Services2NObjMgr::GetStatsOption(string& gratt)
1320{
1321int ropt = Disp_Next;
1322for(int i=0; i<gratt.length(); i++) gratt[i] = tolower(gratt[i]);
1323// On separe en mots separes par des virgules
1324gratt = ","+gratt;
1325size_t p = 0;
1326size_t q = 0;
1327size_t l = gratt.length();
1328string token;
1329
1330GraTok grt;
1331
1332while (q < l) {
1333 p = gratt.find_first_not_of(" ,",q+1); // au debut d'un token
1334 if (p>=l) break;
1335 q = gratt.find_first_of(" ,",p); // la fin du token;
1336 token = gratt.substr(p,q-p);
1337 grt.push_back(token);
1338 }
1339int k;
1340bool fgsame = false;
1341int option = 0;
1342for(k=0; k<grt.size(); k++) {
1343 if ( (grt[k] == "same") || (grt[k] == "s") ) option = 1;
1344 else if ( (grt[k] == "stat") || (grt[k] == "stats") ) option = 2;
1345 else if ( (grt[k] == "nostat") || (grt[k] == "nostats") ) option = 3;
1346}
1347
1348if (option == 0) return(stats_option);
1349else if ( (option == 1) || (option == 3) ) return(false);
1350else return(true);
1351}
1352
1353/* --Methode-- */
1354int Services2NObjMgr::DecodeDispOption(string& gratt, bool& fgsrgr)
1355{
1356int ropt = Disp_Next;
1357if (!mImgapp) return(ropt);
1358
1359for(int i=0; i<gratt.length(); i++) gratt[i] = tolower(gratt[i]);
1360
1361if (fgsrgr) mImgapp->SaveGraphicAtt();
1362
1363if ( (gratt == "def") || (gratt == "default") ) { // Remise aux valeurs par defaut = non defini
1364 mImgapp->SetColAtt();
1365 mImgapp->SetLineAtt();
1366 mImgapp->SetFontAtt();
1367 mImgapp->SetMarkerAtt();
1368 mImgapp->SetColMapId();
1369 mImgapp->SetZoomAtt();
1370 mImgapp->SetAxesAtt();
1371 mImgapp->SetXYLimits();
1372 mImgapp->UseXYLimits();
1373 mImgapp->SetImageCenterPosition();
1374 mImgapp->UseImageCenter();
1375 mImgapp->SetXLogScale();
1376 mImgapp->SetYLogScale();
1377 mImgapp->SetAutoAddTitle();
1378 stats_option = true;
1379 return(ropt);
1380 }
1381
1382// On separe en mots separes par des virgules
1383gratt = ","+gratt;
1384size_t p = 0;
1385size_t q = 0;
1386size_t l = gratt.length();
1387string token;
1388
1389GraTok grt;
1390
1391while (q < l) {
1392 p = gratt.find_first_not_of(" ,",q+1); // au debut d'un token
1393 if (p>=l) break;
1394 q = gratt.find_first_of(" ,",p); // la fin du token;
1395 token = gratt.substr(p,q-p);
1396 grt.push_back(token);
1397 }
1398
1399
1400static GrAttNames::iterator it;
1401
1402int k;
1403bool fgcont = true;
1404fgsrgr = false;
1405
1406for(k=0; k<grt.size(); k++) {
1407// cout << "--DBG--SetGraphicAttributes() " << grt[k] << endl;
1408
1409 // Decodage option affichage (win, next, etc
1410 fgcont = true;
1411 if ( (grt[k] == "win") || (grt[k] == "w") ) ropt = Disp_Win;
1412 else if ( (grt[k] == "same") || (grt[k] == "s") ) ropt = Disp_Same;
1413 else if ( (grt[k] == "inset") || (grt[k] == "ins") ) ropt = Disp_Inset;
1414 else if ( (grt[k] == "stack") || (grt[k] == "st") ) ropt = Disp_Stack;
1415 else fgcont = false;
1416 if (fgcont) continue;
1417
1418 // Utilisation limites X-Y
1419 if ( grt[k] == "xylimits" ) { mImgapp->UseXYLimits(true); fgsrgr = true; continue; }
1420 if ( grt[k] == "centerimg" ) { mImgapp->UseImageCenter(true); fgsrgr = true; continue; }
1421 // Echelle logarithmique d'axe
1422 if ( grt[k] == "logx" ) { mImgapp->SetXLogScale(true); fgsrgr = true; continue; }
1423 if ( grt[k] == "linx" ) { mImgapp->SetXLogScale(false); fgsrgr = true; continue; }
1424 if ( grt[k] == "logy" ) { mImgapp->SetYLogScale(true); fgsrgr = true; continue; }
1425 if ( grt[k] == "liny" ) { mImgapp->SetYLogScale(false); fgsrgr = true; continue; }
1426 // Ajout automatique de titre
1427 if ( ( grt[k] == "tit" ) || ( grt[k] == "title" ) )
1428 { mImgapp->SetAutoAddTitle(true); fgsrgr = true; continue; }
1429 if ( ( grt[k] == "notit" ) || ( grt[k] == "notitle" ) )
1430 { mImgapp->SetAutoAddTitle(false); fgsrgr = true; continue; }
1431
1432 // Si c'est une couleur
1433 it = GrAcolors.find(grt[k]);
1434 if (it != GrAcolors.end()) { mImgapp->SetColAtt((PIColors)((*it).second.a1)); fgsrgr = true; continue; }
1435 // Si c'est un attribut de lignes
1436 it = GrAlines.find(grt[k]);
1437 if (it != GrAlines.end()) { mImgapp->SetLineAtt((PILineAtt)((*it).second.a1)); fgsrgr = true; continue; }
1438 // Si c'est un attribut de fontes
1439 it = GrAfonts.find(grt[k]);
1440 if (it != GrAfonts.end()) { mImgapp->SetFontAtt((PIFontSize)((*it).second.a2), (PIFontAtt)((*it).second.a1) );
1441 fgsrgr = true; continue; }
1442 // Si c'est un attribut de markers
1443 it = GrAmarkers.find(grt[k]);
1444 if (it != GrAmarkers.end()) { mImgapp->SetMarkerAtt((*it).second.a2, (PIMarker)((*it).second.a1) );
1445 fgsrgr = true; continue; }
1446 // Si c'est un colormap
1447 it = GrAcmap.find(grt[k]);
1448 if (it != GrAcmap.end()) { mImgapp->SetColMapId( (CMapId)((*it).second.a1) ); fgsrgr = true; continue; }
1449 // Si c'est un facteur de zoom
1450 it = GrAzoom.find(grt[k]);
1451 if (it != GrAzoom.end()) { mImgapp->SetZoomAtt( (*it).second.a1 ); fgsrgr = true; continue; }
1452 // Si c'est un attribut d'axe
1453 it = GrAaxes.find(grt[k]);
1454 if (it != GrAaxes.end()) { mImgapp->SetAxesAtt( (*it).second.a1 ); fgsrgr = true; continue; }
1455
1456 }
1457
1458return(ropt);
1459}
1460
1461
1462// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1463// Initialisation des chaines de caracteres designant les attributs graphiques
1464
1465/* --Methode-- */
1466void Services2NObjMgr::InitGrAttNames()
1467{
1468gratt_item gi;
1469// Les couleurs
1470gi.a2 = 0;
1471gi.a1 = PI_NotDefColor;
1472GrAcolors["defcol"] = gi;
1473gi.a1 = PI_Black;
1474GrAcolors["black"] = gi;
1475gi.a1 = PI_White;
1476GrAcolors["white"] = gi;
1477gi.a1 = PI_Grey;
1478GrAcolors["grey"] = gi;
1479gi.a1 = PI_Red;
1480GrAcolors["red"] = gi;
1481gi.a1 = PI_Blue;
1482GrAcolors["blue"] = gi;
1483gi.a1 = PI_Green;
1484GrAcolors["green"] = gi;
1485gi.a1 = PI_Yellow;
1486GrAcolors["yellow"] = gi;
1487gi.a1 = PI_Magenta;
1488GrAcolors["magenta"] = gi;
1489
1490gi.a1 = PI_Cyan;
1491GrAcolors["cyan"] = gi;
1492gi.a1 = PI_Turquoise;
1493GrAcolors["turquoise"] = gi;
1494gi.a1 = PI_NavyBlue;
1495GrAcolors["navyblue"] = gi;
1496gi.a1 = PI_Orange;
1497GrAcolors["orange"] = gi;
1498gi.a1 = PI_SiennaRed;
1499GrAcolors["siennared"] = gi;
1500gi.a1 = PI_Purple;
1501GrAcolors["purple"] = gi;
1502gi.a1 = PI_LimeGreen;
1503GrAcolors["limegreen"] = gi;
1504gi.a1 = PI_Gold;
1505GrAcolors["gold"] = gi;
1506
1507// Les attributs de lignes
1508gi.a2 = 0;
1509gi.a1 = PI_NotDefLineAtt;
1510GrAlines["defline"] = gi;
1511gi.a1 = PI_NormalLine;
1512GrAlines["normalline"] = gi;
1513gi.a1 = PI_ThinLine;
1514GrAlines["thinline"] = gi;
1515gi.a1 = PI_ThickLine;
1516GrAlines["thickline"] = gi;
1517gi.a1 = PI_DashedLine;
1518GrAlines["dashedline"] = gi;
1519gi.a1 = PI_ThinDashedLine;
1520GrAlines["thindashedline"] = gi;
1521gi.a1 = PI_ThickDashedLine;
1522GrAlines["thickdashedline"] = gi;
1523gi.a1 = PI_DottedLine;
1524GrAlines["dottedline"] = gi;
1525gi.a1 = PI_ThinDottedLine;
1526GrAlines["thindottedline"] = gi;
1527gi.a1 = PI_ThickDottedLine;
1528GrAlines["thickdottedline"] = gi;
1529
1530// Les fontes
1531gi.a2 = PI_NotDefFontSize;
1532gi.a1 = PI_NotDefFontAtt;
1533GrAfonts["deffont"] = gi;
1534
1535gi.a2 = PI_NormalSizeFont;
1536gi.a1 = PI_RomanFont;
1537GrAfonts["normalfont"] = gi;
1538gi.a1 = PI_BoldFont;
1539GrAfonts["boldfont"] = gi;
1540gi.a1 = PI_ItalicFont;
1541GrAfonts["italicfont"] = gi;
1542gi.a2 = PI_SmallSizeFont;
1543gi.a1 = PI_RomanFont;
1544GrAfonts["smallfont"] = gi;
1545gi.a1 = PI_BoldFont;
1546GrAfonts["smallboldfont"] = gi;
1547gi.a1 = PI_ItalicFont;
1548GrAfonts["smallitalicfont"] = gi;
1549gi.a2 = PI_BigSizeFont;
1550gi.a1 = PI_RomanFont;
1551GrAfonts["bigfont"] = gi;
1552gi.a1 = PI_BoldFont;
1553GrAfonts["bigboldfont"] = gi;
1554gi.a1 = PI_ItalicFont;
1555GrAfonts["bigitalicfont"] = gi;
1556gi.a2 = PI_HugeSizeFont;
1557gi.a1 = PI_RomanFont;
1558GrAfonts["hugefont"] = gi;
1559gi.a1 = PI_BoldFont;
1560GrAfonts["hugeboldfont"] = gi;
1561gi.a1 = PI_ItalicFont;
1562GrAfonts["hugeitalicfont"] = gi;
1563
1564
1565// Les markers
1566const char* mrkn[11] = { "dotmarker", "plusmarker", "crossmarker",
1567 "circlemarker", "fcirclemarker", "boxmarker", "fboxmarker",
1568 "trianglemarker", "ftrianglemarker", "starmarker", "fstarmarker"};
1569PIMarker mrk[11] = { PI_DotMarker, PI_PlusMarker, PI_CrossMarker,
1570 PI_CircleMarker, PI_FCircleMarker, PI_BoxMarker, PI_FBoxMarker,
1571 PI_TriangleMarker, PI_FTriangleMarker, PI_StarMarker, PI_FStarMarker};
1572
1573gi.a2 = 0;
1574gi.a1 = PI_NotDefMarker;
1575GrAmarkers["defmarker"] = gi;
1576
1577for(int j=0; j<11; j++) {
1578 string smrk;
1579 char buff[16];
1580 for(int m=1; m<10; m+=2) {
1581 sprintf(buff,"%d",m);
1582 smrk = (string)mrkn[j] + (string)buff;
1583 gi.a1 = mrk[j]; gi.a2 = m;
1584 GrAmarkers[smrk] = gi;
1585 }
1586 }
1587
1588// Les tables de couleurs
1589gi.a2 = 0;
1590gi.a1 = CMAP_OTHER;
1591GrAcmap["defcmap"] = gi;
1592for(int kcc=0; kcc<PIColorMap::NumberStandardColorMaps(); kcc++) {
1593 gi.a1 = PIColorMap::GetStandardColorMapId(kcc);
1594 string colname = PIColorMap::GetStandardColorMapName(kcc);
1595 for(int jll=0; jll<colname.length(); jll++)
1596 colname[jll] = tolower(colname[jll]);
1597 GrAcmap[colname] = gi;
1598}
1599
1600
1601// La valeur de zoom
1602gi.a2 = 0;
1603gi.a1 = 0;
1604GrAzoom["defzoom"] = gi;
1605gi.a1 = 1;
1606GrAzoom["zoomx1"] = gi;
1607gi.a1 = 2;
1608GrAzoom["zoomx2"] = gi;
1609gi.a1 = 3;
1610GrAzoom["zoomx3"] = gi;
1611gi.a1 = 4;
1612GrAzoom["zoomx4"] = gi;
1613gi.a1 = 5;
1614GrAzoom["zoomx5"] = gi;
1615gi.a1 = -2;
1616GrAzoom["zoom/2"] = gi;
1617gi.a1 = -3;
1618GrAzoom["zoom/3"] = gi;
1619gi.a1 = -4;
1620GrAzoom["zoom/4"] = gi;
1621gi.a1 = -5;
1622GrAzoom["zoom/5"] = gi;
1623
1624// Attributs d'axes
1625gi.a2 = 0;
1626gi.a1 = (int)(kBoxAxes | kExtTicks | kLabels);
1627GrAaxes["stdaxes"] = gi;
1628GrAaxes["defaxes"] = gi;
1629GrAaxes["boxaxes"] = gi;
1630gi.a1 = (int)kAxesDflt;
1631GrAaxes["simpleaxes"] = gi;
1632gi.a1 = (int)(kBoxAxes | kExtTicks | kLabels | kGridOn);
1633GrAaxes["boxaxesgrid"] = gi;
1634
1635gi.a1 = (int)(kBoxAxes | kTicks | kLabels | kMinTicks | kMajTicks);
1636GrAaxes["fineaxes"] = gi;
1637 gi.a1 = (int)(kBoxAxes | kTicks | kLabels | kMinTicks | kMajTicks | kGridOn);
1638GrAaxes["grid"] = gi;
1639GrAaxes["fineaxesgrid"] = gi;
1640
1641}
1642
1643
1644// SANS_EVOLPLANCK Attention !
1645#ifdef SANS_EVOLPLANCK
1646#include "pclassids.h"
1647
1648/* --Methode-- */
1649char* Services2NObjMgr::PClassIdToClassName(int cid)
1650{
1651switch (cid) {
1652 case ClassId_Poly1 :
1653 return("Poly1");
1654 case ClassId_Poly2 :
1655 return("Poly2");
1656 case ClassId_Matrix :
1657 return("Matrix");
1658 case ClassId_Vector :
1659 return("Vector");
1660
1661 case ClassId_DVList :
1662 return("DVList");
1663
1664 case ClassId_Histo1D :
1665 return("Histo1D");
1666 case ClassId_Histo2D :
1667 return("Histo2D");
1668 case ClassId_HProf :
1669 return("HProf");
1670 case ClassId_NTuple :
1671 return("NTuple");
1672 case ClassId_XNTuple :
1673 return("XNTuple");
1674 case ClassId_GeneralFitData :
1675 return("GeneralFitData");
1676
1677 case ClassId_Image :
1678 return("RzImage");
1679 case ClassId_Image + kuint_1 :
1680 return("ImageU1");
1681 case ClassId_Image + kint_1 :
1682 return("ImageI1");
1683 case ClassId_Image + kuint_2 :
1684 return("ImageU2");
1685 case ClassId_Image + kint_2 :
1686 return("ImageI2");
1687 case ClassId_Image + kuint_4 :
1688 return("ImageU4");
1689 case ClassId_Image + kint_4 :
1690 return("ImageI4");
1691 case ClassId_Image + kr_4 :
1692 return("ImageR4");
1693 case ClassId_Image + kr_8 :
1694 return("ImageR8");
1695 case ClassId_ZFidu :
1696 return("ZFidu");
1697
1698 case ClassId_StarList :
1699 return("StarList");
1700 case ClassId_Transfo :
1701 return("Transfo");
1702 case ClassId_PSF :
1703 return("PSF");
1704
1705
1706// - Ajout objet PPF
1707 default:
1708 return("AnyDataObj");
1709 }
1710}
1711
1712#else
1713char* Services2NObjMgr::PClassIdToClassName(int cid)
1714{
1715 return("AnyDataObj");
1716}
1717#endif
Note: See TracBrowser for help on using the repository browser.