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

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

Ajout SetXYLimits et debut d'introduction de repertoire dans la gestion des objets nommes - Reza 28/6/99

File size: 47.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#include "datatypes.h"
18
19#include "nobjmgr.h"
20#include "servnobjm.h"
[330]21#include "nomgadapter.h"
[165]22#include "pistdimgapp.h"
23
24#include "matrix.h"
25#include "cvector.h"
[326]26#include "ntuple.h"
[165]27
[293]28// EVOL-PLANCK
29#ifdef SANS_EVOLPLANCK
30#include "fitsimage.h"
31#endif
32
[165]33#include "fct1dfit.h"
34#include "fct2dfit.h"
35
[295]36#include "pisurfdr.h"
[165]37#include "pipodrw.h"
38#include "pihisto.h"
39#include "hisprof.h"
40#include "pihisto2d.h"
41#include "pintuple.h"
42#include "pintup3d.h"
43#include "pigfd1.h"
44#include "pigfd2.h"
45
46
47//++
48// Class NamedObjMgr
49// Lib PI
50// include nobjmgr.h
51//
52// Cette classe fournit les services nécéssaire àla gestion des objets
53// (l'ensemble des objets PPersist de PEIDA++) au sein du programme
54// d'analyse interactive *piapp* . Elle constitue en outre l'interface
55// entre les fonctions utilisateur et l'application graphique.
56//--
57//++
58// Links Voir aussi
59// PIStdImgApp
60// Services2NObjMgr
61// PIACmd
62//--
63
64
65// ..................................................................
66// ...... Gestion des objets nommes, variables globales ............
[331]67struct nobj_diritem {
68 int id;
69 int nobj;
70};
71
72typedef map<string, nobj_diritem, less<string> > NObjDirList;
73
[165]74struct nobj_item {
[295]75 AnyDataObj* obj;
76 NObjMgrAdapter* obja;
[165]77 int num;
[331]78 int dirid;
[165]79 list<int> wrsid;
80 bool operator==(nobj_item const& b) const
81 { return (this->obj == b.obj); }
82};
83
84typedef map<string, nobj_item, less<string> > NObjList;
85
[331]86static NObjDirList* myDirs = NULL;
87static NObjList* myObjs = NULL;
[165]88static int fgOInit = 0;
89static int myNObj = 0;
[331]90static int myDirId = 0;
91static string* currDir;
[165]92
93static PIStdImgApp* myImgApp=NULL;
94static Services2NObjMgr* servnobjm=NULL;
95
96static string* TmpDir; // Repertoire pour les compilations / link dynamique
97
98//++
99// Titre Constructeurs
100//--
101//++
102// NamedObjMgr()
103// Constructeur. Les différents instantiation de la classe "NamedObjMgr"
104// dans une même application créent des objets qui travaillent sur la même
105// liste d'objets. Les objets de cette classe ne possedent en effet pas
106// de variables membres.
107//--
108
109/* --Methode-- */
110NamedObjMgr::NamedObjMgr()
111{
112if (fgOInit == 0) {
[331]113 myDirs = new NObjDirList;
[165]114 myObjs = new NObjList;
[331]115 currDir = new string("home");
[165]116 char* varenv;
117 TmpDir = new string("");
118 if ( (varenv=getenv("PEIDA_TMP")) != NULL ) (*TmpDir) = varenv;
119 else if ( (varenv=getenv("TMPDIR")) != NULL ) (*TmpDir) = varenv;
120 int l = (*TmpDir).length();
121 if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/';
122 servnobjm = new Services2NObjMgr(NULL, (*TmpDir));
123 }
124fgOInit++;
125}
126
127
128/* --Methode-- */
129NamedObjMgr::~NamedObjMgr()
130{
131fgOInit--;
132if (fgOInit == 0) delete myObjs;
133}
134
135//++
136// Titre Méthodes
137//--
138//++
139// void SetImgApp(PIStdImgApp* app)
140// Spécifie l'objet "PIStdImgApp" associé.
141// PIStdImgApp* GetImgApp()
142// Accès à l'objet "PIStdImgApp" associé.
143//--
144
145/* --Methode-- */
146void NamedObjMgr::SetImgApp(PIStdImgApp* app)
147{
148myImgApp = app;
149servnobjm->SetImgApp(app);
150}
151
152/* --Methode-- */
153PIStdImgApp* NamedObjMgr::GetImgApp()
154{
155return(myImgApp);
156}
157
158/* --Methode-- */
159Services2NObjMgr* NamedObjMgr::GetServiceObj()
160{
161return(servnobjm);
162}
163
[331]164/* --Methode-- */
165void NamedObjMgr::CreateDir(string const& dirname)
166{
167}
168
169/* --Methode-- */
170void NamedObjMgr::DeleteDir(string const& dirname)
171{
172}
173
174/* --Methode-- */
175void NamedObjMgr::SetCurrentDir(string const& dirname)
176{
177}
178
179/* --Methode-- */
180void NamedObjMgr::CleanTmpDir()
181{
182}
183
184/* --Methode-- */
185void NamedObjMgr::CleanOldDir()
186{
187}
188
[165]189//++
190// Titre Gestion de la liste des objets
191//--
192//++
[295]193// void AddObj(AnyDataObj* obj, string& nom)
[165]194// Ajoute l'objet "obj" à la liste, identifié par "nom".
195// Si un objet de même nom existe, l'ancien objet est renommé en concaténant
196// un numéro à son nom.
197// void DelObj(string const& nom, bool fgd=true)
198// Supprime l'objet "nom" de la liste. L'objet est détruit si "fgd==true" ("delete obj")
199// void DelObjects(string const& patt, bool fgd=true)
200// Supprime l'ensemble des objets dont le nom correspond au patron "patt".
201// Le patron peut contenir les caractères "*" et "?" . Les objets sont détruits si "fgd==true"
[295]202// AnyDataObj* GetObj(string const& nom)
[165]203// Retourne l'objet identifié par "nom" dans la liste. Retourne "NULL" si "nom" n'est
204// pas dans la liste.
205// void RenameObj(string const& nom, string& nomnew)
206// Change le nom d'un objet dans la liste.
207//--
208
209
210/* --Methode-- */
[331]211void NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool)
[165]212{
213
214if (obj == NULL) return;
215// on supprime les blancs de debut et de fin
216size_t p = nom.find_first_not_of(" ");
217if(p>nom.length()) {
218 nom = "";
219} else {
220 nom = nom.substr(p);
221 p = nom.find_first_of(" ");
222 if(p>nom.length()) p=nom.length();
223 nom = nom.substr(0, p);
224}
225
226myNObj++;
[295]227if (nom.length() < 1) nom = typeid(*obj).name();
[165]228NObjList::iterator it = myObjs->find(nom);
229if (it != myObjs->end()) { // l'objet existe deja
230 char strg[16];
231 sprintf(strg, "%d", myNObj);
232 string nomnew = nom + strg;
233 RenameObj(nom, nomnew);
234 }
235
236nobj_item no;
237no.obj = obj;
[295]238no.obja = servnobjm->GetAdapter(obj); // L'adaptateur
[165]239no.num = myNObj;
[331]240(*myObjs)[nom] = no;
[165]241if (myImgApp) {
[331]242 string str = nom + " (T= " + typeid(*obj).name() + ")" ;
[165]243 (myImgApp->ObjMgrW())->AddObj(str.c_str(), myNObj+1000);
244}
245
[331]246cout << "NamedObjMgr::AddObj() Object " << nom << " ( "
[295]247 << typeid(*obj).name() << " ) added (Total= " << myObjs->size() << ")" << endl;
[165]248return;
249}
250
251/* --Methode-- */
[331]252void NamedObjMgr::RenameObj(string & nom, string& nomnew)
[165]253{
[331]254AnyDataObj* obj = GetObj(nom);
255if (obj == NULL) return;
256DelObj(nom, false);
257AddObj(obj, nomnew);
258return;
259}
260
261/* --Methode-- */
262void NamedObjMgr::DelObj(string & nom, bool fgd)
263{
[165]264NObjList::iterator it = myObjs->find(nom);
265if (it == myObjs->end()) return;
266list<int>::iterator ii;
267if (myImgApp) {
268//DBG cerr << " *DBG* NamedObjMgr::DelObj Sz= " << (*it).second.wrsid.size() << endl;
269 for(ii=(*it).second.wrsid.begin(); ii != (*it).second.wrsid.end(); ii++)
270 myImgApp->DelWRsId((*ii));
271 (myImgApp->ObjMgrW())->DelObj((*it).second.num+1000);
272}
[314]273delete (*it).second.obja; // destruction de l'adaptateur
[165]274if (fgd) delete (*it).second.obj;
275myObjs->erase(it);
276if (fgd) cout << "NamedObjMgr::DelObj() Object " << nom << " deleted (Total= " << myObjs->size() << ")" << endl;
277else cout << "NamedObjMgr::DelObj() Object " << nom << " removed (Total= " << myObjs->size() << ")" << endl;
278return;
279}
280
281/* --Methode-- */
[331]282void NamedObjMgr::DelObj_Id(int oid)
[165]283{
[331]284}
285
286/* --Methode-- */
287void NamedObjMgr::DelObjects(string & patt, bool fgd)
288{
[165]289NObjList::iterator it;
290list<string> odel;
291string cn;
292for(it = myObjs->begin(); it != myObjs->end(); it++) {
293 cn = (*it).first;
294 if (csh_parse(cn.c_str(), patt.c_str()) != 0) odel.push_back(cn);
295 }
296list<string>::iterator ii;
297for(ii=odel.begin(); ii != odel.end(); ii++) DelObj(*ii, fgd);
298}
299
300/* --Methode-- */
[331]301AnyDataObj* NamedObjMgr::GetObj(string & nom)
[165]302{
303NObjList::iterator it = myObjs->find(nom);
304if (it == myObjs->end()) return(NULL);
305return((*it).second.obj);
306}
307
308/* --Methode-- */
[331]309NObjMgrAdapter* NamedObjMgr::GetObjAdapter(string & nom)
[295]310{
311NObjList::iterator it = myObjs->find(nom);
312if (it == myObjs->end()) return(NULL);
313return((*it).second.obja);
314}
315
316/* --Methode-- */
[331]317void NamedObjMgr::ListObjs(string & patt)
[165]318{
[331]319int k;
320AnyDataObj* obj=NULL;
321string ctyp;
322char strg[256];
323
324cout << "NamedObjMgr::ListObjs() NObjs= " << myObjs->size() << "\n" ;
325NObjList::iterator it; k = 0;
326for(it = myObjs->begin(); it != myObjs->end(); it++) {
327 obj = (*it).second.obj;
328
329 ctyp = typeid(*obj).name();
330 sprintf(strg, "%2d/ %16s : %s", k, typeid(*obj).name(), ((*it).first).c_str());
331 ctyp = strg;
332 cout << ctyp << "\n" ;
333 k++;
334}
335cout << endl;
[165]336return;
337}
338
339/* --Methode-- */
[331]340void NamedObjMgr::GetObjList(string & patt, vector<string> &)
[165]341{
342}
343
344//++
345// Titre Entrées-Sorties (I/O) sur les objets
346//--
347//++
348// void ReadObj(PInPersist& s, int num=-1)
349// Lit l'objet à partir avec le tag numéro "num" dans le flot "PInPersist s"
350// et l'ajoute à la liste. Si "num" est négatif, tous les objets présents
351// sur le flot "s" sont créés et ajoutés à la liste.
352// void ReadObj(string const & nomppf, string nobj="")
353// Lit le premier objet à partir du fichier PPF "nomppf". L'objet est ajouté
354// à la liste avec le nom "nobj". Si "nobj" est une chaîne vide, un nom est
355// composé à partir du nom de fichier.
356//--
357
358/* --Methode-- */
[331]359void NamedObjMgr::ReadObj(string const & flnm, string & nobj)
[165]360{
361PPersist* obj=NULL;
362bool ok = true;
363
364TRY{
365 PInPersist pis(flnm);
366 obj = PPersistMgr::ReadObject(pis);
367 if (obj == NULL) ok = false;
368} CATCH(merr)
369 { printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n",
370 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
371
372if (!ok) return;
373if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
[295]374AddObj(obj->DataObj(), nobj);
[165]375return;
376}
377
378/* --Methode-- */
379void NamedObjMgr::ReadObj(PInPersist& s, int num)
380{
381int i, cid, key, ln;
382int n0, n1;
383bool ok = true;
384PPersist* obj=NULL;
385string nom;
386
387if ( (s.NbTags() < 1) || (num >= s.NbTags()) ) {
388 if (num >= 0) {
389 printf("NamedObjMgr::ReadObj(PInPersist, %d) Error! NbTags = %d \n", num, s.NbTags());
390 return;
391 }
392 TRY {
393 obj = PPersistMgr::ReadObject(s);
394 if (obj == NULL) ok = false;
395 } CATCH(merr) {
396 printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
397 ok = false;
398 } ENDTRY;
399 if (!ok) return;
400 nom = "";
[295]401 AddObj(obj->DataObj(), nom);
[165]402}
403
404if (num < 0) { n0 = 0; n1 = s.NbTags(); }
405else { n0 = num; n1 = num+1; }
406for(i=n0; i<n1; i++) {
407 key = s.TagKey(i, cid, ln);
408 if (ln <= 0) nom = "";
409 else nom = s.TagName(i);
410 s.GotoTag(i);
411 TRY {
412 obj = PPersistMgr::ReadObject(s);
413 if (obj == NULL) ok = false;
414 } CATCH(merr) {
415 printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
416 ok = false;
417 } ENDTRY;
[295]418 if (ok) AddObj(obj->DataObj(), nom);
[165]419}
420
421return;
422}
423/* --Methode-- */
424void NamedObjMgr::ReadAll(string const & flnm)
425{
426bool ok = true;
427PPersist* obj=NULL;
428
429PInPersist* ppin;
430TRY{
431 ppin = new PInPersist(flnm);
432 if (ppin->NbTags() < 1) obj = PPersistMgr::ReadObject((*ppin));
433 else obj = NULL;
434} CATCH(merr)
435 { printf("NamedObjMgr::ReadAll()/Error Exception= %ld (%s) \n",
436 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
437
438if (!ok) return;
439if (obj) {
440 string nom = servnobjm->FileName2Name(flnm);
[295]441 AddObj(obj->DataObj(), nom);
[165]442 }
443else ReadObj((*ppin), -1);
444delete ppin;
445return;
446}
447
448/* --Methode-- */
[331]449void NamedObjMgr::ReadFits(string const & flnm, string & nobj)
[165]450{
451bool ok = true;
452RzImage* obj;
453
454TRY{
455// obj = RzReadFits((char*)flnm.c_str(), ImgOffX, ImgOffY, ImgSizX, ImgSizY, ImgBitSgn);
[293]456#ifdef SANS_EVOLPLANCK
[165]457 obj = RzReadFits((char*)flnm.c_str());
[293]458#else
459 printf("NamedObjMgr::ReadFITS( NON-Disponible EVOL-PLANCK) \n");
460 obj = NULL;
461#endif
[165]462 if (obj == NULL) ok = false;
463} CATCH(merr) {
464 printf("NamedObjMgr::ReadFITS(_Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
465 ok = false;
466} ENDTRY;
467if (ok) {
468 if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
[295]469 AddObj((AnyDataObj*)obj, nobj);
[165]470}
471return;
472}
473
474
475static int key_for_write = 5000;
476/* --Methode-- */
[331]477void NamedObjMgr::SaveObj(string & nom, POutPersist& s)
[165]478{
[295]479NObjMgrAdapter* obja=NULL;
480obja = GetObjAdapter(nom);
481if (obja == NULL) return;
[165]482printf("NamedObjMgr::SaveObj(%s, ) (Type=%s) \n",
[295]483 nom.c_str(), typeid(*(obja->GetDataObj())).name());
484obja->SavePPF(s, nom);
[165]485return;
486}
487
488/* --Methode-- */
489void NamedObjMgr::SaveAll(string const& flnm)
490{
491bool ok = true;
492
493POutPersist* pout;
494TRY{
495 pout = new POutPersist(flnm);
496} CATCH(merr)
497 { printf("NamedObjMgr::SaveAll()/Error Exception= %ld (%s) \n",
498 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
499if (!ok) return;
500NObjList::iterator it;
501for(it = myObjs->begin(); it != myObjs->end(); it++) SaveObj((*it).first, (*pout));
502delete pout;
503return;
504}
505
506/* --Methode-- */
[331]507void NamedObjMgr::SaveFits(string& nom, string const & flnm)
[165]508{
[295]509NObjMgrAdapter* obja=NULL;
510obja = GetObjAdapter(nom);
511if (obja == NULL) return;
512obja->SaveFits(flnm);
[293]513return;
[165]514}
515
516
517
518/* --Methode-- */
[331]519void NamedObjMgr::PrintObj(string& nom)
[165]520{
[295]521NObjMgrAdapter* obja=NULL;
522obja = GetObjAdapter(nom);
523if (obja == NULL) return;
[165]524
[295]525string ctyp = typeid(*obja->GetDataObj()).name();
526cout << "NamedObjMgr::PrintObj(" << nom << ") Type: " << ctyp << endl;
527obja->Print(cout);
[165]528
529return;
530}
531
532/* --Methode-- */
[331]533void NamedObjMgr::DisplayObj(string& nom, string dopt)
[165]534{
[295]535NObjMgrAdapter* obja=NULL;
536obja = GetObjAdapter(nom);
537if (obja == NULL) {
[165]538 cout << "NamedObjMgr::DisplayObj() Error , Pas d'objet de nom " << nom << endl;
539 return;
540}
541if (!myImgApp) return;
542
[295]543PIDrawer * dr = NULL;
544P2DArrayAdapter* arr = NULL;
545dr = obja->GetDrawer(dopt);
546if (!dr) arr = obja->Get2DArray(dopt);
[165]547
[295]548if (!dr && !arr) {
549 string ctyp = typeid(*(obja->GetDataObj())).name();
550 cout << "NamedObjMgr::DisplayObj() Error , Pas de display pour " << ctyp << endl;
551 return;
552 }
553
[165]554int wrsid = 0;
555bool fgsr = true;
556int opt = servnobjm->DecodeDispOption(dopt, fgsr);
557
[295]558if (dr) {
559 PIDrawer3D * dr3 = dynamic_cast<PIDrawer3D *>(dr);
560 if(dr3) wrsid = myImgApp->Disp3DDrawer(dr3, nom, opt);
561 else wrsid = myImgApp->DispScDrawer( dr, nom, opt);
562 }
563else if (arr) wrsid = myImgApp->DispImage(arr, nom, opt);
[165]564
[295]565if(wrsid != 0) {
566 NObjList::iterator it = myObjs->find(nom);
567 if (it == myObjs->end()) return;
568 (*it).second.wrsid.push_back(wrsid);
569 }
570if (fgsr) myImgApp->RestoreGraphicAtt();
571return;
572}
[165]573
[295]574/* --Methode-- */
[331]575void NamedObjMgr::DisplayImage(string& nom, string dopt)
[295]576{
577NObjMgrAdapter* obja=NULL;
578obja = GetObjAdapter(nom);
579if (obja == NULL) {
580 cout << "NamedObjMgr::DisplayImage() Error , Pas d'objet de nom " << nom << endl;
581 return;
582}
583if (!myImgApp) return;
584
585P2DArrayAdapter* arr = obja->Get2DArray(dopt);
[165]586
[295]587if (!arr) {
588 string ctyp = typeid(*(obja->GetDataObj())).name();
589 cout << "NamedObjMgr::DisplayImage() Error , Non supporte pour " << ctyp << endl;
590 return;
591 }
[165]592
[295]593int wrsid = 0;
594bool fgsr = true;
595int opt = servnobjm->DecodeDispOption(dopt, fgsr);
596wrsid = myImgApp->DispImage(arr, nom, opt);
[165]597
[295]598if(wrsid != 0) {
599 NObjList::iterator it = myObjs->find(nom);
600 if (it == myObjs->end()) return;
601 (*it).second.wrsid.push_back(wrsid);
602 }
603if (fgsr) myImgApp->RestoreGraphicAtt();
604return;
605}
606/* --Methode-- */
[331]607void NamedObjMgr::DisplaySurf3D(string& nom, string dopt)
[295]608{
609NObjMgrAdapter* obja=NULL;
610obja = GetObjAdapter(nom);
611if (obja == NULL) {
612 cout << "NamedObjMgr::DisplayImage() Error , Pas d'objet de nom " << nom << endl;
613 return;
614}
615if (!myImgApp) return;
616
617P2DArrayAdapter* arr = obja->Get2DArray(dopt);
[165]618
[295]619if (!arr) {
620 string ctyp = typeid(*(obja->GetDataObj())).name();
621 cout << "NamedObjMgr::DisplaySurf3D() Error , Non supporte pour " << ctyp << endl;
622 return;
623 }
[165]624
[295]625if ((arr->XSize() > 250) || (arr->YSize() > 250)) {
626 cout << "NamedObjMgr::DisplaySurf3D() Error , 2D-Array(" << arr->XSize()
627 << "x" << arr->YSize() << ") trop grand (max=250x250)" << endl;
628 delete arr;
629 return;
[165]630 }
631
[295]632int wrsid = 0;
633bool fgsr = true;
634int opt = servnobjm->DecodeDispOption(dopt, fgsr);
635PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
636wrsid = myImgApp->Disp3DDrawer(sdr, nom, opt);
637if(wrsid >= 0) {
[165]638 NObjList::iterator it = myObjs->find(nom);
639 if (it == myObjs->end()) return;
640 (*it).second.wrsid.push_back(wrsid);
641 }
[295]642
643if (fgsr) myImgApp->RestoreGraphicAtt();
644return;
[165]645}
646
647/* --Methode-- */
[331]648void NamedObjMgr::DisplayNT(string& nom, string& nmx, string& nmy, string& nmz,
[165]649 string& erx, string& ery, string& erz, string dopt)
650{
[295]651AnyDataObj* obj=GetObj(nom);
[165]652if (obj == NULL) {
653 cout << "NamedObjMgr::DisplayNT() Error , Pas d'objet de nom " << nom << endl;
654 return;
655}
656if (!myImgApp) return;
657
[326]658NTupleInterface * nt = dynamic_cast<NTupleInterface *>(obj);
659if (nt == NULL) {
660// if (typeid(*obj) != typeid(NTupleInterface)) {
[295]661 string ctyp = typeid(*obj).name();
[165]662 cout << "NamedObjMgr::DisplayNT() Error , Objet n'est pas un NTuple " << ctyp << endl;
663 return;
664 }
665
666int wrsid = 0;
667bool fgsr = true;
[326]668dopt = "defline," + dopt;
[165]669int opt = servnobjm->DecodeDispOption(dopt, fgsr);
670
671if (nmz.length()>0) { // Display 3D
[326]672 PINTuple3D* pin = new PINTuple3D(nt, false);
[165]673 pin->SelectXYZ(nmx.c_str(), nmy.c_str(), nmz.c_str());
674 pin->SelectErrBar(erx.c_str(), ery.c_str(), erz.c_str());
675 string titre = nmz + "%" + nmy + "%" + nmz;
676 wrsid = myImgApp->Disp3DDrawer(pin, nom, opt, titre);
677}
678else {
[326]679 PINTuple* pin = new PINTuple(nt, false);
[165]680 pin->SelectXY(nmx.c_str(), nmy.c_str());
681 pin->SelectErrBar(erx.c_str(), ery.c_str());
682 string titre = nmy + "%" + nmz;
683 wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, nom, opt, titre);
684 }
685
686if(wrsid >= 0) {
687 NObjList::iterator it = myObjs->find(nom);
688 if (it == myObjs->end()) return;
689 (*it).second.wrsid.push_back(wrsid);
690 }
691
692if (fgsr) myImgApp->RestoreGraphicAtt();
693return;
694}
695
696/* --Methode-- cmv 13/10/98 */
[331]697void NamedObjMgr::DisplayGFD(string& nom, string& numvarx, string& numvary, string& err, string dopt)
[165]698// Pour le display 2D ou 3D d'un ``GeneralFitData''.
699//| nom = nom de l'objet GeneralFitData a representer.
700//| numvarx = numero (nombre entier) de la 1ere variable d'abscisse.
701//| numvary = numero (nombre entier) de la 2sd variable d'abscisse (3D).
702//| Pour le display 2D, numvary="" string vide.
703//| err = qu'elles erreurs faut il representer ?
704//| - 2D : x y xy (display y=f(x))
705//| - 3D : x y z xy xz yz xzy (display z=f(x,y))
706//| Ceci n'est suivi que si on a PI_NotDefLineAtt, sinon toutes
707//| les barres d'erreurs sont representees.
708//| opt = options generales pour le display.
709{
[295]710AnyDataObj* obj=GetObj(nom);
[165]711if(obj == NULL)
712 {cout << "NamedObjMgr::DisplayGFD() Error , Pas d'objet de nom " << nom << endl;
713 return;}
714if(!myImgApp) return;
[295]715if(typeid(*obj) != typeid(GeneralFitData))
716 {string ctyp = typeid(*obj).name();
[165]717 cout<<"NamedObjMgr::DisplayGFD() Error , Objet n'est pas un GeneralFitData "<<ctyp<<endl;
718 return;}
719
720// Decodage des options classiques
721bool fgsr = true;
722int opt = servnobjm->DecodeDispOption(dopt, fgsr);
723// Decodage des erreurs a representer
724bool errx=false, erry=false, errz=false;
725if(err.length()>0) {
726 for(int i=0;i<err.length();i++)
727 if (err[i]=='x' || err[i]=='X') errx = true;
728 else if(err[i]=='y' || err[i]=='Y') erry = true;
729 else if(err[i]=='z' || err[i]=='Z') errz = true;
730}
731// Decodage des numeros de variables en abscisse
732int numvx=-1, numvy=-1;
733if(numvarx.length()>0) numvx = atoi(numvarx.c_str());
734if(numvary.length()>0) numvy = atoi(numvary.c_str());
735
736int wrsid = 0;
737if(numvy>=0) { // Display 3D
738 PIGenFitDat3D* pigfd = new PIGenFitDat3D(((GeneralFitData*)obj),false);
739 pigfd->SelectXY(numvx,numvy);
740 pigfd->SelectErrBar(errx,erry,errz);
741 wrsid = myImgApp->Disp3DDrawer(pigfd,nom,opt);
742} else { // Display 2D
743 PIGenFitDat* pigfd = new PIGenFitDat(((GeneralFitData*)obj),false);
744 pigfd->SelectX(numvx);
745 pigfd->SelectErrBar(errx,erry);
746 wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,nom,opt);
747}
748
749if(wrsid >= 0) {
750 NObjList::iterator it = myObjs->find(nom);
751 if (it == myObjs->end()) return;
752 (*it).second.wrsid.push_back(wrsid);
753}
754if (fgsr) myImgApp->RestoreGraphicAtt();
755return;
756}
757
758/* --Methode--
[331]759void NamedObjMgr::DisplayImage(string& nom, string dopt)
[165]760{
761 cout << "NamedObjMgr::DisplayImage() a faire ! " << endl;
762}
763*/
764
765
766
767
768/* --Methode-- */
769void NamedObjMgr::SetGraphicAttributes(string gratt)
770{
771bool fg = false;
772servnobjm->DecodeDispOption(gratt, fg);
773}
774/* --Methode-- */
775void NamedObjMgr::SetGraphicWinZone(int nzx, int nzy, bool fcr)
776{
777if (!myImgApp) return;
778if (fcr) myImgApp->CreateGraphWin(nzx, nzy);
779else myImgApp->SetZone(nzx, nzy);
780}
781
782/* --Methode-- */
[331]783void NamedObjMgr::DisplayPoints2D(string& nom, string& expx, string& expy,
[165]784 string& experrx, string& experry,
785 string& expcut, string dopt)
786{
[295]787NObjMgrAdapter* obja=NULL;
788obja = GetObjAdapter(nom);
789if (obja == NULL) {
[165]790 cout << "NamedObjMgr::DisplayPoints2D() Error , Pas d'objet de nom " << nom << endl;
791 return;
[295]792 }
[165]793if (!myImgApp) return;
794
795// Creation NTuple
[179]796char* ntn[4] = {"expx","expy","expex","expey",};
[165]797NTuple* nt = NULL;
798bool haserr = false;
799
[321]800if ( (experrx.length() > 0 ) && (experry.length() > 0 ) ) { haserr = true; nt = new NTuple(4, ntn); }
[165]801else { haserr = false; experrx = experry = "0."; nt = new NTuple(2, ntn); }
802
[295]803servnobjm->Nobj_ComputeExpressions(obja, expx, expy, experrx, experry, expcut, nt, NULL, NULL);
[165]804
805if (nt->NEntry() < 1) {
806 cout << "NamedObjMgr::DisplayPoints2D() Warning Zero points satisfy cut !" << endl;
807 delete nt;
808 return;
809 }
810
811// nt->Show();
812// nt->Print(0,10);
813PINTuple* pin = new PINTuple(nt, true);
814pin->SelectXY(ntn[0], ntn[1]);
815if ( haserr ) pin->SelectErrBar(ntn[2], ntn[3]);
816
817bool fgsr = true;
[326]818dopt = "defline," + dopt;
[165]819int opt = servnobjm->DecodeDispOption(dopt, fgsr);
820string titre = nom + ":" + expy + "%" + expx;
821myImgApp->DispScDrawer( (PIDrawer*)pin, titre, opt);
822if (fgsr) myImgApp->RestoreGraphicAtt();
823return;
824}
825
826/* --Methode-- */
[331]827void NamedObjMgr::DisplayPoints3D(string& nom, string& expx, string& expy, string& expz,
[165]828 string& expcut, string dopt)
829{
[295]830NObjMgrAdapter* obja=NULL;
831obja = GetObjAdapter(nom);
832if (obja == NULL) {
[165]833 cout << "NamedObjMgr::DisplayPoints3D() Error , Pas d'objet de nom " << nom << endl;
834 return;
835 }
836if (!myImgApp) return;
837
[179]838char* ntn[3] = {"expx","expy","expz"};
[165]839NTuple* nt = new NTuple(3,ntn); // Creation NTuple
840
841string expwt = "1.";
[295]842servnobjm->Nobj_ComputeExpressions(obja, expx, expy, expz, expwt, expcut, nt, NULL, NULL);
[165]843
844if (nt->NEntry() < 1) {
845 cout << "NamedObjMgr::DisplayPoints3D() Warning Zero points satisfy cut !" << endl;
846 delete nt;
847 return;
848 }
849nt->Show();
850nt->Print(0,10);
851PINTuple3D* pin = new PINTuple3D(nt, true);
852pin->SelectXYZ(ntn[0], ntn[1], ntn[2]);
853bool fgsr = true;
[326]854dopt = "defline," + dopt;
[165]855int opt = servnobjm->DecodeDispOption(dopt, fgsr);
856
857// Pour plot a partir de DispScDrawer
858// string nomdisp = "_NT3D_";
859// myImgApp->DispScDrawer( (PIDrawer*)pin, nomdisp, opt);
860// Pour plot a partir de Disp3DDrawer
861string titre = nom + ":" + expy + "%" + expx;
862myImgApp->Disp3DDrawer(pin, titre, opt);
863
864if (fgsr) myImgApp->RestoreGraphicAtt();
865return;
866}
867
868/* --Methode-- */
[331]869void NamedObjMgr::ProjectH1(string& nom, string& expx, string& expwt, string& expcut, string& nomh1, string dopt)
[165]870{
[295]871NObjMgrAdapter* obja=NULL;
872obja = GetObjAdapter(nom);
873if (obja == NULL) {
[165]874 cout << "NamedObjMgr::ProjectH1() Error , Pas d'objet de nom " << nom << endl;
875 return;
876 }
877if (!myImgApp) return;
878
879Histo* h1 = NULL;
880NTuple* nt = NULL;
[295]881AnyDataObj* oh = NULL;
[165]882if (nomh1.length() > 0) oh=GetObj(nomh1);
883else nomh1 = "H1Proj";
[295]884if ( (oh != NULL) && (typeid(*oh) == typeid(Histo)) ) h1 = (Histo*)oh; // Pas de remise a zero ! h1->Zero();
[165]885else {
[179]886 char* ntn[2]= {"hxval", "hwt"};
[165]887 nt = new NTuple(2,ntn); // Creation NTuple
888 }
889string expz = "0.";
[295]890servnobjm->Nobj_ComputeExpressions(obja, expx, expwt, expz, expwt, expcut, nt, h1, NULL);
[165]891
892if ((!h1) && (!nt)) return;
893if (!h1) {
894 if (nt->NEntry() < 1) {
895 cout << "NamedObjMgr::ProjectH1() Warning Zero points satisfy cut !" << endl;
896 delete nt;
897 return;
898 }
[326]899 double xmin, xmax;
[165]900 nt->GetMinMax(0, xmin, xmax);
901 h1 = new Histo(xmin, xmax, 100);
902 int k;
903 float* xn;
904 for(k=0; k<nt->NEntry(); k++) {
905 xn = nt->GetVec(k);
906 h1->Add(xn[0], xn[1]);
907 }
908 delete nt;
909 AddObj(h1, nomh1);
910 }
911
912DisplayObj(nomh1, dopt);
913return;
914}
915
916/* --Methode-- */
[331]917void NamedObjMgr::ProjectH2(string& nom, string& expx, string& expy, string& expwt, string& expcut,
[165]918 string& nomh2, string dopt)
919{
[295]920NObjMgrAdapter* obja=NULL;
921obja = GetObjAdapter(nom);
922if (obja == NULL) {
[165]923 cout << "NamedObjMgr::ProjectH2() Error , Pas d'objet de nom " << nom << endl;
924 return;
925 }
926if (!myImgApp) return;
927
928Histo2D* h2 = NULL;
929NTuple* nt = NULL;
[295]930AnyDataObj* oh = NULL;
[165]931if (nomh2.length() > 0) oh=GetObj(nomh2);
932else nomh2 = "H2Proj";
[295]933if ( (oh != NULL) && (typeid(*oh) == typeid(Histo2D)) ) h2 = (Histo2D*)oh; // Pas de remise a zero ! h2->Zero();
[165]934else {
[179]935 char* ntn[3]= {"hxval", "hyval", "hwt"};
[165]936 nt = new NTuple(3,ntn); // Creation NTuple
937 }
938string expz = "0.";
[295]939servnobjm->Nobj_ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, nt, NULL, h2);
[165]940
941if ((!h2) && (!nt)) return;
942if (!h2) {
943 if (nt->NEntry() < 1) {
944 cout << "NamedObjMgr::ProjectH2() Warning Zero points satisfy cut !" << endl;
945 delete nt;
946 return;
947 }
[326]948 double xmin, xmax, ymin, ymax;
[165]949 nt->GetMinMax(0, xmin, xmax);
950 nt->GetMinMax(0, ymin, ymax);
951 h2 = new Histo2D(xmin, xmax, 50, ymin, ymax, 50);
952 int k;
953 float* xn;
954 for(k=0; k<nt->NEntry(); k++) {
955 xn = nt->GetVec(k);
956 h2->Add(xn[0], xn[1], xn[2]);
957 }
958 delete nt;
959 AddObj(h2, nomh2);
960 }
961
962DisplayObj(nomh2, dopt);
963return;
964
965}
966
967/* --Methode-- cmv 13/10/98 */
[331]968void NamedObjMgr::ProjectHProf(string& nom, string& expx, string& expy, string& expwt, string& expcut,
[165]969 string& nomprof, string dopt)
970// Pour remplir un ``GeneralFitData'' a partir de divers objets:
971//| nom = nom de l'objet a projeter dans un HProf.
972//| expx = expression X de definition du bin.
973//| expy = expression Y a additionner dans le bin.
974//| expwt = expression W du poids a additionner.
975//| expcut = expression du test de selection.
976//| nomprof = nom du HProf engendre (optionnel). Si l'objet n'existe pas
977//| les limites Xmin,Xmax sont calculees automatiquement.
978//| sinon ce sont celles de l'objet preexistant.
979//| opt = options generales pour le display.
980{
[295]981NObjMgrAdapter* obja=NULL;
982obja = GetObjAdapter(nom);
983if (obja == NULL) {
[165]984 cout << "NamedObjMgr::ProjectHProf() Error , Pas d'objet de nom " << nom << endl;
985 return;
986 }
987if (!myImgApp) return;
988
989HProf* hprof = NULL;
990NTuple* nt = NULL;
[295]991AnyDataObj* oh = NULL;
[165]992if (nomprof.length() > 0) oh=GetObj(nomprof);
993else nomprof = "ProfProj";
[295]994if( (oh!=NULL) && (typeid(*oh) == typeid(HProf)) ) hprof = (HProf*)oh;
[165]995else {
[179]996 char* ntn[3]= {"hxval", "hyval", "hwt"};
[165]997 nt = new NTuple(3,ntn); // Creation NTuple
998}
999string expz = "0.";
[295]1000servnobjm->Nobj_ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, nt, NULL, NULL, hprof);
[165]1001
1002if((!hprof) && (!nt)) return;
1003if(!hprof) {
1004 if (nt->NEntry() < 1) {
1005 cout << "NamedObjMgr::ProjectHProf() Warning Zero points satisfy cut !" << endl;
1006 delete nt;
1007 return;
1008 }
[326]1009 double xmin, xmax;
[165]1010 nt->GetMinMax(0, xmin, xmax);
1011 hprof = new HProf(xmin, xmax, 100);
1012 int k;
1013 float* xn;
1014 for(k=0; k<nt->NEntry(); k++) {
1015 xn = nt->GetVec(k);
1016 hprof->Add(xn[0], xn[1], xn[2]);
1017 }
1018 delete nt;
1019 AddObj(hprof, nomprof);
1020 }
1021hprof->UpdateHisto();
1022
1023DisplayObj(nomprof, dopt);
1024return;
1025}
1026
1027/* --Methode-- */
[331]1028void NamedObjMgr::FillVect(string& nom, string& expx, string& expcut, string& nomvec, string dopt)
[165]1029{
[295]1030NObjMgrAdapter* obja=NULL;
1031obja = GetObjAdapter(nom);
1032if (obja == NULL) {
[165]1033 cout << "NamedObjMgr::FillVect() Error , Pas d'objet de nom " << nom << endl;
1034 return;
1035 }
1036if (!myImgApp) return;
1037
1038NTuple* nt = NULL;
1039if (nomvec.length() < 1) nomvec = "VecFill";
1040
[179]1041char* ntn[2]= {"vecval", "vecwt"};
[165]1042nt = new NTuple(1,ntn); // Creation NTuple
1043
1044string expwt = "1.";
1045string expz = "0.";
[295]1046servnobjm->Nobj_ComputeExpressions(obja, expx, expz, expz, expwt, expcut, nt, NULL, NULL);
[165]1047
1048if (!nt) return;
1049if (nt->NEntry() < 1) {
1050 cout << "NamedObjMgr::FillVect() Warning Zero points satisfy cut !" << endl;
1051 delete nt;
1052 return;
1053 }
1054
1055Vector* vec = new Vector(nt->NEntry());
1056int k;
1057float* xn;
1058for(k=0; k<nt->NEntry(); k++) {
1059 xn = nt->GetVec(k);
1060 (*vec)(k) = xn[0];
1061 }
1062delete nt;
1063AddObj(vec, nomvec);
1064DisplayObj(nomvec, dopt);
1065return;
1066}
1067
1068/* --Methode-- */
[331]1069void NamedObjMgr::FillNT(string& nom, string& expx, string& expy, string& expz, string& expt,
[165]1070 string& expcut, string& nomnt)
1071{
[295]1072NObjMgrAdapter* obja=NULL;
1073obja = GetObjAdapter(nom);
1074if (obja == NULL) {
[165]1075 cout << "NamedObjMgr::FillNT() Error , Pas d'objet de nom " << nom << endl;
1076 return;
1077 }
1078if (!myImgApp) return;
1079
1080bool fgnnt = false;
1081NTuple* nt = NULL;
[295]1082AnyDataObj* oh = NULL;
[165]1083if (nomnt.length() > 0) oh=GetObj(nomnt);
1084else nomnt = "NTFill";
[295]1085if ( (oh != NULL) && (typeid(*oh) == typeid(HProf)) ) {
[165]1086 nt = (NTuple*)oh;
1087 if (nt->NVar() > 10) {
1088 cout << "NamedObjMgr::FillNT() Warning , Max 10 var ds NTuple -> new NTuple" << endl;
1089 nt = NULL;
1090 }
1091 }
1092if (nt == NULL) {
[179]1093 char* ntn[4]= {"x", "y","z","t"};
[165]1094 nt = new NTuple(4,ntn); // Creation NTuple
1095 fgnnt = true;
1096 }
1097
[295]1098servnobjm->Nobj_ComputeExpressions(obja, expx, expy, expz, expt, expcut, nt, NULL, NULL);
[165]1099
1100if (fgnnt) AddObj(nt, nomnt);
1101return;
1102
1103}
1104
1105/* --Methode-- cmv 13/10/98 */
[331]1106void NamedObjMgr::FillGFD(string& nom, string& expx, string& expy, string& expz,
[165]1107 string& experr, string& expcut, string& nomgfd)
1108// Pour remplir un ``GeneralFitData'' a partir de divers objets:
1109//| nom = nom de l'objet a transcrire selon 1D: Z=f(X) ou 2D: Z=f(X,Y) .
1110//| Vector,Matrix,Histo,HProf,Histo2D,Image<T>,StarList,NTuple,GeneralFitData
1111//| expx = expression X du GeneralFitData (1er abscisse)
1112//| expy = expression Y du GeneralFitData (2sd abscisse si non "", Z=f(X,Y))
1113//| expz = expression Z du GeneralFitData (valeur de l'ordonnee)
1114//| experr = expression de l'erreur sur l'ordonnee Z
1115//| expcut = expression du test de selection
1116//| nomgfd = nom du GeneralFitData engendre (optionnel)
1117{
[295]1118NObjMgrAdapter* obja=NULL;
1119obja = GetObjAdapter(nom);
1120if (obja == NULL) {
1121 cout << "NamedObjMgr::FillGFD() Error , Pas d'objet de nom "<<nom<<endl;
1122 return;
1123 }
[165]1124if(!myImgApp) return;
1125
1126// 2D ou 3D?
1127int nvar = 2;
1128if(expy.length()<=0) {nvar = 1; expy = "0.";}
1129
[295]1130// $CHECK$ - cmv calculait le nombre d'entree ndata
1131// en fonction de chaque objet - Je l'ai vire Reza 11/05/99
[165]1132
1133// Creation NTuple Buffer
[179]1134char* ntn[4]= {"x","y","f","e"};
[165]1135NTuple*nt = new NTuple(4,ntn);
1136
1137// Remplissage NTuple buffer
[295]1138servnobjm->Nobj_ComputeExpressions(obja, expx, expy, expz, experr, expcut, nt, NULL, NULL);
[165]1139if(nt->NEntry() < 1)
1140 {cout<<"NamedObjMgr::FillGFD() Warning Zero points satisfy cut !"<<endl;
1141 delete nt; return;}
1142
1143//Remplissage de la structure GeneraFitData
[295]1144if (nt->NEntry() <= 0) {
1145 cout<<"NamedObjMgr::FillGFD() Warning - NData= " << nt->NEntry() << endl;
1146 delete nt;
1147 return;
1148 }
1149
1150GeneralFitData* gfd = new GeneralFitData(nvar,nt->NEntry(),0);
[165]1151int k;
1152float* xn;
1153for(k=0; k<nt->NEntry(); k++) {
1154 xn = nt->GetVec(k);
1155 gfd->AddData(xn,xn[2],xn[3]);
1156}
1157
1158// Menage et table d'objets
1159delete nt;
1160AddObj(gfd, nomgfd);
1161return;
1162}
1163
1164
1165///////////////////// Fit 1D et 2D //////////////////////////
1166/* --Function static propre aux routines de fit 1D et 2D-- cmv 13/10/98 */
1167struct DFOptions {
1168 int okres, okfun;
1169 int polcx,polcy; double xc,yc;
1170 double err_e, err_E;
1171 double stc2;
1172 int lp,lpg;
1173 int i1,i2,j1,j2;
1174};
1175typedef struct DFOptions DFOPTIONS;
1176static void DecodeFitsOptions(string par,string step,string min,string max,string opt
1177 ,Vector& Par,Vector& Step,Vector& Min,Vector& Max,DFOPTIONS& O);
1178void DecodeFitsOptions(string par,string step,string min,string max,string opt
1179 ,Vector& Par,Vector& Step,Vector& Min,Vector& Max,DFOPTIONS& O)
1180//| Pour decoder les "string" et remplir les vecteurs du fit (cf commentaires dans Fit1D)
1181{
1182// set des vecteurs et decodage des string correspondantes
1183int NParMax = 100;
1184Par.Realloc(NParMax); Step.Realloc(NParMax);
1185Min.Realloc(NParMax); Max.Realloc(NParMax);
1186{
1187 Vector* v; string* s;
1188 {for(int i=0;i<NParMax;i++) {Par(i)=0.; Step(i)=1.; Min(i)=1.; Max(i)=-1.;}}
1189 for(int j=0;j<4;j++) {
1190 if(j==0) {v=&Par; s=&par;}
1191 else if(j==1) {v=&Step; s=&step;}
1192 else if(j==2) {v=&Min; s=&min;}
1193 else if(j==3) {v=&Max; s=&max;}
1194 if(s->length()>0) *s += ",";
1195 for(int i=0;i<NParMax;i++) {
1196 if(s->length()<=0) break;
1197 sscanf(s->c_str(),"%lf",&(*v)(i));
1198 size_t p = s->find_first_of(',') + 1;
1199 if(p>=s->length()) *s = ""; else *s = s->substr(p);
1200 }
1201 }
1202}
1203
1204// Decodage de options de opt
1205O.okres = O.okfun = 0;
1206O.polcx = O.polcy = 0;
1207O.xc = O.yc = 0.;
1208O.stc2 = 1.e-3;
1209O.err_e = O.err_E = -1.;
1210O.lp = 1; O.lpg = 0;
1211O.i1 = O.j1 = O.i2 = O.j2 = -1;
1212
1213if(opt.length()<=0) return;
1214opt = "," + opt + ",";
1215
1216if(strstr(opt.c_str(),",r,")) O.okres = 1; // residus
1217if(strstr(opt.c_str(),",f,")) O.okfun = 1; // fonction fittee
1218if(strstr(opt.c_str(),",x")) { // Demande de centrage (fit X=x-xc)
1219 O.polcx = 2; // Le centrage est calcule automatiquement
1220 size_t p = opt.find(",x");
1221 size_t q = opt.find_first_of(',',p+1);
1222 string dum = opt.substr(p,q-p);
1223 if(dum.length()>2) {
1224 sscanf(dum.c_str(),",x%lf",&O.xc);
1225 O.polcx = 1; // Le centrage est fixe par la valeur lue
1226 }
1227}
1228if(strstr(opt.c_str(),",y")) { // Demande de centrage (fit Y=y-yc)
1229 O.polcy = 2; // Le centrage est calcule automatiquement
1230 size_t p = opt.find(",y");
1231 size_t q = opt.find_first_of(',',p+1);
1232 string dum = opt.substr(p,q-p);
1233 if(dum.length()>2) {
1234 sscanf(dum.c_str(),",y%lf",&O.yc);
1235 O.polcy = 1; // Le centrage est fixe par la valeur lue
1236 }
1237}
1238if(strstr(opt.c_str(),",E")) { // Erreurs imposees a "sqrt(val)" ou "aa.b*sqrt(val)"
1239 size_t p = opt.find(",E");
1240 size_t q = opt.find_first_of(',',p+1);
1241 string dum = opt.substr(p,q-p);
1242 if(dum.length()>2) sscanf(dum.c_str(),",E%lf",&O.err_E);
1243 if(O.err_E<=0.) O.err_E = 1.;
1244 O.err_e=-1.;
1245}
1246if(strstr(opt.c_str(),",e")) { // Erreurs imposees a "1" ou "aa.b"
1247 size_t p = opt.find(",e");
1248 size_t q = opt.find_first_of(',',p+1);
1249 string dum = opt.substr(p,q-p);
1250 if(dum.length()>2) sscanf(dum.c_str(),",e%lf",&O.err_e);
1251 if(O.err_e<=0.) O.err_e = 1.;
1252 O.err_E=-1.;
1253}
1254if(strstr(opt.c_str(),",X")) { // Valeur du StopChi2
1255 size_t p = opt.find(",X");
1256 size_t q = opt.find_first_of(',',p+1);
1257 string dum = opt.substr(p,q-p);
1258 if(dum.length()>2) sscanf(dum.c_str(),",X%lf",&O.stc2);
1259 if(O.stc2<=0.) O.stc2 = 1.e-3;
1260}
1261if(strstr(opt.c_str(),",l")) { // niveau de print
1262 size_t p = opt.find(",l");
1263 size_t q = opt.find_first_of(',',p+1);
1264 string dum = opt.substr(p,q-p);
1265 float ab;
1266 if(dum.length()>2) sscanf(dum.c_str(),",l%f",&ab);
1267 if(ab<0) ab = 0.;
1268 O.lp = (int) ab; O.lpg = (int) 10.*(ab-O.lp);
1269}
1270if(strstr(opt.c_str(),",I")) { // intervalle de fit selon X
1271 size_t p = opt.find(",I");
1272 size_t q = opt.find_first_of(',',p+1);
1273 string dum = opt.substr(p,q-p);
1274 if(dum.length()>2) sscanf(dum.c_str(),",I%d/%d",&O.i1,&O.i2);
1275}
1276if(strstr(opt.c_str(),",J")) { // intervalle de fit selon Y
1277 size_t p = opt.find(",J");
1278 size_t q = opt.find_first_of(',',p+1);
1279 string dum = opt.substr(p,q-p);
1280 if(dum.length()>2) sscanf(dum.c_str(),",J%d/%d",&O.j1,&O.j2);
1281}
1282return;
1283}
1284
1285/* --Methode-- cmv 13/10/98 */
[331]1286void NamedObjMgr:: Fit12D(string& nom, string& func,
[165]1287 string par,string step,string min,string max,
1288 string opt)
1289//| --------------- Fit d'objets a 1 et 2 dimensions ---------------
1290//| nom : nom de l'objet qui peut etre:
1291//| fit-1D: Vector,Histo1D,HProf ou GeneraFitData(1D)
1292//| fit-2D: Matrix,Histo2D,Imagexx ou GeneraFitData(2D)
1293//| func : pnn = fit polynome degre nn avec classe Poly (lineaire) 1D ou 2D
1294//| : Pnn = fit polynome degre nn avec GeneralFit (non-lineaire) 1D ou 2D
1295//| : gnn = fit gaussienne (hauteur) + polynome de degre nn 1D
1296//| : g = fit gaussienne (hauteur) 1D
1297//| : enn = fit exponentielle + polynome de degre nn 1D
1298//| : e = fit exponentielle 1D
1299//| : Gnn = fit gaussienne (volume) + polynome de degre nn 1D
1300//| : G = fit gaussienne (volume) 1D
1301//| : = fit gaussienne+fond (volume) 2D
1302//| : Gi = fit gaussienne+fond integree (volume) 2D
1303//| : d = fit DL de gaussienne+fond (volume) 2D
1304//| : di = fit DL de gaussienne+fond integree (volume) 2D
1305//| : D = fit DL de gaussienne+fond avec coeff variable p6 (volume) 2D
1306//| : Di = fit DL de gaussienne+fond integree avec coeff variable p6 (volume) 2D
1307//| : M = fit Moffat+fond (expos=p6) (volume) 2D
1308//| : Mi = fit Moffat+fond integree (expos=p6) (volume) 2D
1309//| par : p1,...,pn valeur d'initialisation des parametres (def=0)
1310//| step : s1,...,sn valeur des steps de depart (def=1)
1311//| min : m1,...,mn valeur des minima (def=1)
1312//| max : M1,...,Mn valeur des maxima (def=-1) (max<=min : pas de limite)
1313//| opt : options "Eaa.b,eaa.b,f,r,caa.b,Xaa.b"
1314//| f = generation d'un Objet identique contenant la fonction fittee
1315//| r = generation d'un Objet identique contenant les residus
1316//| Xaa.b = aa.b valeur du DXi2 d'arret (def=1.e-3)
1317//| la.b = niveau "a.b" de print: a=niveau de print Fit1/2D
1318//| b=niveau de debug GeneralFit
1319//| Ii1/i2 numeros des bins X de l'histos utilises pour le fit [i1,i2]
1320//|2D Jj1/j2 numeros des bins Y de l'histos utilises pour le fit [j1,j2]
1321//| - L'erreur est celle associee a l'objet si existe, 1 sinon sauf si
1322//| E = erreur prise comme la racine de la valeur a fitter
1323//| Eaa.b = erreur prise aa.b*sqrt(val)
1324//| e = erreur prise egale a 1 pour toutes les valeurs
1325//| eaa.b = erreur prise egale a aa.b
1326//| xaa.b = demande de centrage: on fit x-aa.b au lieu de x)
1327//| x = demande de centrage: on fit x-xc au lieu de x
1328//| avec xc=abscisse du milieu de l'histogramme
1329//| Actif pour: exp+poly 1D, poly 1D
1330//| gauss+poly 1D (mais xc est le centre de la gaussienne)
1331//|2D yaa.b et y = idem "xaa.b et x" mais pour y
1332{
[295]1333AnyDataObj* obj=GetObj(nom);
[165]1334if (obj == NULL) {
1335 cout<<"NamedObjMgr::Fit12D() Error , Pas d'objet de nom "<<nom<<endl;
1336 return;
1337}
1338if (!myImgApp) return;
1339if(func.length()<=0)
1340 {cout<<"NamedObjMgr::Fit12D() Donnez un nom de fonction a fitter."<<endl;
1341 return;}
[295]1342string ctyp = typeid(*obj).name();
[165]1343
1344int ndim = 0, nbinx=0, nbiny=0, ndata = 0;
1345Vector* v = NULL; Histo* h = NULL;
1346Matrix* m = NULL; Histo2D* h2 = NULL; RzImage* im = NULL;
1347GeneralFitData* g = NULL;
[295]1348
[165]1349 // 1D
[295]1350if (typeid(*obj) == typeid(Vector)) {
1351 ndim = 1;
1352 v = (Vector*) obj; nbinx = v->NElts(); nbiny = 1;
1353 }
1354else if ( (typeid(*obj) == typeid(HProf)) || (typeid(*obj) == typeid(Histo)) ) {
1355 ndim = 1;
1356 h = (Histo*) obj; nbinx = h->NBins(); nbiny = 1;
1357 }
1358else if (typeid(*obj) == typeid(Matrix)) {
1359 ndim = 2;
1360 m = (Matrix*) obj; nbinx = m->NCol(); nbiny = m->NRows();
1361 }
1362else if (typeid(*obj) == typeid(Histo2D)) {
1363 ndim = 2;
1364 h2 = (Histo2D*) obj; nbinx = h2->NBinX(); nbiny = h2->NBinY();
1365 }
1366else if (typeid(*obj) == typeid(GeneralFitData)) {
1367 g = (GeneralFitData*) obj; nbinx = g->NData(); nbiny = 1;
1368 if( g->NVar()==1) ndim = 1;
1369 else if(g->NVar()==2) ndim = 2;
1370 else {
1371 cout<<"GeneralFitData ne peut avoir que 1 ou 2 variables d'abscisse: "
1372 <<((GeneralFitData*) obj)->NVar()<<endl; return; }
1373 }
1374else if (dynamic_cast<RzImage*>(obj)) {
1375 ndim = 2;
1376 im = (RzImage*) obj; nbinx = im->XSize(); nbiny = im->YSize();
1377 }
1378else {
1379 cout<<"NamedObjMgr::Fit12D() Error , Objet n'est pas un "
1380 <<"Histo1D/HProf/Vector/Histo2D/Image/Matrix/GeneralFitData "<<ctyp<<endl;
1381 return;
1382 }
1383
[165]1384ndata = nbinx*nbiny;
1385if(ndata<=0)
1386 {cout<<"L'objet a "<<nbinx<<","<<nbiny<<" bins ("<<ndata<<")"<<endl; return;}
1387
1388// Decodage des options et des parametres, mise en forme
1389Vector Par(1); Vector Step(1); Vector Min(1); Vector Max(1); DFOPTIONS O;
1390DecodeFitsOptions(par,step,min,max,opt,Par,Step,Min,Max,O);
1391O.i1 = (O.i1<0||O.i1>=nbinx)? 0: O.i1;
1392O.i2 = (O.i2<0||O.i2>=nbinx||O.i2<O.i1)? nbinx-1: O.i2;
1393if(ndim>=2) {
1394 O.j1 = (O.j1<0||O.j1>=nbiny)? 0: O.j1;
1395 O.j2 = (O.j2<0||O.j2>=nbiny||O.j2<O.j1)? nbiny-1: O.j2;
1396} else O.j2 = O.j1 = 0;
1397if(O.polcx==2) {
1398 if(v||m) O.xc = (O.i2-O.i1+1)/2.;
1399 else if(h) O.xc = (h->XMin()+h->XMax())/2.;
1400 else if(h2) O.xc = (h2->XMin()+h2->XMax())/2.;
1401 else if(g) {double mini,maxi; g->GetMinMax(2,mini,maxi); O.xc=(mini+maxi)/2.;}
1402 else if(im) {O.xc = im->XOrg() * im->XPxSize()*(O.i2-O.i1+1)/2.;}
1403}
1404if(O.polcy==2 && ndim>=2) {
1405 if(m) O.yc = (O.j2-O.j1+1)/2.;
1406 if(h2) O.yc = (h2->YMin()+h2->YMax())/2.;
1407 if(g) {double mini,maxi; g->GetMinMax(12,mini,maxi); O.yc=(mini+maxi)/2.;}
1408 if(im) {O.yc = im->YOrg() * im->YPxSize()*(O.j2-O.j1+1)/2.;}
1409}
1410if(O.lp>0)
1411 cout<<"Fit["<<nbinx<<","<<nbiny<<"] ("<<ndata<<") dim="<<ndim<<":"
1412 <<" Int=["<<O.i1<<","<<O.i2<<"],["<<O.j1<<","<<O.j2<<"]"<<endl
1413 <<" Cent="<<O.polcx<<","<<O.polcy<<","<<O.xc<<"+x"<<","<<O.yc<<"+y"
1414 <<" TypE="<<O.err_e<<","<<O.err_E
1415 <<" StpX2="<<O.stc2
1416 <<" lp,lpg="<<O.lp<<","<<O.lpg<<endl;
1417
1418///////////////////////////////////
1419// Remplissage de GeneralFitData //
1420///////////////////////////////////
1421GeneralFitData mydata(ndim,ndata,0);
1422{for(int i=O.i1;i<=O.i2;i++) for(int j=O.j1;j<=O.j2;j++) {
1423 double x,y,f,e;
1424
1425 if(v)
1426 {x= (double) i; f=(*v)(i); e=1.;}
1427 else if(h)
1428 {x=h->BinCenter(i); f=(*h)(i); e=(h->HasErrors())?h->Error(i):1.;}
1429 else if(m)
1430 {x=(double) i; y=(double) j; f=(*m)(j,i); e=1.;}
1431 else if(h2)
1432 {float xf,yf; h2->BinCenter(i,j,xf,yf); x=(double)xf; y=(double)yf;
1433 f=(*h2)(i,j); e=(h2->HasErrors())?h2->Error(i,j):1.;}
1434 else if(im)
1435 {x=im->XOrg()+(i+0.5)*im->XPxSize(); y=im->YOrg()+(j+0.5)*im->YPxSize();
1436 f=im->DValue(i,j); e=1.;}
1437 else if(g&&ndim==1) {x= g->X(i); f=g->Val(i); e=g->EVal(i);}
1438 else if(g&&ndim==2) {x= g->X(i); y= g->Y(i); f=g->Val(i); e=g->EVal(i);}
1439 else x=y=f=e=0.;
1440
1441 // Gestion des erreurs a utiliser
1442 if(O.err_e>0.) e=O.err_e;
1443 else if(O.err_E>0.) {e=(y<-1.||y>1.)?O.err_E*sqrt(fabs(y)):O.err_E;}
1444
1445 // Remplissage de generalfit
1446 if(func[0]=='p') {x -= O.xc; if(ndim>=2) y -= O.yc;}
1447 if(ndim==1) mydata.AddData1(x,f,e);
1448 else if(ndim==2) mydata.AddData2(x,y,f,e);
1449}}
1450if(mydata.NData()<=0)
1451 {cout<<"Pas de donnees dans GeneralFitData: "<<mydata.NData()<<endl;
1452 return;}
1453if(O.lpg>1) {
1454 mydata.PrintStatus();
1455 mydata.PrintData(0);
1456 mydata.PrintData(mydata.NData()-1);
1457}
1458
1459////////////////////////////////////////////
1460// Identification de la fonction a fitter //
1461////////////////////////////////////////////
1462GeneralFunction* myfunc = NULL;
1463if(func[0]=='p' && ndim==1) {
1464 // Fit de polynome sans passer par les GeneralFit
1465 int degre = 0;
1466 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1467 cout<<"Fit (lineaire) 1D polynome de degre "<<degre<<endl;
1468 Poly p1(0);
1469 double c2rl = mydata.PolFit(0,p1,degre);
1470 cout<<"C2r_lineaire = "<<c2rl<<endl;
1471 if(O.lp>0) cout<<p1<<endl;
1472 return;
1473
1474} else if(func[0]=='P' && ndim==1) {
1475 // Fit de polynome
1476 int degre = 0;
1477 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1478 cout<<"Fit polynome 1D de degre "<<degre<<endl;
1479 Polyn1D* myf = new Polyn1D(degre,O.xc);
1480 myfunc = myf;
1481
1482} else if(func[0]=='e' && ndim==1) {
1483 // Fit d'exponentielle
1484 int degre =-1;
1485 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1486 cout<<"Fit d'exponentielle+polynome 1D de degre "<<degre<<endl;
1487 Exp1DPol* myf;
1488 if(degre>=0) myf = new Exp1DPol((unsigned int)degre,O.xc);
1489 else myf = new Exp1DPol(O.xc);
1490 myfunc = myf;
1491
1492} else if(func[0]=='g' && ndim==1) {
1493 // Fit de gaussienne en hauteur
1494 int degre =-1;
1495 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1496 cout<<"Fit de Gaussienne_en_hauteur+polynome 1D de degre "<<degre<<endl;
1497 Gauss1DPol* myf;
1498 if(degre>=0) myf = new Gauss1DPol((unsigned int)degre,((O.polcx)?true:false));
[179]1499 else { bool bfg = (O.polcx)?true:false; myf = new Gauss1DPol(bfg); }
[165]1500 myfunc = myf;
1501
1502} else if(func[0]=='G' && ndim==1) {
1503 // Fit de gaussienne en volume
1504 int degre =-1;
1505 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1506 cout<<"Fit de Gaussienne_en_volume+polynome 1D de degre "<<degre<<endl;
1507 GaussN1DPol* myf;
1508 if(degre>=0) myf = new GaussN1DPol((unsigned int)degre,((O.polcx)?true:false));
[179]1509 else { bool bfg = (O.polcx)?true:false; myf = new GaussN1DPol(bfg); }
[165]1510 myfunc = myf;
1511
1512} else if(func[0]=='p' && ndim==2) {
1513 // Fit de polynome 2D sans passer par les GeneralFit
1514 int degre = 0;
1515 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1516 cout<<"Fit (lineaire) polynome 2D de degre "<<degre<<endl;
1517 Poly2 p2(0);
1518 double c2rl = mydata.PolFit(0,1,p2,degre);
1519 cout<<"C2r_lineaire = "<<c2rl<<endl;
1520 if(O.lp>0) cout<<p2<<endl;
1521 return;
1522
1523} else if(func[0]=='P' && ndim==2) {
1524 // Fit de polynome 2D
1525 int degre = 0;
1526 if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
1527 cout<<"Fit polynome 2D de degre "<<degre<<endl;
1528 Polyn2D* myf = new Polyn2D(degre,O.xc,O.yc);
1529 myfunc = myf;
1530
1531} else if(func[0]=='G' && ndim==2) {
1532 // Fit de gaussienne+fond en volume
1533 int integ = 0;
1534 if(func.length()>1) if(func[1]=='i') integ=1;
1535 cout<<"Fit de Gaussienne+Fond 2D integ="<<integ<<endl;
1536 if(integ) {GauRhInt2D* myf = new GauRhInt2D; myfunc = myf;}
1537 else {GauRho2D* myf = new GauRho2D; myfunc = myf;}
1538
1539} else if(func[0]=='d' && ndim==2) {
1540 // Fit de DL gaussienne+fond en volume
1541 int integ = 0;
1542 if(func.length()>1) if(func[1]=='i') integ=1;
1543 cout<<"Fit de DL de Gaussienne+Fond 2D integ="<<integ<<endl;
1544 if(integ) {GdlRhInt2D* myf = new GdlRhInt2D; myfunc = myf;}
1545 else {GdlRho2D* myf = new GdlRho2D; myfunc = myf;}
1546
1547} else if(func[0]=='D' && ndim==2) {
1548 // Fit de DL gaussienne+fond avec coeff variable p6 en volume
1549 int integ = 0;
1550 if(func.length()>1) if(func[1]=='i') integ=1;
1551 cout<<"Fit de DL de Gaussienne+Fond avec coeff variable (p6) 2D integ="<<integ<<endl;
1552 if(integ) {Gdl1RhInt2D* myf = new Gdl1RhInt2D; myfunc = myf;}
1553 else {Gdl1Rho2D* myf = new Gdl1Rho2D; myfunc = myf;}
1554
1555} else if(func[0]=='M' && ndim==2) {
1556 // Fit de Moffat+fond (volume)
1557 int integ = 0;
1558 if(func.length()>1) if(func[1]=='i') integ=1;
1559 cout<<"Fit de Moffat+Fond (expos=p6) 2D integ="<<integ<<endl;
1560 if(integ) {MofRhInt2D* myf = new MofRhInt2D; myfunc = myf;}
1561 else {MofRho2D* myf = new MofRho2D; myfunc = myf;}
1562
1563} else {
1564 cout<<"Fonction "<<func<<" inconnue pour la dim "<<ndim<<endl;
1565 return;
1566}
1567
1568/////////////////////////
1569// Fit avec generalfit //
1570/////////////////////////
1571if(myfunc->NPar()>Par.NElts())
1572 {cout<<"Trop de parametres: "<<myfunc->NPar()<<">"<<Par.NElts()<<endl;
1573 if(myfunc) delete myfunc; return;}
1574GeneralFit myfit(myfunc);
1575myfit.SetDebug(O.lpg);
1576myfit.SetData(&mydata);
1577myfit.SetStopChi2(O.stc2);
1578{for(int i=0;i<myfunc->NPar();i++) {
1579 char str[10];
1580 sprintf(str,"P%d",i);
1581 myfit.SetParam(i,str,Par(i),Step(i),Min(i),Max(i));
1582}}
1583if(O.lp>1) myfit.PrintFit();
1584double c2r = (double) myfit.Fit();
1585if(O.lp>0) myfit.PrintFit();
1586if(c2r>0.) {
1587 c2r = myfit.GetChi2Red();
1588 cout<<"C2r_Reduit = "<<c2r<<" nstep="<<myfit.GetNStep()<<endl;
1589 Vector ParFit(myfunc->NPar());
1590 for(int i=0;i<myfunc->NPar();i++) ParFit(i)=myfit.GetParm(i);
1591} else {
1592 cout<<"echec Fit, rc = "<<c2r<<" nstep="<<myfit.GetNStep()<<endl;
1593}
1594
1595// Mise a disposition des resultats
1596if(c2r>=0. && myfunc && (O.okres>0||O.okfun>0)) {
1597 string nomres = nom + "res";
1598 string nomfun = nom + "fun";
1599 if(v) {
1600 if(O.okres) {Vector* ob = v->FitResidus(myfit); if(ob) AddObj(ob,nomres);}
1601 if(O.okfun) {Vector* ob = v->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
1602 } else if(h) {
1603 if(O.okres) {Histo* ob = h->FitResidus(myfit); if(ob) AddObj(ob,nomres);}
1604 if(O.okfun) {Histo* ob = h->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
1605 } else if(m) {
1606 if(O.okres) {Matrix* ob = m->FitResidus(myfit); if(ob) AddObj(ob,nomres);}
1607 if(O.okfun) {Matrix* ob = m->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
1608 } else if(h2) {
1609 if(O.okres) {Histo2D* ob = h2->FitResidus(myfit); if(ob) AddObj(ob,nomres);}
1610 if(O.okfun) {Histo2D* ob = h2->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
1611 } else if(im) {
1612 if(O.okres) {RzImage* ob = im->FitResidus(myfit); if(ob) AddObj(ob,nomres);}
1613 if(O.okfun) {RzImage* ob = im->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
1614 } else if(g) {
1615 if(O.okres) {GeneralFitData* ob = g->FitResidus(myfit); if(ob) AddObj(ob,nomres);}
1616 if(O.okfun) {GeneralFitData* ob = g->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
1617 }
1618}
1619
1620// Nettoyage
1621if(myfunc) delete myfunc;
1622return;
1623}
1624
Note: See TracBrowser for help on using the repository browser.