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

Last change on this file since 357 was 357, checked in by ercodmgr, 26 years ago

Ajout de parametres de Loop (plot2d, ...), Ajout de fonction de
remplissage de matrices et vecteurs a partir de NTuples,
Rationalisation des commandes (arguments par defauts ...) Reza 6/8/99

File size: 58.1 KB
RevLine 
[165]1#include <stdio.h>
2#include <stdlib.h>
3#include <ctype.h>
4
[295]5#include <typeinfo>
[165]6#include <iostream.h>
7#include <string>
8#include <list>
9#include <map>
10#if defined(__KCC__)
11using std::string ;
12#include <list.h>
13#include <map.h>
14#endif
15
16#include "strutil.h"
17
18#include "nobjmgr.h"
19#include "servnobjm.h"
[330]20#include "nomgadapter.h"
[165]21#include "pistdimgapp.h"
22
[333]23#include "fct1dfit.h"
24#include "fct2dfit.h"
25
26#include "matrix.h"
27#include "cvector.h"
28#include "ntuple.h"
29#include "cimage.h"
30
[165]31#include "histos.h"
32#include "histos2.h"
33#include "ntuple.h"
34#include "hisprof.h"
35
[326]36#include "piscdrawwdg.h"
37#include "pisurfdr.h"
[333]38
39#include "pintuple.h"
40#include "pintup3d.h"
41
[326]42#include "pipodrw.h"
[165]43
44
[326]45
[165]46/* --Methode-- */
[333]47Services2NObjMgr::Services2NObjMgr(NamedObjMgr* omg, string& tmpdir)
[165]48{
49TmpDir = tmpdir;
[171]50PDynLinkMgr::SetTmpDir(tmpdir);
[333]51mImgapp = NULL;
52mOmg = omg;
[171]53dynlink = NULL;
[165]54InitGrAttNames();
55}
56
57/* --Methode-- */
58Services2NObjMgr::~Services2NObjMgr()
59{
60CloseDLL();
61}
62
63/* --Methode-- */
[295]64void Services2NObjMgr::RegisterClass(AnyDataObj* o, NObjMgrAdapter* oa)
[165]65{
[295]66ObjAdaptList::iterator it;
67for(it = objadaplist.begin(); it != objadaplist.end(); it++)
68 if (typeid(*o) == typeid(*((*it).obj))) THROW(dupIdErr);
[165]69
[295]70dataobj_adapter oba;
71oba.obj = o;
72oba.obja = oa;
73objadaplist.push_back(oba);
74}
[165]75
[295]76/* --Methode-- */
77NObjMgrAdapter* Services2NObjMgr::GetAdapter(AnyDataObj* o)
78{
79ObjAdaptList::iterator it;
80for(it = objadaplist.begin(); it != objadaplist.end(); it++)
81 if (typeid(*o) == typeid(*((*it).obj))) return((*it).obja->Clone(o));
82return(new NObjMgrAdapter(o));
83}
[165]84
[295]85/* --Methode-- */
[333]86void Services2NObjMgr::PlotFunc(string const & expfunc, string & nom, double xmin, double xmax, int np, string dopt)
[295]87{
[165]88FILE *fip;
[326]89string fname = TmpDir + "func1_pia_dl.c";
90string cmd;
91int rc;
92
93if (!mImgapp) return;
94
95cmd = "rm -f " + fname;
96rc = system(cmd.c_str());
97// printf("PlotFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
98
99if ((fip = fopen(fname.c_str(), "w")) == NULL) {
100 string sn = fname;
[333]101 cout << "Services2NObjMgr/PlotFunc_Erreur: Pb. Ouverture " << sn << endl;
[326]102 return;
103 }
104
105// constitution du fichier a compiler
106fputs("#include <math.h> \n", fip);
107fputs("double func1_pia_dl_func(double x) \n{\n", fip);
108fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
109fclose(fip);
110
111string func = "func1_pia_dl_func";
112DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);
113if (!f) return;
[333]114PlotFunc(f, nom, xmin, xmax, np, dopt);
[326]115CloseDLL();
116return;
117}
118
119/* --Methode-- */
[333]120void Services2NObjMgr::PlotFunc2D(string const & expfunc, string & nom, double xmin, double xmax,
121 double ymin, double ymax, int npx, int npy, string dopt)
[326]122{
123FILE *fip;
124string fname = TmpDir + "func2_pia_dl.c";
125string cmd;
126int rc;
127
128if (!mImgapp) return;
129
130cmd = "rm " + fname;
131rc = system(cmd.c_str());
132// printf("PlotFunc2D_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
133
134if ((fip = fopen(fname.c_str(), "w")) == NULL) {
135 string sn = fname;
[333]136 cout << "Services2NObjMgr/PlotFunc2D_Erreur: Pb. Ouverture " << sn << endl;
[326]137 return;
138 }
139
140// constitution du fichier a compiler
141fputs("#include <math.h> \n", fip);
142fputs("double func2_pia_dl_func(double x, double y) \n{\n", fip);
143fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
144fclose(fip);
145
146string func = "func2_pia_dl_func";
147DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);
148if (!f) return;
[333]149PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt);
[326]150CloseDLL();
151return;
152}
153
154/* --Methode-- */
[333]155void Services2NObjMgr::PlotFuncFrCFile(string const & fname, string const & func, string & nom,
156 double xmin, double xmax, int np, string dopt)
[326]157{
158DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);
159if (!f) return;
[333]160PlotFunc(f, nom, xmin, xmax, np, dopt);
[326]161CloseDLL();
162return;
163}
164
165/* --Methode-- */
[333]166void Services2NObjMgr::PlotFunc2DFrCFile(string const & fname, string const & func, string & nom,
167 double xmin, double xmax, double ymin, double ymax, int npx, int npy, string dopt)
[326]168{
169DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);
170if (!f) return;
[333]171PlotFunc2D(f, nom, xmin, xmax, ymin, ymax, npx, npy, dopt);
[326]172CloseDLL();
173return;
174}
175
176/* --Methode-- */
[333]177void Services2NObjMgr::PlotFunc(DlFunctionOfX f, string & nom, double xmin, double xmax, int np, string dopt)
[326]178{
179if (!mImgapp) return;
180
181int k;
182if (np < 1) np = 1;
183if (xmax <= xmin) xmax = xmin+1.;
184Vector* vpy = new Vector(np);
185
186double xx;
187double dx = (xmax-xmin)/np;
188TRY {
189 for(k=0; k<np; k++) { xx = xmin+dx*k; (*vpy)(k) = f(xx); }
190} CATCH(merr) {
191 fflush(stdout);
192 cout << endl;
193 cerr << endl;
194 string es = PeidaExc(merr);
195 cerr << "Services2NObjMgr::PlotFunc() Exception :" << merr << es;
196 delete vpy;
197 vpy = NULL;
198 } ENDTRY;
199
200
201if (vpy) {
[344]202 string titre;
203 if (nom.length() < 1) {
204 titre = "Function f(x)";
[357]205 nom = "/home/func";
[344]206 }
207 else titre = nom;
208
209 P1DArrayAdapter* vya = new POVectorAdapter(vpy, false);
[326]210 vya->DefineXCoordinate(xmin, (xmax-xmin)/np);
211 PIYfXDrawer* dr = new PIYfXDrawer(vya, NULL, true) ;
212 bool fgsr = true;
213 dopt = "thinline," + dopt;
214 int opt = DecodeDispOption(dopt, fgsr);
[333]215 int rsid = mImgapp->DispScDrawer(dr, titre, opt);
[326]216 if (fgsr) mImgapp->RestoreGraphicAtt();
[333]217 if (nom.length() > 0) {
218 mOmg->AddObj(vpy, nom);
219 mOmg->AddWRsId(nom, rsid);
220 }
[326]221 }
222
223return;
224}
225
226/* --Methode-- */
[333]227void Services2NObjMgr::PlotFunc2D(DlFunctionOfXY f, string & nom, double xmin, double xmax, double ymin, double ymax,
[326]228 int npx, int npy, string dopt)
229{
230if (!mImgapp) return;
231
232if (npx < 3) npx = 3;
233if (npy < 3) npy = 3;
234if (npx > 250) npx = 250;
235if (npy > 250) npy = 250;
236if (xmax <= xmin) xmax = xmin+1.;
237if (ymax <= ymin) ymax = ymin+1.;
238
239Matrix* mtx = new Matrix(npy, npx);
240
241int i,j;
242double xx, yy;
243double dx = (xmax-xmin)/npx;
244double dy = (ymax-ymin)/npy;
245// printf(" -- DBG -- %d %d , %g %g , %g %g \n", npx, npy, xmin, xmax, ymin, ymax);
246TRY {
247 for(j=0; j<npy; j++) {
248 yy = ymin+dy*j;
249 for(i=0; i<npx; i++) {
250 xx = xmin+dx*i;
251 (*mtx)(j, i) = f(xx, yy);
252 }
253 }
254} CATCH(merr) {
255 fflush(stdout);
256 cout << endl;
257 cerr << endl;
258 string es = PeidaExc(merr);
259 cerr << "Services2NObjMgr::PlotFunc2D() Exception :" << merr << es;
260 delete mtx; mtx = NULL;
261 } ENDTRY;
262
263if (mtx) {
[344]264 string titre;
265 if (nom.length() < 1) {
266 titre = "Function f(x,y)";
[357]267 nom = "/home/func2d";
[344]268 }
269 else titre = nom;
[326]270 bool fgsr = true;
271 int opt = DecodeDispOption(dopt, fgsr);
[344]272 P2DArrayAdapter* arr = new POMatrixAdapter(mtx, false);
[326]273 arr->DefineXYCoordinates(xmin, ymin, dx, dy);
274 PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
[333]275 int rsid = mImgapp->Disp3DDrawer(sdr, titre, opt);
[326]276 if (fgsr) mImgapp->RestoreGraphicAtt();
[333]277 if (nom.length() > 0) {
278 mOmg->AddObj(mtx, nom);
279 mOmg->AddWRsId(nom, rsid);
280 }
[326]281 }
282
283return;
284}
285
286/* --Methode-- */
[333]287void Services2NObjMgr::DisplayPoints2D(string& nom, string& expx, string& expy,
288 string& experrx, string& experry,
[357]289 string& expcut, string dopt, string loop)
[333]290{
291NObjMgrAdapter* obja=NULL;
292obja = mOmg->GetObjAdapter(nom);
293if (obja == NULL) {
294 cout << "Services2NObjMgr::DisplayPoints2D() Error , Pas d'objet de nom " << nom << endl;
295 return;
296 }
297if (!mImgapp) return;
298
299// Creation NTuple
300char* ntn[4] = {"expx","expy","expex","expey",};
301NTuple* nt = NULL;
302bool haserr = false;
303
304if ( (experrx.length() > 0 ) && (experry.length() > 0 ) ) { haserr = true; nt = new NTuple(4, ntn); }
305else { haserr = false; experrx = experry = "0."; nt = new NTuple(2, ntn); }
306
[357]307ComputeExpressions(obja, expx, expy, experrx, experry, expcut, loop, nt, NULL, NULL);
[333]308
309if (nt->NEntry() < 1) {
310 cout << "Services2NObjMgr::DisplayPoints2D() Warning Zero points satisfy cut !" << endl;
311 delete nt;
312 return;
313 }
314
315// nt->Show();
316// nt->Print(0,10);
317PINTuple* pin = new PINTuple(nt, true);
318pin->SelectXY(ntn[0], ntn[1]);
319if ( haserr ) pin->SelectErrBar(ntn[2], ntn[3]);
320
321bool fgsr = true;
322dopt = "defline," + dopt;
323int opt = DecodeDispOption(dopt, fgsr);
324string titre = nom + ":" + expy + "%" + expx;
325mImgapp->DispScDrawer( (PIDrawer*)pin, titre, opt);
326if (fgsr) mImgapp->RestoreGraphicAtt();
327return;
328}
329
330/* --Methode-- */
331void Services2NObjMgr::DisplayPoints3D(string& nom, string& expx, string& expy,
[357]332 string& expz, string& expcut, string dopt, string loop)
[333]333{
334NObjMgrAdapter* obja=NULL;
335obja = mOmg->GetObjAdapter(nom);
336if (obja == NULL) {
337 cout << "Services2NObjMgr::DisplayPoints3D() Error , Pas d'objet de nom " << nom << endl;
338 return;
339 }
340if (!mImgapp) return;
341
342char* ntn[3] = {"expx","expy","expz"};
343NTuple* nt = new NTuple(3,ntn); // Creation NTuple
344
345string expwt = "1.";
[357]346ComputeExpressions(obja, expx, expy, expz, expwt, expcut, loop, nt, NULL, NULL);
[333]347
348if (nt->NEntry() < 1) {
349 cout << "Services2NObjMgr::DisplayPoints3D() Warning Zero points satisfy cut !" << endl;
350 delete nt;
351 return;
352 }
353nt->Show();
354nt->Print(0,10);
355PINTuple3D* pin = new PINTuple3D(nt, true);
356pin->SelectXYZ(ntn[0], ntn[1], ntn[2]);
357bool fgsr = true;
358dopt = "defline," + dopt;
359int opt = DecodeDispOption(dopt, fgsr);
360
361// Pour plot a partir de DispScDrawer
362// string nomdisp = "_NT3D_";
363// mImgapp->DispScDrawer( (PIDrawer*)pin, nomdisp, opt);
364// Pour plot a partir de Disp3DDrawer
365string titre = nom + ":" + expy + "%" + expx;
366mImgapp->Disp3DDrawer(pin, titre, opt);
367
368if (fgsr) mImgapp->RestoreGraphicAtt();
369return;
370}
371
372/* --Methode-- */
373void Services2NObjMgr::DisplayPoints2DW(string& nom, string& expx, string& expy,
[357]374 string& expwt, string& expcut, string dopt, string loop)
[333]375{
376NObjMgrAdapter* obja=NULL;
377obja = mOmg->GetObjAdapter(nom);
378if (obja == NULL) {
379 cout << "Services2NObjMgr::DisplayPoints2DW() Error , Pas d'objet de nom " << nom << endl;
380 return;
381 }
382if (!mImgapp) return;
383
384char* ntn[3] = {"expx","expy","expw"};
385NTuple* nt = new NTuple(3,ntn); // Creation NTuple
386
387string exp = "1.";
[357]388ComputeExpressions(obja, expx, expy, expwt, exp, expcut, loop, nt, NULL, NULL);
[333]389
390if (nt->NEntry() < 1) {
391 cout << "Services2NObjMgr::DisplayPoints2DW() Warning Zero points satisfy cut !" << endl;
392 delete nt;
393 return;
394 }
395
396PINTuple* pin = new PINTuple(nt, true);
397pin->SelectXY(ntn[0], ntn[1]);
398pin->SelectWt(ntn[2]);
399
400bool fgsr = true;
401int opt = DecodeDispOption(dopt, fgsr);
402string titre = nom + ":" + expwt + "_" + expy + "%" + expx ;
403mImgapp->DispScDrawer( (PIDrawer*)pin, titre, opt);
404if (fgsr) mImgapp->RestoreGraphicAtt();
405return;
406}
407
408/* --Methode-- */
409void Services2NObjMgr::ProjectH1(string& nom, string& expx, string& expwt,
[357]410 string& expcut, string& nomh1, string dopt, string loop)
[333]411{
412NObjMgrAdapter* obja=NULL;
413obja = mOmg->GetObjAdapter(nom);
414if (obja == NULL) {
415 cout << "Services2NObjMgr::ProjectH1() Error , Pas d'objet de nom " << nom << endl;
416 return;
417 }
418if (!mImgapp) return;
419
420Histo* h1 = NULL;
421NTuple* nt = NULL;
422AnyDataObj* oh = NULL;
423if (nomh1.length() > 0) oh=mOmg->GetObj(nomh1);
424else nomh1 = "/tmp/projh1d";
425if ( (oh != NULL) && (typeid(*oh) == typeid(Histo)) ) h1 = (Histo*)oh; // Pas de remise a zero ! h1->Zero();
426else {
427 char* ntn[2]= {"hxval", "hwt"};
428 nt = new NTuple(2,ntn); // Creation NTuple
429 }
430string expz = "0.";
[357]431ComputeExpressions(obja, expx, expwt, expz, expwt, expcut, loop, nt, h1, NULL);
[333]432
433if ((!h1) && (!nt)) return;
434if (!h1) {
435 if (nt->NEntry() < 1) {
436 cout << "Services2NObjMgr::ProjectH1() Warning Zero points satisfy cut !" << endl;
437 delete nt;
438 return;
439 }
440 double xmin, xmax;
441 nt->GetMinMax(0, xmin, xmax);
442 h1 = new Histo(xmin, xmax, 100);
443 int k;
444 float* xn;
445 for(k=0; k<nt->NEntry(); k++) {
446 xn = nt->GetVec(k);
447 h1->Add(xn[0], xn[1]);
448 }
449 delete nt;
450 mOmg->AddObj(h1, nomh1);
451 }
452
453mOmg->DisplayObj(nomh1, dopt);
454return;
455}
456
457/* --Methode-- */
458void Services2NObjMgr::ProjectH2(string& nom, string& expx, string& expy, string& expwt,
[357]459 string& expcut, string& nomh2, string dopt, string loop)
[333]460{
461NObjMgrAdapter* obja=NULL;
462obja = mOmg->GetObjAdapter(nom);
463if (obja == NULL) {
464 cout << "Services2NObjMgr::ProjectH2() Error , Pas d'objet de nom " << nom << endl;
465 return;
466 }
467if (!mImgapp) return;
468
469Histo2D* h2 = NULL;
470NTuple* nt = NULL;
471AnyDataObj* oh = NULL;
472if (nomh2.length() > 0) oh=mOmg->GetObj(nomh2);
473else nomh2 = "/tmp/projh2d";
474if ( (oh != NULL) && (typeid(*oh) == typeid(Histo2D)) ) h2 = (Histo2D*)oh; // Pas de remise a zero ! h2->Zero();
475else {
476 char* ntn[3]= {"hxval", "hyval", "hwt"};
477 nt = new NTuple(3,ntn); // Creation NTuple
478 }
479string expz = "0.";
[357]480ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, loop, nt, NULL, h2);
[333]481
482if ((!h2) && (!nt)) return;
483if (!h2) {
484 if (nt->NEntry() < 1) {
485 cout << "Services2NObjMgr::ProjectH2() Warning Zero points satisfy cut !" << endl;
486 delete nt;
487 return;
488 }
489 double xmin, xmax, ymin, ymax;
490 nt->GetMinMax(0, xmin, xmax);
491 nt->GetMinMax(0, ymin, ymax);
492 h2 = new Histo2D(xmin, xmax, 50, ymin, ymax, 50);
493 int k;
494 float* xn;
495 for(k=0; k<nt->NEntry(); k++) {
496 xn = nt->GetVec(k);
497 h2->Add(xn[0], xn[1], xn[2]);
498 }
499 delete nt;
500 mOmg->AddObj(h2, nomh2);
501 }
502
503mOmg->DisplayObj(nomh2, dopt);
504return;
505
506}
507
508/* --Methode-- cmv 13/10/98 */
509void Services2NObjMgr::ProjectHProf(string& nom, string& expx, string& expy, string& expwt,
[357]510 string& expcut, string& nomprof, string dopt, string loop)
511// Pour remplir un ``GeneralFitData'' a partir de divers objets:
[333]512//| nom = nom de l'objet a projeter dans un HProf.
513//| expx = expression X de definition du bin.
514//| expy = expression Y a additionner dans le bin.
515//| expwt = expression W du poids a additionner.
516//| expcut = expression du test de selection.
517//| nomprof = nom du HProf engendre (optionnel). Si l'objet n'existe pas
518//| les limites Xmin,Xmax sont calculees automatiquement.
519//| sinon ce sont celles de l'objet preexistant.
520//| opt = options generales pour le display.
521{
522NObjMgrAdapter* obja=NULL;
523obja = mOmg->GetObjAdapter(nom);
524if (obja == NULL) {
525 cout << "Services2NObjMgr::ProjectHProf() Error , Pas d'objet de nom " << nom << endl;
526 return;
527 }
528if (!mImgapp) return;
529
530HProf* hprof = NULL;
531NTuple* nt = NULL;
532AnyDataObj* oh = NULL;
533if (nomprof.length() > 0) oh=mOmg->GetObj(nomprof);
534else nomprof = "/tmp/projprof";
535if( (oh!=NULL) && (typeid(*oh) == typeid(HProf)) ) hprof = (HProf*)oh;
536else {
537 char* ntn[3]= {"hxval", "hyval", "hwt"};
538 nt = new NTuple(3,ntn); // Creation NTuple
539}
540string expz = "0.";
[357]541ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, loop, nt, NULL, NULL, hprof);
[333]542
543if((!hprof) && (!nt)) return;
544if(!hprof) {
545 if (nt->NEntry() < 1) {
546 cout << "Services2NObjMgr::ProjectHProf() Warning Zero points satisfy cut !" << endl;
547 delete nt;
548 return;
549 }
550 double xmin, xmax;
551 nt->GetMinMax(0, xmin, xmax);
552 hprof = new HProf(xmin, xmax, 100);
553 int k;
554 float* xn;
555 for(k=0; k<nt->NEntry(); k++) {
556 xn = nt->GetVec(k);
557 hprof->Add(xn[0], xn[1], xn[2]);
558 }
559 delete nt;
560 mOmg->AddObj(hprof, nomprof);
561 }
562hprof->UpdateHisto();
563
564mOmg->DisplayObj(nomprof, dopt);
565return;
566}
567
[357]568
[333]569/* --Methode-- */
[357]570void Services2NObjMgr::FillVect(string& nom, string& expx, string& expv,
571 string& expcut, string& nomvec, string dopt, string loop)
[333]572{
573NObjMgrAdapter* obja=NULL;
574obja = mOmg->GetObjAdapter(nom);
575if (obja == NULL) {
[357]576 cout << "Services2NObjMgr::FillVect() Error , No such object: " << nom << endl;
[333]577 return;
578 }
579if (!mImgapp) return;
580
[357]581Vector* v1 = NULL;
582AnyDataObj* ov = NULL;
583ov=mOmg->GetObj(nomvec);
584if (ov != NULL) v1 = dynamic_cast<Vector *>(ov);
585if (v1 == NULL) {
586 cout << "Services2NObjMgr::FillVect() Error , No such object or not a vector: " << nomvec << endl;
587 return;
588 }
589
590char* ntn[2]= {"vi", "vv"};
591NTuple* nt = new NTuple(2,ntn); // Creation NTuple
592
593string expz = "0.";
594ComputeExpressions(obja, expx, expv, expz, expz, expcut, loop, nt);
595
596if (!nt) return;
597if (nt->NEntry() < 1) {
598 cout << "Services2NObjMgr::FillVect() Warning Zero points satisfy cut !" << endl;
599 delete nt;
600 return;
601 }
602
603 int i,k;
604 double* xn;
605 for(k=0; k<nt->NEntry(); k++) {
606 xn = nt->GetLineD(k);
607 i = xn[0]+0.5;
608 if ( (i < 0) || i >= v1->NElts() ) continue;
609 (*v1)(i) = xn[1];
610 }
611 delete nt;
612
613
614mOmg->DisplayObj(nomvec, dopt);
615return;
616}
617
618/* --Methode-- */
619void Services2NObjMgr::FillMatx(string& nom, string& expx, string& expy, string& expv,
620 string& expcut, string& nommtx, string dopt, string loop)
621{
622NObjMgrAdapter* obja=NULL;
623obja = mOmg->GetObjAdapter(nom);
624if (obja == NULL) {
625 cout << "Services2NObjMgr::FillMatx() Error , No such objet " << nom << endl;
626 return;
627 }
628if (!mImgapp) return;
629
630Matrix* mtx = NULL;
631AnyDataObj* om = NULL;
632om=mOmg->GetObj(nommtx);
633if (om != NULL) mtx = dynamic_cast<Matrix *>(om);
634if (mtx == NULL) {
635 cout << "Services2NObjMgr::FillMatx() Error , No such object or not a matrix " << nommtx << endl;
636 return;
637 }
638
639char* ntn[3]= {"mi", "mj", "mv"};
640NTuple* nt = new NTuple(3,ntn); // Creation NTuple
641
642string expz = "0.";
643ComputeExpressions(obja, expx, expy, expv, expz, expcut, loop, nt);
644
645if (!nt) return;
646if (nt->NEntry() < 1) {
647 cout << "Services2NObjMgr::FillMatx() Warning Zero points satisfy cut !" << endl;
648 delete nt;
649 return;
650 }
651
652 int ic, jl, k;
653 double* xn;
654 for(k=0; k<nt->NEntry(); k++) {
655 xn = nt->GetLineD(k);
656 ic = xn[0]+0.5;
657 jl = xn[1]+0.5;
658 if ( (ic < 0) || ic >= mtx->NCol() ) continue;
659 if ( (jl < 0) || jl >= mtx->NRows() ) continue;
660 (*mtx)(jl, ic) = xn[2];
661 }
662 delete nt;
663
664
665mOmg->DisplayObj(nommtx, dopt);
666return;
667
668}
669
670/* --Methode-- */
671void Services2NObjMgr::ExpressionToVector(string& nom, string& expx, string& expcut,
672 string& nomvec, string dopt, string loop)
673{
674NObjMgrAdapter* obja=NULL;
675obja = mOmg->GetObjAdapter(nom);
676if (obja == NULL) {
677 cout << "Services2NObjMgr::ExpressionToVector() Error , Pas d'objet de nom " << nom << endl;
678 return;
679 }
680if (!mImgapp) return;
681
[333]682NTuple* nt = NULL;
[357]683if (nomvec.length() < 1) nomvec = "/tmp/expvec";
[333]684
685char* ntn[2]= {"vecval", "vecwt"};
686nt = new NTuple(1,ntn); // Creation NTuple
687
688string expwt = "1.";
689string expz = "0.";
[357]690ComputeExpressions(obja, expx, expz, expz, expwt, expcut, loop, nt, NULL, NULL);
[333]691
692if (!nt) return;
693if (nt->NEntry() < 1) {
[357]694 cout << "Services2NObjMgr::ExpressionToVector() Warning Zero points satisfy cut !" << endl;
[333]695 delete nt;
696 return;
697 }
698
699Vector* vec = new Vector(nt->NEntry());
700int k;
701float* xn;
702for(k=0; k<nt->NEntry(); k++) {
703 xn = nt->GetVec(k);
704 (*vec)(k) = xn[0];
705 }
706delete nt;
707mOmg->AddObj(vec, nomvec);
708mOmg->DisplayObj(nomvec, dopt);
709return;
710}
711
712/* --Methode-- */
713void Services2NObjMgr::FillNT(string& nom, string& expx, string& expy, string& expz,
[357]714 string& expt, string& expcut, string& nomnt, string loop)
[333]715{
716NObjMgrAdapter* obja=NULL;
717obja = mOmg->GetObjAdapter(nom);
718if (obja == NULL) {
719 cout << "Services2NObjMgr::FillNT() Error , Pas d'objet de nom " << nom << endl;
720 return;
721 }
722if (!mImgapp) return;
723
724bool fgnnt = false;
725NTuple* nt = NULL;
726AnyDataObj* oh = NULL;
727if (nomnt.length() > 0) oh=mOmg->GetObj(nomnt);
728else nomnt = "/tmp/fillnt";
729if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
730 nt = (NTuple*)oh;
731 if (nt->NVar() > 10) {
732 cout << "Services2NObjMgr::FillNT() Warning , Max 10 var ds NTuple -> new NTuple" << endl;
733 nt = NULL;
734 }
735 }
736if (nt == NULL) {
737 char* ntn[4]= {"x", "y","z","t"};
738 nt = new NTuple(4,ntn); // Creation NTuple
739 fgnnt = true;
740 }
741
[357]742ComputeExpressions(obja, expx, expy, expz, expt, expcut, loop, nt, NULL, NULL);
[333]743
744if (fgnnt) mOmg->AddObj(nt, nomnt);
745return;
746
747}
748
749/* --Methode-- */
750void Services2NObjMgr::FillNTFrCFile(string & nom, string const & fname,
[357]751 string const & funcname, string & nomnt, string loop)
[333]752{
753if (!mImgapp) return;
754
755NObjMgrAdapter* obja=NULL;
756obja = mOmg->GetObjAdapter(nom);
757if (obja == NULL) {
758 cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) No such object" <<endl;
759 return;
760 }
[344]761bool adel = true;
762NTupleInterface* objnt = obja->GetNTupleInterface(adel);
[333]763if (objnt == NULL) {
764 cout << "Services2NObjMgr::FillNTFrCFile( " << nom << "...) No NTupleInterface !" <<endl;
765 return;
766 }
767
768NTLoopExprFunc f = (NTLoopExprFunc)LinkFunctionFromFile(fname, funcname);
769if (!f) {
770 cerr << "Services2NObjMgr::FillNTFrCFile Error Creation NTLoopExprFunc" << endl;
[344]771 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
[333]772 return;
773 }
774
775bool fgnnt = false;
776NTuple* nt = NULL;
777if (nomnt.length() > 0) {
778 AnyDataObj* oh = NULL;
779 oh=mOmg->GetObj(nomnt);
780 if ( (oh != NULL) && (typeid(*oh) == typeid(NTuple)) ) {
781 nt = (NTuple*)oh;
782 if (nt->NVar() > 10) {
783 cout << "Services2NObjMgr::FillNTFrCFile() Warning , Max 10 var ds NTuple -> new NTuple" << endl;
784 nt = NULL;
785 }
786 }
787 if (nt == NULL) {
788 char* ntn[4]= {"x", "y","z","t"};
789 nt = new NTuple(4,ntn); // Creation NTuple
790 fgnnt = true;
791 }
792 }
793
794double xnt[10];
795float fxnt[10];
796
797int i,k;
798for(i=0; i<10; i++) fxnt[i] = xnt[i] = 0.;
799
800
801// $CHECK$ A virer des que possible - Pb blocage application quand trop d'impression
802// redirige - On redirige la sortie sur le terminal
803bool red = mImgapp->HasRedirectedStdOutErr();
804mImgapp->RedirectStdOutErr(false);
805
[357]806int k1,k2,dk;
807k1 = 0; k2 = objnt->NbLines(); dk = 1;
808DecodeLoopParameters(loop, k1, k2, dk);
809if (k1 < 0) k1 = 0;
810if (k2 < 0) k2 = objnt->NbLines();
811if (k2 > objnt->NbLines()) k2 = objnt->NbLines();
812if (dk <= 0) dk = 1;
813
[333]814TRY {
815 double* xn;
[357]816 int kmax = k2;
817 for(k=k1; k<kmax; k+=dk) {
[333]818 xn = objnt->GetLineD(k);
819 if (f(xn, xnt, xnt+1, xnt+2, xnt+3, k, kmax) != 0) {
820 if (nt) {
821 for(i=0; i<4; i++) fxnt[i] = xnt[i];
822 nt->Fill(fxnt);
823 }
824 }
825 }
826 }
827CATCH(merr) {
828 fflush(stdout);
829 cout << endl;
830 cerr << endl;
831 string es = PeidaExc(merr);
832 cerr << "Services2NObjMgr::FillNTFrCFile() Exception :" << merr << es;
833 } ENDTRY;
[344]834
835if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
[333]836CloseDLL();
837
838// $CHECK$ A virer des que possible On redirige la sortie sur la fenetre PIConsole
839mImgapp->RedirectStdOutErr(red);
840
841if (fgnnt) mOmg->AddObj(nt, nomnt);
842return;
843}
844
845/* --Methode-- */
846void Services2NObjMgr::PrepareNTExpressionCFile(string & nom, string const & fname,
847 string const & funcname)
848{
849NObjMgrAdapter* obja=NULL;
850obja = mOmg->GetObjAdapter(nom);
851if (obja == NULL) {
852 cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom << "...) No such object" <<endl;
853 return;
854 }
[344]855bool adel = true;
856NTupleInterface* objnt = obja->GetNTupleInterface(adel);
[333]857if (objnt == NULL) {
858 cout << "Services2NObjMgr::PrepareNTExpressionCFile( " << nom
859 << "...) No NTupleInterface !" <<endl;
860 return;
861 }
862string vardec = objnt->VarList_C("_xnti_");
863
864FILE *fip;
865if ((fip = fopen(fname.c_str(), "w")) == NULL) {
866 cout << "Services2NObjMgr::PrepareNTExpressionCFile()_Error: fopen " << fname << endl;
[344]867 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
[333]868 return;
869 }
[344]870
[333]871// constitution du fichier des decalarations des variables de l'interface NTuple
872fputs("#include <stdlib.h> \n", fip);
873fputs("#include <stdio.h> \n", fip);
874fputs("#include <math.h> \n\n", fip);
[344]875
876fputs("/* ------ Some random number generators --------- */ \n", fip);
877fputs("#define frand01() ( (float) drand48() ) \n", fip);
878fputs("#define drand01() drand48() \n", fip);
879fputs("#define rand01() drand48() \n", fip);
880fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
881fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
882fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
883fputs("double NorRand(void) \n", fip);
884fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
885fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
[345]886fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
[344]887fputs(" return(x); \n } \n", fip);
888fputs("#define GauRand() NorRand() \n", fip);
889fputs("#define gaurand() NorRand() \n\n", fip);
890
[333]891fputs("/* NTupleInterface Variable declaration - Generated by piapp \n", fip);
892fputs(" -- Services2NObjMgr::PrepareNTExpressionCFile() -- */ \n\n", fip);
893fprintf(fip,"int %s(double* _xnti_, double* _rx_, double* _ry_, double* _rz_, \n",
894 funcname.c_str());
895fprintf(fip," double* _rt_, int _n_, int _nmax_) \n");
896fprintf(fip, "{ \n %s \n", vardec.c_str());
897fputs(" if (!1) { /* Cut Expression failed */ \n", fip);
898fputs(" *_rx_ = *_ry_ = *_rz_ = *_rt_ = 0.; return(0);", fip);
899fputs(" } \n /* Cut expression satisfied */ \n", fip);
900fputs(" *_rx_ = 1.; \n *_ry_ = 1.; \n *_rz_ = 1.; \n *_rt_ = 1.; \n", fip);
901fputs(" return(1); \n} \n", fip);
902
903fclose(fip);
[344]904
905if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
[333]906return;
907}
908
909
910/* --Methode-- cmv 13/10/98 */
911void Services2NObjMgr::FillGFD(string& nom, string& expx, string& expy, string& expz,
[357]912 string& experr, string& expcut, string& nomgfd, string loop)
[333]913// Pour remplir un ``GeneralFitData'' a partir de divers objets:
914//| nom = nom de l'objet a transcrire selon 1D: Z=f(X) ou 2D: Z=f(X,Y) .
915//| Vector,Matrix,Histo,HProf,Histo2D,Image<T>,StarList,NTuple,GeneralFitData
916//| expx = expression X du GeneralFitData (1er abscisse)
917//| expy = expression Y du GeneralFitData (2sd abscisse si non "", Z=f(X,Y))
918//| expz = expression Z du GeneralFitData (valeur de l'ordonnee)
919//| experr = expression de l'erreur sur l'ordonnee Z
920//| expcut = expression du test de selection
921//| nomgfd = nom du GeneralFitData engendre (optionnel)
922{
923NObjMgrAdapter* obja=NULL;
924obja = mOmg->GetObjAdapter(nom);
925if (obja == NULL) {
926 cout << "Services2NObjMgr::FillGFD() Error , Pas d'objet de nom "<<nom<<endl;
927 return;
928 }
929if(!mImgapp) return;
930
931// 2D ou 3D?
932int nvar = 2;
933if(expy.length()<=0) {nvar = 1; expy = "0.";}
934
935// Creation NTuple Buffer
936char* ntn[4]= {"x","y","f","e"};
937NTuple*nt = new NTuple(4,ntn);
938
939// Remplissage NTuple buffer
[357]940ComputeExpressions(obja, expx, expy, expz, experr, expcut, loop, nt, NULL, NULL);
[333]941if(nt->NEntry() < 1)
942 {cout<<"Services2NObjMgr::FillGFD() Warning Zero points satisfy cut !"<<endl;
943 delete nt; return;}
944
945//Remplissage de la structure GeneraFitData
946if (nt->NEntry() <= 0) {
947 cout<<"Services2NObjMgr::FillGFD() Warning - NData= " << nt->NEntry() << endl;
948 delete nt;
949 return;
950 }
951
952GeneralFitData* gfd = new GeneralFitData(nvar,nt->NEntry(),0);
953int k;
954float* xn;
955for(k=0; k<nt->NEntry(); k++) {
956 xn = nt->GetVec(k);
957 gfd->AddData(xn,xn[2],xn[3]);
958}
959
960// Menage et table d'objets
961delete nt;
962mOmg->AddObj(gfd, nomgfd);
963return;
964}
965
966
967///////////////////// Fit 1D et 2D //////////////////////////
968/* --Function static propre aux routines de fit 1D et 2D-- cmv 13/10/98 */
969struct DFOptions {
970 int okres, okfun;
971 int polcx,polcy; double xc,yc;
972 double err_e, err_E;
973 double stc2;
[341]974 int nstep;
[333]975 int lp,lpg;
976 int i1,i2,j1,j2;
977};
978typedef struct DFOptions DFOPTIONS;
979static void DecodeFitsOptions(string par,string step,string min,string max,string opt
980 ,Vector& Par,Vector& Step,Vector& Min,Vector& Max,DFOPTIONS& O);
981void DecodeFitsOptions(string par,string step,string min,string max,string opt
982 ,Vector& Par,Vector& Step,Vector& Min,Vector& Max,DFOPTIONS& O)
983//| Pour decoder les "string" et remplir les vecteurs du fit (cf commentaires dans Fit1D)
984{
985// set des vecteurs et decodage des string correspondantes
986int NParMax = 100;
987Par.Realloc(NParMax); Step.Realloc(NParMax);
988Min.Realloc(NParMax); Max.Realloc(NParMax);
989{
990 Vector* v=NULL; string* s=NULL;
991 {for(int i=0;i<NParMax;i++) {Par(i)=0.; Step(i)=1.; Min(i)=1.; Max(i)=-1.;}}
992 for(int j=0;j<4;j++) {
993 if(j==0) {v=&Par; s=&par;}
994 else if(j==1) {v=&Step; s=&step;}
995 else if(j==2) {v=&Min; s=&min;}
996 else if(j==3) {v=&Max; s=&max;}
997 if(s->length()>0) *s += ",";
998 for(int i=0;i<NParMax;i++) {
999 if(s->length()<=0) break;
1000 sscanf(s->c_str(),"%lf",&(*v)(i));
1001 size_t p = s->find_first_of(',') + 1;
1002 if(p>=s->length()) *s = ""; else *s = s->substr(p);
1003 }
1004 }
1005}
1006
1007// Decodage de options de opt
1008O.okres = O.okfun = 0;
1009O.polcx = O.polcy = 0;
1010O.xc = O.yc = 0.;
1011O.stc2 = 1.e-3;
[341]1012O.nstep = 100;
[333]1013O.err_e = O.err_E = -1.;
1014O.lp = 1; O.lpg = 0;
1015O.i1 = O.j1 = O.i2 = O.j2 = -1;
1016
1017if(opt.length()<=0) return;
1018opt = "," + opt + ",";
1019
1020if(strstr(opt.c_str(),",r,")) O.okres = 1; // residus
1021if(strstr(opt.c_str(),",f,")) O.okfun = 1; // fonction fittee
1022if(strstr(opt.c_str(),",x")) { // Demande de centrage (fit X=x-xc)
1023 O.polcx = 2; // Le centrage est calcule automatiquement
1024 size_t p = opt.find(",x");
1025 size_t q = opt.find_first_of(',',p+1);
1026 string dum = opt.substr(p,q-p);
1027 if(dum.length()>2) {
1028 sscanf(dum.c_str(),",x%lf",&O.xc);
1029 O.polcx = 1; // Le centrage est fixe par la valeur lue
1030 }
1031}
1032if(strstr(opt.c_str(),",y")) { // Demande de centrage (fit Y=y-yc)
1033 O.polcy = 2; // Le centrage est calcule automatiquement
1034 size_t p = opt.find(",y");
1035 size_t q = opt.find_first_of(',',p+1);
1036 string dum = opt.substr(p,q-p);
1037 if(dum.length()>2) {
1038 sscanf(dum.c_str(),",y%lf",&O.yc);
1039 O.polcy = 1; // Le centrage est fixe par la valeur lue
1040 }
1041}
1042if(strstr(opt.c_str(),",E")) { // Erreurs imposees a "sqrt(val)" ou "aa.b*sqrt(val)"
1043 size_t p = opt.find(",E");
1044 size_t q = opt.find_first_of(',',p+1);
1045 string dum = opt.substr(p,q-p);
1046 if(dum.length()>2) sscanf(dum.c_str(),",E%lf",&O.err_E);
1047 if(O.err_E<=0.) O.err_E = 1.;
1048 O.err_e=-1.;
1049}
1050if(strstr(opt.c_str(),",e")) { // Erreurs imposees a "1" ou "aa.b"
1051 size_t p = opt.find(",e");
1052 size_t q = opt.find_first_of(',',p+1);
1053 string dum = opt.substr(p,q-p);
1054 if(dum.length()>2) sscanf(dum.c_str(),",e%lf",&O.err_e);
1055 if(O.err_e<=0.) O.err_e = 1.;
1056 O.err_E=-1.;
1057}
1058if(strstr(opt.c_str(),",X")) { // Valeur du StopChi2
1059 size_t p = opt.find(",X");
1060 size_t q = opt.find_first_of(',',p+1);
1061 string dum = opt.substr(p,q-p);
1062 if(dum.length()>2) sscanf(dum.c_str(),",X%lf",&O.stc2);
1063 if(O.stc2<=0.) O.stc2 = 1.e-3;
1064}
[341]1065if(strstr(opt.c_str(),",N")) { // Nombre maximum d'iterations
1066 size_t p = opt.find(",N");
1067 size_t q = opt.find_first_of(',',p+1);
1068 string dum = opt.substr(p,q-p);
1069 if(dum.length()>2) sscanf(dum.c_str(),",N%d",&O.nstep);
1070 if(O.nstep<2) O.nstep = 100;
1071}
[333]1072if(strstr(opt.c_str(),",l")) { // niveau de print
1073 size_t p = opt.find(",l");
1074 size_t q = opt.find_first_of(',',p+1);
1075 string dum = opt.substr(p,q-p);
1076 float ab;
1077 if(dum.length()>2) sscanf(dum.c_str(),",l%f",&ab);
1078 if(ab<0) ab = 0.;
[341]1079 O.lp = (int) ab; O.lpg = int(10.*(ab-(float)O.lp+0.01));
[333]1080}
1081if(strstr(opt.c_str(),",I")) { // intervalle de fit selon X
1082 size_t p = opt.find(",I");
1083 size_t q = opt.find_first_of(',',p+1);
1084 string dum = opt.substr(p,q-p);
1085 if(dum.length()>2) sscanf(dum.c_str(),",I%d/%d",&O.i1,&O.i2);
1086}
1087if(strstr(opt.c_str(),",J")) { // intervalle de fit selon Y
1088 size_t p = opt.find(",J");
1089 size_t q = opt.find_first_of(',',p+1);
1090 string dum = opt.substr(p,q-p);
1091 if(dum.length()>2) sscanf(dum.c_str(),",J%d/%d",&O.j1,&O.j2);
1092}
1093return;
1094}
1095
1096/* --Methode-- cmv 13/10/98 */
1097void Services2NObjMgr::Fit12D(string& nom, string& func,
1098 string par,string step,string min,string max,
1099 string opt)
1100//| --------------- Fit d'objets a 1 et 2 dimensions ---------------
1101//| nom : nom de l'objet qui peut etre:
1102//| fit-1D: Vector,Histo1D,HProf ou GeneraFitData(1D)
[341]1103//| fit-2D: Matrix,Histo2D,Image<T> ou GeneraFitData(2D)
1104//| func : pnn : fit polynome degre nn avec classe Poly (lineaire) 1D ou 2D
1105//| : Pnn : fit polynome degre nn avec GeneralFit (non-lineaire) 1D ou 2D
1106//| : gnn : fit gaussienne (hauteur) + polynome de degre nn 1D
1107//| : g : fit gaussienne (hauteur) 1D
1108//| : enn : fit exponentielle + polynome de degre nn 1D
1109//| : e : fit exponentielle 1D
1110//| : Gnn : fit gaussienne (volume) + polynome de degre nn 1D
1111//| : G : fit gaussienne (volume) 1D
1112//| : : fit gaussienne+fond (volume) 2D
1113//| : Gi : fit gaussienne+fond integree (volume) 2D
1114//| : d : fit DL de gaussienne+fond (volume) 2D
1115//| : di : fit DL de gaussienne+fond integree (volume) 2D
1116//| : D : fit DL de gaussienne+fond avec coeff variable p6 (volume) 2D
1117//| : Di : fit DL de gaussienne+fond integree avec coeff variable p6 (volume) 2D
1118//| : M : fit Moffat+fond (expos=p6) (volume) 2D
1119//| : Mi : fit Moffat+fond integree (expos=p6) (volume) 2D
1120//| par : p1,...,pn : valeur d'initialisation des parametres (def=0)
1121//| step : s1,...,sn : valeur des steps de depart (def=1)
1122//| min : m1,...,mn : valeur des minima (def=1)
1123//| max : M1,...,Mn : valeur des maxima (def=-1) (max<=min : pas de limite)
[333]1124//| opt : options "Eaa.b,eaa.b,f,r,caa.b,Xaa.b"
[341]1125//| f : generation d'un Objet identique contenant la fonction fittee
1126//| r : generation d'un Objet identique contenant les residus
1127//| Xaa.b : aa.b valeur du DXi2 d'arret (def=1.e-3)
1128//| Naa : aa nombre maximum d'iterations (def=100)
1129//| la.b : niveau "a.b" de print: a=niveau de print Fit1/2D
1130//| b=niveau de debug GeneralFit
1131//| Ii1/i2 numeros des bins X de l'histos utilises pour le fit [i1,i2]
1132//|2D Jj1/j2 numeros des bins Y de l'histos utilises pour le fit [j1,j2]
1133//| - L'erreur est celle associee a l'objet (si elle existe),
1134//| elle est mise a 1 sinon, sauf si E... ou e... est precise:
1135//| Eaa.b : si |val|>=1 erreur = aa.b*sqrt(|val|)
1136//| si |val|<1 erreur = aa.b
1137//| si aa.b <=0 alors aa.b=1.0
1138//| E seul est equivalent a E1.0
1139//| eaa.b : erreur = aa.b
1140//| si aa.b <=0 alors aa.b=1.0
1141//| e seul est equivalent a e1.0
1142//| xaa.b : demande de centrage: on fit x-aa.b au lieu de x)
1143//| x : demande de centrage: on fit x-xc au lieu de x
1144//| avec xc=abscisse du milieu de l'histogramme
1145//| Actif pour exp+poly 1D, poly 1D
1146//| pour gauss+poly 1D, xc est le centre de la gaussienne.
1147//|2D yaa.b et y : idem "xaa.b et x" mais pour y
[333]1148{
1149AnyDataObj* obj=mOmg->GetObj(nom);
1150if (obj == NULL) {
1151 cout<<"Services2NObjMgr::Fit12D() Error , Pas d'objet de nom "<<nom<<endl;
1152 return;
1153}
1154if (!mImgapp) return;
1155if(func.length()<=0)
1156 {cout<<"Services2NObjMgr::Fit12D() Donnez un nom de fonction a fitter."<<endl;
1157 return;}
1158string ctyp = typeid(*obj).name();
1159
1160int ndim = 0, nbinx=0, nbiny=0, ndata = 0;
1161Vector* v = NULL; Histo* h = NULL;
1162Matrix* m = NULL; Histo2D* h2 = NULL; RzImage* im = NULL;
1163GeneralFitData* g = NULL;
1164
1165 // 1D
1166if (typeid(*obj) == typeid(Vector)) {
1167 ndim = 1;
1168 v = (Vector*) obj; nbinx = v->NElts(); nbiny = 1;
1169 }
1170else if ( (typeid(*obj) == typeid(HProf)) || (typeid(*obj) == typeid(Histo)) ) {
1171 ndim = 1;
1172 h = (Histo*) obj; nbinx = h->NBins(); nbiny = 1;
1173 }
1174else if (typeid(*obj) == typeid(Matrix)) {
1175 ndim = 2;
1176 m = (Matrix*) obj; nbinx = m->NCol(); nbiny = m->NRows();
1177 }
1178else if (typeid(*obj) == typeid(Histo2D)) {
1179 ndim = 2;
1180 h2 = (Histo2D*) obj; nbinx = h2->NBinX(); nbiny = h2->NBinY();
1181 }
1182else if (typeid(*obj) == typeid(GeneralFitData)) {
1183 g = (GeneralFitData*) obj; nbinx = g->NData(); nbiny = 1;
1184 if( g->NVar()==1) ndim = 1;
1185 else if(g->NVar()==2) ndim = 2;
1186 else {
1187 cout<<"GeneralFitData ne peut avoir que 1 ou 2 variables d'abscisse: "
1188 <<((GeneralFitData*) obj)->NVar()<<endl; return; }
1189 }
1190else if (dynamic_cast<RzImage*>(obj)) {
1191 ndim = 2;
1192 im = (RzImage*) obj; nbinx = im->XSize(); nbiny = im->YSize();
1193 }
1194else {
1195 cout<<"Services2NObjMgr::Fit12D() Error , Objet n'est pas un "
1196 <<"Histo1D/HProf/Vector/Histo2D/Image/Matrix/GeneralFitData "<<ctyp<<endl;
1197 return;
1198 }
1199
1200ndata = nbinx*nbiny;
1201if(ndata<=0)
1202 {cout<<"L'objet a "<<nbinx<<","<<nbiny<<" bins ("<<ndata<<")"<<endl; return;}
1203
1204// Decodage des options et des parametres, mise en forme
1205Vector Par(1); Vector Step(1); Vector Min(1); Vector Max(1); DFOPTIONS O;
1206DecodeFitsOptions(par,step,min,max,opt,Par,Step,Min,Max,O);
1207O.i1 = (O.i1<0||O.i1>=nbinx)? 0: O.i1;
1208O.i2 = (O.i2<0||O.i2>=nbinx||O.i2<O.i1)? nbinx-1: O.i2;
1209if(ndim>=2) {
1210 O.j1 = (O.j1<0||O.j1>=nbiny)? 0: O.j1;
1211 O.j2 = (O.j2<0||O.j2>=nbiny||O.j2<O.j1)? nbiny-1: O.j2;
1212} else O.j2 = O.j1 = 0;
1213if(O.polcx==2) {
1214 if(v||m) O.xc = (O.i2-O.i1+1)/2.;
1215 else if(h) O.xc = (h->XMin()+h->XMax())/2.;
1216 else if(h2) O.xc = (h2->XMin()+h2->XMax())/2.;
1217 else if(g) {double mini,maxi; g->GetMinMax(2,mini,maxi); O.xc=(mini+maxi)/2.;}
1218 else if(im) {O.xc = im->XOrg() * im->XPxSize()*(O.i2-O.i1+1)/2.;}
1219}
1220if(O.polcy==2 && ndim>=2) {
1221 if(m) O.yc = (O.j2-O.j1+1)/2.;
1222 if(h2) O.yc = (h2->YMin()+h2->YMax())/2.;
1223 if(g) {double mini,maxi; g->GetMinMax(12,mini,maxi); O.yc=(mini+maxi)/2.;}
1224 if(im) {O.yc = im->YOrg() * im->YPxSize()*(O.j2-O.j1+1)/2.;}
1225}
1226if(O.lp>0)
1227 cout<<"Fit["<<nbinx<<","<<nbiny<<"] ("<<ndata<<") dim="<<ndim<<":"
1228 <<" Int=["<<O.i1<<","<<O.i2<<"],["<<O.j1<<","<<O.j2<<"]"<<endl
1229 <<" Cent="<<O.polcx<<","<<O.polcy<<","<<O.xc<<"+x"<<","<<O.yc<<"+y"
1230 <<" TypE="<<O.err_e<<","<<O.err_E
[341]1231 <<" StpX2="<<O.stc2<<" Nstep="<<O.nstep
[333]1232 <<" lp,lpg="<<O.lp<<","<<O.lpg<<endl;
1233
1234///////////////////////////////////
1235// Remplissage de GeneralFitData //
1236///////////////////////////////////
1237GeneralFitData mydata(ndim,ndata,0);
1238{for(int i=O.i1;i<=O.i2;i++) for(int j=O.j1;j<=O.j2;j++) {
1239 double x,y,f,e;
1240
1241 if(v)
1242 {x= (double) i; f=(*v)(i); e=1.;}
1243 else if(h)
1244 {x=h->BinCenter(i); f=(*h)(i); e=(h->HasErrors())?h->Error(i):1.;}
1245 else if(m)
1246 {x=(double) i; y=(double) j; f=(*m)(j,i); e=1.;}
1247 else if(h2)
1248 {float xf,yf; h2->BinCenter(i,j,xf,yf); x=(double)xf; y=(double)yf;
1249 f=(*h2)(i,j); e=(h2->HasErrors())?h2->Error(i,j):1.;}
1250 else if(im)
1251 {x=im->XOrg()+(i+0.5)*im->XPxSize(); y=im->YOrg()+(j+0.5)*im->YPxSize();
1252 f=im->DValue(i,j); e=1.;}
1253 else if(g&&ndim==1) {x= g->X(i); f=g->Val(i); e=g->EVal(i);}
1254 else if(g&&ndim==2) {x= g->X(i); y= g->Y(i); f=g->Val(i); e=g->EVal(i);}
1255 else x=y=f=e=0.;
1256
1257 // Gestion des erreurs a utiliser
1258 if(O.err_e>0.) e=O.err_e;
[341]1259 else if(O.err_E>0.) {e=(f<-1.||f>1.)?O.err_E*sqrt(fabs(f)):O.err_E;}
[333]1260
1261 // Remplissage de generalfit
1262 if(func[0]=='p') {x -= O.xc; if(ndim>=2) y -= O.yc;}
1263 if(ndim==1) mydata.AddData1(x,f,e);
1264 else if(ndim==2) mydata.AddData2(x,y,f,e);
1265}}
1266if(mydata.NData()<=0)
1267 {cout<<"Pas de donnees dans GeneralFitData: "<<mydata.NData()<<endl;
1268 return;}
1269if(O.lpg>1) {
1270 mydata.PrintStatus();
1271 mydata.PrintData(0);
1272 mydata.PrintData(mydata.NData()-1);
1273}
1274
1275////////////////////////////////////////////
1276// Identification de la fonction a fitter //
1277////////////////////////////////////////////
1278GeneralFunction* myfunc = NULL;
1279if(func[0]=='p' && ndim==1) {
1280 // Fit de polynome sans passer par les GeneralFit
1281 int degre = 0;
1282 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1283 cout<<"Fit (lineaire) 1D polynome de degre "<<degre<<endl;
1284 Poly p1(0);
1285 double c2rl = mydata.PolFit(0,p1,degre);
1286 cout<<"C2r_lineaire = "<<c2rl<<endl;
1287 if(O.lp>0) cout<<p1<<endl;
1288 return;
1289
1290} else if(func[0]=='P' && ndim==1) {
1291 // Fit de polynome
1292 int degre = 0;
1293 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1294 cout<<"Fit polynome 1D de degre "<<degre<<endl;
1295 Polyn1D* myf = new Polyn1D(degre,O.xc);
1296 myfunc = myf;
1297
1298} else if(func[0]=='e' && ndim==1) {
1299 // Fit d'exponentielle
1300 int degre =-1;
1301 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1302 cout<<"Fit d'exponentielle+polynome 1D de degre "<<degre<<endl;
1303 Exp1DPol* myf;
1304 if(degre>=0) myf = new Exp1DPol((unsigned int)degre,O.xc);
1305 else myf = new Exp1DPol(O.xc);
1306 myfunc = myf;
1307
1308} else if(func[0]=='g' && ndim==1) {
1309 // Fit de gaussienne en hauteur
1310 int degre =-1;
1311 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1312 cout<<"Fit de Gaussienne_en_hauteur+polynome 1D de degre "<<degre<<endl;
1313 Gauss1DPol* myf;
1314 if(degre>=0) myf = new Gauss1DPol((unsigned int)degre,((O.polcx)?true:false));
1315 else { bool bfg = (O.polcx)?true:false; myf = new Gauss1DPol(bfg); }
1316 myfunc = myf;
1317
1318} else if(func[0]=='G' && ndim==1) {
1319 // Fit de gaussienne en volume
1320 int degre =-1;
1321 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1322 cout<<"Fit de Gaussienne_en_volume+polynome 1D de degre "<<degre<<endl;
1323 GaussN1DPol* myf;
1324 if(degre>=0) myf = new GaussN1DPol((unsigned int)degre,((O.polcx)?true:false));
1325 else { bool bfg = (O.polcx)?true:false; myf = new GaussN1DPol(bfg); }
1326 myfunc = myf;
1327
1328} else if(func[0]=='p' && ndim==2) {
1329 // Fit de polynome 2D sans passer par les GeneralFit
1330 int degre = 0;
1331 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1332 cout<<"Fit (lineaire) polynome 2D de degre "<<degre<<endl;
1333 Poly2 p2(0);
1334 double c2rl = mydata.PolFit(0,1,p2,degre);
1335 cout<<"C2r_lineaire = "<<c2rl<<endl;
1336 if(O.lp>0) cout<<p2<<endl;
1337 return;
1338
1339} else if(func[0]=='P' && ndim==2) {
1340 // Fit de polynome 2D
1341 int degre = 0;
1342 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1343 cout<<"Fit polynome 2D de degre "<<degre<<endl;
1344 Polyn2D* myf = new Polyn2D(degre,O.xc,O.yc);
1345 myfunc = myf;
1346
1347} else if(func[0]=='G' && ndim==2) {
1348 // Fit de gaussienne+fond en volume
1349 int integ = 0;
1350 if(func.length()>1) if(func[1]=='i') integ=1;
1351 cout<<"Fit de Gaussienne+Fond 2D integ="<<integ<<endl;
1352 if(integ) {GauRhInt2D* myf = new GauRhInt2D; myfunc = myf;}
1353 else {GauRho2D* myf = new GauRho2D; myfunc = myf;}
1354
1355} else if(func[0]=='d' && ndim==2) {
1356 // Fit de DL gaussienne+fond en volume
1357 int integ = 0;
1358 if(func.length()>1) if(func[1]=='i') integ=1;
1359 cout<<"Fit de DL de Gaussienne+Fond 2D integ="<<integ<<endl;
1360 if(integ) {GdlRhInt2D* myf = new GdlRhInt2D; myfunc = myf;}
1361 else {GdlRho2D* myf = new GdlRho2D; myfunc = myf;}
1362
1363} else if(func[0]=='D' && ndim==2) {
1364 // Fit de DL gaussienne+fond avec coeff variable p6 en volume
1365 int integ = 0;
1366 if(func.length()>1) if(func[1]=='i') integ=1;
1367 cout<<"Fit de DL de Gaussienne+Fond avec coeff variable (p6) 2D integ="<<integ<<endl;
1368 if(integ) {Gdl1RhInt2D* myf = new Gdl1RhInt2D; myfunc = myf;}
1369 else {Gdl1Rho2D* myf = new Gdl1Rho2D; myfunc = myf;}
1370
1371} else if(func[0]=='M' && ndim==2) {
1372 // Fit de Moffat+fond (volume)
1373 int integ = 0;
1374 if(func.length()>1) if(func[1]=='i') integ=1;
1375 cout<<"Fit de Moffat+Fond (expos=p6) 2D integ="<<integ<<endl;
1376 if(integ) {MofRhInt2D* myf = new MofRhInt2D; myfunc = myf;}
1377 else {MofRho2D* myf = new MofRho2D; myfunc = myf;}
1378
1379} else {
1380 cout<<"Fonction "<<func<<" inconnue pour la dim "<<ndim<<endl;
1381 return;
1382}
1383
1384/////////////////////////
1385// Fit avec generalfit //
1386/////////////////////////
1387if(myfunc->NPar()>Par.NElts())
1388 {cout<<"Trop de parametres: "<<myfunc->NPar()<<">"<<Par.NElts()<<endl;
1389 if(myfunc) delete myfunc; return;}
1390GeneralFit myfit(myfunc);
1391myfit.SetDebug(O.lpg);
1392myfit.SetData(&mydata);
1393myfit.SetStopChi2(O.stc2);
[341]1394myfit.SetMaxStep(O.nstep);
[333]1395{for(int i=0;i<myfunc->NPar();i++) {
1396 char str[10];
1397 sprintf(str,"P%d",i);
1398 myfit.SetParam(i,str,Par(i),Step(i),Min(i),Max(i));
1399}}
1400if(O.lp>1) myfit.PrintFit();
[341]1401double c2r = -1.;
1402int rcfit = (double) myfit.Fit();
[333]1403if(O.lp>0) myfit.PrintFit();
[341]1404if(rcfit>0) {
[333]1405 c2r = myfit.GetChi2Red();
[341]1406 cout<<"C2r_Reduit = "<<c2r<<" nstep="<<myfit.GetNStep()<<" rc="<<rcfit<<endl;
[333]1407 Vector ParFit(myfunc->NPar());
1408 for(int i=0;i<myfunc->NPar();i++) ParFit(i)=myfit.GetParm(i);
1409} else {
[341]1410 cout<<"echec Fit, rc = "<<rcfit<<" nstep="<<myfit.GetNStep()<<endl;
1411 myfit.PrintFitErr(rcfit);
[333]1412}
1413
1414// Mise a disposition des resultats
[341]1415if(rcfit>=0 && myfunc && (O.okres>0||O.okfun>0)) {
[333]1416 string nomres = nom + "res";
1417 string nomfun = nom + "fun";
1418 if(v) {
1419 if(O.okres) {Vector* ob = v->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);}
1420 if(O.okfun) {Vector* ob = v->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);}
1421 } else if(h) {
1422 if(O.okres) {Histo* ob = h->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);}
1423 if(O.okfun) {Histo* ob = h->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);}
1424 } else if(m) {
1425 if(O.okres) {Matrix* ob = m->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);}
1426 if(O.okfun) {Matrix* ob = m->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);}
1427 } else if(h2) {
1428 if(O.okres) {Histo2D* ob = h2->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);}
1429 if(O.okfun) {Histo2D* ob = h2->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);}
1430 } else if(im) {
1431 if(O.okres) {RzImage* ob = im->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);}
1432 if(O.okfun) {RzImage* ob = im->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);}
1433 } else if(g) {
1434 if(O.okres) {GeneralFitData* ob = g->FitResidus(myfit); if(ob) mOmg->AddObj(ob,nomres);}
1435 if(O.okfun) {GeneralFitData* ob = g->FitFunction(myfit); if(ob) mOmg->AddObj(ob,nomfun);}
1436 }
1437}
1438
1439// Nettoyage
1440if(myfunc) delete myfunc;
1441return;
1442}
1443
1444
1445/* --Methode-- */
1446void Services2NObjMgr::ComputeExpressions(NObjMgrAdapter* obja, string& expx,
[357]1447 string& expy, string& expz, string& expt, string& expcut, string& loop,
[333]1448 NTuple* nt, Histo* h1, Histo2D* h2, HProf* hp)
1449{
1450if (obja == NULL) return;
[344]1451bool adel = true;
1452NTupleInterface* objnt = obja->GetNTupleInterface(adel);
[333]1453if (objnt == NULL) return;
1454string vardec = objnt->VarList_C("_zz6qi_");
1455
1456PlotExprFunc f = LinkExprFunc(vardec, expx, expy, expz, expt, expcut);
1457if (!f) {
1458 cerr << "Services2NObjMgr::::ComputeExpressions() Error Creation PlotExprFunc " << endl;
[344]1459 if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
[333]1460 return;
1461 }
1462
1463double xnt[10];
1464float fxnt[10];
1465
1466int i,k;
1467for(i=0; i<10; i++) xnt[i] = 0.;
[357]1468int k1,k2,dk;
1469k1 = 0; k2 = objnt->NbLines(); dk = 1;
1470DecodeLoopParameters(loop, k1, k2, dk);
1471if (k1 < 0) k1 = 0;
1472if (k2 < 0) k2 = objnt->NbLines();
1473if (k2 > objnt->NbLines()) k2 = objnt->NbLines();
1474if (dk <= 0) dk = 1;
[333]1475TRY {
1476 double* xn;
[357]1477 for(k=k1; k<k2; k += dk) {
[333]1478 xn = objnt->GetLineD(k);
1479 if (f(xn, xnt, xnt+1, xnt+2, xnt+3) != 0) {
1480 if (nt) {
1481 for(i=0; i<4; i++) fxnt[i] = xnt[i];
1482 nt->Fill(fxnt);
1483 }
1484 if (h1) h1->Add(xnt[0], xnt[3]);
1485 if (h2) h2->Add(xnt[0], xnt[1], xnt[3]);
1486 if (hp) hp->Add(xnt[0], xnt[1], xnt[3]);
1487 }
1488 }
1489 }
1490CATCH(merr) {
1491 fflush(stdout);
1492 cout << endl;
1493 cerr << endl;
1494 string es = PeidaExc(merr);
1495 cerr << "Services2NObjMgr::ComputeExpressions() Exception :" << merr << es;
1496 } ENDTRY;
1497
1498
[344]1499if (adel) delete objnt; // Delete de l'objet NTupleInterface si necessaire
[333]1500// Fermeture du fichier .so
1501CloseDLL();
1502return;
1503}
1504
1505
1506/* --Methode-- */
1507PlotExprFunc Services2NObjMgr::LinkExprFunc(string& vardec, string& expx, string& expy,
1508 string& expz, string& expt, string& cut)
1509{
1510FILE *fip;
1511string fname = TmpDir + "expf_pia_dl.c";
1512string cmd;
1513int rc;
1514
1515cmd = "rm -f " + fname;
1516rc = system(cmd.c_str());
1517//DBG printf("LinkExprFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
1518
1519if ((fip = fopen(fname.c_str(), "w")) == NULL) {
1520 string sn = fname;
1521 cout << "Services2NObjMgr/LinkExprFunc_Erreur: Pb. Ouverture " << sn << endl;
1522 return(NULL);
1523 }
1524
1525// constitution du fichier a compiler
1526fputs("#include <stdlib.h> \n", fip);
1527fputs("#include <math.h> \n", fip);
[344]1528
1529fputs("/* ------ Some random number generators --------- */ \n", fip);
1530fputs("#define frand01() ( (float) drand48() ) \n", fip);
1531fputs("#define drand01() drand48() \n", fip);
1532fputs("#define rand01() drand48() \n", fip);
1533fputs("#define frandpm1() ( 2. * frand01() - 1.) \n", fip);
1534fputs("#define drandpm1() ( 2. * drand01() - 1.) \n", fip);
1535fputs("#define randpm1() ( 2. * drand01() - 1.) \n", fip);
1536fputs("double NorRand(void) \n", fip);
1537fputs(" { \n double x,A,B; \n LAB10: \n A = drand01(); \n", fip);
1538fputs(" if ( A == 0. ) goto LAB10; \n B = drand01(); \n", fip);
[345]1539fputs(" x = sqrt(-2.*log(A))*cos(2.*M_PI*B); \n", fip);
[344]1540fputs(" return(x); \n } \n", fip);
1541fputs("#define GauRand() NorRand() \n", fip);
1542fputs("#define gaurand() NorRand() \n\n", fip);
1543
[333]1544fputs("int expf_pia_dl_func(double* _zz6qi_, double* _rx_6q_, double* _ry_6q_, double* _rz_6q_, double* _rt_6q_) \n{\n", fip);
1545fprintf(fip,"%s \n", vardec.c_str());
1546fprintf(fip, "if (!(%s)) { *_rx_6q_ = *_ry_6q_ = *_rz_6q_ = *_rt_6q_ = 0.; return(0); } \n", cut.c_str());
1547fprintf(fip, "*_rx_6q_ = %s ; \n", expx.c_str());
1548fprintf(fip, "*_ry_6q_ = %s ; \n", expy.c_str());
1549fprintf(fip, "*_rz_6q_ = %s ; \n", expz.c_str());
1550fprintf(fip, "*_rt_6q_ = %s ; \n", expt.c_str());
1551fputs("return(1); \n} \n", fip);
1552fclose(fip);
1553string func = "expf_pia_dl_func";
1554return((PlotExprFunc)LinkFunctionFromFile(fname, func));
1555}
1556
1557
1558/* --Methode-- */
1559DlFunction Services2NObjMgr::LinkFunctionFromFile(string const & fname, string const & funcname)
1560{
1561// Le link dynamique
1562CloseDLL();
1563dynlink = PDynLinkMgr::BuildFromCFile(fname);
1564if (dynlink == NULL) {
1565 cerr << "Services2NObjMgr/LinkFunctionFromFile_Erreur: Erreur creation/Ouverture SO " << endl;
1566 return(NULL);
1567 }
1568
1569DlFunction retfunc = dynlink->GetFunction(funcname);
1570if (retfunc == NULL) {
1571 string sn = funcname;
1572 cerr << "Services2NObjMgr/LinkExprFunc_Erreur: Erreur linking " << sn << endl;
1573 CloseDLL();
1574 return(NULL);
1575 }
1576else return(retfunc);
1577}
1578
1579/* --Methode-- */
1580void Services2NObjMgr::CloseDLL()
1581{
1582if (dynlink) delete dynlink; dynlink = NULL;
1583}
1584
[357]1585// Fonction static
1586/* --Methode-- */
1587void Services2NObjMgr::DecodeLoopParameters(string& loop, int& i1, int& i2, int& di)
1588{
1589// Decode des paramatres de boucle for(int i=i1; i<i2; i+=di) specifies
1590// sous forme i1[:i2[:di]]
1591// cout << "LoopParam() " << loop << " I1=" << i1 << " I2=" << i2 << " DI=" << di;
1592size_t l = loop.length();
1593if (l < 1) return;
1594size_t p = loop.find(':');
1595if (p >= l) { i1 = atoi(loop.c_str()); return; }
1596i1 = atoi(loop.substr(0, p).c_str());
1597string aa = loop.substr(p+1);
1598p = aa.find(':');
1599if (p < aa.length() ) {
1600 i2 = atoi(aa.substr(0,p).c_str());
1601 di = atoi(aa.substr(p+1).c_str());
1602 }
1603else i2 = atoi(aa.c_str());
1604// cout << "-> I1= " << i1 << " I2= " << i2 << " DI= " << di << endl;
1605return;
1606}
[333]1607
1608/* --Methode-- */
[165]1609string Services2NObjMgr::FileName2Name(string const & fn)
1610{
1611
1612char fsep[2] = {FILESEP, '\0'};
1613char tsep[2] = {'.', '\0'};
1614size_t p = fn.find_last_of(fsep);
[194]1615size_t l = fn.length();
1616if (p >= l) p = 0;
1617else p++;
1618size_t q = fn.find_first_of(tsep,p);
1619if (q < p) q = l;
[165]1620return(fn.substr(p,q-p));
1621}
1622
1623
1624typedef vector<string> GraTok;
1625
1626/* --Methode-- */
1627int Services2NObjMgr::DecodeDispOption(string& gratt, bool& fgsrgr)
1628{
1629int ropt = Disp_Next;
1630if (!mImgapp) return(ropt);
1631
1632for(int i=0; i<gratt.length(); i++) gratt[i] = tolower(gratt[i]);
1633
1634if (fgsrgr) mImgapp->SaveGraphicAtt();
1635
[326]1636if ( (gratt == "def") || (gratt == "default") ) { // Remise aux valeurs par defaut = non defini
[165]1637 mImgapp->SetColAtt();
1638 mImgapp->SetLineAtt();
1639 mImgapp->SetFontAtt();
1640 mImgapp->SetMarkerAtt();
1641 mImgapp->SetColMapId();
1642 mImgapp->SetZoomAtt();
[331]1643 mImgapp->SetAxesAtt();
1644 mImgapp->SetXYLimits();
1645 mImgapp->UseXYLimits();
[165]1646 return(ropt);
1647 }
1648
1649// On separe en mots separes par des virgules
1650gratt = ","+gratt;
1651size_t p = 0;
1652size_t q = 0;
1653size_t l = gratt.length();
1654string token;
1655
1656GraTok grt;
1657
1658while (q < l) {
1659 p = gratt.find_first_not_of(" ,",q+1); // au debut d'un token
1660 if (p>=l) break;
1661 q = gratt.find_first_of(" ,",p); // la fin du token;
1662 token = gratt.substr(p,q-p);
1663 grt.push_back(token);
1664 }
1665
1666
1667static GrAttNames::iterator it;
1668
1669int k;
1670bool fgcont = true;
1671fgsrgr = false;
1672
1673for(k=0; k<grt.size(); k++) {
1674// cout << "--DBG--SetGraphicAttributes() " << grt[k] << endl;
1675
1676 // Decodage option affichage (win, next, etc
1677 fgcont = true;
1678 if ( (grt[k] == "win") || (grt[k] == "w") ) ropt = Disp_Win;
1679 else if ( (grt[k] == "same") || (grt[k] == "s") ) ropt = Disp_Same;
1680 else if ( (grt[k] == "stack") || (grt[k] == "st") ) ropt = Disp_Stack;
1681 else fgcont = false;
1682 if (fgcont) continue;
[331]1683
1684 // Utilisation limites X-Y
1685 if ( grt[k] == "xylimits" ) { mImgapp->UseXYLimits(true); fgsrgr = true; continue; }
[165]1686 // Si c'est une couleur
1687 it = GrAcolors.find(grt[k]);
1688 if (it != GrAcolors.end()) { mImgapp->SetColAtt((PIColors)((*it).second.a1)); fgsrgr = true; continue; }
1689 // Si c'est un attribut de lignes
1690 it = GrAlines.find(grt[k]);
1691 if (it != GrAlines.end()) { mImgapp->SetLineAtt((PILineAtt)((*it).second.a1)); fgsrgr = true; continue; }
1692 // Si c'est un attribut de fontes
1693 it = GrAfonts.find(grt[k]);
1694 if (it != GrAfonts.end()) { mImgapp->SetFontAtt((PIFontSize)((*it).second.a2), (PIFontAtt)((*it).second.a1) );
1695 fgsrgr = true; continue; }
1696 // Si c'est un attribut de markers
1697 it = GrAmarkers.find(grt[k]);
1698 if (it != GrAmarkers.end()) { mImgapp->SetMarkerAtt((*it).second.a2, (PIMarker)((*it).second.a1) );
1699 fgsrgr = true; continue; }
1700 // Si c'est un colormap
1701 it = GrAcmap.find(grt[k]);
1702 if (it != GrAcmap.end()) { mImgapp->SetColMapId( (CMapId)((*it).second.a1) ); fgsrgr = true; continue; }
1703 // Si c'est un facteur de zoom
1704 it = GrAzoom.find(grt[k]);
1705 if (it != GrAzoom.end()) { mImgapp->SetZoomAtt( (*it).second.a1 ); fgsrgr = true; continue; }
[203]1706 // Si c'est un attribut d'axe
1707 it = GrAaxes.find(grt[k]);
1708 if (it != GrAaxes.end()) { mImgapp->SetAxesAtt( (*it).second.a1 ); fgsrgr = true; continue; }
[165]1709
1710 }
1711
1712return(ropt);
1713}
1714
1715
1716
1717// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1718// Initialisation des chaines de caracteres designant les attributs graphiques
1719
1720/* --Methode-- */
1721void Services2NObjMgr::InitGrAttNames()
1722{
1723gratt_item gi;
1724// Les couleurs
1725gi.a2 = 0;
1726gi.a1 = PI_NotDefColor;
1727GrAcolors["defcol"] = gi;
1728gi.a1 = PI_Black;
1729GrAcolors["black"] = gi;
1730gi.a1 = PI_White;
1731GrAcolors["white"] = gi;
1732gi.a1 = PI_Grey;
1733GrAcolors["grey"] = gi;
1734gi.a1 = PI_Red;
1735GrAcolors["red"] = gi;
1736gi.a1 = PI_Blue;
1737GrAcolors["blue"] = gi;
1738gi.a1 = PI_Green;
1739GrAcolors["green"] = gi;
1740gi.a1 = PI_Yellow;
1741GrAcolors["yellow"] = gi;
1742gi.a1 = PI_Magenta;
1743GrAcolors["magenta"] = gi;
1744
1745gi.a1 = PI_Cyan;
1746GrAcolors["cyan"] = gi;
1747gi.a1 = PI_Turquoise;
1748GrAcolors["turquoise"] = gi;
1749gi.a1 = PI_NavyBlue;
1750GrAcolors["navyblue"] = gi;
1751gi.a1 = PI_Orange;
1752GrAcolors["orange"] = gi;
1753gi.a1 = PI_SiennaRed;
1754GrAcolors["siennared"] = gi;
1755gi.a1 = PI_Purple;
1756GrAcolors["purple"] = gi;
1757gi.a1 = PI_LimeGreen;
1758GrAcolors["limegreen"] = gi;
1759gi.a1 = PI_Gold;
1760GrAcolors["gold"] = gi;
1761
1762// Les attributs de lignes
1763gi.a2 = 0;
1764gi.a1 = PI_NotDefLineAtt;
1765GrAlines["defline"] = gi;
1766gi.a1 = PI_NormalLine;
1767GrAlines["normalline"] = gi;
1768gi.a1 = PI_ThinLine;
1769GrAlines["thinline"] = gi;
1770gi.a1 = PI_ThickLine;
1771GrAlines["thickline"] = gi;
1772gi.a1 = PI_DashedLine;
1773GrAlines["dashedline"] = gi;
1774gi.a1 = PI_ThinDashedLine;
1775GrAlines["thindashedline"] = gi;
1776gi.a1 = PI_ThickDashedLine;
1777GrAlines["thickdashedline"] = gi;
[192]1778gi.a1 = PI_DottedLine;
1779GrAlines["dottedline"] = gi;
1780gi.a1 = PI_ThinDottedLine;
1781GrAlines["thindottedline"] = gi;
1782gi.a1 = PI_ThickDottedLine;
1783GrAlines["thickdottedline"] = gi;
[165]1784
[293]1785// Les fontes
[165]1786gi.a2 = PI_NotDefFontSize;
1787gi.a1 = PI_NotDefFontAtt;
[349]1788GrAfonts["deffont"] = gi;
[165]1789
1790gi.a2 = PI_NormalSizeFont;
1791gi.a1 = PI_RomanFont;
[349]1792GrAfonts["normalfont"] = gi;
[165]1793gi.a1 = PI_BoldFont;
[349]1794GrAfonts["boldfont"] = gi;
[165]1795gi.a1 = PI_ItalicFont;
[349]1796GrAfonts["italicfont"] = gi;
[165]1797gi.a2 = PI_SmallSizeFont;
1798gi.a1 = PI_RomanFont;
[349]1799GrAfonts["smallfont"] = gi;
[165]1800gi.a1 = PI_BoldFont;
[349]1801GrAfonts["smallboldfont"] = gi;
[165]1802gi.a1 = PI_ItalicFont;
[349]1803GrAfonts["smallitalicfont"] = gi;
[165]1804gi.a2 = PI_BigSizeFont;
1805gi.a1 = PI_RomanFont;
[349]1806GrAfonts["bigfont"] = gi;
[165]1807gi.a1 = PI_BoldFont;
[349]1808GrAfonts["bigboldfont"] = gi;
[165]1809gi.a1 = PI_ItalicFont;
[349]1810GrAfonts["bigitalicfont"] = gi;
[192]1811gi.a2 = PI_HugeSizeFont;
1812gi.a1 = PI_RomanFont;
[349]1813GrAfonts["hugefont"] = gi;
[192]1814gi.a1 = PI_BoldFont;
[349]1815GrAfonts["hugeboldfont"] = gi;
[192]1816gi.a1 = PI_ItalicFont;
[349]1817GrAfonts["hugeitalicfont"] = gi;
[165]1818
1819
1820// Les markers
[176]1821const char* mrkn[11] = { "dotmarker", "plusmarker", "crossmarker",
1822 "circlemarker", "fcirclemarker", "boxmarker", "fboxmarker",
1823 "trianglemarker", "ftrianglemarker", "starmarker", "fstarmarker"};
[165]1824PIMarker mrk[11] = { PI_DotMarker, PI_PlusMarker, PI_CrossMarker,
1825 PI_CircleMarker, PI_FCircleMarker, PI_BoxMarker, PI_FBoxMarker,
1826 PI_TriangleMarker, PI_FTriangleMarker, PI_StarMarker, PI_FStarMarker};
1827
1828gi.a2 = 0;
1829gi.a1 = PI_NotDefMarker;
1830GrAmarkers["defmarker"] = gi;
1831
1832for(int j=0; j<11; j++) {
1833 string smrk;
1834 char buff[16];
1835 for(int m=1; m<10; m+=2) {
1836 sprintf(buff,"%d",m);
1837 smrk = (string)mrkn[j] + (string)buff;
1838 gi.a1 = mrk[j]; gi.a2 = m;
1839 GrAmarkers[smrk] = gi;
1840 }
1841 }
1842
1843// Les tables de couleurs
1844gi.a2 = 0;
1845gi.a1 = CMAP_OTHER;
1846GrAcmap["defcmap"] = gi;
1847gi.a1 = CMAP_GREY32;
1848GrAcmap["grey32"] = gi;
1849gi.a1 = CMAP_GREYINV32;
1850GrAcmap["greyinv32"] = gi;
1851gi.a1 = CMAP_COLRJ32;
1852GrAcmap["colrj32"] = gi;
1853gi.a1 = CMAP_COLBR32;
1854GrAcmap["colbr32"] = gi;
1855gi.a1 = CMAP_GREY128;
1856GrAcmap["grey128"] = gi;
1857gi.a1 = CMAP_GREYINV128;
1858GrAcmap["greyinv128"] = gi;
1859gi.a1 = CMAP_COLRJ128;
1860GrAcmap["colrj128"] = gi;
1861gi.a1 = CMAP_COLBR128;
1862GrAcmap["colbr128"] = gi;
1863
[203]1864// La valeur de zoom
[165]1865gi.a2 = 0;
1866gi.a1 = 0;
1867GrAzoom["defzoom"] = gi;
1868gi.a1 = 1;
1869GrAzoom["zoomx1"] = gi;
1870gi.a1 = 2;
1871GrAzoom["zoomx2"] = gi;
1872gi.a1 = 3;
1873GrAzoom["zoomx3"] = gi;
1874gi.a1 = 4;
1875GrAzoom["zoomx4"] = gi;
1876gi.a1 = 5;
1877GrAzoom["zoomx5"] = gi;
1878gi.a1 = -2;
1879GrAzoom["zoom/2"] = gi;
1880gi.a1 = -3;
1881GrAzoom["zoom/3"] = gi;
1882gi.a1 = -4;
1883GrAzoom["zoom/4"] = gi;
1884gi.a1 = -5;
1885GrAzoom["zoom/5"] = gi;
[203]1886
1887// Attributs d'axes
1888gi.a2 = 0;
1889gi.a1 = (int)(kBoxAxes | kExtTicks | kLabels);
1890GrAaxes["stdaxes"] = gi;
1891GrAaxes["defaxes"] = gi;
1892GrAaxes["boxaxes"] = gi;
1893gi.a1 = (int)kAxesDflt;
1894GrAaxes["simpleaxes"] = gi;
1895gi.a1 = (int)(kBoxAxes | kExtTicks | kLabels | kGridOn);
1896GrAaxes["boxaxesgrid"] = gi;
1897
1898gi.a1 = (int)(kBoxAxes | kTicks | kLabels | kMinTicks | kMajTicks);
1899GrAaxes["fineaxes"] = gi;
1900 gi.a1 = (int)(kBoxAxes | kTicks | kLabels | kMinTicks | kMajTicks | kGridOn);
1901GrAaxes["grid"] = gi;
1902GrAaxes["fineaxesgrid"] = gi;
1903
[165]1904}
[333]1905
1906
1907// SANS_EVOLPLANCK Attention !
1908#include "pclassids.h"
1909
1910/* --Methode-- */
1911char* Services2NObjMgr::PClassIdToClassName(int cid)
1912{
1913switch (cid) {
1914 case ClassId_Poly1 :
1915 return("Poly1");
1916 case ClassId_Poly2 :
1917 return("Poly2");
1918 case ClassId_Matrix :
1919 return("Matrix");
1920 case ClassId_Vector :
1921 return("Vector");
1922
1923 case ClassId_DVList :
1924 return("DVList");
1925
1926 case ClassId_Histo1D :
1927 return("Histo1D");
1928 case ClassId_Histo2D :
1929 return("Histo2D");
1930 case ClassId_HProf :
1931 return("HProf");
1932 case ClassId_NTuple :
1933 return("NTuple");
1934 case ClassId_GeneralFitData :
1935 return("GeneralFitData");
1936
1937 case ClassId_Image :
1938 return("RzImage");
1939 case ClassId_Image + kuint_1 :
1940 return("ImageU1");
1941 case ClassId_Image + kint_1 :
1942 return("ImageI1");
1943 case ClassId_Image + kuint_2 :
1944 return("ImageU2");
1945 case ClassId_Image + kint_2 :
1946 return("ImageI2");
1947 case ClassId_Image + kuint_4 :
1948 return("ImageU4");
1949 case ClassId_Image + kint_4 :
1950 return("ImageI4");
1951 case ClassId_Image + kr_4 :
1952 return("ImageR4");
1953 case ClassId_Image + kr_8 :
1954 return("ImageR8");
1955
1956 case ClassId_ZFidu :
1957 return("ZFidu");
1958
1959 case ClassId_StarList :
1960 return("StarList");
1961 case ClassId_Transfo :
1962 return("Transfo");
1963 case ClassId_PSF :
1964 return("PSF");
1965
1966
1967// - Ajout objet PPF
1968 default:
1969 return("AnyDataObj");
1970 }
1971}
1972
Note: See TracBrowser for help on using the repository browser.