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