source: Sophya/trunk/SophyaPI/PIext/nobjmgr.cc@ 179

Last change on this file since 179 was 179, checked in by ercodmgr, 27 years ago

Petits pb de compil aCC Reza 23/12/98

File size: 59.0 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <ctype.h>
4
5#include <iostream.h>
6#include <string>
7#include <list>
8#include <map>
9#if defined(__KCC__)
10using std::string ;
11#include <list.h>
12#include <map.h>
13#endif
14
15#include "strutil.h"
16#include "datatypes.h"
17#include "fitsimage.h"
18
19#include "nobjmgr.h"
20#include "servnobjm.h"
21#include "pistdimgapp.h"
22
23#include "pclassids.h"
24#include "poly.h"
25#include "dvlist.h"
26#include "matrix.h"
27#include "cvector.h"
28#include "zfidu.h"
29
30#include "fft.h"
31#include "fct1dfit.h"
32#include "fct2dfit.h"
33
34#include "pimgadapter.h"
35#include "pipodrw.h"
36
37#include "pihisto.h"
38#include "hisprof.h"
39#include "pihisto2d.h"
40#include "pintuple.h"
41#include "pisurfdr.h"
42#include "pintup3d.h"
43#include "pigfd1.h"
44#include "pigfd2.h"
45
46// Si le module StarReco++ a ete compile (Pour les StarList, Transfo, etc ...
47#ifndef SANS_StarReco
48#include "pistlist.h"
49#include "transfo.h"
50#endif
51
52//++
53// Class NamedObjMgr
54// Lib PI
55// include nobjmgr.h
56//
57// Cette classe fournit les services nécéssaire àla gestion des objets
58// (l'ensemble des objets PPersist de PEIDA++) au sein du programme
59// d'analyse interactive *piapp* . Elle constitue en outre l'interface
60// entre les fonctions utilisateur et l'application graphique.
61//--
62//++
63// Links Voir aussi
64// PIStdImgApp
65// Services2NObjMgr
66// PIACmd
67//--
68
69
70// ..................................................................
71// ...... Gestion des objets nommes, variables globales ............
72struct nobj_item {
73 PPersist* obj;
74 int num;
75 list<int> wrsid;
76 bool operator==(nobj_item const& b) const
77 { return (this->obj == b.obj); }
78};
79
80typedef map<string, nobj_item, less<string> > NObjList;
81
82static NObjList* myObjs;
83static int fgOInit = 0;
84static int myNObj = 0;
85static string* lastobj = NULL;
86
87static PIStdImgApp* myImgApp=NULL;
88static Services2NObjMgr* servnobjm=NULL;
89
90static string* TmpDir; // Repertoire pour les compilations / link dynamique
91
92//++
93// Titre Constructeurs
94//--
95//++
96// NamedObjMgr()
97// Constructeur. Les différents instantiation de la classe "NamedObjMgr"
98// dans une même application créent des objets qui travaillent sur la même
99// liste d'objets. Les objets de cette classe ne possedent en effet pas
100// de variables membres.
101//--
102
103/* --Methode-- */
104NamedObjMgr::NamedObjMgr()
105{
106if (fgOInit == 0) {
107 myObjs = new NObjList;
108 lastobj = new string("");
109 char* varenv;
110 TmpDir = new string("");
111 if ( (varenv=getenv("PEIDA_TMP")) != NULL ) (*TmpDir) = varenv;
112 else if ( (varenv=getenv("TMPDIR")) != NULL ) (*TmpDir) = varenv;
113 int l = (*TmpDir).length();
114 if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/';
115 servnobjm = new Services2NObjMgr(NULL, (*TmpDir));
116 }
117fgOInit++;
118}
119
120
121/* --Methode-- */
122NamedObjMgr::~NamedObjMgr()
123{
124fgOInit--;
125if (fgOInit == 0) delete myObjs;
126}
127
128//++
129// Titre Méthodes
130//--
131//++
132// void SetImgApp(PIStdImgApp* app)
133// Spécifie l'objet "PIStdImgApp" associé.
134// PIStdImgApp* GetImgApp()
135// Accès à l'objet "PIStdImgApp" associé.
136//--
137
138/* --Methode-- */
139void NamedObjMgr::SetImgApp(PIStdImgApp* app)
140{
141myImgApp = app;
142servnobjm->SetImgApp(app);
143}
144
145/* --Methode-- */
146PIStdImgApp* NamedObjMgr::GetImgApp()
147{
148return(myImgApp);
149}
150
151/* --Methode-- */
152Services2NObjMgr* NamedObjMgr::GetServiceObj()
153{
154return(servnobjm);
155}
156
157//++
158// Titre Gestion de la liste des objets
159//--
160//++
161// void AddObj(PPersist* obj, string& nom)
162// Ajoute l'objet "obj" à la liste, identifié par "nom".
163// Si un objet de même nom existe, l'ancien objet est renommé en concaténant
164// un numéro à son nom.
165// void DelObj(string const& nom, bool fgd=true)
166// Supprime l'objet "nom" de la liste. L'objet est détruit si "fgd==true" ("delete obj")
167// void DelObjects(string const& patt, bool fgd=true)
168// Supprime l'ensemble des objets dont le nom correspond au patron "patt".
169// Le patron peut contenir les caractères "*" et "?" . Les objets sont détruits si "fgd==true"
170// PPersist* GetObj(string const& nom)
171// Retourne l'objet identifié par "nom" dans la liste. Retourne "NULL" si "nom" n'est
172// pas dans la liste.
173// void RenameObj(string const& nom, string& nomnew)
174// Change le nom d'un objet dans la liste.
175// string LastObjName()
176// Renvoie le nom du dernier objet ajouté à la liste
177//--
178
179
180/* --Methode-- */
181void NamedObjMgr::AddObj(PPersist* obj, string& nom)
182{
183
184if (obj == NULL) return;
185// on supprime les blancs de debut et de fin
186size_t p = nom.find_first_not_of(" ");
187if(p>nom.length()) {
188 nom = "";
189} else {
190 nom = nom.substr(p);
191 p = nom.find_first_of(" ");
192 if(p>nom.length()) p=nom.length();
193 nom = nom.substr(0, p);
194}
195
196myNObj++;
197if (nom.length() < 1) nom = servnobjm->PClassIdToShortClassName(obj->ClassId());
198NObjList::iterator it = myObjs->find(nom);
199if (it != myObjs->end()) { // l'objet existe deja
200 char strg[16];
201 sprintf(strg, "%d", myNObj);
202 string nomnew = nom + strg;
203 RenameObj(nom, nomnew);
204 }
205
206(*lastobj) = nom;
207nobj_item no;
208no.obj = obj;
209no.num = myNObj;
210(*myObjs)[(*lastobj)] = no;
211if (myImgApp) {
212 string str = (*lastobj) + " (T= " + servnobjm->PClassIdToClassName(obj->ClassId()) + ")" ;
213 (myImgApp->ObjMgrW())->AddObj(str.c_str(), myNObj+1000);
214}
215
216cout << "NamedObjMgr::AddObj() Object " << (*lastobj) << " ( "
217 << servnobjm->PClassIdToClassName(obj->ClassId()) << " ) added (Total= " << myObjs->size() << ")" << endl;
218return;
219}
220
221/* --Methode-- */
222void NamedObjMgr::DelObj(string const& nom, bool fgd)
223{
224NObjList::iterator it = myObjs->find(nom);
225if (it == myObjs->end()) return;
226list<int>::iterator ii;
227if (myImgApp) {
228//DBG cerr << " *DBG* NamedObjMgr::DelObj Sz= " << (*it).second.wrsid.size() << endl;
229 for(ii=(*it).second.wrsid.begin(); ii != (*it).second.wrsid.end(); ii++)
230 myImgApp->DelWRsId((*ii));
231 (myImgApp->ObjMgrW())->DelObj((*it).second.num+1000);
232}
233if (fgd) delete (*it).second.obj;
234myObjs->erase(it);
235if (fgd) cout << "NamedObjMgr::DelObj() Object " << nom << " deleted (Total= " << myObjs->size() << ")" << endl;
236else cout << "NamedObjMgr::DelObj() Object " << nom << " removed (Total= " << myObjs->size() << ")" << endl;
237return;
238}
239
240/* --Methode-- */
241void NamedObjMgr::DelObjects(string const& patt, bool fgd)
242{
243NObjList::iterator it;
244list<string> odel;
245string cn;
246for(it = myObjs->begin(); it != myObjs->end(); it++) {
247 cn = (*it).first;
248 if (csh_parse(cn.c_str(), patt.c_str()) != 0) odel.push_back(cn);
249 }
250list<string>::iterator ii;
251for(ii=odel.begin(); ii != odel.end(); ii++) DelObj(*ii, fgd);
252}
253
254/* --Methode-- */
255PPersist* NamedObjMgr::GetObj(string const& nom)
256{
257NObjList::iterator it = myObjs->find(nom);
258if (it == myObjs->end()) return(NULL);
259return((*it).second.obj);
260}
261
262/* --Methode-- */
263void NamedObjMgr::RenameObj(string const& nom, string& nomnew)
264{
265PPersist* obj = GetObj(nom);
266if (obj == NULL) return;
267DelObj(nom, false);
268AddObj(obj, nomnew);
269return;
270}
271
272/* --Methode-- */
273string NamedObjMgr::LastObjName()
274{
275return((*lastobj));
276}
277
278//++
279// Titre Entrées-Sorties (I/O) sur les objets
280//--
281//++
282// void ReadObj(PInPersist& s, int num=-1)
283// Lit l'objet à partir avec le tag numéro "num" dans le flot "PInPersist s"
284// et l'ajoute à la liste. Si "num" est négatif, tous les objets présents
285// sur le flot "s" sont créés et ajoutés à la liste.
286// void ReadObj(string const & nomppf, string nobj="")
287// Lit le premier objet à partir du fichier PPF "nomppf". L'objet est ajouté
288// à la liste avec le nom "nobj". Si "nobj" est une chaîne vide, un nom est
289// composé à partir du nom de fichier.
290//--
291
292/* --Methode-- */
293void NamedObjMgr::ReadObj(string const & flnm, string nobj)
294{
295PPersist* obj=NULL;
296bool ok = true;
297
298TRY{
299 PInPersist pis(flnm);
300 obj = PPersistMgr::ReadObject(pis);
301 if (obj == NULL) ok = false;
302} CATCH(merr)
303 { printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n",
304 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
305
306if (!ok) return;
307if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
308AddObj(obj, nobj);
309return;
310}
311
312/* --Methode-- */
313void NamedObjMgr::ReadObj(PInPersist& s, int num)
314{
315int i, cid, key, ln;
316int n0, n1;
317bool ok = true;
318PPersist* obj=NULL;
319string nom;
320
321if ( (s.NbTags() < 1) || (num >= s.NbTags()) ) {
322 if (num >= 0) {
323 printf("NamedObjMgr::ReadObj(PInPersist, %d) Error! NbTags = %d \n", num, s.NbTags());
324 return;
325 }
326 TRY {
327 obj = PPersistMgr::ReadObject(s);
328 if (obj == NULL) ok = false;
329 } CATCH(merr) {
330 printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
331 ok = false;
332 } ENDTRY;
333 if (!ok) return;
334 nom = "";
335 AddObj(obj, nom);
336}
337
338if (num < 0) { n0 = 0; n1 = s.NbTags(); }
339else { n0 = num; n1 = num+1; }
340for(i=n0; i<n1; i++) {
341 key = s.TagKey(i, cid, ln);
342 if (ln <= 0) nom = "";
343 else nom = s.TagName(i);
344 s.GotoTag(i);
345 TRY {
346 obj = PPersistMgr::ReadObject(s);
347 if (obj == NULL) ok = false;
348 } CATCH(merr) {
349 printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
350 ok = false;
351 } ENDTRY;
352 if (ok) AddObj(obj, nom);
353}
354
355return;
356}
357/* --Methode-- */
358void NamedObjMgr::ReadAll(string const & flnm)
359{
360bool ok = true;
361PPersist* obj=NULL;
362
363PInPersist* ppin;
364TRY{
365 ppin = new PInPersist(flnm);
366 if (ppin->NbTags() < 1) obj = PPersistMgr::ReadObject((*ppin));
367 else obj = NULL;
368} CATCH(merr)
369 { printf("NamedObjMgr::ReadAll()/Error Exception= %ld (%s) \n",
370 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
371
372if (!ok) return;
373if (obj) {
374 string nom = servnobjm->FileName2Name(flnm);
375 AddObj(obj, nom);
376 }
377else ReadObj((*ppin), -1);
378delete ppin;
379return;
380}
381
382/* --Methode-- */
383void NamedObjMgr::ReadFits(string const & flnm, string nobj)
384{
385bool ok = true;
386RzImage* obj;
387
388TRY{
389// obj = RzReadFits((char*)flnm.c_str(), ImgOffX, ImgOffY, ImgSizX, ImgSizY, ImgBitSgn);
390 obj = RzReadFits((char*)flnm.c_str());
391 if (obj == NULL) ok = false;
392} CATCH(merr) {
393 printf("NamedObjMgr::ReadFITS(_Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
394 ok = false;
395} ENDTRY;
396if (ok) {
397 if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
398 AddObj((PPersist*)obj, nobj);
399}
400return;
401}
402
403
404static int key_for_write = 5000;
405/* --Methode-- */
406void NamedObjMgr::SaveObj(string const& nom, POutPersist& s)
407{
408PPersist* obj=NULL;
409obj = GetObj(nom);
410if (obj == NULL) return;
411printf("NamedObjMgr::SaveObj(%s, ) (Type=%s) \n",
412 nom.c_str(), servnobjm->PClassIdToClassName(obj->ClassId()));
413string nm = nom; // A cause de const
414obj->Write(s, key_for_write, nm);
415key_for_write++;
416return;
417}
418
419/* --Methode-- */
420void NamedObjMgr::SaveAll(string const& flnm)
421{
422bool ok = true;
423
424POutPersist* pout;
425TRY{
426 pout = new POutPersist(flnm);
427} CATCH(merr)
428 { printf("NamedObjMgr::SaveAll()/Error Exception= %ld (%s) \n",
429 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
430if (!ok) return;
431NObjList::iterator it;
432for(it = myObjs->begin(); it != myObjs->end(); it++) SaveObj((*it).first, (*pout));
433delete pout;
434return;
435}
436
437/* --Methode-- */
438void NamedObjMgr::SaveFits(string const& nom, string const & flnm)
439{
440PPersist* obj=NULL;
441obj = GetObj(nom);
442if (obj == NULL) return;
443
444int cid = obj->ClassId();
445if ( (cid < ClassId_Image) && ( cid > ClassId_Image+kr_8) ) {
446 printf("NamedObjMgr::SaveFits(%s, ) Error - Object is NOT an image (type=%s) \n",
447 nom.c_str(), servnobjm->PClassIdToClassName(obj->ClassId()) );
448 return;
449}
450
451RzImage* pim = (RzImage*)obj;
452TRY {
453 switch (pim->PixelType()) {
454 case kuint_2:
455 {
456 FitsImageU2 imgfits(*pim);
457 imgfits.Save(flnm);
458 }
459 break;
460 case kint_2:
461 {
462 FitsImageI2 imgfits(*pim);
463 imgfits.Save(flnm);
464 }
465 break;
466 case kint_4:
467 {
468 FitsImageI4 imgfits(*pim);
469 imgfits.Save(flnm);
470 }
471 break;
472 case kr_4:
473 {
474 FitsImageR4 imgfits(*pim);
475 imgfits.Save(flnm);
476 }
477 break;
478 default :
479 printf("NamedObjMgr::SaveObj()/Error Type d'image (%d) NON supporte en FITS \n",
480 (int)pim->PixelType());
481 break;
482 }
483} CATCH(merr) {
484 printf("NamedObjMgr::SaveObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
485} ENDTRY;
486
487return;
488}
489
490
491/* --Methode-- */
492void NamedObjMgr::ListObjs()
493{
494int k;
495PPersist* obj=NULL;
496string ctyp;
497char strg[256];
498int cid;
499
500cout << "NamedObjMgr::ListObjs() NObjs= " << myObjs->size() << "\n" ;
501NObjList::iterator it; k = 0;
502for(it = myObjs->begin(); it != myObjs->end(); it++) {
503 obj = (*it).second.obj;
504
505 cid = obj->ClassId();
506 ctyp = servnobjm->PClassIdToClassName(cid);
507 sprintf(strg, "%2d/ %16s : %s", k, servnobjm->PClassIdToClassName(obj->ClassId()), ((*it).first).c_str());
508 ctyp = strg;
509 cout << ctyp << "\n" ;
510 k++;
511}
512cout << endl;
513return;
514}
515
516/* --Methode-- */
517void NamedObjMgr::PrintObj(string const& nom)
518{
519PPersist* obj=GetObj(nom);
520if (obj == NULL) {
521 cout << "NamedObjMgr::PrintObj() Error , Pas d'objet de nom " << nom << endl;
522 return;
523}
524
525int cid = obj->ClassId();
526string ctyp = servnobjm->PClassIdToClassName(cid);
527
528cout << "NamedObjMgr::PrintObj(" << nom << ") Type: " << ctyp
529 << "Cid= " << cid << ")" << endl;
530
531int i4dum;
532switch (cid) {
533 case ClassId_Poly1 :
534 ((Poly*)obj)->Print(cout);
535 break;
536 case ClassId_Poly2 :
537 ((Poly2*)obj)->Print(cout);
538 break;
539 case ClassId_Matrix :
540 case ClassId_Vector :
541 cout << *((Matrix*)obj);
542 break;
543
544 case ClassId_DVList :
545 ((DVList*)obj)->Print();
546 break;
547
548 case ClassId_Histo1D :
549 ((Histo*)obj)->Print(60);
550 break;
551 case ClassId_Histo2D :
552 ((Histo2D*)obj)->Print();
553 break;
554 case ClassId_HProf :
555 ((HProf*)obj)->Print(60);
556 break;
557 case ClassId_NTuple :
558 cout << ((NTuple*)obj)->Info();
559 cout << *((NTuple*)obj);
560 break;
561 case ClassId_GeneralFitData :
562 ((GeneralFitData*)obj)->PrintStatus();
563 i4dum = ((GeneralFitData*)obj)->NData();
564 if(i4dum>0) {
565 ((GeneralFitData*)obj)->PrintData(0);
566 ((GeneralFitData*)obj)->PrintData(i4dum-1);
567 }
568 break;
569
570 case ClassId_Image :
571 case ClassId_Image + kuint_1 :
572 case ClassId_Image + kint_1 :
573 case ClassId_Image + kuint_2 :
574 case ClassId_Image + kint_2 :
575 case ClassId_Image + kuint_4 :
576 case ClassId_Image + kint_4 :
577 case ClassId_Image + kr_4 :
578 case ClassId_Image + kr_8 :
579 ((RzImage*)obj)->Print();
580 break;
581
582 case ClassId_ZFidu :
583 ((ZFidu*)obj)->Print();
584 break;
585
586#ifndef SANS_StarReco
587 case ClassId_StarList :
588 ((StarList*)obj)->Print(10, 1, 50);
589 break;
590 case ClassId_Transfo :
591 ((Transfo*)obj)->Print(cout);
592 break;
593 case ClassId_PSF :
594 break;
595
596 case ClassId_Star + BStar_Type :
597 case ClassId_Star + RzStar_Type :
598 case ClassId_Star + PSFStar_Type :
599 case ClassId_Star + MCStar_Type :
600 case ClassId_Star + CircRFixStar_Type :
601 case ClassId_Star + PSFDHStar_Type :
602 case ClassId_Star + PSFSEStar_Type :
603 case ClassId_Star + MCDHStar_Type :
604 ((BStar*)obj)->Print(1);
605 break;
606#endif
607
608// - Ajout objet PPF
609 default:
610 break;
611 }
612cout << endl;
613return;
614}
615
616/* --Methode-- */
617void NamedObjMgr::DisplayObj(string const& nom, string dopt)
618{
619PPersist* obj=GetObj(nom);
620if (obj == NULL) {
621 cout << "NamedObjMgr::DisplayObj() Error , Pas d'objet de nom " << nom << endl;
622 return;
623}
624if (!myImgApp) return;
625
626int cid = obj->ClassId();
627string ctyp = servnobjm->PClassIdToClassName(cid);
628
629int wrsid = 0;
630bool fgsr = true;
631// On veut tracer une ligne pour vecteur et histo1D par defaut
632if ( (cid == ClassId_Vector) || (cid == ClassId_Histo1D) ) dopt = "thinline," + dopt;
633else if(cid == ClassId_HProf) dopt = "fcirclemarker5," + dopt;
634int opt = servnobjm->DecodeDispOption(dopt, fgsr);
635
636switch (cid) {
637 case ClassId_Poly1 :
638 case ClassId_Poly2 :
639 case ClassId_DVList :
640 cout << "NamedObjMgr::DisplayObj() Error , Pas de display pour " << ctyp << endl;
641 break;
642
643 case ClassId_Matrix :
644 {
645 wrsid = myImgApp->DispImage(new POMatrixAdapter((Matrix*)obj, false), nom, opt);
646 break;
647 }
648 case ClassId_Vector :
649 {
650 PIYfXDrawer* dr = new PIYfXDrawer( new POVectorAdapter((Vector*)obj, false), NULL, true);
651 wrsid = myImgApp->DispScDrawer( (PIDrawer*)dr, nom, opt);
652 break;
653 }
654 case ClassId_Histo1D :
655 {
656 PIHisto* pih = new PIHisto(((Histo*)obj), false);
657 wrsid = myImgApp->DispScDrawer( (PIDrawer*)pih, nom, opt);
658 break;
659 }
660 case ClassId_Histo2D :
661 {
662 PIHisto2D* pih2 = new PIHisto2D(((Histo2D*)obj), false);
663 wrsid = myImgApp->DispScDrawer( (PIDrawer*)pih2, nom, opt, nom, true);
664 break;
665 }
666 case ClassId_HProf :
667 {
668 PIHisto* pihp = new PIHisto(((Histo*)obj), false);
669 wrsid = myImgApp->DispScDrawer( (PIDrawer*)pihp, nom, opt);
670 break;
671 }
672 case ClassId_GeneralFitData :
673 {
674 GeneralFitData* gfd = (GeneralFitData*)obj;
675 if(gfd->NVar()==1) {
676 PIGenFitDat* pigfd = new PIGenFitDat(gfd,false);
677 wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,nom,opt);
678 } else if(gfd->NVar()==2) {
679 PIGenFitDat3D* pigfd = new PIGenFitDat3D(gfd,false);
680 wrsid = myImgApp->Disp3DDrawer(pigfd,nom,opt);
681 } else {
682 cout<<"NamedObjMgr::DisplayObj() Error , Utilisez DisplayGFD pour GeneralFitData "
683 <<ctyp<<"\n de "<<gfd->NVar()<<" variables (!=1,2)"<<endl;
684 }
685 break;
686 }
687
688 case ClassId_NTuple :
689 cout << "NamedObjMgr::DisplayObj() Error , Utilisez DisplayNt pour NTuple " << ctyp << endl;
690 break;
691
692 case ClassId_Image :
693 case ClassId_Image + kuint_1 :
694 case ClassId_Image + kint_1 :
695 case ClassId_Image + kr_8 :
696 case ClassId_Image + kuint_4 :
697 wrsid = myImgApp->DispImage(new RzImageAdapter((RzImage*)obj, false), nom, opt);
698 break;
699 case ClassId_Image + kuint_2 :
700 wrsid = myImgApp->DispImage(new ImageAdapter<uint_2>((ImageU2*)obj, false), nom, opt);
701 break;
702 case ClassId_Image + kint_2 :
703 wrsid = myImgApp->DispImage(new ImageAdapter<int_2>((ImageI2*)obj, false), nom, opt);
704 break;
705 case ClassId_Image + kint_4 :
706 wrsid = myImgApp->DispImage(new ImageAdapter<int_4>((ImageI4*)obj, false), nom, opt);
707 break;
708 case ClassId_Image + kr_4 :
709 wrsid = myImgApp->DispImage(new ImageAdapter<r_4>((ImageR4*)obj, false), nom, opt);
710 break;
711
712 case ClassId_ZFidu :
713 {
714 int nx = ((ZFidu*)obj)->XMax() - ((ZFidu*)obj)->XMin();
715 int ny = ((ZFidu*)obj)->YMax() - ((ZFidu*)obj)->YMin();
716 if (nx > 1024) nx = 1024;
717 if (ny > 1024) ny = 1024;
718 if (nx < 128) nx = 128;
719 if (ny < 128) nx = 128;
720 ImageU2* msk = ((ZFidu*)obj)->MakeBadZoneMask(nx, ny);
721 myImgApp->DispImage(new ImageAdapter<uint_2>((ImageU2*)msk, true), nom, opt);
722 break;
723 }
724
725#ifndef SANS_StarReco
726 case ClassId_StarList :
727 {
728 PIStarList* pist = new PIStarList(((StarList*)obj), false);
729 wrsid = myImgApp->DispScDrawer( (PIDrawer*)pist, nom, opt);
730 break;
731 }
732
733 case ClassId_Transfo :
734 case ClassId_PSF :
735 case ClassId_Star + BStar_Type :
736 case ClassId_Star + RzStar_Type :
737 case ClassId_Star + PSFStar_Type :
738 case ClassId_Star + MCStar_Type :
739 case ClassId_Star + CircRFixStar_Type :
740 case ClassId_Star + PSFDHStar_Type :
741 case ClassId_Star + PSFSEStar_Type :
742 case ClassId_Star + MCDHStar_Type :
743 cout << "NamedObjMgr::DisplayObj() Error , Pas de display pour " << ctyp << endl;
744 break;
745#endif
746
747// - Ajout objet PPF
748 default:
749 break;
750 }
751
752if(wrsid != 0) {
753 NObjList::iterator it = myObjs->find(nom);
754 if (it == myObjs->end()) return;
755 (*it).second.wrsid.push_back(wrsid);
756 }
757if (fgsr) myImgApp->RestoreGraphicAtt();
758return;
759}
760
761
762/* --Methode-- */
763void NamedObjMgr::DisplayNT(string const& nom, string& nmx, string& nmy, string& nmz,
764 string& erx, string& ery, string& erz, string dopt)
765{
766PPersist* obj=GetObj(nom);
767if (obj == NULL) {
768 cout << "NamedObjMgr::DisplayNT() Error , Pas d'objet de nom " << nom << endl;
769 return;
770}
771if (!myImgApp) return;
772
773int cid = obj->ClassId();
774if (cid != ClassId_NTuple) {
775 string ctyp = servnobjm->PClassIdToClassName(cid);
776 cout << "NamedObjMgr::DisplayNT() Error , Objet n'est pas un NTuple " << ctyp << endl;
777 return;
778 }
779
780int wrsid = 0;
781bool fgsr = true;
782int opt = servnobjm->DecodeDispOption(dopt, fgsr);
783
784if (nmz.length()>0) { // Display 3D
785 PINTuple3D* pin = new PINTuple3D(((NTuple*)obj), false);
786 pin->SelectXYZ(nmx.c_str(), nmy.c_str(), nmz.c_str());
787 pin->SelectErrBar(erx.c_str(), ery.c_str(), erz.c_str());
788 string titre = nmz + "%" + nmy + "%" + nmz;
789 wrsid = myImgApp->Disp3DDrawer(pin, nom, opt, titre);
790}
791else {
792 PINTuple* pin = new PINTuple(((NTuple*)obj), false);
793 pin->SelectXY(nmx.c_str(), nmy.c_str());
794 pin->SelectErrBar(erx.c_str(), ery.c_str());
795 string titre = nmy + "%" + nmz;
796 wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, nom, opt, titre);
797 }
798
799if(wrsid >= 0) {
800 NObjList::iterator it = myObjs->find(nom);
801 if (it == myObjs->end()) return;
802 (*it).second.wrsid.push_back(wrsid);
803 }
804
805if (fgsr) myImgApp->RestoreGraphicAtt();
806return;
807}
808
809/* --Methode-- cmv 13/10/98 */
810void NamedObjMgr::DisplayGFD(string const& nom, string& numvarx, string& numvary, string& err, string dopt)
811// Pour le display 2D ou 3D d'un ``GeneralFitData''.
812//| nom = nom de l'objet GeneralFitData a representer.
813//| numvarx = numero (nombre entier) de la 1ere variable d'abscisse.
814//| numvary = numero (nombre entier) de la 2sd variable d'abscisse (3D).
815//| Pour le display 2D, numvary="" string vide.
816//| err = qu'elles erreurs faut il representer ?
817//| - 2D : x y xy (display y=f(x))
818//| - 3D : x y z xy xz yz xzy (display z=f(x,y))
819//| Ceci n'est suivi que si on a PI_NotDefLineAtt, sinon toutes
820//| les barres d'erreurs sont representees.
821//| opt = options generales pour le display.
822{
823PPersist* obj=GetObj(nom);
824if(obj == NULL)
825 {cout << "NamedObjMgr::DisplayGFD() Error , Pas d'objet de nom " << nom << endl;
826 return;}
827if(!myImgApp) return;
828int cid = obj->ClassId();
829if(cid != ClassId_GeneralFitData)
830 {string ctyp = servnobjm->PClassIdToClassName(cid);
831 cout<<"NamedObjMgr::DisplayGFD() Error , Objet n'est pas un GeneralFitData "<<ctyp<<endl;
832 return;}
833
834// Decodage des options classiques
835bool fgsr = true;
836int opt = servnobjm->DecodeDispOption(dopt, fgsr);
837// Decodage des erreurs a representer
838bool errx=false, erry=false, errz=false;
839if(err.length()>0) {
840 for(int i=0;i<err.length();i++)
841 if (err[i]=='x' || err[i]=='X') errx = true;
842 else if(err[i]=='y' || err[i]=='Y') erry = true;
843 else if(err[i]=='z' || err[i]=='Z') errz = true;
844}
845// Decodage des numeros de variables en abscisse
846int numvx=-1, numvy=-1;
847if(numvarx.length()>0) numvx = atoi(numvarx.c_str());
848if(numvary.length()>0) numvy = atoi(numvary.c_str());
849
850int wrsid = 0;
851if(numvy>=0) { // Display 3D
852 PIGenFitDat3D* pigfd = new PIGenFitDat3D(((GeneralFitData*)obj),false);
853 pigfd->SelectXY(numvx,numvy);
854 pigfd->SelectErrBar(errx,erry,errz);
855 wrsid = myImgApp->Disp3DDrawer(pigfd,nom,opt);
856} else { // Display 2D
857 PIGenFitDat* pigfd = new PIGenFitDat(((GeneralFitData*)obj),false);
858 pigfd->SelectX(numvx);
859 pigfd->SelectErrBar(errx,erry);
860 wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,nom,opt);
861}
862
863if(wrsid >= 0) {
864 NObjList::iterator it = myObjs->find(nom);
865 if (it == myObjs->end()) return;
866 (*it).second.wrsid.push_back(wrsid);
867}
868if (fgsr) myImgApp->RestoreGraphicAtt();
869return;
870}
871
872/* --Methode--
873void NamedObjMgr::DisplayImage(string const& nom, string dopt)
874{
875 cout << "NamedObjMgr::DisplayImage() a faire ! " << endl;
876}
877*/
878
879
880/* --Methode-- */
881void NamedObjMgr::DisplaySurf3D(string const& nom, string dopt)
882{
883PPersist* obj=GetObj(nom);
884if (obj == NULL) {
885 cout << "NamedObjMgr::DisplaySurf3D() Error , Pas d'objet de nom " << nom << endl;
886 return;
887}
888if (!myImgApp) return;
889
890int cid = obj->ClassId();
891
892
893P2DArrayAdapter* arr=NULL;
894switch (cid) {
895 case ClassId_Matrix :
896 arr = new POMatrixAdapter((Matrix*)obj, false);
897 break;
898 case ClassId_Histo2D :
899 arr = new POH2DAdapter((Histo2D*)obj, false);
900 break;
901 case ClassId_Image :
902 case ClassId_Image + kuint_1 :
903 case ClassId_Image + kint_1 :
904 case ClassId_Image + kr_8 :
905 case ClassId_Image + kuint_4 :
906 arr = new RzImageAdapter((RzImage*)obj, false);
907 break;
908 case ClassId_Image + kuint_2 :
909 arr = new ImageAdapter<uint_2>((ImageU2*)obj, false);
910 break;
911 case ClassId_Image + kint_2 :
912 arr = new ImageAdapter<int_2>((ImageI2*)obj, false);
913 break;
914 case ClassId_Image + kint_4 :
915 arr = new ImageAdapter<int_4>((ImageI4*)obj, false);
916 break;
917 case ClassId_Image + kr_4 :
918 arr = new ImageAdapter<r_4>((ImageR4*)obj, false);
919 break;
920
921 default :
922 cout << "NamedObjMgr::DisplaySurf3D() Error , Pas de display pour " << servnobjm->PClassIdToClassName(cid) << endl;
923 return;
924 }
925
926if (!arr) return;
927if ((arr->XSize() > 250) || (arr->YSize() > 250)) {
928 cout << "NamedObjMgr::DisplaySurf3D() Error , 2D-Array(" << arr->XSize()
929 << "x" << arr->YSize() << ") trop grand (max=250x250)" << endl;
930 delete arr;
931 return;
932 }
933
934int wrsid = 0;
935bool fgsr = true;
936int opt = servnobjm->DecodeDispOption(dopt, fgsr);
937if (cid == ClassId_Histo2D) arr->DefineXYCoordinates(0., 0., 1., 1.);
938PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
939wrsid = myImgApp->Disp3DDrawer(sdr, nom, opt);
940if(wrsid >= 0) {
941 NObjList::iterator it = myObjs->find(nom);
942 if (it == myObjs->end()) return;
943 (*it).second.wrsid.push_back(wrsid);
944 }
945
946if (fgsr) myImgApp->RestoreGraphicAtt();
947return;
948}
949
950
951/* --Methode-- */
952void NamedObjMgr::SetGraphicAttributes(string gratt)
953{
954bool fg = false;
955servnobjm->DecodeDispOption(gratt, fg);
956}
957/* --Methode-- */
958void NamedObjMgr::SetGraphicWinZone(int nzx, int nzy, bool fcr)
959{
960if (!myImgApp) return;
961if (fcr) myImgApp->CreateGraphWin(nzx, nzy);
962else myImgApp->SetZone(nzx, nzy);
963}
964
965/* --Methode-- */
966void NamedObjMgr::DisplayPoints2D(string const& nom, string& expx, string& expy,
967 string& experrx, string& experry,
968 string& expcut, string dopt)
969{
970PPersist* obj=GetObj(nom);
971if (obj == NULL) {
972 cout << "NamedObjMgr::DisplayPoints2D() Error , Pas d'objet de nom " << nom << endl;
973 return;
974}
975if (!myImgApp) return;
976
977// Creation NTuple
978char* ntn[4] = {"expx","expy","expex","expey",};
979NTuple* nt = NULL;
980bool haserr = false;
981
982if ( (experrx.length() > 0 ) && (experry.length() > 0 ) ) { haserr = true; nt = new NTuple(2, ntn); }
983else { haserr = false; experrx = experry = "0."; nt = new NTuple(2, ntn); }
984
985servnobjm->Nobj_ComputeExpressions(obj, expx, expy, experrx, experry, expcut, nt, NULL, NULL);
986
987if (nt->NEntry() < 1) {
988 cout << "NamedObjMgr::DisplayPoints2D() Warning Zero points satisfy cut !" << endl;
989 delete nt;
990 return;
991 }
992
993// nt->Show();
994// nt->Print(0,10);
995PINTuple* pin = new PINTuple(nt, true);
996pin->SelectXY(ntn[0], ntn[1]);
997if ( haserr ) pin->SelectErrBar(ntn[2], ntn[3]);
998
999bool fgsr = true;
1000int opt = servnobjm->DecodeDispOption(dopt, fgsr);
1001string titre = nom + ":" + expy + "%" + expx;
1002myImgApp->DispScDrawer( (PIDrawer*)pin, titre, opt);
1003if (fgsr) myImgApp->RestoreGraphicAtt();
1004return;
1005}
1006
1007/* --Methode-- */
1008void NamedObjMgr::DisplayPoints3D(string const& nom, string& expx, string& expy, string& expz,
1009 string& expcut, string dopt)
1010{
1011PPersist* obj=GetObj(nom);
1012if (obj == NULL) {
1013 cout << "NamedObjMgr::DisplayPoints3D() Error , Pas d'objet de nom " << nom << endl;
1014 return;
1015 }
1016if (!myImgApp) return;
1017
1018char* ntn[3] = {"expx","expy","expz"};
1019NTuple* nt = new NTuple(3,ntn); // Creation NTuple
1020
1021string expwt = "1.";
1022servnobjm->Nobj_ComputeExpressions(obj, expx, expy, expz, expwt, expcut, nt, NULL, NULL);
1023
1024if (nt->NEntry() < 1) {
1025 cout << "NamedObjMgr::DisplayPoints3D() Warning Zero points satisfy cut !" << endl;
1026 delete nt;
1027 return;
1028 }
1029nt->Show();
1030nt->Print(0,10);
1031PINTuple3D* pin = new PINTuple3D(nt, true);
1032pin->SelectXYZ(ntn[0], ntn[1], ntn[2]);
1033bool fgsr = true;
1034int opt = servnobjm->DecodeDispOption(dopt, fgsr);
1035
1036// Pour plot a partir de DispScDrawer
1037// string nomdisp = "_NT3D_";
1038// myImgApp->DispScDrawer( (PIDrawer*)pin, nomdisp, opt);
1039// Pour plot a partir de Disp3DDrawer
1040string titre = nom + ":" + expy + "%" + expx;
1041myImgApp->Disp3DDrawer(pin, titre, opt);
1042
1043if (fgsr) myImgApp->RestoreGraphicAtt();
1044return;
1045}
1046
1047/* --Methode-- */
1048void NamedObjMgr::ProjectH1(string const& nom, string& expx, string& expwt, string& expcut, string& nomh1, string dopt)
1049{
1050PPersist* obj=GetObj(nom);
1051
1052if (obj == NULL) {
1053 cout << "NamedObjMgr::ProjectH1() Error , Pas d'objet de nom " << nom << endl;
1054 return;
1055 }
1056if (!myImgApp) return;
1057
1058Histo* h1 = NULL;
1059NTuple* nt = NULL;
1060PPersist* oh = NULL;
1061if (nomh1.length() > 0) oh=GetObj(nomh1);
1062else nomh1 = "H1Proj";
1063if ( (oh != NULL) && (oh->ClassId() == ClassId_Histo1D) ) h1 = (Histo*)oh; // Pas de remise a zero ! h1->Zero();
1064else {
1065 char* ntn[2]= {"hxval", "hwt"};
1066 nt = new NTuple(2,ntn); // Creation NTuple
1067 }
1068string expz = "0.";
1069servnobjm->Nobj_ComputeExpressions(obj, expx, expwt, expz, expwt, expcut, nt, h1, NULL);
1070
1071if ((!h1) && (!nt)) return;
1072if (!h1) {
1073 if (nt->NEntry() < 1) {
1074 cout << "NamedObjMgr::ProjectH1() Warning Zero points satisfy cut !" << endl;
1075 delete nt;
1076 return;
1077 }
1078 float xmin, xmax;
1079 nt->GetMinMax(0, xmin, xmax);
1080 h1 = new Histo(xmin, xmax, 100);
1081 int k;
1082 float* xn;
1083 for(k=0; k<nt->NEntry(); k++) {
1084 xn = nt->GetVec(k);
1085 h1->Add(xn[0], xn[1]);
1086 }
1087 delete nt;
1088 AddObj(h1, nomh1);
1089 }
1090
1091DisplayObj(nomh1, dopt);
1092return;
1093}
1094
1095/* --Methode-- */
1096void NamedObjMgr::ProjectH2(string const& nom, string& expx, string& expy, string& expwt, string& expcut,
1097 string& nomh2, string dopt)
1098{
1099PPersist* obj=GetObj(nom);
1100
1101if (obj == NULL) {
1102 cout << "NamedObjMgr::ProjectH2() Error , Pas d'objet de nom " << nom << endl;
1103 return;
1104 }
1105if (!myImgApp) return;
1106
1107Histo2D* h2 = NULL;
1108NTuple* nt = NULL;
1109PPersist* oh = NULL;
1110if (nomh2.length() > 0) oh=GetObj(nomh2);
1111else nomh2 = "H2Proj";
1112if ( (oh != NULL) && (oh->ClassId() == ClassId_Histo2D) ) h2 = (Histo2D*)oh; // Pas de remise a zero ! h2->Zero();
1113else {
1114 char* ntn[3]= {"hxval", "hyval", "hwt"};
1115 nt = new NTuple(3,ntn); // Creation NTuple
1116 }
1117string expz = "0.";
1118servnobjm->Nobj_ComputeExpressions(obj, expx, expy, expwt, expwt, expcut, nt, NULL, h2);
1119
1120if ((!h2) && (!nt)) return;
1121if (!h2) {
1122 if (nt->NEntry() < 1) {
1123 cout << "NamedObjMgr::ProjectH2() Warning Zero points satisfy cut !" << endl;
1124 delete nt;
1125 return;
1126 }
1127 float xmin, xmax, ymin, ymax;
1128 nt->GetMinMax(0, xmin, xmax);
1129 nt->GetMinMax(0, ymin, ymax);
1130 h2 = new Histo2D(xmin, xmax, 50, ymin, ymax, 50);
1131 int k;
1132 float* xn;
1133 for(k=0; k<nt->NEntry(); k++) {
1134 xn = nt->GetVec(k);
1135 h2->Add(xn[0], xn[1], xn[2]);
1136 }
1137 delete nt;
1138 AddObj(h2, nomh2);
1139 }
1140
1141DisplayObj(nomh2, dopt);
1142return;
1143
1144}
1145
1146/* --Methode-- cmv 13/10/98 */
1147void NamedObjMgr::ProjectHProf(string const& nom, string& expx, string& expy, string& expwt, string& expcut,
1148 string& nomprof, string dopt)
1149// Pour remplir un ``GeneralFitData'' a partir de divers objets:
1150//| nom = nom de l'objet a projeter dans un HProf.
1151//| expx = expression X de definition du bin.
1152//| expy = expression Y a additionner dans le bin.
1153//| expwt = expression W du poids a additionner.
1154//| expcut = expression du test de selection.
1155//| nomprof = nom du HProf engendre (optionnel). Si l'objet n'existe pas
1156//| les limites Xmin,Xmax sont calculees automatiquement.
1157//| sinon ce sont celles de l'objet preexistant.
1158//| opt = options generales pour le display.
1159{
1160PPersist* obj=GetObj(nom);
1161
1162if (obj == NULL) {
1163 cout << "NamedObjMgr::ProjectHProf() Error , Pas d'objet de nom " << nom << endl;
1164 return;
1165 }
1166if (!myImgApp) return;
1167
1168HProf* hprof = NULL;
1169NTuple* nt = NULL;
1170PPersist* oh = NULL;
1171if (nomprof.length() > 0) oh=GetObj(nomprof);
1172else nomprof = "ProfProj";
1173if( (oh!=NULL) && (oh->ClassId()== ClassId_HProf) ) hprof = (HProf*)oh;
1174else {
1175 char* ntn[3]= {"hxval", "hyval", "hwt"};
1176 nt = new NTuple(3,ntn); // Creation NTuple
1177}
1178string expz = "0.";
1179servnobjm->Nobj_ComputeExpressions(obj, expx, expy, expwt, expwt, expcut, nt, NULL, NULL, hprof);
1180
1181if((!hprof) && (!nt)) return;
1182if(!hprof) {
1183 if (nt->NEntry() < 1) {
1184 cout << "NamedObjMgr::ProjectHProf() Warning Zero points satisfy cut !" << endl;
1185 delete nt;
1186 return;
1187 }
1188 float xmin, xmax;
1189 nt->GetMinMax(0, xmin, xmax);
1190 hprof = new HProf(xmin, xmax, 100);
1191 int k;
1192 float* xn;
1193 for(k=0; k<nt->NEntry(); k++) {
1194 xn = nt->GetVec(k);
1195 hprof->Add(xn[0], xn[1], xn[2]);
1196 }
1197 delete nt;
1198 AddObj(hprof, nomprof);
1199 }
1200hprof->UpdateHisto();
1201
1202DisplayObj(nomprof, dopt);
1203return;
1204}
1205
1206/* --Methode-- */
1207void NamedObjMgr::FillVect(string const& nom, string& expx, string& expcut, string& nomvec, string dopt)
1208{
1209PPersist* obj=GetObj(nom);
1210
1211if (obj == NULL) {
1212 cout << "NamedObjMgr::FillVect() Error , Pas d'objet de nom " << nom << endl;
1213 return;
1214 }
1215if (!myImgApp) return;
1216
1217NTuple* nt = NULL;
1218if (nomvec.length() < 1) nomvec = "VecFill";
1219
1220char* ntn[2]= {"vecval", "vecwt"};
1221nt = new NTuple(1,ntn); // Creation NTuple
1222
1223string expwt = "1.";
1224string expz = "0.";
1225servnobjm->Nobj_ComputeExpressions(obj, expx, expz, expz, expwt, expcut, nt, NULL, NULL);
1226
1227if (!nt) return;
1228if (nt->NEntry() < 1) {
1229 cout << "NamedObjMgr::FillVect() Warning Zero points satisfy cut !" << endl;
1230 delete nt;
1231 return;
1232 }
1233
1234Vector* vec = new Vector(nt->NEntry());
1235int k;
1236float* xn;
1237for(k=0; k<nt->NEntry(); k++) {
1238 xn = nt->GetVec(k);
1239 (*vec)(k) = xn[0];
1240 }
1241delete nt;
1242AddObj(vec, nomvec);
1243DisplayObj(nomvec, dopt);
1244return;
1245}
1246
1247/* --Methode-- */
1248void NamedObjMgr::FillNT(string const& nom, string& expx, string& expy, string& expz, string& expt,
1249 string& expcut, string& nomnt)
1250{
1251PPersist* obj=GetObj(nom);
1252
1253if (obj == NULL) {
1254 cout << "NamedObjMgr::FillNT() Error , Pas d'objet de nom " << nom << endl;
1255 return;
1256 }
1257if (!myImgApp) return;
1258
1259bool fgnnt = false;
1260NTuple* nt = NULL;
1261PPersist* oh = NULL;
1262if (nomnt.length() > 0) oh=GetObj(nomnt);
1263else nomnt = "NTFill";
1264if ( (oh != NULL) && (oh->ClassId() == ClassId_NTuple) ) {
1265 nt = (NTuple*)oh;
1266 if (nt->NVar() > 10) {
1267 cout << "NamedObjMgr::FillNT() Warning , Max 10 var ds NTuple -> new NTuple" << endl;
1268 nt = NULL;
1269 }
1270 }
1271if (nt == NULL) {
1272 char* ntn[4]= {"x", "y","z","t"};
1273 nt = new NTuple(4,ntn); // Creation NTuple
1274 fgnnt = true;
1275 }
1276
1277servnobjm->Nobj_ComputeExpressions(obj, expx, expy, expz, expt, expcut, nt, NULL, NULL);
1278
1279if (fgnnt) AddObj(nt, nomnt);
1280return;
1281
1282}
1283
1284/* --Methode-- cmv 13/10/98 */
1285void NamedObjMgr::FillGFD(string const& nom, string& expx, string& expy, string& expz,
1286 string& experr, string& expcut, string& nomgfd)
1287// Pour remplir un ``GeneralFitData'' a partir de divers objets:
1288//| nom = nom de l'objet a transcrire selon 1D: Z=f(X) ou 2D: Z=f(X,Y) .
1289//| Vector,Matrix,Histo,HProf,Histo2D,Image<T>,StarList,NTuple,GeneralFitData
1290//| expx = expression X du GeneralFitData (1er abscisse)
1291//| expy = expression Y du GeneralFitData (2sd abscisse si non "", Z=f(X,Y))
1292//| expz = expression Z du GeneralFitData (valeur de l'ordonnee)
1293//| experr = expression de l'erreur sur l'ordonnee Z
1294//| expcut = expression du test de selection
1295//| nomgfd = nom du GeneralFitData engendre (optionnel)
1296{
1297PPersist* obj=GetObj(nom);
1298if(obj == NULL)
1299 {cout<<"NamedObjMgr::FillGFD() Error , Pas d'objet de nom "<<nom<<endl;
1300 return;}
1301if(!myImgApp) return;
1302
1303// 2D ou 3D?
1304int nvar = 2;
1305if(expy.length()<=0) {nvar = 1; expy = "0.";}
1306
1307// Que faut-il copier dans GeneralFitData
1308int ndata=0;
1309int cid = obj->ClassId();
1310switch (cid) {
1311 case ClassId_Vector :
1312 ndata=((Vector*)obj)->NElts();
1313 break;
1314 case ClassId_Matrix :
1315 ndata=((Matrix*)obj)->NCol()*((Matrix*)obj)->NRows();
1316 break;
1317 case ClassId_Histo1D :
1318 case ClassId_HProf :
1319 ndata=((Histo*)obj)->NBins();
1320 break;
1321 case ClassId_Histo2D :
1322 ndata=((Histo2D*)obj)->NBinX()*((Histo2D*)obj)->NBinY();
1323 break;
1324 case ClassId_Image :
1325 case ClassId_Image + kuint_1 :
1326 case ClassId_Image + kint_1 :
1327 case ClassId_Image + kr_8 :
1328 case ClassId_Image + kuint_4 :
1329 case ClassId_Image + kuint_2 :
1330 case ClassId_Image + kint_2 :
1331 case ClassId_Image + kint_4 :
1332 case ClassId_Image + kr_4 :
1333 ndata=((RzImage*)obj)->XSize()*((RzImage*)obj)->YSize();
1334 break;
1335#ifndef SANS_StarReco
1336 case ClassId_StarList :
1337 ndata=((StarList*)obj)->NbStars();
1338 break;
1339#endif
1340 case ClassId_NTuple :
1341 ndata=((NTuple*)obj)->NEntry();
1342 break;
1343 case ClassId_GeneralFitData :
1344 ndata=((GeneralFitData*)obj)->NData();
1345 break;
1346 default :
1347 cout<<"FillGFD Erreur: N/A to "<<servnobjm->PClassIdToClassName(cid)<<endl;
1348 return;
1349}
1350
1351// Nom du GeneralFitData cree.
1352if (nomgfd.length() <= 0) nomgfd = "GFDFill";
1353// Consistence ndata.
1354if(ndata<=0)
1355 {cout<<"NamedObjMgr::FillGFD() Warning ndata="<<ndata<<endl;
1356 return;}
1357
1358// Creation NTuple Buffer
1359char* ntn[4]= {"x","y","f","e"};
1360NTuple*nt = new NTuple(4,ntn);
1361
1362// Remplissage NTuple buffer
1363servnobjm->Nobj_ComputeExpressions(obj, expx, expy, expz, experr, expcut, nt, NULL, NULL);
1364if(nt->NEntry() < 1)
1365 {cout<<"NamedObjMgr::FillGFD() Warning Zero points satisfy cut !"<<endl;
1366 delete nt; return;}
1367
1368//Remplissage de la structure GeneraFitData
1369GeneralFitData* gfd = new GeneralFitData(nvar,ndata,0);
1370int k;
1371float* xn;
1372for(k=0; k<nt->NEntry(); k++) {
1373 xn = nt->GetVec(k);
1374 gfd->AddData(xn,xn[2],xn[3]);
1375}
1376
1377// Menage et table d'objets
1378delete nt;
1379AddObj(gfd, nomgfd);
1380return;
1381}
1382
1383/* --Methode-- */
1384void NamedObjMgr::PlotFunc(string& expfunc, float xmin, float xmax, int np, string dopt)
1385{
1386FILE *fip;
1387string fname = (*TmpDir) + "func1_pia_dl.c";
1388string fnamer = (*TmpDir) + "func1_pia_dl";
1389string cmd;
1390int rc;
1391
1392if (!myImgApp) return;
1393
1394cmd = "rm " + fname;
1395rc = system(cmd.c_str());
1396printf("PlotFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
1397
1398if ((fip = fopen(fname.c_str(), "w")) == NULL) {
1399 string sn = fname;
1400 cout << "NamedObjMgr/PlotFunc_Erreur: Pb. Ouverture " << sn << endl;
1401 return;
1402 }
1403
1404// constitution du fichier a compiler
1405fputs("#include <math.h> \n", fip);
1406fputs("double func1_pia_dl_func(double x) \n{\n", fip);
1407fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
1408fclose(fip);
1409
1410DlFunctionOfX f = (DlFunctionOfX) servnobjm->LinkFunctionFromFile(fnamer, "func1_pia_dl_func");
1411if (!f) return;
1412PlotFunc(f, xmin, xmax, np, dopt);
1413servnobjm->CloseDLL();
1414return;
1415}
1416
1417/* --Methode-- */
1418void NamedObjMgr::PlotFunc2D(string& expfunc, float xmin, float xmax, float ymin, float ymax,
1419 int npx, int npy, string dopt)
1420{
1421FILE *fip;
1422string fname = (*TmpDir) + "func2_pia_dl.c";
1423string fnamer = (*TmpDir) + "func2_pia_dl";
1424string cmd;
1425int rc;
1426
1427if (!myImgApp) return;
1428
1429cmd = "rm " + fname;
1430rc = system(cmd.c_str());
1431printf("PlotFunc2D_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
1432
1433if ((fip = fopen(fname.c_str(), "w")) == NULL) {
1434 string sn = fname;
1435 cout << "NamedObjMgr/PlotFunc2D_Erreur: Pb. Ouverture " << sn << endl;
1436 return;
1437 }
1438
1439// constitution du fichier a compiler
1440fputs("#include <math.h> \n", fip);
1441fputs("double func2_pia_dl_func(double x, double y) \n{\n", fip);
1442fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
1443fclose(fip);
1444
1445DlFunctionOfXY f = (DlFunctionOfXY) servnobjm->LinkFunctionFromFile(fnamer, "func2_pia_dl_func");
1446if (!f) return;
1447PlotFunc2D(f, xmin, xmax, ymin, ymax, npx, npy, dopt);
1448servnobjm->CloseDLL();
1449return;
1450}
1451
1452/* --Methode-- */
1453void NamedObjMgr::PlotFunc(DlFunctionOfX f, float xmin, float xmax, int np, string dopt)
1454{
1455if (!myImgApp) return;
1456
1457int k;
1458if (np < 1) np = 1;
1459if (xmax <= xmin) xmax = xmin+1.;
1460Vector* vpy = new Vector(np);
1461
1462double xx;
1463double dx = (xmax-xmin)/np;
1464TRY {
1465 for(k=0; k<np; k++) { xx = xmin+dx*k; (*vpy)(k) = f(xx); }
1466} CATCH(merr) {
1467 fflush(stdout);
1468 cout << endl;
1469 cerr << endl;
1470 string es = PeidaExc(merr);
1471 cerr << "NamedObjMgr::PlotFunc() Exception :" << merr << es;
1472 delete vpy;
1473 vpy = NULL;
1474 } ENDTRY;
1475
1476
1477if (vpy) {
1478 string nom = "Func";
1479 AddObj(vpy, nom);
1480 P1DArrayAdapter* vya = new POVectorAdapter(vpy, false);
1481 vya->DefineXCoordinate(xmin, (xmax-xmin)/np);
1482 PIYfXDrawer* dr = new PIYfXDrawer(vya, NULL, true) ;
1483 bool fgsr = true;
1484 dopt = "thinline," + dopt;
1485 int opt = servnobjm->DecodeDispOption(dopt, fgsr);
1486 int wrsid = myImgApp->DispScDrawer(dr, nom, opt);
1487 if(wrsid >= 0) {
1488 NObjList::iterator it = myObjs->find(nom);
1489 if (it == myObjs->end()) return;
1490 (*it).second.wrsid.push_back(wrsid);
1491 }
1492 if (fgsr) myImgApp->RestoreGraphicAtt();
1493 }
1494
1495return;
1496}
1497
1498/* --Methode-- */
1499void NamedObjMgr::PlotFunc2D(DlFunctionOfXY f, float xmin, float xmax, float ymin, float ymax,
1500 int npx, int npy, string dopt)
1501{
1502if (!myImgApp) return;
1503
1504if (npx < 1) npx = 1;
1505if (npy < 1) npy = 1;
1506if (xmax <= xmin) xmax = xmin+1.;
1507if (ymax <= ymin) ymax = ymin+1.;
1508
1509Matrix* mtx = new Matrix(npy, npx);
1510
1511int i,j;
1512double xx, yy;
1513double dx = (xmax-xmin)/npx;
1514double dy = (ymax-ymin)/npy;
1515// printf(" -- DBG -- %d %d , %g %g , %g %g \n", npx, npy, xmin, xmax, ymin, ymax);
1516TRY {
1517 for(j=0; j<npy; j++) {
1518 yy = ymin+dy*j;
1519 for(i=0; i<npx; i++) {
1520 xx = xmin+dx*i;
1521 (*mtx)(j, i) = f(xx, yy);
1522 }
1523 }
1524} CATCH(merr) {
1525 fflush(stdout);
1526 cout << endl;
1527 cerr << endl;
1528 string es = PeidaExc(merr);
1529 cerr << "NamedObjMgr::PlotFunc2D() Exception :" << merr << es;
1530 delete mtx; mtx = NULL;
1531 } ENDTRY;
1532
1533if (mtx) {
1534 string nom = "Func2";
1535 AddObj(mtx, nom);
1536 DisplaySurf3D(nom, dopt);
1537 }
1538
1539return;
1540}
1541
1542///////////////////// Fit 1D et 2D //////////////////////////
1543/* --Function static propre aux routines de fit 1D et 2D-- cmv 13/10/98 */
1544struct DFOptions {
1545 int okres, okfun;
1546 int polcx,polcy; double xc,yc;
1547 double err_e, err_E;
1548 double stc2;
1549 int lp,lpg;
1550 int i1,i2,j1,j2;
1551};
1552typedef struct DFOptions DFOPTIONS;
1553static void DecodeFitsOptions(string par,string step,string min,string max,string opt
1554 ,Vector& Par,Vector& Step,Vector& Min,Vector& Max,DFOPTIONS& O);
1555void DecodeFitsOptions(string par,string step,string min,string max,string opt
1556 ,Vector& Par,Vector& Step,Vector& Min,Vector& Max,DFOPTIONS& O)
1557//| Pour decoder les "string" et remplir les vecteurs du fit (cf commentaires dans Fit1D)
1558{
1559// set des vecteurs et decodage des string correspondantes
1560int NParMax = 100;
1561Par.Realloc(NParMax); Step.Realloc(NParMax);
1562Min.Realloc(NParMax); Max.Realloc(NParMax);
1563{
1564 Vector* v; string* s;
1565 {for(int i=0;i<NParMax;i++) {Par(i)=0.; Step(i)=1.; Min(i)=1.; Max(i)=-1.;}}
1566 for(int j=0;j<4;j++) {
1567 if(j==0) {v=&Par; s=&par;}
1568 else if(j==1) {v=&Step; s=&step;}
1569 else if(j==2) {v=&Min; s=&min;}
1570 else if(j==3) {v=&Max; s=&max;}
1571 if(s->length()>0) *s += ",";
1572 for(int i=0;i<NParMax;i++) {
1573 if(s->length()<=0) break;
1574 sscanf(s->c_str(),"%lf",&(*v)(i));
1575 size_t p = s->find_first_of(',') + 1;
1576 if(p>=s->length()) *s = ""; else *s = s->substr(p);
1577 }
1578 }
1579}
1580
1581// Decodage de options de opt
1582O.okres = O.okfun = 0;
1583O.polcx = O.polcy = 0;
1584O.xc = O.yc = 0.;
1585O.stc2 = 1.e-3;
1586O.err_e = O.err_E = -1.;
1587O.lp = 1; O.lpg = 0;
1588O.i1 = O.j1 = O.i2 = O.j2 = -1;
1589
1590if(opt.length()<=0) return;
1591opt = "," + opt + ",";
1592
1593if(strstr(opt.c_str(),",r,")) O.okres = 1; // residus
1594if(strstr(opt.c_str(),",f,")) O.okfun = 1; // fonction fittee
1595if(strstr(opt.c_str(),",x")) { // Demande de centrage (fit X=x-xc)
1596 O.polcx = 2; // Le centrage est calcule automatiquement
1597 size_t p = opt.find(",x");
1598 size_t q = opt.find_first_of(',',p+1);
1599 string dum = opt.substr(p,q-p);
1600 if(dum.length()>2) {
1601 sscanf(dum.c_str(),",x%lf",&O.xc);
1602 O.polcx = 1; // Le centrage est fixe par la valeur lue
1603 }
1604}
1605if(strstr(opt.c_str(),",y")) { // Demande de centrage (fit Y=y-yc)
1606 O.polcy = 2; // Le centrage est calcule automatiquement
1607 size_t p = opt.find(",y");
1608 size_t q = opt.find_first_of(',',p+1);
1609 string dum = opt.substr(p,q-p);
1610 if(dum.length()>2) {
1611 sscanf(dum.c_str(),",y%lf",&O.yc);
1612 O.polcy = 1; // Le centrage est fixe par la valeur lue
1613 }
1614}
1615if(strstr(opt.c_str(),",E")) { // Erreurs imposees a "sqrt(val)" ou "aa.b*sqrt(val)"
1616 size_t p = opt.find(",E");
1617 size_t q = opt.find_first_of(',',p+1);
1618 string dum = opt.substr(p,q-p);
1619 if(dum.length()>2) sscanf(dum.c_str(),",E%lf",&O.err_E);
1620 if(O.err_E<=0.) O.err_E = 1.;
1621 O.err_e=-1.;
1622}
1623if(strstr(opt.c_str(),",e")) { // Erreurs imposees a "1" ou "aa.b"
1624 size_t p = opt.find(",e");
1625 size_t q = opt.find_first_of(',',p+1);
1626 string dum = opt.substr(p,q-p);
1627 if(dum.length()>2) sscanf(dum.c_str(),",e%lf",&O.err_e);
1628 if(O.err_e<=0.) O.err_e = 1.;
1629 O.err_E=-1.;
1630}
1631if(strstr(opt.c_str(),",X")) { // Valeur du StopChi2
1632 size_t p = opt.find(",X");
1633 size_t q = opt.find_first_of(',',p+1);
1634 string dum = opt.substr(p,q-p);
1635 if(dum.length()>2) sscanf(dum.c_str(),",X%lf",&O.stc2);
1636 if(O.stc2<=0.) O.stc2 = 1.e-3;
1637}
1638if(strstr(opt.c_str(),",l")) { // niveau de print
1639 size_t p = opt.find(",l");
1640 size_t q = opt.find_first_of(',',p+1);
1641 string dum = opt.substr(p,q-p);
1642 float ab;
1643 if(dum.length()>2) sscanf(dum.c_str(),",l%f",&ab);
1644 if(ab<0) ab = 0.;
1645 O.lp = (int) ab; O.lpg = (int) 10.*(ab-O.lp);
1646}
1647if(strstr(opt.c_str(),",I")) { // intervalle de fit selon X
1648 size_t p = opt.find(",I");
1649 size_t q = opt.find_first_of(',',p+1);
1650 string dum = opt.substr(p,q-p);
1651 if(dum.length()>2) sscanf(dum.c_str(),",I%d/%d",&O.i1,&O.i2);
1652}
1653if(strstr(opt.c_str(),",J")) { // intervalle de fit selon Y
1654 size_t p = opt.find(",J");
1655 size_t q = opt.find_first_of(',',p+1);
1656 string dum = opt.substr(p,q-p);
1657 if(dum.length()>2) sscanf(dum.c_str(),",J%d/%d",&O.j1,&O.j2);
1658}
1659return;
1660}
1661
1662/* --Methode-- cmv 13/10/98 */
1663void NamedObjMgr:: Fit12D(string const& nom, string& func,
1664 string par,string step,string min,string max,
1665 string opt)
1666//| --------------- Fit d'objets a 1 et 2 dimensions ---------------
1667//| nom : nom de l'objet qui peut etre:
1668//| fit-1D: Vector,Histo1D,HProf ou GeneraFitData(1D)
1669//| fit-2D: Matrix,Histo2D,Imagexx ou GeneraFitData(2D)
1670//| func : pnn = fit polynome degre nn avec classe Poly (lineaire) 1D ou 2D
1671//| : Pnn = fit polynome degre nn avec GeneralFit (non-lineaire) 1D ou 2D
1672//| : gnn = fit gaussienne (hauteur) + polynome de degre nn 1D
1673//| : g = fit gaussienne (hauteur) 1D
1674//| : enn = fit exponentielle + polynome de degre nn 1D
1675//| : e = fit exponentielle 1D
1676//| : Gnn = fit gaussienne (volume) + polynome de degre nn 1D
1677//| : G = fit gaussienne (volume) 1D
1678//| : = fit gaussienne+fond (volume) 2D
1679//| : Gi = fit gaussienne+fond integree (volume) 2D
1680//| : d = fit DL de gaussienne+fond (volume) 2D
1681//| : di = fit DL de gaussienne+fond integree (volume) 2D
1682//| : D = fit DL de gaussienne+fond avec coeff variable p6 (volume) 2D
1683//| : Di = fit DL de gaussienne+fond integree avec coeff variable p6 (volume) 2D
1684//| : M = fit Moffat+fond (expos=p6) (volume) 2D
1685//| : Mi = fit Moffat+fond integree (expos=p6) (volume) 2D
1686//| par : p1,...,pn valeur d'initialisation des parametres (def=0)
1687//| step : s1,...,sn valeur des steps de depart (def=1)
1688//| min : m1,...,mn valeur des minima (def=1)
1689//| max : M1,...,Mn valeur des maxima (def=-1) (max<=min : pas de limite)
1690//| opt : options "Eaa.b,eaa.b,f,r,caa.b,Xaa.b"
1691//| f = generation d'un Objet identique contenant la fonction fittee
1692//| r = generation d'un Objet identique contenant les residus
1693//| Xaa.b = aa.b valeur du DXi2 d'arret (def=1.e-3)
1694//| la.b = niveau "a.b" de print: a=niveau de print Fit1/2D
1695//| b=niveau de debug GeneralFit
1696//| Ii1/i2 numeros des bins X de l'histos utilises pour le fit [i1,i2]
1697//|2D Jj1/j2 numeros des bins Y de l'histos utilises pour le fit [j1,j2]
1698//| - L'erreur est celle associee a l'objet si existe, 1 sinon sauf si
1699//| E = erreur prise comme la racine de la valeur a fitter
1700//| Eaa.b = erreur prise aa.b*sqrt(val)
1701//| e = erreur prise egale a 1 pour toutes les valeurs
1702//| eaa.b = erreur prise egale a aa.b
1703//| xaa.b = demande de centrage: on fit x-aa.b au lieu de x)
1704//| x = demande de centrage: on fit x-xc au lieu de x
1705//| avec xc=abscisse du milieu de l'histogramme
1706//| Actif pour: exp+poly 1D, poly 1D
1707//| gauss+poly 1D (mais xc est le centre de la gaussienne)
1708//|2D yaa.b et y = idem "xaa.b et x" mais pour y
1709{
1710PPersist* obj=GetObj(nom);
1711if (obj == NULL) {
1712 cout<<"NamedObjMgr::Fit12D() Error , Pas d'objet de nom "<<nom<<endl;
1713 return;
1714}
1715if (!myImgApp) return;
1716if(func.length()<=0)
1717 {cout<<"NamedObjMgr::Fit12D() Donnez un nom de fonction a fitter."<<endl;
1718 return;}
1719int cid = obj->ClassId();
1720string ctyp = servnobjm->PClassIdToClassName(cid);
1721
1722int ndim = 0, nbinx=0, nbiny=0, ndata = 0;
1723Vector* v = NULL; Histo* h = NULL;
1724Matrix* m = NULL; Histo2D* h2 = NULL; RzImage* im = NULL;
1725GeneralFitData* g = NULL;
1726switch (cid) {
1727 // 1D
1728 case ClassId_Vector :
1729 ndim = 1;
1730 v = (Vector*) obj; nbinx = v->NElts(); nbiny = 1;
1731 break;
1732 case ClassId_HProf :
1733 case ClassId_Histo1D :
1734 ndim = 1;
1735 h = (Histo*) obj; nbinx = h->NBins(); nbiny = 1;
1736 break;
1737 // 2D
1738 case ClassId_Matrix :
1739 ndim = 2;
1740 m = (Matrix*) obj; nbinx = m->NCol(); nbiny = m->NRows();
1741 break;
1742 case ClassId_Histo2D :
1743 ndim = 2;
1744 h2 = (Histo2D*) obj; nbinx = h2->NBinX(); nbiny = h2->NBinY();
1745 break;
1746 // 1D ou 2D selon
1747 case ClassId_GeneralFitData :
1748 g = (GeneralFitData*) obj; nbinx = g->NData(); nbiny = 1;
1749 if( g->NVar()==1) ndim = 1;
1750 else if(g->NVar()==2) ndim = 2;
1751 else {
1752 cout<<"GeneralFitData ne peut avoir que 1 ou 2 variables d'abscisse: "
1753 <<((GeneralFitData*) obj)->NVar()<<endl; return;}
1754 break;
1755 case ClassId_Image :
1756 case ClassId_Image + kuint_1 :
1757 case ClassId_Image + kuint_2 :
1758 case ClassId_Image + kint_2 :
1759 case ClassId_Image + kint_4 :
1760 case ClassId_Image + kr_4 :
1761 case ClassId_Image + kr_8 :
1762 ndim = 2;
1763 im = (RzImage*) obj; nbinx = im->XSize(); nbiny = im->YSize();
1764 break;
1765 default:
1766 cout<<"NamedObjMgr::Fit12D() Error , Objet n'est pas un "
1767 <<"Histo1D/HProf/Vector/Histo2D/Image/Matrix/GeneralFitData "<<ctyp<<endl;
1768 return;
1769 break;
1770}
1771ndata = nbinx*nbiny;
1772if(ndata<=0)
1773 {cout<<"L'objet a "<<nbinx<<","<<nbiny<<" bins ("<<ndata<<")"<<endl; return;}
1774
1775// Decodage des options et des parametres, mise en forme
1776Vector Par(1); Vector Step(1); Vector Min(1); Vector Max(1); DFOPTIONS O;
1777DecodeFitsOptions(par,step,min,max,opt,Par,Step,Min,Max,O);
1778O.i1 = (O.i1<0||O.i1>=nbinx)? 0: O.i1;
1779O.i2 = (O.i2<0||O.i2>=nbinx||O.i2<O.i1)? nbinx-1: O.i2;
1780if(ndim>=2) {
1781 O.j1 = (O.j1<0||O.j1>=nbiny)? 0: O.j1;
1782 O.j2 = (O.j2<0||O.j2>=nbiny||O.j2<O.j1)? nbiny-1: O.j2;
1783} else O.j2 = O.j1 = 0;
1784if(O.polcx==2) {
1785 if(v||m) O.xc = (O.i2-O.i1+1)/2.;
1786 else if(h) O.xc = (h->XMin()+h->XMax())/2.;
1787 else if(h2) O.xc = (h2->XMin()+h2->XMax())/2.;
1788 else if(g) {double mini,maxi; g->GetMinMax(2,mini,maxi); O.xc=(mini+maxi)/2.;}
1789 else if(im) {O.xc = im->XOrg() * im->XPxSize()*(O.i2-O.i1+1)/2.;}
1790}
1791if(O.polcy==2 && ndim>=2) {
1792 if(m) O.yc = (O.j2-O.j1+1)/2.;
1793 if(h2) O.yc = (h2->YMin()+h2->YMax())/2.;
1794 if(g) {double mini,maxi; g->GetMinMax(12,mini,maxi); O.yc=(mini+maxi)/2.;}
1795 if(im) {O.yc = im->YOrg() * im->YPxSize()*(O.j2-O.j1+1)/2.;}
1796}
1797if(O.lp>0)
1798 cout<<"Fit["<<nbinx<<","<<nbiny<<"] ("<<ndata<<") dim="<<ndim<<":"
1799 <<" Int=["<<O.i1<<","<<O.i2<<"],["<<O.j1<<","<<O.j2<<"]"<<endl
1800 <<" Cent="<<O.polcx<<","<<O.polcy<<","<<O.xc<<"+x"<<","<<O.yc<<"+y"
1801 <<" TypE="<<O.err_e<<","<<O.err_E
1802 <<" StpX2="<<O.stc2
1803 <<" lp,lpg="<<O.lp<<","<<O.lpg<<endl;
1804
1805///////////////////////////////////
1806// Remplissage de GeneralFitData //
1807///////////////////////////////////
1808GeneralFitData mydata(ndim,ndata,0);
1809{for(int i=O.i1;i<=O.i2;i++) for(int j=O.j1;j<=O.j2;j++) {
1810 double x,y,f,e;
1811
1812 if(v)
1813 {x= (double) i; f=(*v)(i); e=1.;}
1814 else if(h)
1815 {x=h->BinCenter(i); f=(*h)(i); e=(h->HasErrors())?h->Error(i):1.;}
1816 else if(m)
1817 {x=(double) i; y=(double) j; f=(*m)(j,i); e=1.;}
1818 else if(h2)
1819 {float xf,yf; h2->BinCenter(i,j,xf,yf); x=(double)xf; y=(double)yf;
1820 f=(*h2)(i,j); e=(h2->HasErrors())?h2->Error(i,j):1.;}
1821 else if(im)
1822 {x=im->XOrg()+(i+0.5)*im->XPxSize(); y=im->YOrg()+(j+0.5)*im->YPxSize();
1823 f=im->DValue(i,j); e=1.;}
1824 else if(g&&ndim==1) {x= g->X(i); f=g->Val(i); e=g->EVal(i);}
1825 else if(g&&ndim==2) {x= g->X(i); y= g->Y(i); f=g->Val(i); e=g->EVal(i);}
1826 else x=y=f=e=0.;
1827
1828 // Gestion des erreurs a utiliser
1829 if(O.err_e>0.) e=O.err_e;
1830 else if(O.err_E>0.) {e=(y<-1.||y>1.)?O.err_E*sqrt(fabs(y)):O.err_E;}
1831
1832 // Remplissage de generalfit
1833 if(func[0]=='p') {x -= O.xc; if(ndim>=2) y -= O.yc;}
1834 if(ndim==1) mydata.AddData1(x,f,e);
1835 else if(ndim==2) mydata.AddData2(x,y,f,e);
1836}}
1837if(mydata.NData()<=0)
1838 {cout<<"Pas de donnees dans GeneralFitData: "<<mydata.NData()<<endl;
1839 return;}
1840if(O.lpg>1) {
1841 mydata.PrintStatus();
1842 mydata.PrintData(0);
1843 mydata.PrintData(mydata.NData()-1);
1844}
1845
1846////////////////////////////////////////////
1847// Identification de la fonction a fitter //
1848////////////////////////////////////////////
1849GeneralFunction* myfunc = NULL;
1850if(func[0]=='p' && ndim==1) {
1851 // Fit de polynome sans passer par les GeneralFit
1852 int degre = 0;
1853 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1854 cout<<"Fit (lineaire) 1D polynome de degre "<<degre<<endl;
1855 Poly p1(0);
1856 double c2rl = mydata.PolFit(0,p1,degre);
1857 cout<<"C2r_lineaire = "<<c2rl<<endl;
1858 if(O.lp>0) cout<<p1<<endl;
1859 return;
1860
1861} else if(func[0]=='P' && ndim==1) {
1862 // Fit de polynome
1863 int degre = 0;
1864 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1865 cout<<"Fit polynome 1D de degre "<<degre<<endl;
1866 Polyn1D* myf = new Polyn1D(degre,O.xc);
1867 myfunc = myf;
1868
1869} else if(func[0]=='e' && ndim==1) {
1870 // Fit d'exponentielle
1871 int degre =-1;
1872 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1873 cout<<"Fit d'exponentielle+polynome 1D de degre "<<degre<<endl;
1874 Exp1DPol* myf;
1875 if(degre>=0) myf = new Exp1DPol((unsigned int)degre,O.xc);
1876 else myf = new Exp1DPol(O.xc);
1877 myfunc = myf;
1878
1879} else if(func[0]=='g' && ndim==1) {
1880 // Fit de gaussienne en hauteur
1881 int degre =-1;
1882 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1883 cout<<"Fit de Gaussienne_en_hauteur+polynome 1D de degre "<<degre<<endl;
1884 Gauss1DPol* myf;
1885 if(degre>=0) myf = new Gauss1DPol((unsigned int)degre,((O.polcx)?true:false));
1886 else { bool bfg = (O.polcx)?true:false; myf = new Gauss1DPol(bfg); }
1887 myfunc = myf;
1888
1889} else if(func[0]=='G' && ndim==1) {
1890 // Fit de gaussienne en volume
1891 int degre =-1;
1892 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1893 cout<<"Fit de Gaussienne_en_volume+polynome 1D de degre "<<degre<<endl;
1894 GaussN1DPol* myf;
1895 if(degre>=0) myf = new GaussN1DPol((unsigned int)degre,((O.polcx)?true:false));
1896 else { bool bfg = (O.polcx)?true:false; myf = new GaussN1DPol(bfg); }
1897 myfunc = myf;
1898
1899} else if(func[0]=='p' && ndim==2) {
1900 // Fit de polynome 2D sans passer par les GeneralFit
1901 int degre = 0;
1902 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1903 cout<<"Fit (lineaire) polynome 2D de degre "<<degre<<endl;
1904 Poly2 p2(0);
1905 double c2rl = mydata.PolFit(0,1,p2,degre);
1906 cout<<"C2r_lineaire = "<<c2rl<<endl;
1907 if(O.lp>0) cout<<p2<<endl;
1908 return;
1909
1910} else if(func[0]=='P' && ndim==2) {
1911 // Fit de polynome 2D
1912 int degre = 0;
1913 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1914 cout<<"Fit polynome 2D de degre "<<degre<<endl;
1915 Polyn2D* myf = new Polyn2D(degre,O.xc,O.yc);
1916 myfunc = myf;
1917
1918} else if(func[0]=='G' && ndim==2) {
1919 // Fit de gaussienne+fond en volume
1920 int integ = 0;
1921 if(func.length()>1) if(func[1]=='i') integ=1;
1922 cout<<"Fit de Gaussienne+Fond 2D integ="<<integ<<endl;
1923 if(integ) {GauRhInt2D* myf = new GauRhInt2D; myfunc = myf;}
1924 else {GauRho2D* myf = new GauRho2D; myfunc = myf;}
1925
1926} else if(func[0]=='d' && ndim==2) {
1927 // Fit de DL gaussienne+fond en volume
1928 int integ = 0;
1929 if(func.length()>1) if(func[1]=='i') integ=1;
1930 cout<<"Fit de DL de Gaussienne+Fond 2D integ="<<integ<<endl;
1931 if(integ) {GdlRhInt2D* myf = new GdlRhInt2D; myfunc = myf;}
1932 else {GdlRho2D* myf = new GdlRho2D; myfunc = myf;}
1933
1934} else if(func[0]=='D' && ndim==2) {
1935 // Fit de DL gaussienne+fond avec coeff variable p6 en volume
1936 int integ = 0;
1937 if(func.length()>1) if(func[1]=='i') integ=1;
1938 cout<<"Fit de DL de Gaussienne+Fond avec coeff variable (p6) 2D integ="<<integ<<endl;
1939 if(integ) {Gdl1RhInt2D* myf = new Gdl1RhInt2D; myfunc = myf;}
1940 else {Gdl1Rho2D* myf = new Gdl1Rho2D; myfunc = myf;}
1941
1942} else if(func[0]=='M' && ndim==2) {
1943 // Fit de Moffat+fond (volume)
1944 int integ = 0;
1945 if(func.length()>1) if(func[1]=='i') integ=1;
1946 cout<<"Fit de Moffat+Fond (expos=p6) 2D integ="<<integ<<endl;
1947 if(integ) {MofRhInt2D* myf = new MofRhInt2D; myfunc = myf;}
1948 else {MofRho2D* myf = new MofRho2D; myfunc = myf;}
1949
1950} else {
1951 cout<<"Fonction "<<func<<" inconnue pour la dim "<<ndim<<endl;
1952 return;
1953}
1954
1955/////////////////////////
1956// Fit avec generalfit //
1957/////////////////////////
1958if(myfunc->NPar()>Par.NElts())
1959 {cout<<"Trop de parametres: "<<myfunc->NPar()<<">"<<Par.NElts()<<endl;
1960 if(myfunc) delete myfunc; return;}
1961GeneralFit myfit(myfunc);
1962myfit.SetDebug(O.lpg);
1963myfit.SetData(&mydata);
1964myfit.SetStopChi2(O.stc2);
1965{for(int i=0;i<myfunc->NPar();i++) {
1966 char str[10];
1967 sprintf(str,"P%d",i);
1968 myfit.SetParam(i,str,Par(i),Step(i),Min(i),Max(i));
1969}}
1970if(O.lp>1) myfit.PrintFit();
1971double c2r = (double) myfit.Fit();
1972if(O.lp>0) myfit.PrintFit();
1973if(c2r>0.) {
1974 c2r = myfit.GetChi2Red();
1975 cout<<"C2r_Reduit = "<<c2r<<" nstep="<<myfit.GetNStep()<<endl;
1976 Vector ParFit(myfunc->NPar());
1977 for(int i=0;i<myfunc->NPar();i++) ParFit(i)=myfit.GetParm(i);
1978} else {
1979 cout<<"echec Fit, rc = "<<c2r<<" nstep="<<myfit.GetNStep()<<endl;
1980}
1981
1982// Mise a disposition des resultats
1983if(c2r>=0. && myfunc && (O.okres>0||O.okfun>0)) {
1984 string nomres = nom + "res";
1985 string nomfun = nom + "fun";
1986 if(v) {
1987 if(O.okres) {Vector* ob = v->FitResidus(myfit); if(ob) AddObj(ob,nomres);}
1988 if(O.okfun) {Vector* ob = v->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
1989 } else if(h) {
1990 if(O.okres) {Histo* ob = h->FitResidus(myfit); if(ob) AddObj(ob,nomres);}
1991 if(O.okfun) {Histo* ob = h->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
1992 } else if(m) {
1993 if(O.okres) {Matrix* ob = m->FitResidus(myfit); if(ob) AddObj(ob,nomres);}
1994 if(O.okfun) {Matrix* ob = m->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
1995 } else if(h2) {
1996 if(O.okres) {Histo2D* ob = h2->FitResidus(myfit); if(ob) AddObj(ob,nomres);}
1997 if(O.okfun) {Histo2D* ob = h2->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
1998 } else if(im) {
1999 if(O.okres) {RzImage* ob = im->FitResidus(myfit); if(ob) AddObj(ob,nomres);}
2000 if(O.okfun) {RzImage* ob = im->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
2001 } else if(g) {
2002 if(O.okres) {GeneralFitData* ob = g->FitResidus(myfit); if(ob) AddObj(ob,nomres);}
2003 if(O.okfun) {GeneralFitData* ob = g->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
2004 }
2005}
2006
2007// Nettoyage
2008if(myfunc) delete myfunc;
2009return;
2010}
2011
2012/* --Methode-- */
2013void NamedObjMgr::FFT(string const& nom, string dopt)
2014{
2015PPersist* obj=GetObj(nom);
2016if (obj == NULL) {
2017 cout << "NamedObjMgr::FFT() Error , Pas d'objet de nom " << nom << endl;
2018 return;
2019}
2020if (!myImgApp) return;
2021
2022int cid = obj->ClassId();
2023if (cid != ClassId_Vector) {
2024 string ctyp = servnobjm->PClassIdToClassName(cid);
2025 cout << "NamedObjMgr::FFT() Error , Objet n'est pas un vecteur " << ctyp << endl;
2026 return;
2027 }
2028
2029FFT1 fft( *((Vector*)obj) );
2030
2031if (fft.NData() < 1) return;
2032
2033char* ntn[3] = {"refc", "imfc", "pfc"};
2034NTuple* nt = new NTuple(3,ntn); // Creation NTuple
2035Vector* vf = new Vector(fft.NData()/2);
2036
2037float xnt[3];
2038double pf;
2039for(int k=0; k<fft.NData()/2; k++) {
2040 xnt[0] = fft.ReF(k); xnt[1] = fft.ImF(k);
2041 pf = (xnt[0]*xnt[0]+xnt[1]*xnt[1]);
2042 if (pf >= 0.) pf = sqrt(pf);
2043 xnt[2] = pf; (*vf)(k) = pf;
2044 nt->Fill(xnt);
2045 }
2046
2047P1DArrayAdapter* vya = new POVectorAdapter(vf, true);
2048// vya->DefineXCoordinate(xmin, xmax); a determiner
2049PIYfXDrawer* dr = new PIYfXDrawer(vya, NULL, true) ;
2050bool fgsr = true;
2051dopt = "thinline," + dopt;
2052int opt = servnobjm->DecodeDispOption(dopt, fgsr);
2053myImgApp->DispScDrawer(dr, nom, opt);
2054if (fgsr) myImgApp->RestoreGraphicAtt();
2055
2056return;
2057}
Note: See TracBrowser for help on using the repository browser.