Changeset 333 in Sophya for trunk/SophyaPI/PIext/nobjmgr.cc


Ignore:
Timestamp:
Jul 12, 1999, 1:12:29 PM (26 years ago)
Author:
ercodmgr
Message:

Trace de NTuple en 2D avec Marker de taille proportionnelle a Weight
Introduction des repertoires dans la gestion d'objets NameObjMgr
Reorganisation NamedObjMgr et Services2NObjMgr, ajout de commandes , ...
Reza 12/7/99

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/nobjmgr.cc

    r332 r333  
    2222#include "pistdimgapp.h"
    2323
    24 #include "matrix.h"
    25 #include "cvector.h"
    26 #include "ntuple.h"
    2724
    2825// EVOL-PLANCK
     
    3128#endif
    3229
    33 #include "fct1dfit.h"
    34 #include "fct2dfit.h"
    35 
    3630#include "pisurfdr.h"
    3731#include "pipodrw.h"
    38 #include "pihisto.h"
    39 #include "hisprof.h"
    40 #include "pihisto2d.h"
     32
    4133#include "pintuple.h"
    4234#include "pintup3d.h"
     
    7567  AnyDataObj* obj;
    7668  NObjMgrAdapter* obja;
    77   int num;
     69  int oid;
    7870  int dirid;
    7971  list<int> wrsid;
     
    9587
    9688static string* TmpDir;  // Repertoire pour les compilations / link dynamique
     89
     90// Pour completer le nom de l'objet avec le nom du repertoire
     91static void RemoveSpacesFromName(string & nom);
     92static bool CheckDirName(string & nom);
     93static int  ParseObjectName(string & nom, string & nomrep, string & nomobj);
     94// ..................................................................
    9795
    9896//++
     
    111109{
    112110if (fgOInit == 0) {
     111  myNObj = 0;
     112  myDirId = 0;
    113113  myDirs = new NObjDirList;
    114114  myObjs = new NObjList; 
    115115  currDir = new string("home");
     116  string dirn = "home";
     117  CreateDir(dirn);
     118  dirn = "tmp";
     119  CreateDir(dirn);
     120  dirn = "old";
     121  CreateDir(dirn);
     122  dirn = "home";
     123  SetCurrentDir(dirn);
     124  myDirId = 50;
    116125  char* varenv;
    117126  TmpDir = new string("");
     
    120129  int l = (*TmpDir).length();
    121130  if ( (l>0) && ((*TmpDir)[l-1] != '/') )  (*TmpDir) += '/';
    122   servnobjm = new Services2NObjMgr(NULL, (*TmpDir));
     131  servnobjm = new Services2NObjMgr(this, (*TmpDir));
    123132  }
    124133fgOInit++;
     
    148157myImgApp = app;
    149158servnobjm->SetImgApp(app);
     159
     160NObjDirList::iterator it;
     161string cn;
     162for(it= myDirs->begin(); it != myDirs->end(); it++) {
     163  cn = '/' + (*it).first;
     164  (myImgApp->ObjMgrW())->AddDirectory(cn.c_str(), (*it).second.id);
     165  }
    150166}
    151167
     
    163179
    164180/* --Methode-- */
    165 void NamedObjMgr::CreateDir(string const& dirname)
    166 {
    167 }
    168 
    169 /* --Methode-- */
    170 void NamedObjMgr::DeleteDir(string const& dirname)
    171 {
    172 }
    173 
    174 /* --Methode-- */
    175 void NamedObjMgr::SetCurrentDir(string const& dirname)
    176 {
     181void NamedObjMgr::CreateDir(string & dirname)
     182{
     183if ( !CheckDirName(dirname) ) {
     184  cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Invalid name !" << endl;
     185  return;
     186  }
     187NObjDirList::iterator it = myDirs->find(dirname);
     188if (it != myDirs->end()) {
     189  cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Existing directory !" << endl;
     190  return;
     191  }
     192myDirId++;
     193nobj_diritem di;
     194di.id = myDirId;
     195di.nobj = 0;
     196(*myDirs)[dirname] = di;
     197if (myImgApp)  {
     198  string str = '/' + dirname;
     199  (myImgApp->ObjMgrW())->AddDirectory(str.c_str(), myDirId);
     200  }
     201cout << "NamedObjMgr::CreateDir() " << dirname << " Created " << endl;
     202}
     203
     204/* --Methode-- */
     205void NamedObjMgr::DeleteDir(string & dirname)
     206{
     207if ( !CheckDirName(dirname) ) {
     208  cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - Invalid name !" << endl;
     209  return;
     210  }
     211NObjDirList::iterator it = myDirs->find(dirname);
     212if (it == myDirs->end()) {
     213  cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - No such directory !" << endl;
     214  return;
     215  }
     216if ((*it).second.nobj > 0) {
     217  cout << "NamedObjMgr::DeleteDir() " << dirname << " not empty ! " << endl;
     218  return;
     219  }
     220if ((*it).second.id < 50) {
     221  cout << "NamedObjMgr::DeleteDir() " << dirname << " cannot be deleted ! " << endl;
     222  return;
     223  }
     224
     225if (myImgApp) 
     226  (myImgApp->ObjMgrW())->DelDirectory((*it).second.id);
     227myDirs->erase(it);
     228cout << "amedObjMgr::DeleteDir() " << dirname << " deleted " << endl; 
     229}
     230
     231/* --Methode-- */
     232void NamedObjMgr::SetCurrentDir(string & dirname)
     233{
     234if ( !CheckDirName(dirname) ) {
     235  cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - Invalid name !" << endl;
     236  return;
     237  }
     238NObjDirList::iterator it = myDirs->find(dirname);
     239if (it == myDirs->end()) {
     240  cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - No such directory !" << endl;
     241  return;
     242  }
     243*currDir = dirname;
     244cout << "NamedObjMgr::SetCurrentDir() -> " << dirname << endl;
     245}
     246
     247/* --Methode-- */
     248void NamedObjMgr::GetCurrentDir(string & dirname)
     249{
     250dirname = *currDir;
     251}
     252
     253/* --Methode-- */
     254void NamedObjMgr::ListDirs(string & patt)
     255{
     256NObjDirList::iterator it;
     257string cn;
     258cout << "NamedObjMgr::ListDirs( " << patt << " ) " << endl;
     259int k = 0;
     260for(it= myDirs->begin(); it != myDirs->end(); it++) {
     261  cn = (*it).first;
     262  if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
     263  k++;
     264  cout << k << "- " << (*it).first << "  (NbObj= " << (*it).second.nobj << ")" << endl;
     265  }
     266}
     267
     268/* --Methode-- */
     269void NamedObjMgr::GetDirList(string & patt, vector<string>& lstd)
     270{
     271NObjDirList::iterator it;
     272string cn;
     273for(it= myDirs->begin(); it != myDirs->end(); it++) {
     274  cn = (*it).first;
     275  if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
     276  lstd.push_back(cn);
     277  }
    177278}
    178279
     
    186287{
    187288}
     289
    188290
    189291//++
     
    209311
    210312/* --Methode-- */
    211 void NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool)
     313void NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool crd)
    212314{
    213315
    214316if (obj == NULL)  return;
    215 // on supprime les blancs de debut et de fin
    216 size_t p = nom.find_first_not_of(" ");
    217 if(p>nom.length()) {
    218   nom = "";
    219 } else {
    220   nom = nom.substr(p);
    221   p = nom.find_first_of(" ");
    222   if(p>nom.length()) p=nom.length();
    223   nom = nom.substr(0, p);
    224 }
     317// On verifie si l'objet est deja dans la liste
     318NObjList::iterator it;
     319for(it = myObjs->begin(); it != myObjs->end(); it++) {
     320  if ((*it).second.obj == obj) {
     321    cout << "NamedObjMgr::AddObj() Object already present with name " << (*it).first << endl;
     322    return;
     323    }
     324  }
     325string nobj;
     326string nrep;
     327char buff[32];
     328int did = ParseObjectName(nom, nrep, nobj);
     329if (did == 0) {
     330  if (!crd) {
     331    cout << "NamedObjMgr::AddObj() No " << nrep << " Directory " << endl;
     332    return;
     333    }
     334  else { CreateDir(nrep);  did =  myDirId; }
     335  }
    225336
    226337myNObj++;
    227 if (nom.length() < 1) nom = typeid(*obj).name();
    228 NObjList::iterator it = myObjs->find(nom);
     338if (nobj.length() < 1) {
     339  sprintf(buff,"O%d", myNObj);
     340  nobj = buff;
     341  }
     342
     343nom = '/' + nrep + '/' + nobj; 
     344it = myObjs->find(nom);
    229345if (it != myObjs->end()) { // l'objet existe deja
    230   char strg[16];
    231   sprintf(strg, "%d", myNObj);
    232   string nomnew = nom + strg;
    233   RenameObj(nom, nomnew);
     346  if (nrep == "tmp") {  // Les objets de /tmp sont jetes
     347    cout << "NamedObjMgr::AddObj() - Replacing " << nom << endl;
     348    DelObj(nom);
     349    }
     350  else {  // On met l'ancien objet dans /old
     351    string on,od;
     352    ParseObjectName((*it).first, od, on);
     353    sprintf(buff, "%d", (*it).second.oid);
     354    string nomnew = "/old/" + on + buff;
     355    RenameObj(nom, nomnew);
     356    }
    234357  }
    235358
     
    237360no.obj = obj;
    238361no.obja = servnobjm->GetAdapter(obj);  // L'adaptateur
    239 no.num =  myNObj;
     362no.oid =  myNObj;
     363no.dirid = did;
    240364(*myObjs)[nom] = no;
    241 if (myImgApp)  {
    242   string str = nom + "    (T= " + typeid(*obj).name() + ")" ;
    243   (myImgApp->ObjMgrW())->AddObj(str.c_str(), myNObj+1000);
    244 }
    245  
     365
     366NObjDirList::iterator itr = myDirs->find(nrep);
     367(*itr).second.nobj++;
     368
    246369cout << "NamedObjMgr::AddObj()  Object " << nom << " ( " 
    247370     << typeid(*obj).name() << " ) added (Total= " << myObjs->size() << ")" << endl; 
     
    252375void NamedObjMgr::RenameObj(string & nom, string& nomnew)
    253376{
    254 AnyDataObj* obj = GetObj(nom);
    255 if (obj == NULL) return;
    256 DelObj(nom, false);
    257 AddObj(obj, nomnew);
     377string n1,r1,n2,r2;
     378ParseObjectName(nom, r1, n1);
     379int did = ParseObjectName(nomnew, r2, n2);
     380if (did == 0) {
     381  cout << "NamedObjMgr::RenameObj() Error - No " << r2 << " directory !" << endl;
     382  return;
     383  }
     384nom = '/' + r1 + '/' + n1;
     385nomnew = '/' + r2 + '/' + n2;
     386NObjList::iterator it1 = myObjs->find(nom);
     387if (it1 == myObjs->end()) {
     388  cout << "NamedObjMgr::RenameObj() Error -  No " << nom << " object !" << endl;
     389  return;
     390  }
     391NObjList::iterator it2 = myObjs->find(nomnew);
     392if (it2 != myObjs->end()) {
     393  cout << "NamedObjMgr::RenameObj() Error -  Object " << nomnew << " exist !" << endl;
     394  return;
     395  }
     396
     397nobj_item no = (*it1).second;
     398no.dirid = did;
     399myObjs->erase(it1);
     400NObjDirList::iterator itr = myDirs->find(r1);
     401(*itr).second.nobj--;
     402(*myObjs)[nomnew] = no;
     403itr = myDirs->find(r2);
     404(*itr).second.nobj++;
     405cout << "NamedObjMgr::RenameObj() - Object " << nom << " renamed to " << nomnew << endl;
    258406return;
    259407}
     
    262410void NamedObjMgr::DelObj(string & nom, bool fgd)
    263411{
     412string n1,r1;
     413ParseObjectName(nom, r1, n1);
     414nom = '/' + r1 + '/' + n1;
    264415NObjList::iterator it = myObjs->find(nom);
    265416if (it == myObjs->end()) return;
     
    269420  for(ii=(*it).second.wrsid.begin(); ii != (*it).second.wrsid.end(); ii++)
    270421      myImgApp->DelWRsId((*ii));
    271   (myImgApp->ObjMgrW())->DelObj((*it).second.num+1000);
    272422}
    273423delete (*it).second.obja;  // destruction de l'adaptateur
    274424if (fgd) delete (*it).second.obj;
     425
    275426myObjs->erase(it);
     427NObjDirList::iterator itr = myDirs->find(r1);
     428(*itr).second.nobj--;
     429
    276430if (fgd) cout << "NamedObjMgr::DelObj()  Object " << nom << " deleted (Total= " << myObjs->size() << ")" << endl;
    277431else  cout << "NamedObjMgr::DelObj()  Object " << nom << " removed (Total= " << myObjs->size() << ")" << endl;
     
    282436void NamedObjMgr::DelObj_Id(int oid)
    283437{
     438NObjList::iterator it;
     439string nom;
     440bool of = false;
     441for(it = myObjs->begin(); it != myObjs->end(); it++)
     442  if ( (*it).second.oid == oid ) {
     443    of = true;  nom = (*it).first;
     444    break;
     445  }
     446if (of) DelObj(nom, true);
    284447}
    285448
     
    287450void NamedObjMgr::DelObjects(string & patt, bool fgd)
    288451{
     452string n1,r1;
     453ParseObjectName(patt, r1, n1);
     454patt = '/' + r1 + '/' + n1;
    289455NObjList::iterator it; 
    290456list<string> odel;
     
    301467AnyDataObj* NamedObjMgr::GetObj(string & nom)
    302468{
     469string n1,r1;
     470ParseObjectName(nom, r1, n1);
     471nom = '/' + r1 + '/' + n1;
    303472NObjList::iterator it = myObjs->find(nom);
    304473if (it == myObjs->end()) return(NULL);
     
    309478NObjMgrAdapter* NamedObjMgr::GetObjAdapter(string & nom)
    310479{
     480string n1,r1;
     481ParseObjectName(nom, r1, n1);
     482nom = '/' + r1 + '/' + n1;
    311483NObjList::iterator it = myObjs->find(nom);
    312484if (it == myObjs->end()) return(NULL);
     
    322494char strg[256];
    323495
    324 cout << "NamedObjMgr::ListObjs() NObjs= " << myObjs->size() << "\n" ;
     496string n1,r1;
     497ParseObjectName(patt, r1, n1);
     498patt = '/' + r1 + '/' + n1;
     499 cout << "NamedObjMgr::ListObjs( " << patt << " ) TotNObjs= " << myObjs->size() << "\n" ;
    325500NObjList::iterator it;  k = 0;
     501string cn;
    326502for(it = myObjs->begin(); it != myObjs->end(); it++) {
     503  cn = (*it).first;
     504  if (csh_parse(cn.c_str(), patt.c_str()) == 0)  continue;
    327505  obj = (*it).second.obj;
    328 
    329506  ctyp = typeid(*obj).name();
    330507  sprintf(strg, "%2d/ %16s : %s", k, typeid(*obj).name(), ((*it).first).c_str());
     
    338515
    339516/* --Methode-- */
    340 void NamedObjMgr::GetObjList(string & patt, vector<string> &)
    341 {
     517void NamedObjMgr::GetObjList(string & patt, vector<string> &lst)
     518{
     519string n1,r1;
     520if (patt.length() < 1)  return;
     521bool fgr = (patt[0] == '/') ? true : false;
     522ParseObjectName(patt, r1, n1);
     523patt = '/' + r1 + '/' + n1;
     524NObjList::iterator it;
     525string cn;
     526for(it = myObjs->begin(); it != myObjs->end(); it++) {
     527  cn = (*it).first;
     528  if (csh_parse(cn.c_str(), patt.c_str()) == 0)  continue;
     529  if (fgr) lst.push_back(cn);
     530  else {
     531    ParseObjectName(cn, r1, n1);
     532    lst.push_back(n1);
     533    }
     534  }
    342535}
    343536
     
    372565if (!ok)  return;
    373566if (nobj.length()<1)  nobj = servnobjm->FileName2Name(flnm);
    374 AddObj(obj->DataObj(), nobj);
     567AddObj(obj->DataObj(), nobj, true);
    375568return;
    376569}
     
    416609    ok = false;
    417610  } ENDTRY;
    418   if (ok)  AddObj(obj->DataObj(), nom); 
     611  if (ok)  AddObj(obj->DataObj(), nom, true); 
    419612}
    420613
     
    475668static int key_for_write = 5000;
    476669/* --Methode-- */
    477 void NamedObjMgr::SaveObj(string & nom, POutPersist& s)
    478 {
     670void NamedObjMgr::SaveObj(string & nom, POutPersist& s, bool keeppath)
     671{
     672if (nom.length() < 1) return;
     673string nob,rep;
     674ParseObjectName(nom, rep, nob);
     675nom = '/' + rep + '/' + nob;
    479676NObjMgrAdapter* obja=NULL;
     677string nomf = (keeppath) ? nom : nob;
    480678obja = GetObjAdapter(nom);
    481679if (obja == NULL)  return;
    482680printf("NamedObjMgr::SaveObj(%s, )  (Type=%s) \n", 
    483681       nom.c_str(), typeid(*(obja->GetDataObj())).name());
    484 obja->SavePPF(s, nom);
     682obja->SavePPF(s, nomf);
    485683return;
     684}
     685
     686/* --Methode-- */
     687void NamedObjMgr::SaveObjects(string & patt, string const& flnm)
     688{
     689string n1,r1;
     690if (patt.length() < 1)  return;
     691bool keeppath = (patt[0] == '/') ? true : false;
     692ParseObjectName(patt, r1, n1);
     693patt = '/' + r1 + '/' + n1;
     694
     695bool ok = true;
     696POutPersist* pout;
     697TRY{
     698  pout = new POutPersist(flnm);
     699}  CATCH(merr)
     700  { printf("NamedObjMgr::SaveObjects()/Error Exception= %ld (%s) \n",
     701    (long)merr, PeidaExc(merr));  ok = false; } ENDTRY;
     702if (!ok)  return;
     703NObjList::iterator it;
     704string cn;
     705for(it = myObjs->begin(); it != myObjs->end(); it++) {
     706  cn = (*it).first;
     707  if (csh_parse(cn.c_str(), patt.c_str()) == 0)  continue;
     708  SaveObj(cn, (*pout), keeppath);
     709  }
     710delete pout;
     711return;
    486712}
    487713
     
    502728for(it = myObjs->begin(); it != myObjs->end(); it++) {
    503729  no = (*it).first;
    504   SaveObj(no, (*pout));
     730  SaveObj(no, (*pout), true);
    505731  }
    506732delete pout;
     
    651877/* --Methode-- */
    652878void NamedObjMgr::DisplayNT(string& nom, string& nmx, string& nmy, string& nmz,
    653                             string& erx, string& ery, string& erz, string dopt)
     879                            string& erx, string& ery, string& erz, string dopt, bool fg3d)
    654880{
    655881AnyDataObj* obj=GetObj(nom);
     
    673899int opt = servnobjm->DecodeDispOption(dopt, fgsr);
    674900
    675 if (nmz.length()>0)  { // Display 3D
     901if ( fg3d && (nmz.length()>0) )  { // Display 3D
    676902  PINTuple3D* pin = new PINTuple3D(nt, false);
    677903  pin->SelectXYZ(nmx.c_str(), nmy.c_str(), nmz.c_str());
     
    684910  pin->SelectXY(nmx.c_str(), nmy.c_str());
    685911  pin->SelectErrBar(erx.c_str(), ery.c_str());
    686   string titre = nmy + "%" + nmz;
     912  if ( nmz.length()>0 ) pin->SelectWt(nmz.c_str());
     913  string titre = nmy + "%" + nmx;
    687914  wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, nom, opt, titre);
    688915  }
     
    7761003servnobjm->DecodeDispOption(gratt, fg);
    7771004}
     1005
    7781006/* --Methode-- */
    7791007void NamedObjMgr::SetGraphicWinZone(int nzx, int nzy, bool fcr)
     
    7851013
    7861014/* --Methode-- */
    787 void NamedObjMgr::DisplayPoints2D(string& nom,  string& expx, string& expy,
    788                                   string& experrx, string& experry,
    789                                   string& expcut, string dopt)
    790 {
    791 NObjMgrAdapter* obja=NULL;
    792 obja = GetObjAdapter(nom);
    793 if (obja == NULL) {
    794   cout << "NamedObjMgr::DisplayPoints2D() Error , Pas d'objet de nom " << nom << endl;
    795   return;
    796   }
    797 if (!myImgApp)  return;
    798 
    799 // Creation NTuple
    800 char* ntn[4] = {"expx","expy","expex","expey",};
    801 NTuple* nt = NULL;
    802 bool haserr = false;
    803 
    804 if ( (experrx.length() > 0 ) && (experry.length() > 0 ) ) {  haserr = true;   nt = new NTuple(4, ntn); }
    805 else {  haserr = false;  experrx = experry = "0."; nt = new NTuple(2, ntn); }
    806 
    807 servnobjm->Nobj_ComputeExpressions(obja, expx, expy, experrx, experry, expcut, nt, NULL, NULL);
    808 
    809 if (nt->NEntry() < 1) {
    810   cout << "NamedObjMgr::DisplayPoints2D() Warning  Zero points satisfy cut !" << endl;
    811   delete nt;
    812   return;
    813   }
    814 
    815 // nt->Show();
    816 // nt->Print(0,10);
    817 PINTuple* pin = new PINTuple(nt, true);
    818 pin->SelectXY(ntn[0], ntn[1]);
    819 if ( haserr ) pin->SelectErrBar(ntn[2], ntn[3]);
    820 
    821 bool fgsr = true;
    822 dopt = "defline," + dopt;
    823 int opt = servnobjm->DecodeDispOption(dopt, fgsr);
    824 string titre =  nom + ":" + expy + "%" + expx;
    825 myImgApp->DispScDrawer( (PIDrawer*)pin, titre, opt);
    826 if (fgsr) myImgApp->RestoreGraphicAtt();
    827 return;
    828 }
    829 
    830 /* --Methode-- */
    831 void NamedObjMgr::DisplayPoints3D(string& nom,  string& expx, string& expy, string& expz,
    832                                   string& expcut, string dopt)
    833 {
    834 NObjMgrAdapter* obja=NULL;
    835 obja = GetObjAdapter(nom);
    836 if (obja == NULL) {
    837   cout << "NamedObjMgr::DisplayPoints3D() Error , Pas d'objet de nom " << nom << endl;
    838   return;
    839   }
    840 if (!myImgApp)  return;
    841 
    842 char* ntn[3] = {"expx","expy","expz"};
    843 NTuple* nt = new NTuple(3,ntn);  // Creation NTuple
    844 
    845 string expwt = "1.";
    846 servnobjm->Nobj_ComputeExpressions(obja, expx, expy, expz, expwt, expcut, nt, NULL, NULL);
    847 
    848 if (nt->NEntry() < 1) {
    849   cout << "NamedObjMgr::DisplayPoints3D() Warning  Zero points satisfy cut !" << endl;
    850   delete nt;
    851   return;
    852   }
    853 nt->Show();
    854 nt->Print(0,10);
    855 PINTuple3D* pin = new PINTuple3D(nt, true);
    856 pin->SelectXYZ(ntn[0], ntn[1], ntn[2]);
    857 bool fgsr = true;
    858 dopt = "defline," + dopt;
    859 int opt = servnobjm->DecodeDispOption(dopt, fgsr);
    860 
    861 // Pour plot a partir de DispScDrawer
    862 // string nomdisp = "_NT3D_";
    863 // myImgApp->DispScDrawer( (PIDrawer*)pin, nomdisp, opt);
    864 // Pour plot a partir de Disp3DDrawer
    865 string titre =  nom + ":" + expy + "%" + expx;
    866 myImgApp->Disp3DDrawer(pin, titre, opt);
    867 
    868 if (fgsr) myImgApp->RestoreGraphicAtt();
    869 return;
    870 }
    871 
    872 /* --Methode-- */
    873 void NamedObjMgr::ProjectH1(string& nom, string& expx, string& expwt, string& expcut, string& nomh1, string dopt)
    874 {
    875 NObjMgrAdapter* obja=NULL;
    876 obja = GetObjAdapter(nom);
    877 if (obja == NULL) {
    878   cout << "NamedObjMgr::ProjectH1() Error , Pas d'objet de nom " << nom << endl;
    879   return;
    880   }
    881 if (!myImgApp)  return;
    882 
    883 Histo* h1 = NULL;
    884 NTuple* nt = NULL;
    885 AnyDataObj* oh = NULL;
    886 if (nomh1.length() > 0) oh=GetObj(nomh1);
    887 else nomh1 = "H1Proj";
    888 if ( (oh != NULL) && (typeid(*oh) == typeid(Histo)) )  h1 = (Histo*)oh;  // Pas de remise a zero ! h1->Zero();
     1015void NamedObjMgr::AddWRsId(string & nom, int wrsid)
     1016{
     1017if(wrsid != 0) {
     1018  NObjList::iterator it = myObjs->find(nom);
     1019  if (it == myObjs->end()) return;
     1020  (*it).second.wrsid.push_back(wrsid);
     1021  }
     1022return;
     1023}
     1024
     1025/* --Methode-- */
     1026void NamedObjMgr::UpdateObjMgrWindow(int did)
     1027{
     1028if (!myImgApp)  return;
     1029(myImgApp->ObjMgrW())->ClearHelpList();
     1030
     1031NObjList::iterator it; 
     1032string cn;
     1033for(it = myObjs->begin(); it != myObjs->end(); it++) {
     1034  if ((*it).second.dirid != did) continue;
     1035  cn = (*it).first.substr(1);
     1036  cn = cn.substr(cn.find('/')+1) + "  (T= " + typeid(*((*it).second.obj)).name() + ")" ;
     1037  (myImgApp->ObjMgrW())->AddObj(cn.c_str());
     1038  }
     1039}
     1040
     1041
     1042/* Nouvelle-Fonction */
     1043void RemoveSpacesFromName(string & nom)
     1044{
     1045// on supprime les blancs de debut et de fin
     1046size_t p = nom.find_first_not_of(" ");
     1047if(p>nom.length()) { nom = ""; return; }
     1048nom = nom.substr(p);
     1049p = nom.find(' ');
     1050if(p>nom.length()) p=nom.length();
     1051nom = nom.substr(0, p);
     1052}
     1053
     1054/* Nouvelle-Fonction */
     1055bool CheckDirName(string & nom)
     1056{
     1057RemoveSpacesFromName(nom);
     1058if (nom.length() < 1)  return(false);
     1059if (nom[0] == '/') nom = nom.substr(1) ;
     1060size_t p = nom.find('/');
     1061if (p < nom.length()) nom = nom.substr(0,p);
     1062if (nom.length() < 1)  return(false);
     1063return(true);
     1064}
     1065
     1066/* Nouvelle-Fonction */
     1067int ParseObjectName(string & nom, string & nomrep, string & nomobj)
     1068{
     1069RemoveSpacesFromName(nom);
     1070// Si le nom ne commence pas par un slash, c'est le repertoire courant
     1071if (nom[0] != '/') { nomrep = *currDir;  nomobj = nom; }
    8891072else {
    890   char* ntn[2]= {"hxval", "hwt"};
    891   nt = new NTuple(2,ntn);  // Creation NTuple
    892   }
    893 string expz = "0.";   
    894 servnobjm->Nobj_ComputeExpressions(obja, expx, expwt, expz, expwt, expcut, nt, h1, NULL);
    895 
    896 if ((!h1) && (!nt)) return;
    897 if (!h1) {
    898   if (nt->NEntry() < 1) {
    899     cout << "NamedObjMgr::ProjectH1() Warning  Zero points satisfy cut !" << endl;
    900     delete nt;
    901     return;
     1073  string xx = nom.substr(1);
     1074  size_t p = xx.find('/');
     1075  if (p < xx.length())  {
     1076    nomrep = xx.substr(0,p);
     1077    nomobj = xx.substr(p+1);
    9021078    }
    903   double xmin, xmax;
    904   nt->GetMinMax(0, xmin, xmax);
    905   h1 = new Histo(xmin, xmax, 100);
    906   int k;
    907   float* xn;
    908   for(k=0; k<nt->NEntry(); k++)    {
    909     xn = nt->GetVec(k);
    910     h1->Add(xn[0], xn[1]);   
     1079  else {
     1080    nomrep = xx;
     1081    nomobj = "";
    9111082    }
    912   delete nt;
    913   AddObj(h1, nomh1);
    914   }
    915 
    916 DisplayObj(nomh1, dopt);
    917 return; 
    918 }
    919 
    920 /* --Methode-- */
    921 void NamedObjMgr::ProjectH2(string& nom, string& expx, string& expy, string& expwt, string& expcut,
    922                             string& nomh2, string dopt)
    923 {
    924 NObjMgrAdapter* obja=NULL;
    925 obja = GetObjAdapter(nom);
    926 if (obja == NULL) {
    927   cout << "NamedObjMgr::ProjectH2() Error , Pas d'objet de nom " << nom << endl;
    928   return;
    929   }
    930 if (!myImgApp)  return;
    931 
    932 Histo2D* h2 = NULL;
    933 NTuple* nt = NULL;
    934 AnyDataObj* oh = NULL;
    935 if (nomh2.length() > 0)  oh=GetObj(nomh2);
    936 else nomh2 = "H2Proj";
    937 if ( (oh != NULL) && (typeid(*oh) == typeid(Histo2D)) )  h2 = (Histo2D*)oh;  // Pas de remise a zero ! h2->Zero();
    938 else {
    939   char* ntn[3]= {"hxval", "hyval", "hwt"};
    940   nt = new NTuple(3,ntn);  // Creation NTuple
    941   }
    942 string expz = "0.";   
    943 servnobjm->Nobj_ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, nt, NULL, h2);
    944 
    945 if ((!h2) && (!nt)) return;
    946 if (!h2) {
    947   if (nt->NEntry() < 1) {
    948     cout << "NamedObjMgr::ProjectH2() Warning  Zero points satisfy cut !" << endl;
    949     delete nt;
    950     return;
    951     }
    952   double xmin, xmax, ymin, ymax;
    953   nt->GetMinMax(0, xmin, xmax);
    954   nt->GetMinMax(0, ymin, ymax);
    955   h2 = new Histo2D(xmin, xmax, 50, ymin, ymax, 50);
    956   int k;
    957   float* xn;
    958   for(k=0; k<nt->NEntry(); k++)    {
    959     xn = nt->GetVec(k);
    960     h2->Add(xn[0], xn[1], xn[2]);   
    961     }
    962   delete nt;
    963   AddObj(h2, nomh2);
    964   }
    965 
    966 DisplayObj(nomh2, dopt);
    967 return; 
    968 
    969 }
    970 
    971 /* --Methode-- cmv 13/10/98 */
    972 void NamedObjMgr::ProjectHProf(string& nom, string& expx, string& expy, string& expwt, string& expcut,
    973                               string& nomprof, string dopt)
    974 //      Pour remplir un ``GeneralFitData'' a partir de divers objets:
    975 //| nom = nom de l'objet a projeter dans un HProf.
    976 //| expx = expression X de definition du bin.
    977 //| expy = expression Y a additionner dans le bin.
    978 //| expwt = expression W du poids a additionner.
    979 //| expcut = expression du test de selection.
    980 //| nomprof = nom du HProf engendre (optionnel). Si l'objet n'existe pas
    981 //|           les limites Xmin,Xmax sont calculees automatiquement.
    982 //|           sinon ce sont celles de l'objet preexistant.
    983 //| opt = options generales pour le display.
    984 {
    985 NObjMgrAdapter* obja=NULL;
    986 obja = GetObjAdapter(nom);
    987 if (obja == NULL) {
    988   cout << "NamedObjMgr::ProjectHProf() Error , Pas d'objet de nom " << nom << endl;
    989   return;
    990   }
    991 if (!myImgApp)  return;
    992 
    993 HProf* hprof = NULL;
    994 NTuple* nt = NULL;
    995 AnyDataObj* oh = NULL;
    996 if (nomprof.length() > 0)  oh=GetObj(nomprof);
    997 else nomprof = "ProfProj";
    998 if( (oh!=NULL) && (typeid(*oh) == typeid(HProf)) )  hprof = (HProf*)oh;
    999 else {
    1000   char* ntn[3]= {"hxval", "hyval", "hwt"};
    1001   nt = new NTuple(3,ntn);  // Creation NTuple
    1002 }
    1003 string expz = "0.";
    1004 servnobjm->Nobj_ComputeExpressions(obja, expx, expy, expwt, expwt, expcut, nt, NULL, NULL, hprof);
    1005 
    1006 if((!hprof) && (!nt)) return;
    1007 if(!hprof) {
    1008   if (nt->NEntry() < 1) {
    1009     cout << "NamedObjMgr::ProjectHProf() Warning  Zero points satisfy cut !" << endl;
    1010     delete nt;
    1011     return;
    1012   }
    1013   double xmin, xmax;
    1014   nt->GetMinMax(0, xmin, xmax);
    1015   hprof = new HProf(xmin, xmax, 100);
    1016   int k;
    1017   float* xn;
    1018   for(k=0; k<nt->NEntry(); k++)    {
    1019     xn = nt->GetVec(k);
    1020     hprof->Add(xn[0], xn[1], xn[2]);
    1021     }
    1022   delete nt;
    1023   AddObj(hprof, nomprof);
    1024   }
    1025 hprof->UpdateHisto();
    1026 
    1027 DisplayObj(nomprof, dopt);
    1028 return;
    1029 }
    1030 
    1031 /* --Methode-- */
    1032 void NamedObjMgr::FillVect(string& nom, string& expx, string& expcut, string& nomvec, string dopt)
    1033 {
    1034 NObjMgrAdapter* obja=NULL;
    1035 obja = GetObjAdapter(nom);
    1036 if (obja == NULL) {
    1037   cout << "NamedObjMgr::FillVect() Error , Pas d'objet de nom " << nom << endl;
    1038   return;
    1039   }
    1040 if (!myImgApp)  return;
    1041 
    1042 NTuple* nt = NULL;
    1043 if (nomvec.length() < 1) nomvec = "VecFill";
    1044 
    1045 char* ntn[2]= {"vecval", "vecwt"};
    1046 nt = new NTuple(1,ntn);  // Creation NTuple
    1047  
    1048 string expwt = "1.";
    1049 string expz = "0.";   
    1050 servnobjm->Nobj_ComputeExpressions(obja, expx, expz, expz, expwt, expcut, nt, NULL, NULL);
    1051 
    1052 if (!nt) return;
    1053 if (nt->NEntry() < 1) {
    1054   cout << "NamedObjMgr::FillVect() Warning  Zero points satisfy cut !" << endl;
    1055   delete nt;
    1056   return;
    1057   }
    1058  
    1059 Vector* vec = new Vector(nt->NEntry());
    1060 int k;
    1061 float* xn;
    1062 for(k=0; k<nt->NEntry(); k++)    {
    1063   xn = nt->GetVec(k);
    1064   (*vec)(k) = xn[0];
    1065   }
    1066 delete nt;
    1067 AddObj(vec, nomvec);
    1068 DisplayObj(nomvec, dopt);
    1069 return; 
    1070 }
    1071 
    1072 /* --Methode-- */
    1073 void NamedObjMgr::FillNT(string& nom, string& expx, string& expy, string& expz, string& expt,
    1074                          string& expcut, string& nomnt)
    1075 {
    1076 NObjMgrAdapter* obja=NULL;
    1077 obja = GetObjAdapter(nom);
    1078 if (obja == NULL) {
    1079   cout << "NamedObjMgr::FillNT() Error , Pas d'objet de nom " << nom << endl;
    1080   return;
    1081   }
    1082 if (!myImgApp)  return;
    1083 
    1084 bool fgnnt = false;
    1085 NTuple* nt = NULL;
    1086 AnyDataObj* oh = NULL;
    1087 if (nomnt.length() > 0)  oh=GetObj(nomnt);
    1088 else nomnt = "NTFill";
    1089 if ( (oh != NULL) && (typeid(*oh) == typeid(HProf)) )  {
    1090   nt = (NTuple*)oh;
    1091   if (nt->NVar() > 10) {
    1092     cout << "NamedObjMgr::FillNT() Warning , Max 10 var ds NTuple -> new NTuple" << endl;
    1093     nt = NULL;
    1094     }
    1095   } 
    1096 if (nt == NULL) {
    1097   char* ntn[4]= {"x", "y","z","t"};
    1098   nt = new NTuple(4,ntn);  // Creation NTuple
    1099   fgnnt = true;
    1100   }
    1101 
    1102 servnobjm->Nobj_ComputeExpressions(obja, expx, expy, expz, expt, expcut, nt, NULL, NULL);
    1103 
    1104 if (fgnnt) AddObj(nt, nomnt);
    1105 return; 
    1106 
    1107 }
    1108 
    1109 /* --Methode-- cmv 13/10/98 */
    1110 void NamedObjMgr::FillGFD(string& nom, string& expx, string& expy, string& expz,
    1111                           string& experr, string& expcut, string& nomgfd)
    1112 //      Pour remplir un ``GeneralFitData'' a partir de divers objets:
    1113 //| nom = nom de l'objet a transcrire selon 1D: Z=f(X) ou 2D: Z=f(X,Y) .
    1114 //|       Vector,Matrix,Histo,HProf,Histo2D,Image<T>,StarList,NTuple,GeneralFitData
    1115 //| expx = expression X du GeneralFitData (1er abscisse)
    1116 //| expy = expression Y du GeneralFitData (2sd abscisse si non "", Z=f(X,Y))
    1117 //| expz = expression Z du GeneralFitData (valeur de l'ordonnee)
    1118 //| experr = expression de l'erreur sur l'ordonnee Z
    1119 //| expcut = expression du test de selection
    1120 //| nomgfd = nom du GeneralFitData engendre (optionnel)
    1121 {
    1122 NObjMgrAdapter* obja=NULL;
    1123 obja = GetObjAdapter(nom);
    1124 if (obja == NULL) {
    1125   cout << "NamedObjMgr::FillGFD() Error , Pas d'objet de nom "<<nom<<endl;
    1126   return;
    1127   }
    1128 if(!myImgApp)  return;
    1129 
    1130 // 2D ou 3D?
    1131 int nvar = 2;
    1132 if(expy.length()<=0) {nvar = 1; expy = "0.";}
    1133 
    1134 // $CHECK$ - cmv calculait le nombre d'entree ndata
    1135 // en fonction de chaque objet - Je l'ai vire Reza 11/05/99
    1136 
    1137 // Creation NTuple Buffer
    1138 char* ntn[4]= {"x","y","f","e"};
    1139 NTuple*nt = new NTuple(4,ntn);
    1140 
    1141 // Remplissage NTuple buffer
    1142 servnobjm->Nobj_ComputeExpressions(obja, expx, expy, expz, experr, expcut, nt, NULL, NULL);
    1143 if(nt->NEntry() < 1)
    1144   {cout<<"NamedObjMgr::FillGFD() Warning  Zero points satisfy cut !"<<endl;
    1145    delete nt; return;}
    1146 
    1147 //Remplissage de la structure GeneraFitData
    1148 if (nt->NEntry() <= 0) {
    1149   cout<<"NamedObjMgr::FillGFD() Warning - NData= " << nt->NEntry() << endl;
    1150   delete nt;
    1151   return;
    1152   }
    1153 
    1154 GeneralFitData* gfd = new GeneralFitData(nvar,nt->NEntry(),0);
    1155 int k;
    1156 float* xn;
    1157 for(k=0; k<nt->NEntry(); k++) {
    1158   xn = nt->GetVec(k);
    1159   gfd->AddData(xn,xn[2],xn[3]);
    1160 }
    1161 
    1162 // Menage et table d'objets
    1163 delete nt;
    1164 AddObj(gfd, nomgfd);
    1165 return;
    1166 }
    1167 
    1168 
    1169 ///////////////////// Fit 1D et 2D //////////////////////////
    1170 /* --Function static propre aux routines de fit 1D et 2D-- cmv 13/10/98 */
    1171 struct DFOptions {
    1172   int okres, okfun;
    1173   int polcx,polcy; double xc,yc;
    1174   double err_e, err_E;
    1175   double stc2;
    1176   int lp,lpg;
    1177   int i1,i2,j1,j2;
    1178 };
    1179 typedef struct DFOptions DFOPTIONS;
    1180 static void DecodeFitsOptions(string par,string step,string min,string max,string opt
    1181                       ,Vector& Par,Vector& Step,Vector& Min,Vector& Max,DFOPTIONS& O);
    1182 void DecodeFitsOptions(string par,string step,string min,string max,string opt
    1183                       ,Vector& Par,Vector& Step,Vector& Min,Vector& Max,DFOPTIONS& O)
    1184 //| Pour decoder les "string" et remplir les vecteurs du fit (cf commentaires dans Fit1D)
    1185 {
    1186 // set des vecteurs et decodage des string correspondantes
    1187 int NParMax = 100;
    1188 Par.Realloc(NParMax); Step.Realloc(NParMax);
    1189 Min.Realloc(NParMax); Max.Realloc(NParMax);
    1190 {
    1191   Vector* v; string* s;
    1192   {for(int i=0;i<NParMax;i++) {Par(i)=0.; Step(i)=1.; Min(i)=1.; Max(i)=-1.;}}
    1193   for(int j=0;j<4;j++) {
    1194     if(j==0)      {v=&Par; s=&par;}
    1195     else if(j==1) {v=&Step; s=&step;}
    1196     else if(j==2) {v=&Min; s=&min;}
    1197     else if(j==3) {v=&Max; s=&max;}
    1198     if(s->length()>0) *s += ",";
    1199     for(int i=0;i<NParMax;i++) {
    1200       if(s->length()<=0) break;
    1201       sscanf(s->c_str(),"%lf",&(*v)(i));
    1202       size_t p = s->find_first_of(',') + 1;
    1203       if(p>=s->length()) *s = ""; else *s = s->substr(p);
    1204     }
    1205   }
    1206 }
    1207 
    1208 // Decodage de options de opt
    1209 O.okres = O.okfun = 0;
    1210 O.polcx = O.polcy = 0;
    1211 O.xc = O.yc = 0.;
    1212 O.stc2 = 1.e-3;
    1213 O.err_e = O.err_E = -1.;
    1214 O.lp = 1; O.lpg = 0;
    1215 O.i1 = O.j1 = O.i2 = O.j2 = -1;
    1216 
    1217 if(opt.length()<=0) return;
    1218 opt = "," + opt + ",";
    1219 
    1220 if(strstr(opt.c_str(),",r,")) O.okres = 1;  // residus
    1221 if(strstr(opt.c_str(),",f,")) O.okfun = 1;  // fonction fittee
    1222 if(strstr(opt.c_str(),",x")) { // Demande de centrage (fit X=x-xc)
    1223   O.polcx = 2; // Le centrage est calcule automatiquement
    1224   size_t p = opt.find(",x");
    1225   size_t q = opt.find_first_of(',',p+1);
    1226   string dum = opt.substr(p,q-p);
    1227   if(dum.length()>2) {
    1228     sscanf(dum.c_str(),",x%lf",&O.xc);
    1229     O.polcx = 1; // Le centrage est fixe par la valeur lue
    1230   }
    1231 }
    1232 if(strstr(opt.c_str(),",y")) { // Demande de centrage (fit Y=y-yc)
    1233   O.polcy = 2; // Le centrage est calcule automatiquement
    1234   size_t p = opt.find(",y");
    1235   size_t q = opt.find_first_of(',',p+1);
    1236   string dum = opt.substr(p,q-p);
    1237   if(dum.length()>2) {
    1238     sscanf(dum.c_str(),",y%lf",&O.yc);
    1239     O.polcy = 1; // Le centrage est fixe par la valeur lue
    1240   }
    1241 }
    1242 if(strstr(opt.c_str(),",E")) { // Erreurs imposees a "sqrt(val)" ou "aa.b*sqrt(val)"
    1243   size_t p = opt.find(",E");
    1244   size_t q = opt.find_first_of(',',p+1);
    1245   string dum = opt.substr(p,q-p);
    1246   if(dum.length()>2) sscanf(dum.c_str(),",E%lf",&O.err_E);
    1247   if(O.err_E<=0.) O.err_E = 1.;
    1248   O.err_e=-1.;
    1249 }
    1250 if(strstr(opt.c_str(),",e")) { // Erreurs imposees a "1" ou "aa.b"
    1251   size_t p = opt.find(",e");
    1252   size_t q = opt.find_first_of(',',p+1);
    1253   string dum = opt.substr(p,q-p);
    1254   if(dum.length()>2) sscanf(dum.c_str(),",e%lf",&O.err_e);
    1255   if(O.err_e<=0.) O.err_e = 1.;
    1256   O.err_E=-1.;
    1257 }
    1258 if(strstr(opt.c_str(),",X")) { // Valeur du StopChi2
    1259   size_t p = opt.find(",X");
    1260   size_t q = opt.find_first_of(',',p+1);
    1261   string dum = opt.substr(p,q-p);
    1262   if(dum.length()>2) sscanf(dum.c_str(),",X%lf",&O.stc2);
    1263   if(O.stc2<=0.) O.stc2 = 1.e-3;
    1264 }
    1265 if(strstr(opt.c_str(),",l")) { // niveau de print
    1266   size_t p = opt.find(",l");
    1267   size_t q = opt.find_first_of(',',p+1);
    1268   string dum = opt.substr(p,q-p);
    1269   float ab;
    1270   if(dum.length()>2) sscanf(dum.c_str(),",l%f",&ab);
    1271   if(ab<0) ab = 0.;
    1272   O.lp = (int) ab; O.lpg = (int) 10.*(ab-O.lp);
    1273 }
    1274 if(strstr(opt.c_str(),",I")) { // intervalle de fit selon X
    1275   size_t p = opt.find(",I");
    1276   size_t q = opt.find_first_of(',',p+1);
    1277   string dum = opt.substr(p,q-p);
    1278   if(dum.length()>2) sscanf(dum.c_str(),",I%d/%d",&O.i1,&O.i2);
    1279 }
    1280 if(strstr(opt.c_str(),",J")) { // intervalle de fit selon Y
    1281   size_t p = opt.find(",J");
    1282   size_t q = opt.find_first_of(',',p+1);
    1283   string dum = opt.substr(p,q-p);
    1284   if(dum.length()>2) sscanf(dum.c_str(),",J%d/%d",&O.j1,&O.j2);
    1285 }
    1286 return;
    1287 }
    1288 
    1289 /* --Methode-- cmv 13/10/98 */
    1290 void  NamedObjMgr:: Fit12D(string& nom, string& func,
    1291                           string par,string step,string min,string max,
    1292                           string opt)
    1293 //| --------------- Fit d'objets a 1 et 2 dimensions ---------------
    1294 //| nom  : nom de l'objet qui peut etre:
    1295 //|        fit-1D:  Vector,Histo1D,HProf ou GeneraFitData(1D)
    1296 //|        fit-2D:  Matrix,Histo2D,Imagexx ou GeneraFitData(2D)
    1297 //| func : pnn = fit polynome degre nn avec classe Poly (lineaire) 1D ou 2D
    1298 //|      : Pnn = fit polynome degre nn avec GeneralFit (non-lineaire) 1D ou 2D
    1299 //|      : gnn = fit gaussienne (hauteur) + polynome de degre nn 1D
    1300 //|      : g   = fit gaussienne (hauteur) 1D
    1301 //|      : enn = fit exponentielle + polynome de degre nn 1D
    1302 //|      : e   = fit exponentielle 1D
    1303 //|      : Gnn = fit gaussienne (volume) + polynome de degre nn 1D
    1304 //|      : G   = fit gaussienne (volume) 1D
    1305 //|      :     = fit gaussienne+fond (volume) 2D
    1306 //|      : Gi  = fit gaussienne+fond integree (volume) 2D
    1307 //|      : d   = fit DL de gaussienne+fond (volume) 2D
    1308 //|      : di  = fit DL de gaussienne+fond integree (volume) 2D
    1309 //|      : D   = fit DL de gaussienne+fond avec coeff variable p6 (volume) 2D
    1310 //|      : Di  = fit DL de gaussienne+fond integree avec coeff variable p6 (volume) 2D
    1311 //|      : M   = fit Moffat+fond (expos=p6) (volume) 2D
    1312 //|      : Mi  = fit Moffat+fond integree (expos=p6) (volume) 2D
    1313 //| par  : p1,...,pn valeur d'initialisation des parametres (def=0)
    1314 //| step : s1,...,sn valeur des steps de depart (def=1)
    1315 //| min  : m1,...,mn valeur des minima (def=1)
    1316 //| max  : M1,...,Mn valeur des maxima (def=-1) (max<=min : pas de limite)
    1317 //| opt  : options "Eaa.b,eaa.b,f,r,caa.b,Xaa.b"
    1318 //|       f = generation d'un Objet identique contenant la fonction fittee
    1319 //|       r = generation d'un Objet identique contenant les residus
    1320 //|       Xaa.b = aa.b valeur du DXi2 d'arret (def=1.e-3)
    1321 //|       la.b = niveau "a.b" de print: a=niveau de print Fit1/2D
    1322 //|                                     b=niveau de debug GeneralFit
    1323 //|       Ii1/i2 numeros des bins X de l'histos utilises pour le fit [i1,i2]
    1324 //|2D     Jj1/j2 numeros des bins Y de l'histos utilises pour le fit [j1,j2]
    1325 //|       - L'erreur est celle associee a l'objet si existe, 1 sinon sauf si
    1326 //|       E = erreur prise comme la racine de la valeur a fitter
    1327 //|       Eaa.b = erreur prise aa.b*sqrt(val)
    1328 //|       e = erreur prise egale a 1 pour toutes les valeurs
    1329 //|       eaa.b = erreur prise egale a aa.b
    1330 //|       xaa.b = demande de centrage: on fit x-aa.b au lieu de x)
    1331 //|       x = demande de centrage: on fit x-xc au lieu de x
    1332 //|           avec xc=abscisse du milieu de l'histogramme
    1333 //|           Actif pour: exp+poly 1D, poly 1D
    1334 //|                       gauss+poly 1D (mais xc est le centre de la gaussienne)
    1335 //|2D     yaa.b et y = idem "xaa.b et x" mais pour y
    1336 {
    1337 AnyDataObj* obj=GetObj(nom);
    1338 if (obj == NULL) {
    1339   cout<<"NamedObjMgr::Fit12D() Error , Pas d'objet de nom "<<nom<<endl;
    1340   return;
    1341 }
    1342 if (!myImgApp)  return;
    1343 if(func.length()<=0)
    1344   {cout<<"NamedObjMgr::Fit12D() Donnez un nom de fonction a fitter."<<endl;
    1345    return;}
    1346 string ctyp = typeid(*obj).name();
    1347 
    1348 int ndim = 0, nbinx=0, nbiny=0, ndata = 0;
    1349 Vector* v = NULL; Histo* h = NULL;
    1350 Matrix* m = NULL; Histo2D* h2 = NULL; RzImage* im = NULL;
    1351 GeneralFitData* g = NULL;
    1352 
    1353   // 1D
    1354 if (typeid(*obj) == typeid(Vector)) {
    1355   ndim = 1;
    1356   v = (Vector*) obj; nbinx = v->NElts(); nbiny = 1;
    1357   }
    1358 else if ( (typeid(*obj) == typeid(HProf)) || (typeid(*obj) == typeid(Histo)) ) {
    1359   ndim = 1;
    1360   h = (Histo*)  obj; nbinx = h->NBins(); nbiny = 1;
    1361   }
    1362 else if (typeid(*obj) == typeid(Matrix)) {
    1363   ndim = 2;
    1364   m = (Matrix*) obj; nbinx = m->NCol(); nbiny = m->NRows();
    1365   }
    1366 else if (typeid(*obj) == typeid(Histo2D)) {
    1367   ndim = 2;
    1368   h2 = (Histo2D*) obj; nbinx = h2->NBinX(); nbiny = h2->NBinY();
    1369   }
    1370 else if (typeid(*obj) == typeid(GeneralFitData)) {
    1371   g = (GeneralFitData*) obj; nbinx = g->NData(); nbiny = 1;
    1372   if(     g->NVar()==1) ndim = 1;
    1373   else if(g->NVar()==2) ndim = 2;
    1374   else {
    1375      cout<<"GeneralFitData ne peut avoir que 1 ou 2 variables d'abscisse: "
    1376          <<((GeneralFitData*) obj)->NVar()<<endl; return; }
    1377   }
    1378 else if (dynamic_cast<RzImage*>(obj)) {
    1379   ndim = 2;
    1380   im = (RzImage*) obj; nbinx = im->XSize(); nbiny = im->YSize();
    1381   }
    1382 else  {
    1383   cout<<"NamedObjMgr::Fit12D() Error , Objet n'est pas un "
    1384       <<"Histo1D/HProf/Vector/Histo2D/Image/Matrix/GeneralFitData "<<ctyp<<endl;
    1385   return;
    1386   }
    1387 
    1388 ndata = nbinx*nbiny;
    1389 if(ndata<=0)
    1390   {cout<<"L'objet a "<<nbinx<<","<<nbiny<<" bins ("<<ndata<<")"<<endl; return;}
    1391 
    1392 // Decodage des options et des parametres, mise en forme
    1393 Vector Par(1); Vector Step(1); Vector Min(1); Vector Max(1); DFOPTIONS O;
    1394 DecodeFitsOptions(par,step,min,max,opt,Par,Step,Min,Max,O);
    1395 O.i1 = (O.i1<0||O.i1>=nbinx)? 0: O.i1;
    1396 O.i2 = (O.i2<0||O.i2>=nbinx||O.i2<O.i1)? nbinx-1: O.i2;
    1397 if(ndim>=2) {
    1398   O.j1 = (O.j1<0||O.j1>=nbiny)? 0: O.j1;
    1399   O.j2 = (O.j2<0||O.j2>=nbiny||O.j2<O.j1)? nbiny-1: O.j2;
    1400 } else O.j2 = O.j1 = 0;
    1401 if(O.polcx==2) {
    1402   if(v||m)    O.xc = (O.i2-O.i1+1)/2.;
    1403   else if(h)  O.xc = (h->XMin()+h->XMax())/2.;
    1404   else if(h2) O.xc = (h2->XMin()+h2->XMax())/2.;
    1405   else if(g)  {double mini,maxi; g->GetMinMax(2,mini,maxi); O.xc=(mini+maxi)/2.;}
    1406   else if(im) {O.xc = im->XOrg() * im->XPxSize()*(O.i2-O.i1+1)/2.;}
    1407 }
    1408 if(O.polcy==2 && ndim>=2) {
    1409   if(m)  O.yc = (O.j2-O.j1+1)/2.;
    1410   if(h2) O.yc = (h2->YMin()+h2->YMax())/2.;
    1411   if(g)  {double mini,maxi; g->GetMinMax(12,mini,maxi); O.yc=(mini+maxi)/2.;}
    1412   if(im) {O.yc = im->YOrg() * im->YPxSize()*(O.j2-O.j1+1)/2.;}
    1413 }
    1414 if(O.lp>0)
    1415   cout<<"Fit["<<nbinx<<","<<nbiny<<"] ("<<ndata<<") dim="<<ndim<<":"
    1416       <<" Int=["<<O.i1<<","<<O.i2<<"],["<<O.j1<<","<<O.j2<<"]"<<endl
    1417       <<" Cent="<<O.polcx<<","<<O.polcy<<","<<O.xc<<"+x"<<","<<O.yc<<"+y"
    1418       <<" TypE="<<O.err_e<<","<<O.err_E
    1419       <<" StpX2="<<O.stc2
    1420       <<" lp,lpg="<<O.lp<<","<<O.lpg<<endl;
    1421 
    1422 ///////////////////////////////////
    1423 // Remplissage de GeneralFitData //
    1424 ///////////////////////////////////
    1425 GeneralFitData mydata(ndim,ndata,0);
    1426 {for(int i=O.i1;i<=O.i2;i++) for(int j=O.j1;j<=O.j2;j++) {
    1427   double x,y,f,e;
    1428 
    1429   if(v)
    1430     {x= (double) i; f=(*v)(i); e=1.;}
    1431   else if(h)
    1432     {x=h->BinCenter(i); f=(*h)(i); e=(h->HasErrors())?h->Error(i):1.;}
    1433   else if(m)
    1434     {x=(double) i; y=(double) j; f=(*m)(j,i); e=1.;}
    1435   else if(h2)
    1436     {float xf,yf; h2->BinCenter(i,j,xf,yf); x=(double)xf; y=(double)yf;
    1437      f=(*h2)(i,j); e=(h2->HasErrors())?h2->Error(i,j):1.;}
    1438   else if(im)
    1439     {x=im->XOrg()+(i+0.5)*im->XPxSize(); y=im->YOrg()+(j+0.5)*im->YPxSize();
    1440      f=im->DValue(i,j); e=1.;}
    1441   else if(g&&ndim==1) {x= g->X(i); f=g->Val(i); e=g->EVal(i);}
    1442   else if(g&&ndim==2) {x= g->X(i); y= g->Y(i); f=g->Val(i); e=g->EVal(i);}
    1443   else x=y=f=e=0.;
    1444 
    1445   // Gestion des erreurs a utiliser
    1446   if(O.err_e>0.) e=O.err_e;
    1447   else if(O.err_E>0.) {e=(y<-1.||y>1.)?O.err_E*sqrt(fabs(y)):O.err_E;}
    1448 
    1449   // Remplissage de generalfit
    1450   if(func[0]=='p') {x -= O.xc; if(ndim>=2) y -= O.yc;}
    1451   if(ndim==1)      mydata.AddData1(x,f,e);
    1452   else if(ndim==2) mydata.AddData2(x,y,f,e);
    1453 }}
    1454 if(mydata.NData()<=0)
    1455   {cout<<"Pas de donnees dans GeneralFitData: "<<mydata.NData()<<endl;
    1456    return;}
    1457 if(O.lpg>1) {
    1458   mydata.PrintStatus();
    1459   mydata.PrintData(0);
    1460   mydata.PrintData(mydata.NData()-1);
    1461 }
    1462 
    1463 ////////////////////////////////////////////
    1464 // Identification de la fonction a fitter //
    1465 ////////////////////////////////////////////
    1466 GeneralFunction* myfunc = NULL;
    1467 if(func[0]=='p' && ndim==1) {
    1468   // Fit de polynome sans passer par les GeneralFit
    1469   int degre = 0;
    1470   if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
    1471   cout<<"Fit (lineaire) 1D polynome de degre "<<degre<<endl;
    1472   Poly p1(0);
    1473   double c2rl = mydata.PolFit(0,p1,degre);
    1474   cout<<"C2r_lineaire = "<<c2rl<<endl;
    1475   if(O.lp>0) cout<<p1<<endl;
    1476   return;
    1477 
    1478 } else if(func[0]=='P' && ndim==1) {
    1479   // Fit de polynome
    1480   int degre = 0;
    1481   if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
    1482   cout<<"Fit polynome 1D de degre "<<degre<<endl;
    1483   Polyn1D* myf = new Polyn1D(degre,O.xc);
    1484   myfunc = myf;
    1485 
    1486 } else if(func[0]=='e' && ndim==1) {
    1487   // Fit d'exponentielle
    1488   int degre =-1;
    1489   if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
    1490   cout<<"Fit d'exponentielle+polynome 1D de degre "<<degre<<endl;
    1491   Exp1DPol* myf;
    1492   if(degre>=0) myf = new Exp1DPol((unsigned int)degre,O.xc);
    1493        else    myf = new Exp1DPol(O.xc);
    1494   myfunc = myf;
    1495 
    1496 } else if(func[0]=='g' && ndim==1) {
    1497   // Fit de gaussienne en hauteur
    1498   int degre =-1;
    1499   if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
    1500   cout<<"Fit de Gaussienne_en_hauteur+polynome 1D de degre "<<degre<<endl;
    1501   Gauss1DPol* myf;
    1502   if(degre>=0) myf = new Gauss1DPol((unsigned int)degre,((O.polcx)?true:false));
    1503   else { bool bfg = (O.polcx)?true:false;   myf = new Gauss1DPol(bfg); }
    1504   myfunc = myf;
    1505 
    1506 } else if(func[0]=='G' && ndim==1) {
    1507   // Fit de gaussienne en volume
    1508   int degre =-1;
    1509   if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
    1510   cout<<"Fit de Gaussienne_en_volume+polynome 1D de degre "<<degre<<endl;
    1511   GaussN1DPol* myf;
    1512   if(degre>=0) myf = new GaussN1DPol((unsigned int)degre,((O.polcx)?true:false));
    1513   else  { bool bfg = (O.polcx)?true:false;   myf = new GaussN1DPol(bfg); }
    1514   myfunc = myf;
    1515 
    1516 } else if(func[0]=='p' && ndim==2) {
    1517   // Fit de polynome 2D sans passer par les GeneralFit
    1518   int degre = 0;
    1519   if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
    1520   cout<<"Fit (lineaire) polynome 2D de degre "<<degre<<endl;
    1521   Poly2 p2(0);
    1522   double c2rl = mydata.PolFit(0,1,p2,degre);
    1523   cout<<"C2r_lineaire = "<<c2rl<<endl;
    1524   if(O.lp>0) cout<<p2<<endl;
    1525   return;
    1526 
    1527 } else if(func[0]=='P' && ndim==2) {
    1528   // Fit de polynome 2D
    1529   int degre = 0;
    1530   if(func.length()>1) sscanf(func.c_str()+1,"%d",&degre);
    1531   cout<<"Fit polynome 2D de degre "<<degre<<endl;
    1532   Polyn2D* myf = new Polyn2D(degre,O.xc,O.yc);
    1533   myfunc = myf;
    1534 
    1535 } else if(func[0]=='G' && ndim==2) {
    1536   // Fit de gaussienne+fond en volume
    1537   int integ = 0;
    1538   if(func.length()>1) if(func[1]=='i') integ=1;
    1539   cout<<"Fit de Gaussienne+Fond 2D integ="<<integ<<endl;
    1540   if(integ) {GauRhInt2D* myf = new GauRhInt2D; myfunc = myf;}
    1541     else    {GauRho2D* myf = new GauRho2D; myfunc = myf;}
    1542 
    1543 } else if(func[0]=='d' && ndim==2) {
    1544   // Fit de DL gaussienne+fond en volume
    1545   int integ = 0;
    1546   if(func.length()>1) if(func[1]=='i') integ=1;
    1547   cout<<"Fit de DL de Gaussienne+Fond 2D integ="<<integ<<endl;
    1548   if(integ) {GdlRhInt2D* myf = new GdlRhInt2D; myfunc = myf;}
    1549     else    {GdlRho2D* myf = new GdlRho2D; myfunc = myf;}
    1550 
    1551 } else if(func[0]=='D' && ndim==2) {
    1552   // Fit de DL gaussienne+fond avec coeff variable p6 en volume
    1553   int integ = 0;
    1554   if(func.length()>1) if(func[1]=='i') integ=1;
    1555   cout<<"Fit de DL de Gaussienne+Fond avec coeff variable (p6) 2D integ="<<integ<<endl;
    1556   if(integ) {Gdl1RhInt2D* myf = new Gdl1RhInt2D; myfunc = myf;}
    1557     else    {Gdl1Rho2D* myf = new Gdl1Rho2D; myfunc = myf;}
    1558 
    1559 } else if(func[0]=='M' && ndim==2) {
    1560   // Fit de Moffat+fond (volume)
    1561   int integ = 0;
    1562   if(func.length()>1) if(func[1]=='i') integ=1;
    1563   cout<<"Fit de Moffat+Fond (expos=p6) 2D integ="<<integ<<endl;
    1564   if(integ) {MofRhInt2D* myf = new MofRhInt2D; myfunc = myf;}
    1565     else    {MofRho2D* myf = new MofRho2D; myfunc = myf;}
    1566 
    1567 } else {
    1568   cout<<"Fonction "<<func<<" inconnue pour la dim "<<ndim<<endl;
    1569   return;
    1570 }
    1571 
    1572 /////////////////////////
    1573 // Fit avec generalfit //
    1574 /////////////////////////
    1575 if(myfunc->NPar()>Par.NElts())
    1576   {cout<<"Trop de parametres: "<<myfunc->NPar()<<">"<<Par.NElts()<<endl;
    1577   if(myfunc) delete myfunc; return;}
    1578 GeneralFit myfit(myfunc);
    1579 myfit.SetDebug(O.lpg);
    1580 myfit.SetData(&mydata);
    1581 myfit.SetStopChi2(O.stc2);
    1582 {for(int i=0;i<myfunc->NPar();i++) {
    1583   char str[10];
    1584   sprintf(str,"P%d",i);
    1585   myfit.SetParam(i,str,Par(i),Step(i),Min(i),Max(i));
    1586 }}
    1587 if(O.lp>1) myfit.PrintFit();
    1588 double c2r = (double) myfit.Fit();
    1589 if(O.lp>0) myfit.PrintFit();
    1590 if(c2r>0.) {
    1591   c2r = myfit.GetChi2Red();
    1592   cout<<"C2r_Reduit = "<<c2r<<"  nstep="<<myfit.GetNStep()<<endl;
    1593   Vector ParFit(myfunc->NPar());
    1594   for(int i=0;i<myfunc->NPar();i++) ParFit(i)=myfit.GetParm(i);
    1595 } else {
    1596   cout<<"echec Fit, rc = "<<c2r<<"  nstep="<<myfit.GetNStep()<<endl;
    1597 }
    1598 
    1599 // Mise a disposition des resultats
    1600 if(c2r>=0. && myfunc && (O.okres>0||O.okfun>0)) {
    1601   string nomres = nom + "res";
    1602   string nomfun = nom + "fun";
    1603   if(v) {
    1604     if(O.okres) {Vector* ob = v->FitResidus(myfit);  if(ob) AddObj(ob,nomres);}
    1605     if(O.okfun) {Vector* ob = v->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
    1606   } else if(h) {
    1607     if(O.okres) {Histo* ob = h->FitResidus(myfit);  if(ob) AddObj(ob,nomres);}
    1608     if(O.okfun) {Histo* ob = h->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
    1609   } else if(m) {
    1610     if(O.okres) {Matrix* ob = m->FitResidus(myfit);  if(ob) AddObj(ob,nomres);}
    1611     if(O.okfun) {Matrix* ob = m->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
    1612   } else if(h2) {
    1613     if(O.okres) {Histo2D* ob = h2->FitResidus(myfit);  if(ob) AddObj(ob,nomres);}
    1614     if(O.okfun) {Histo2D* ob = h2->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
    1615   } else if(im) {
    1616     if(O.okres) {RzImage* ob = im->FitResidus(myfit);  if(ob) AddObj(ob,nomres);}
    1617     if(O.okfun) {RzImage* ob = im->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
    1618   } else if(g) {
    1619     if(O.okres) {GeneralFitData* ob = g->FitResidus(myfit);  if(ob) AddObj(ob,nomres);}
    1620     if(O.okfun) {GeneralFitData* ob = g->FitFunction(myfit); if(ob) AddObj(ob,nomfun);}
    1621   }
    1622 }
    1623 
    1624 // Nettoyage
    1625 if(myfunc) delete myfunc;
    1626 return;
    1627 }
    1628 
     1083  }
     1084int rc = 0;
     1085NObjDirList::iterator it = myDirs->find(nomrep);
     1086if (it != myDirs->end())  rc = (*it).second.id;
     1087return(rc);
     1088}
     1089
Note: See TracChangeset for help on using the changeset viewer.