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

Last change on this file since 2605 was 2492, checked in by ansari, 22 years ago

Suite debug piapp multithread : on ne peut pas utiliser ZSync() ds un if (destructeur appele de suite) - Reza 06/01/2004

File size: 43.1 KB
RevLine 
[165]1#include <stdio.h>
2#include <stdlib.h>
3#include <ctype.h>
4
[295]5#include <typeinfo>
[2322]6#include <iostream>
[165]7#include <string>
8#include <list>
9#include <map>
10
11#include "strutil.h"
12#include "datatypes.h"
13
14#include "nobjmgr.h"
15#include "servnobjm.h"
[330]16#include "nomgadapter.h"
[165]17#include "pistdimgapp.h"
18
[1164]19#include "dvlist.h"
[165]20
[293]21// EVOL-PLANCK
22#ifdef SANS_EVOLPLANCK
23#include "fitsimage.h"
[1321]24#else
25#include "fitsautoreader.h"
[1525]26#include "tvector.h"
27#include "pitvmaad.h"
[1905]28#include "piyfxdrw.h"
[293]29#endif
30
[295]31#include "pisurfdr.h"
[165]32#include "pipodrw.h"
[333]33
[165]34#include "pintuple.h"
35#include "pintup3d.h"
36#include "pigfd1.h"
37#include "pigfd2.h"
38
[2491]39#include "zthread.h"
[165]40
[2491]41
[165]42//++
43// Class NamedObjMgr
44// Lib PI
45// include nobjmgr.h
46//
[344]47// Cette classe fournit les services nécéssaires à la gestion des objets
[165]48// (l'ensemble des objets PPersist de PEIDA++) au sein du programme
49// d'analyse interactive *piapp* . Elle constitue en outre l'interface
50// entre les fonctions utilisateur et l'application graphique.
51//--
52//++
53// Links Voir aussi
54// PIStdImgApp
55// Services2NObjMgr
56// PIACmd
57//--
58
59
60// ..................................................................
61// ...... Gestion des objets nommes, variables globales ............
[331]62struct nobj_diritem {
[344]63 int id; // Directory Id
64 int nobj; // Number of objects in directory
65 bool lock; // True -> directory locked, No Add, del or rename
66 bool keepold; // True -> When duplicate object name, old object moved to /old
[331]67};
68
69typedef map<string, nobj_diritem, less<string> > NObjDirList;
70
[165]71struct nobj_item {
[344]72 AnyDataObj* obj; // Object pointer
73 NObjMgrAdapter* obja; // Object adapter pointer
74 int oid; // object Id
75 int dirid; // Directory Id
76 list<int> wrsid; // List of Window Resource Id (Drawer, PIBaseWdg, ...)
77 // (for PIStdImgApp)
[165]78 bool operator==(nobj_item const& b) const
79 { return (this->obj == b.obj); }
80};
81
82typedef map<string, nobj_item, less<string> > NObjList;
83
[331]84static NObjDirList* myDirs = NULL;
85static NObjList* myObjs = NULL;
[165]86static int fgOInit = 0;
87static int myNObj = 0;
[331]88static int myDirId = 0;
89static string* currDir;
[165]90
91static PIStdImgApp* myImgApp=NULL;
92static Services2NObjMgr* servnobjm=NULL;
93
[1164]94static DVList* myVars = NULL; // Pour stocker les variables
95
[165]96static string* TmpDir; // Repertoire pour les compilations / link dynamique
97
[2491]98// Pour gestion multithread
99static ZMutex* myMutex;
[333]100// ..................................................................
101
[165]102//++
103// Titre Constructeurs
104//--
105//++
106// NamedObjMgr()
107// Constructeur. Les différents instantiation de la classe "NamedObjMgr"
108// dans une même application créent des objets qui travaillent sur la même
109// liste d'objets. Les objets de cette classe ne possedent en effet pas
110// de variables membres.
111//--
112
113/* --Methode-- */
[2490]114NamedObjMgr::NamedObjMgr(bool fgimgapp)
[165]115{
[2490]116_fgimgapp = fgimgapp;
[165]117if (fgOInit == 0) {
[333]118 myNObj = 0;
119 myDirId = 0;
[331]120 myDirs = new NObjDirList;
[165]121 myObjs = new NObjList;
[1164]122 myVars = new DVList;
[331]123 currDir = new string("home");
[333]124 string dirn = "home";
[2491]125 CreateDir_P(dirn);
[2132]126 SetKeepOldDirAtt(dirn, false);
[333]127 dirn = "tmp";
[2491]128 CreateDir_P(dirn);
[344]129 SetKeepOldDirAtt(dirn, false);
[466]130 dirn = "autoc";
[2491]131 CreateDir_P(dirn);
[368]132 SetKeepOldDirAtt(dirn, false);
[333]133 dirn = "old";
[2491]134 CreateDir_P(dirn);
[344]135 SetKeepOldDirAtt(dirn, false);
[333]136 dirn = "home";
137 SetCurrentDir(dirn);
138 myDirId = 50;
[165]139 char* varenv;
140 TmpDir = new string("");
[1276]141 if ( (varenv=getenv("TMPDIR")) != NULL ) (*TmpDir) = varenv;
[165]142 int l = (*TmpDir).length();
143 if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/';
[2491]144 servnobjm = new Services2NObjMgr(*TmpDir);
145 myMutex = new ZMutex;
[165]146 }
147fgOInit++;
148}
149
150
151/* --Methode-- */
152NamedObjMgr::~NamedObjMgr()
153{
154fgOInit--;
[1164]155if (fgOInit == 0) {
156 string patt = "/*/*";
157 DelObjects(patt, true);
158 delete myObjs;
159 delete myDirs;
160 delete myVars;
[2491]161 delete myMutex;
[165]162}
[1164]163}
[165]164
165//++
166// Titre Méthodes
167//--
168//++
169// void SetImgApp(PIStdImgApp* app)
170// Spécifie l'objet "PIStdImgApp" associé.
171// PIStdImgApp* GetImgApp()
172// Accès à l'objet "PIStdImgApp" associé.
173//--
174
175/* --Methode-- */
176void NamedObjMgr::SetImgApp(PIStdImgApp* app)
177{
178myImgApp = app;
179servnobjm->SetImgApp(app);
[333]180
181NObjDirList::iterator it;
182string cn;
183for(it= myDirs->begin(); it != myDirs->end(); it++) {
184 cn = '/' + (*it).first;
185 (myImgApp->ObjMgrW())->AddDirectory(cn.c_str(), (*it).second.id);
186 }
[165]187}
188
[449]189
190static bool verbeux = false; // true -> plus de message (creation/suppression d'objets)
191void NamedObjMgr::SetVerbose(bool fg)
192{
193verbeux = fg;
194}
195
[165]196/* --Methode-- */
197PIStdImgApp* NamedObjMgr::GetImgApp()
198{
199return(myImgApp);
200}
201
202/* --Methode-- */
203Services2NObjMgr* NamedObjMgr::GetServiceObj()
204{
205return(servnobjm);
206}
207
[331]208/* --Methode-- */
[1268]209string const& NamedObjMgr::GetTmpDir()
[1265]210{
211return *TmpDir;
212}
213
214/* --Methode-- */
[1268]215void NamedObjMgr::SetTmpDir(string const& tmpdir)
[1265]216{
217if(tmpdir.length()<1) return;
218*TmpDir = tmpdir;
[1276]219int l = (*TmpDir).length();
220if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/';
221servnobjm->SetTmpDir(*TmpDir);
[1265]222}
223
224/* --Methode-- */
[1164]225bool NamedObjMgr::SetVar(string const & key, string const & val)
226{
[2218]227 if ((key.length() < 1) || (! isalpha(key[0])) ) {
228 cout << "NamedObjMgr::SetVar( " << key << " ...) Bad VarName " << endl;
229 return(false);
230 }
[2491]231 ZSync(*myMutex);
[1199]232#ifdef SANS_EVOLPLANCK
233 bool fg = true;
234#else
[1164]235 bool fg = myVars->HasKey(key);
[1199]236#endif
[1164]237 myVars->SetS(key, val);
[1224]238 // cout << " DEBUG::SetVar " << *myVars << endl;
[1164]239 return(fg);
240}
241
242/* --Methode-- */
243bool NamedObjMgr::HasVar(string const & key)
244{
[2218]245 if ((key.length() < 1) || (! isalpha(key[0])) ) {
246 cout << "NamedObjMgr::HasVar( " << key << ") Bad VarName " << endl;
247 return(false);
248 }
[2491]249 ZSync(*myMutex);
[1199]250#ifdef SANS_EVOLPLANCK
[1547]251 DVList::ValList::const_iterator it;
252 for(it=myVars->Begin(); it!= myVars->End(); it++)
253 if ((*it).first == key) return true;
[1199]254 return(false);
255#else
[1164]256 return(myVars->HasKey(key));
[1199]257#endif
[1164]258}
259
260/* --Methode-- */
261bool NamedObjMgr::DeleteVar(string const & key)
262{
[2218]263 if ((key.length() < 1) || (! isalpha(key[0])) ) {
264 cout << "NamedObjMgr::DeleteVar( " << key << ") Bad VarName " << endl;
265 return(false);
266 }
[2491]267 ZSync(*myMutex);
[1199]268#ifdef SANS_EVOLPLANCK
269 return(false);
270#else
[1164]271 return(myVars->DeleteKey(key));
[1199]272#endif
[1164]273}
274
275/* --Methode-- */
276string NamedObjMgr::GetVar(string const & key)
277{
[2218]278 if ((key.length() < 1) || (! isalpha(key[0])) ) {
279 cout << "NamedObjMgr::GetVar( " << key << ") Bad VarName " << endl;
280 return("");
281 }
[2491]282 ZSync(*myMutex);
[1224]283 // cout << " DEBUG::GetVar " << *myVars << endl;
[1164]284 return(myVars->GetS(key));
285}
286
287/* --Methode-- */
288DVList& NamedObjMgr::GetVarList()
289{
[1224]290 // cout << " DEBUG::GetVarList " << *myVars << endl;
[2491]291 ZSync(*myMutex);
[1164]292 return(*myVars);
293}
294
295/* --Methode-- */
[344]296bool NamedObjMgr::CreateDir(string & dirname)
[331]297{
[2491]298 ZSync(*myMutex);
299 return CreateDir_P(dirname);
300}
301
302/* --Methode-- */
303bool NamedObjMgr::CreateDir_P(string & dirname)
304{
[333]305if ( !CheckDirName(dirname) ) {
306 cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Invalid name !" << endl;
[344]307 return(false);
[333]308 }
309NObjDirList::iterator it = myDirs->find(dirname);
310if (it != myDirs->end()) {
311 cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Existing directory !" << endl;
[344]312 return(false);
[333]313 }
314myDirId++;
315nobj_diritem di;
316di.id = myDirId;
317di.nobj = 0;
[344]318di.lock = false;
319di.keepold = false;
[333]320(*myDirs)[dirname] = di;
321if (myImgApp) {
322 string str = '/' + dirname;
[2492]323 if ( !_fgimgapp ) myImgApp->LockMutex();
[333]324 (myImgApp->ObjMgrW())->AddDirectory(str.c_str(), myDirId);
[2492]325 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
326}
[449]327if (verbeux) cout << "NamedObjMgr::CreateDir() " << dirname << " Created " << endl;
[344]328return(true);
[331]329}
330
331/* --Methode-- */
[344]332bool NamedObjMgr::DeleteDir(string & dirname)
[331]333{
[333]334if ( !CheckDirName(dirname) ) {
335 cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - Invalid name !" << endl;
[344]336 return(false);
[333]337 }
[2491]338ZSync(*myMutex);
[333]339NObjDirList::iterator it = myDirs->find(dirname);
340if (it == myDirs->end()) {
341 cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - No such directory !" << endl;
[344]342 return(false);
[333]343 }
344if ((*it).second.nobj > 0) {
345 cout << "NamedObjMgr::DeleteDir() " << dirname << " not empty ! " << endl;
[344]346 return(false);
[333]347 }
[344]348if ((*it).second.lock ) {
349 cout << "NamedObjMgr::DeleteDir() " << dirname << " locked ! " << endl;
350 return(false);
351 }
[333]352if ((*it).second.id < 50) {
353 cout << "NamedObjMgr::DeleteDir() " << dirname << " cannot be deleted ! " << endl;
[344]354 return(false);
[333]355 }
356
[2490]357if (myImgApp) {
[2492]358 if ( !_fgimgapp ) myImgApp->LockMutex();
[333]359 (myImgApp->ObjMgrW())->DelDirectory((*it).second.id);
[2492]360 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[2490]361}
[333]362myDirs->erase(it);
[449]363if (verbeux) cout << "NamedObjMgr::DeleteDir() " << dirname << " deleted " << endl;
[344]364return(true);
[331]365}
366
367/* --Methode-- */
[344]368void NamedObjMgr::LockDir(string & dirname)
[331]369{
[2491]370ZSync(*myMutex);
[344]371if ( !CheckDirName(dirname) ) return;
372NObjDirList::iterator it = myDirs->find(dirname);
373if (it == myDirs->end()) return;
374(*it).second.lock = true;
[449]375if (verbeux) cout << "NamedObjMgr::LockDir() " << dirname << " Locked " << endl;
[344]376return;
377}
378
379/* --Methode-- */
380void NamedObjMgr::UnlockDir(string & dirname)
381{
[2491]382ZSync(*myMutex);
[344]383if ( !CheckDirName(dirname) ) return;
384NObjDirList::iterator it = myDirs->find(dirname);
385if (it == myDirs->end()) return;
386(*it).second.lock = true;
[449]387if (verbeux) cout << "NamedObjMgr::UnlockDir() " << dirname << " Unlocked " << endl;
[344]388return;
389}
390
391/* --Methode-- */
392void NamedObjMgr::SetKeepOldDirAtt(string & dirname, bool keepold)
393{
[2491]394ZSync(*myMutex);
[344]395if ( !CheckDirName(dirname) ) return;
396NObjDirList::iterator it = myDirs->find(dirname);
397if (it == myDirs->end()) return;
398(*it).second.keepold = keepold;
[449]399if (!verbeux) return;
[344]400cout << "NamedObjMgr::SetKeepOldDirAtt() " << dirname << " -> ";
401if ( keepold ) cout << " True " << endl;
402else cout << " False " << endl;
403return;
404}
405
406
407/* --Methode-- */
408bool NamedObjMgr::SetCurrentDir(string & dirname)
409{
[2491]410ZSync(*myMutex);
[333]411if ( !CheckDirName(dirname) ) {
412 cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - Invalid name !" << endl;
[344]413 return(false);
[333]414 }
415NObjDirList::iterator it = myDirs->find(dirname);
416if (it == myDirs->end()) {
417 cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - No such directory !" << endl;
[344]418 return(false);
[333]419 }
420*currDir = dirname;
[449]421if (verbeux) cout << "NamedObjMgr::SetCurrentDir() -> " << dirname << endl;
[344]422return(true);
[331]423}
424
425/* --Methode-- */
[333]426void NamedObjMgr::GetCurrentDir(string & dirname)
427{
[2491]428ZSync(*myMutex);
[333]429dirname = *currDir;
430}
431
432/* --Methode-- */
433void NamedObjMgr::ListDirs(string & patt)
434{
[2491]435ZSync(*myMutex);
[333]436NObjDirList::iterator it;
437string cn;
438cout << "NamedObjMgr::ListDirs( " << patt << " ) " << endl;
439int k = 0;
440for(it= myDirs->begin(); it != myDirs->end(); it++) {
441 cn = (*it).first;
442 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
443 k++;
[344]444 cout << k << "- " << (*it).first;
445 if ( (*it).second.lock ) cout << " Locked " ;
446 if ( (*it).second.keepold ) cout << " KeepOld " ;
447 cout << " (Id= " << (*it).second.id << " NbObj= " << (*it).second.nobj << ")" << endl;
448
[333]449 }
450}
451
452/* --Methode-- */
453void NamedObjMgr::GetDirList(string & patt, vector<string>& lstd)
454{
[2491]455ZSync(*myMutex);
[333]456NObjDirList::iterator it;
457string cn;
458for(it= myDirs->begin(); it != myDirs->end(); it++) {
459 cn = (*it).first;
460 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
461 lstd.push_back(cn);
462 }
463}
464
465/* --Methode-- */
[368]466void NamedObjMgr::CleanDir(string & dirname)
[331]467{
[2491]468ZSync(*myMutex);
469CleanDir_P(dirname);
470}
471
472/* --Methode-- */
473void NamedObjMgr::CleanDir_P(string & dirname)
474{
[368]475if ( !CheckDirName(dirname) ) {
476 cout << "NamedObjMgr::CleanDir( " << dirname << ") Error - Invalid name !" << endl;
[380]477 // return(false); $CHECK$ illegal return value in void function
[368]478 }
479NObjDirList::iterator itr = myDirs->find(dirname);
480if (itr == myDirs->end()) {
481 cout << "NamedObjMgr::CleanDir( " << dirname << ") Error - No such directory !" << endl;
[380]482 // return(false); $CHECK$ illegal return value in void function
[368]483 }
[331]484
[368]485int did = (*itr).second.id;
486NObjList::iterator it;
487list<int>::iterator iwr;
488bool nodisp = true;
489list<string> odel;
490for(it = myObjs->begin(); it != myObjs->end(); it++) {
491 if ((*it).second.dirid != did) continue;
492 nodisp = true;
493 if (myImgApp)
494 for(iwr=(*it).second.wrsid.begin(); iwr != (*it).second.wrsid.end(); iwr++)
495 if (myImgApp->CheckWRsId(*iwr)) { nodisp = false; break; }
496 if (nodisp) odel.push_back((*it).first);
497 }
498list<string>::iterator ii;
499for(ii=odel.begin(); ii != odel.end(); ii++) DelObj(*ii,true);
[2490]500if (myImgApp) {
[2492]501 if ( !_fgimgapp ) myImgApp->LockMutex();
[685]502 (myImgApp->ObjMgrW())->UpdateList(did);
[2492]503 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[331]504}
[2490]505}
[331]506
[333]507
[368]508
[165]509//++
510// Titre Gestion de la liste des objets
511//--
512//++
[295]513// void AddObj(AnyDataObj* obj, string& nom)
[165]514// Ajoute l'objet "obj" à la liste, identifié par "nom".
515// Si un objet de même nom existe, l'ancien objet est renommé en concaténant
516// un numéro à son nom.
517// void DelObj(string const& nom, bool fgd=true)
518// Supprime l'objet "nom" de la liste. L'objet est détruit si "fgd==true" ("delete obj")
519// void DelObjects(string const& patt, bool fgd=true)
520// Supprime l'ensemble des objets dont le nom correspond au patron "patt".
521// Le patron peut contenir les caractères "*" et "?" . Les objets sont détruits si "fgd==true"
[295]522// AnyDataObj* GetObj(string const& nom)
[165]523// Retourne l'objet identifié par "nom" dans la liste. Retourne "NULL" si "nom" n'est
524// pas dans la liste.
525// void RenameObj(string const& nom, string& nomnew)
526// Change le nom d'un objet dans la liste.
[463]527// void CopyObj(string const& nom, string& nomcp)
528// Copy l'objet "nom" de la liste dans l'objet "nomcp" de la liste.
[165]529//--
530
531/* --Methode-- */
[344]532bool NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool crd)
[165]533{
[2491]534 ZSync(*myMutex);
535 return AddObj_P(obj, nom, crd);
536}
[165]537
[2491]538/* --Methode-- */
539bool NamedObjMgr::AddObj_P(AnyDataObj* obj, string & nom, bool crd)
540{
541
[344]542if (obj == NULL) return(false);
[333]543// On verifie si l'objet est deja dans la liste
544NObjList::iterator it;
545for(it = myObjs->begin(); it != myObjs->end(); it++) {
546 if ((*it).second.obj == obj) {
547 cout << "NamedObjMgr::AddObj() Object already present with name " << (*it).first << endl;
[344]548 return(false);
[333]549 }
550 }
551string nobj;
552string nrep;
553char buff[32];
554int did = ParseObjectName(nom, nrep, nobj);
555if (did == 0) {
556 if (!crd) {
557 cout << "NamedObjMgr::AddObj() No " << nrep << " Directory " << endl;
[344]558 return(false);
[333]559 }
[2491]560 else { CreateDir_P(nrep); did = myDirId; }
[333]561 }
[165]562
[466]563// Si c'est le repertoire /autoc, on nettoie
564if (nrep == "autoc") {
[2491]565 CleanDir_P(nrep);
[368]566 }
567
[165]568myNObj++;
[2218]569if ((nobj.length() < 1) || (! isalpha(nobj[0]) ) ) {
570 cout << "NamedObjMgr::AddObj() bad object name " << nobj ;
[333]571 sprintf(buff,"O%d", myNObj);
572 nobj = buff;
[2218]573 cout << " changed to " << nobj << endl;
[333]574 }
575
576nom = '/' + nrep + '/' + nobj;
[344]577NObjDirList::iterator itr = myDirs->find(nrep);
578if ((*itr).second.lock) {
579 cout << "NamedObjMgr::AddObj() " << nrep << " Locked Directory " << endl;
580 return(false);
581 }
[333]582it = myObjs->find(nom);
[165]583if (it != myObjs->end()) { // l'objet existe deja
[466]584 if (nrep == "autoc") { // Dans /autoc , on garde les objets affiches, donc del. par Clean
[368]585 sprintf(buff, "%d", (*it).second.oid);
[466]586 string nomnew = "/autoc/" + nobj + buff;
[2491]587 RenameObj_P(nom, nomnew);
[368]588 }
589 else if ( (*itr).second.keepold ) { // On met l'ancien objet dans /old
[333]590 string on,od;
[335]591// ParseObjectName((*it).first, od, on);
[333]592 sprintf(buff, "%d", (*it).second.oid);
[335]593 string nomnew = "/old/" + nobj + buff;
[2491]594 RenameObj_P(nom, nomnew);
[333]595 }
[344]596 else { // Sinon, on remplace l'objet
597 cout << "NamedObjMgr::AddObj() - Replacing " << nom << endl;
[2491]598 DelObj_P(nom);
[344]599 }
[165]600 }
601
602nobj_item no;
603no.obj = obj;
[295]604no.obja = servnobjm->GetAdapter(obj); // L'adaptateur
[333]605no.oid = myNObj;
606no.dirid = did;
[331]607(*myObjs)[nom] = no;
[333]608
609(*itr).second.nobj++;
610
[2490]611if (myImgApp != NULL) {
[2492]612 if ( !_fgimgapp ) myImgApp->LockMutex();
[2490]613 if ( (myImgApp->ObjMgrW())->Visible() ) {
614 string oln = nobj + " (T= " + no.obja->GetDataObjType() + ")" ;
615 (myImgApp->ObjMgrW())->AddObjList(did, oln.c_str(), no.oid);
[685]616 }
[2492]617 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[2490]618}
[449]619if (verbeux) cout << "NamedObjMgr::AddObj() Object " << nom << " ( "
[295]620 << typeid(*obj).name() << " ) added (Total= " << myObjs->size() << ")" << endl;
[344]621return(true);
[165]622}
623
[1224]624bool NamedObjMgr::AddObj(AnyDataObj& obj, string & nom, bool crd)
625{
[2491]626ZSync(*myMutex);
[1224]627NObjMgrAdapter* adap = GetServiceObj()->GetAdapter(&obj);
628if (adap == NULL) {
629 cout << "NamedObjMgr::AddObj() No Adapter ! " << nom << endl;
630 return(false);
631}
[1315]632AnyDataObj * cloneobj = adap->CloneDataObj(true);
[1224]633delete adap;
634if (cloneobj == NULL) {
635 cout << "NamedObjMgr::AddObj() Pb cloning object ! " << nom << endl;
636 return(false);
637}
[2491]638return ( AddObj_P(cloneobj , nom, crd) );
[1224]639}
640
[165]641/* --Methode-- */
[344]642bool NamedObjMgr::RenameObj(string & nom, string& nomnew)
[165]643{
[2491]644 ZSync(*myMutex);
645 return RenameObj_P(nom, nomnew);
646}
647
648/* --Methode-- */
649bool NamedObjMgr::RenameObj_P(string & nom, string& nomnew)
650{
[333]651string n1,r1,n2,r2;
[344]652int dids = ParseObjectName(nom, r1, n1);
653NObjDirList::iterator itr1 = myDirs->find(r1);
[333]654int did = ParseObjectName(nomnew, r2, n2);
[344]655NObjDirList::iterator itr2 = myDirs->find(r2);
656
[333]657if (did == 0) {
658 cout << "NamedObjMgr::RenameObj() Error - No " << r2 << " directory !" << endl;
[344]659 return(false);
[2218]660}
[333]661nom = '/' + r1 + '/' + n1;
662nomnew = '/' + r2 + '/' + n2;
663NObjList::iterator it1 = myObjs->find(nom);
664if (it1 == myObjs->end()) {
665 cout << "NamedObjMgr::RenameObj() Error - No " << nom << " object !" << endl;
[344]666 return(false);
[2218]667}
668if ((n2.length() < 1) || (! isalpha(n2[0])) ) {
669 cout << "NamedObjMgr::RenameObj() Error - bad new object name" << n2 << endl;
670 return(false);
671}
[333]672NObjList::iterator it2 = myObjs->find(nomnew);
673if (it2 != myObjs->end()) {
674 cout << "NamedObjMgr::RenameObj() Error - Object " << nomnew << " exist !" << endl;
[344]675 return(false);
[333]676 }
677
[344]678if ( (*itr1).second.lock || (*itr2).second.lock ) {
679 cout << "NamedObjMgr::RenameObj() Error - Source or destination directory locked !"
680 << endl;
681 return(false);
682 }
683
684
[333]685nobj_item no = (*it1).second;
686no.dirid = did;
687myObjs->erase(it1);
688NObjDirList::iterator itr = myDirs->find(r1);
689(*itr).second.nobj--;
690(*myObjs)[nomnew] = no;
691itr = myDirs->find(r2);
692(*itr).second.nobj++;
[685]693
[2490]694if (myImgApp != NULL) {
[2492]695 if ( !_fgimgapp ) myImgApp->LockMutex();
[2490]696 if ( (myImgApp->ObjMgrW())->Visible() ) {
697 (myImgApp->ObjMgrW())->DelObjList(dids, no.oid);
698 string oln = n2 + " (T= " + no.obja->GetDataObjType() + ")" ;
699 (myImgApp->ObjMgrW())->AddObjList(did, oln.c_str(), no.oid);
700 }
[2492]701 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[685]702}
[449]703if (verbeux)
704 cout << "NamedObjMgr::RenameObj() - Object " << nom << " renamed to " << nomnew << endl;
[344]705return(true);
[331]706}
707
708/* --Methode-- */
[463]709bool NamedObjMgr::CopyObj(string & nom, string& nomcp)
710{
[2491]711ZSync(*myMutex);
[463]712if(nomcp.length()<=0)
713 {cout<<"NamedObjMgr::CopyObj() Error, copied obj name "<<nomcp<<" not valid"<<endl;
714 return(false);}
715NObjMgrAdapter* obnom = GetObjAdapter(nom);
716if(obnom==NULL)
717 {cout<<"NamedObjMgr::CopyObj() Error - No "<<nom<<" object !"<<endl;
718 return(false);}
[1165]719AnyDataObj* obnomcp = obnom->CloneDataObj();
[463]720if(obnomcp==NULL) return(false);
[2491]721if(! AddObj_P(obnomcp,nomcp,false) ) {delete obnomcp; return(false);}
[463]722return true;
723}
724
725/* --Methode-- */
[344]726bool NamedObjMgr::DelObj(string & nom, bool fgd)
[331]727{
[2491]728 ZSync(*myMutex);
729 return DelObj_P(nom, fgd);
730}
731
732/* --Methode-- */
733bool NamedObjMgr::DelObj_P(string & nom, bool fgd)
734{
[333]735string n1,r1;
[685]736int did = ParseObjectName(nom, r1, n1);
[333]737nom = '/' + r1 + '/' + n1;
[165]738NObjList::iterator it = myObjs->find(nom);
[344]739if (it == myObjs->end()) return(false);
740NObjDirList::iterator itr = myDirs->find(r1);
741if ( (*itr).second.lock ) {
742 cout << "NamedObjMgr::DelObj() Error - Locked directory " << r1 << endl;
743 return(false);
744 }
[165]745list<int>::iterator ii;
746if (myImgApp) {
747//DBG cerr << " *DBG* NamedObjMgr::DelObj Sz= " << (*it).second.wrsid.size() << endl;
[2492]748// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
749 bool fglock = (_fgimgapp) ? false : true;
750 if (fglock) myImgApp->LockMutex();
[165]751 for(ii=(*it).second.wrsid.begin(); ii != (*it).second.wrsid.end(); ii++)
752 myImgApp->DelWRsId((*ii));
[2492]753 if (fglock) myImgApp->UnlockMutex(true);
[165]754}
[314]755delete (*it).second.obja; // destruction de l'adaptateur
[165]756if (fgd) delete (*it).second.obj;
[333]757
[2490]758if (myImgApp != NULL) {
[2492]759 if ( !_fgimgapp ) myImgApp->LockMutex();
[2490]760 if ( (myImgApp->ObjMgrW())->Visible() ) {
761 int olid = (*it).second.oid;
762 (myImgApp->ObjMgrW())->DelObjList(did, olid);
763 }
[2492]764 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[685]765}
[165]766myObjs->erase(it);
[333]767(*itr).second.nobj--;
768
[685]769
[449]770if (!verbeux) return(true);
[165]771if (fgd) cout << "NamedObjMgr::DelObj() Object " << nom << " deleted (Total= " << myObjs->size() << ")" << endl;
772else cout << "NamedObjMgr::DelObj() Object " << nom << " removed (Total= " << myObjs->size() << ")" << endl;
[344]773return(true);
[165]774}
775
776/* --Methode-- */
[344]777bool NamedObjMgr::DelObj_Id(int oid)
[165]778{
[2491]779ZSync(*myMutex);
[333]780NObjList::iterator it;
781string nom;
782bool of = false;
783for(it = myObjs->begin(); it != myObjs->end(); it++)
784 if ( (*it).second.oid == oid ) {
785 of = true; nom = (*it).first;
786 break;
787 }
[344]788if (of) return(DelObj(nom, true));
789else return(false);
[331]790}
791
792/* --Methode-- */
793void NamedObjMgr::DelObjects(string & patt, bool fgd)
794{
[2491]795ZSync(*myMutex);
[333]796string n1,r1;
797ParseObjectName(patt, r1, n1);
798patt = '/' + r1 + '/' + n1;
[165]799NObjList::iterator it;
800list<string> odel;
801string cn;
802for(it = myObjs->begin(); it != myObjs->end(); it++) {
803 cn = (*it).first;
804 if (csh_parse(cn.c_str(), patt.c_str()) != 0) odel.push_back(cn);
805 }
806list<string>::iterator ii;
[2491]807for(ii=odel.begin(); ii != odel.end(); ii++) DelObj_P(*ii, fgd);
[165]808}
809
810/* --Methode-- */
[331]811AnyDataObj* NamedObjMgr::GetObj(string & nom)
[165]812{
[2491]813ZSync(*myMutex);
[333]814string n1,r1;
815ParseObjectName(nom, r1, n1);
816nom = '/' + r1 + '/' + n1;
[165]817NObjList::iterator it = myObjs->find(nom);
818if (it == myObjs->end()) return(NULL);
819return((*it).second.obj);
820}
821
822/* --Methode-- */
[331]823NObjMgrAdapter* NamedObjMgr::GetObjAdapter(string & nom)
[295]824{
[2491]825ZSync(*myMutex);
[333]826string n1,r1;
827ParseObjectName(nom, r1, n1);
828nom = '/' + r1 + '/' + n1;
[295]829NObjList::iterator it = myObjs->find(nom);
830if (it == myObjs->end()) return(NULL);
831return((*it).second.obja);
832}
833
834/* --Methode-- */
[331]835void NamedObjMgr::ListObjs(string & patt)
[165]836{
[2491]837ZSync(*myMutex);
[331]838int k;
839AnyDataObj* obj=NULL;
840string ctyp;
841char strg[256];
842
[333]843string n1,r1;
844ParseObjectName(patt, r1, n1);
845patt = '/' + r1 + '/' + n1;
846 cout << "NamedObjMgr::ListObjs( " << patt << " ) TotNObjs= " << myObjs->size() << "\n" ;
[331]847NObjList::iterator it; k = 0;
[333]848string cn;
[331]849for(it = myObjs->begin(); it != myObjs->end(); it++) {
[333]850 cn = (*it).first;
851 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
[331]852 obj = (*it).second.obj;
853 ctyp = typeid(*obj).name();
854 sprintf(strg, "%2d/ %16s : %s", k, typeid(*obj).name(), ((*it).first).c_str());
855 ctyp = strg;
856 cout << ctyp << "\n" ;
857 k++;
858}
859cout << endl;
[165]860return;
861}
862
863/* --Methode-- */
[333]864void NamedObjMgr::GetObjList(string & patt, vector<string> &lst)
[165]865{
[2491]866ZSync(*myMutex);
[333]867string n1,r1;
868if (patt.length() < 1) return;
869bool fgr = (patt[0] == '/') ? true : false;
870ParseObjectName(patt, r1, n1);
871patt = '/' + r1 + '/' + n1;
872NObjList::iterator it;
873string cn;
874for(it = myObjs->begin(); it != myObjs->end(); it++) {
875 cn = (*it).first;
876 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
877 if (fgr) lst.push_back(cn);
878 else {
879 ParseObjectName(cn, r1, n1);
880 lst.push_back(n1);
881 }
882 }
[165]883}
884
885//++
886// Titre Entrées-Sorties (I/O) sur les objets
887//--
888//++
889// void ReadObj(PInPersist& s, int num=-1)
890// Lit l'objet à partir avec le tag numéro "num" dans le flot "PInPersist s"
891// et l'ajoute à la liste. Si "num" est négatif, tous les objets présents
892// sur le flot "s" sont créés et ajoutés à la liste.
893// void ReadObj(string const & nomppf, string nobj="")
894// Lit le premier objet à partir du fichier PPF "nomppf". L'objet est ajouté
895// à la liste avec le nom "nobj". Si "nobj" est une chaîne vide, un nom est
896// composé à partir du nom de fichier.
897//--
898
899/* --Methode-- */
[331]900void NamedObjMgr::ReadObj(string const & flnm, string & nobj)
[165]901{
[2491]902ZSync(*myMutex);
[495]903PPersist* ppobj=NULL;
[165]904bool ok = true;
[495]905#ifdef SANS_EVOLPLANCK
[165]906TRY{
907 PInPersist pis(flnm);
[495]908 ppobj = PPersistMgr::ReadObject(pis);
909 if (ppobj == NULL) ok = false;
[165]910} CATCH(merr)
911 { printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n",
912 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
[495]913#else
914try {
915 PInPersist pis(flnm);
916 ppobj = pis.ReadObject();
917 }
918catch (IOExc iox) {
919 cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
920 ok = false;
921 }
922#endif
[165]923if (!ok) return;
924if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
[2491]925AddObj_P(ppobj->DataObj(), nobj, true);
[685]926cout << "NamedObjMgr::ReadObj(...) object " << nobj << " read from file " << endl;
[165]927return;
928}
929
930/* --Methode-- */
931void NamedObjMgr::ReadObj(PInPersist& s, int num)
932{
[2491]933ZSync(*myMutex);
[2180]934int_4 i; // $CHECK$ int -> int_4 a cause de TagKey
935#ifdef SANS_EVOLPLANCK
936int_4 cid, key, ln; // $CHECK$ int -> int_4 a cause de TagKey
937#endif
[165]938int n0, n1;
939bool ok = true;
940PPersist* obj=NULL;
941string nom;
942
[449]943int nread = 0;
[2460]944int nbtags = 0;
945#ifdef SANS_EVOLPLANCK
946nbtags = s.NbTags();
947#else
948nbtags = s.NbNameTags();
949#endif
950if ( (nbtags < 1) || (num >= nbtags) ) {
[165]951 if (num >= 0) {
[495]952 cerr << "NamedObjMgr::ReadObj(PInPersist, " << num << " Error! NbTags ="
[2460]953 << nbtags << endl;
[165]954 return;
955 }
[495]956
957#ifdef SANS_EVOLPLANCK
[165]958 TRY {
959 obj = PPersistMgr::ReadObject(s);
960 if (obj == NULL) ok = false;
961 } CATCH(merr) {
962 printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
963 ok = false;
964 } ENDTRY;
[495]965#else
966try {
967 obj = s.ReadObject();
968 }
969catch (IOExc iox) {
970 cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
971 ok = false;
972 }
973#endif
974
[165]975 if (!ok) return;
976 nom = "";
[2491]977 AddObj_P(obj->DataObj(), nom, false);
[449]978 nread++;
[165]979}
980
[2460]981if (num < 0) { n0 = 0; n1 = nbtags; }
[165]982else { n0 = num; n1 = num+1; }
983for(i=n0; i<n1; i++) {
[495]984#ifdef SANS_EVOLPLANCK
[165]985 key = s.TagKey(i, cid, ln);
986 if (ln <= 0) nom = "";
987 else nom = s.TagName(i);
988 s.GotoTag(i);
989 TRY {
990 obj = PPersistMgr::ReadObject(s);
991 if (obj == NULL) ok = false;
992 } CATCH(merr) {
993 printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
994 ok = false;
995 } ENDTRY;
[495]996#else
[2460]997 s.GotoNameTagNum(i);
[584]998 nom = s.GetTagName(i);
[495]999 try {
1000 obj = s.ReadObject();
1001 }
1002 catch (IOExc iox) {
1003 cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
1004 ok = false;
1005 }
1006#endif
[2491]1007 if (ok) { AddObj_P(obj->DataObj(), nom, true); nread++; }
[165]1008}
1009
[449]1010cout << "NamedObjMgr::ReadObj(...) " << nread << " Objects read " << endl;
[165]1011return;
1012}
1013/* --Methode-- */
1014void NamedObjMgr::ReadAll(string const & flnm)
1015{
[2491]1016ZSync(*myMutex);
[165]1017bool ok = true;
1018PPersist* obj=NULL;
1019
[2180]1020PInPersist* ppin=NULL;
[495]1021#ifdef SANS_EVOLPLANCK
[165]1022TRY{
1023 ppin = new PInPersist(flnm);
1024 if (ppin->NbTags() < 1) obj = PPersistMgr::ReadObject((*ppin));
1025 else obj = NULL;
1026} CATCH(merr)
1027 { printf("NamedObjMgr::ReadAll()/Error Exception= %ld (%s) \n",
1028 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
[495]1029#else
1030try {
1031 ppin = new PInPersist(flnm);
[2460]1032 if (ppin->NbNameTags() < 1) obj = ppin->ReadObject();
[495]1033 else obj = NULL;
1034}
1035catch (IOExc iox) {
1036 cerr << "NamedObjMgr::ReadAll()/Error Exception - Msg= " << iox.Msg() << endl;
1037 ok = false;
1038}
1039#endif
[165]1040if (!ok) return;
1041if (obj) {
1042 string nom = servnobjm->FileName2Name(flnm);
[2491]1043 AddObj_P(obj->DataObj(), nom, false);
[165]1044 }
1045else ReadObj((*ppin), -1);
1046delete ppin;
1047return;
1048}
1049
1050/* --Methode-- */
[331]1051void NamedObjMgr::ReadFits(string const & flnm, string & nobj)
[165]1052{
[2491]1053ZSync(*myMutex);
[293]1054#ifdef SANS_EVOLPLANCK
[2180]1055bool ok = false;
[709]1056RzImage* obj=NULL;
[495]1057TRY{
[165]1058 obj = RzReadFits((char*)flnm.c_str());
1059 if (obj == NULL) ok = false;
[709]1060 else ok = true;
[165]1061} CATCH(merr) {
1062 printf("NamedObjMgr::ReadFITS(_Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
1063 ok = false;
1064} ENDTRY;
[709]1065
1066if (ok && (obj != NULL)) {
[165]1067 if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
[2491]1068 AddObj_P((AnyDataObj*)obj, nobj);
[165]1069}
[1105]1070#else
[1321]1071 try {
1072 FITS_AutoReader fiar(flnm);
[1335]1073 char bun[16];
1074 int nhdu = fiar.NbBlocks();
[1321]1075 if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
1076 string name;
1077 AnyDataObj* obj;
[1513]1078 int kon = 1;
[1321]1079 for(int k=1; k<=nhdu; k++) {
1080 obj = fiar.ReadObject(k);
[1330]1081 if (obj) {
[1321]1082 cout << " NamedObjMgr::ReadFits() " << (string)typeid(*obj).name()
1083 << " read From HDU " << k << endl;
[1513]1084 if (typeid(*obj) == typeid(DVList)) {
1085 delete obj;
1086 continue;
1087 }
1088 if (kon > 1) {
1089 sprintf(bun, "%d", kon);
[1330]1090 name = nobj + bun;
1091 }
1092 else name = nobj;
[2491]1093 AddObj_P(obj, name, false);
[1513]1094 kon++;
[1330]1095 }
[1321]1096 else cerr << " NamedObjMgr::ReadFits() NULL pointer from FITS_AutoReader" << endl;
1097 }
1098 }
1099 catch(PThrowable & exc) {
1100 cerr << " NamedObjMgr::ReadFits() / Error - Catched Exception \n "
1101 << " Type= " << (string)typeid(exc).name()
1102 << " - Msg= " << exc.Msg() << endl;
1103
1104 }
[1105]1105#endif
1106
[165]1107return;
1108}
1109
[2491]1110/* --Methode-- */
1111void NamedObjMgr::SaveObj(string & nom, POutPersist& s, bool keeppath)
1112{
1113 ZSync(*myMutex);
1114 SaveObj_P(nom, s, keeppath);
1115}
[165]1116
1117static int key_for_write = 5000;
1118/* --Methode-- */
[2491]1119void NamedObjMgr::SaveObj_P(string & nom, POutPersist& s, bool keeppath)
[165]1120{
[333]1121if (nom.length() < 1) return;
1122string nob,rep;
1123ParseObjectName(nom, rep, nob);
1124nom = '/' + rep + '/' + nob;
[295]1125NObjMgrAdapter* obja=NULL;
[333]1126string nomf = (keeppath) ? nom : nob;
[295]1127obja = GetObjAdapter(nom);
1128if (obja == NULL) return;
[165]1129printf("NamedObjMgr::SaveObj(%s, ) (Type=%s) \n",
[295]1130 nom.c_str(), typeid(*(obja->GetDataObj())).name());
[333]1131obja->SavePPF(s, nomf);
[165]1132return;
1133}
1134
1135/* --Methode-- */
[333]1136void NamedObjMgr::SaveObjects(string & patt, string const& flnm)
1137{
[2491]1138ZSync(*myMutex);
[333]1139string n1,r1;
1140if (patt.length() < 1) return;
1141bool keeppath = (patt[0] == '/') ? true : false;
1142ParseObjectName(patt, r1, n1);
1143patt = '/' + r1 + '/' + n1;
1144
1145bool ok = true;
[2180]1146POutPersist* pout=NULL;
[495]1147#ifdef SANS_EVOLPLANCK
[333]1148TRY{
1149 pout = new POutPersist(flnm);
1150} CATCH(merr)
1151 { printf("NamedObjMgr::SaveObjects()/Error Exception= %ld (%s) \n",
1152 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
[495]1153#else
1154try {
1155 pout = new POutPersist(flnm);
1156}
1157catch (IOExc iox) {
1158 cerr << "NamedObjMgr::SaveObjects()/Error Exception - Msg= " << iox.Msg() << endl;
1159 ok = false;
1160}
1161#endif
[333]1162if (!ok) return;
1163NObjList::iterator it;
1164string cn;
1165for(it = myObjs->begin(); it != myObjs->end(); it++) {
1166 cn = (*it).first;
1167 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
[2491]1168 SaveObj_P(cn, (*pout), keeppath);
[333]1169 }
1170delete pout;
1171return;
1172}
1173
1174/* --Methode-- */
[165]1175void NamedObjMgr::SaveAll(string const& flnm)
1176{
[2491]1177ZSync(*myMutex);
[165]1178bool ok = true;
1179
[2180]1180POutPersist* pout=NULL;
[495]1181#ifdef SANS_EVOLPLANCK
[165]1182TRY{
1183 pout = new POutPersist(flnm);
1184} CATCH(merr)
1185 { printf("NamedObjMgr::SaveAll()/Error Exception= %ld (%s) \n",
1186 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
[495]1187#else
1188try {
1189 pout = new POutPersist(flnm);
1190}
1191catch (IOExc iox) {
1192 cerr << "NamedObjMgr::SaveAll()/Error Exception - Msg= " << iox.Msg() << endl;
1193 ok = false;
1194}
1195#endif
[165]1196if (!ok) return;
[332]1197NObjList::iterator it;
1198string no;
1199for(it = myObjs->begin(); it != myObjs->end(); it++) {
1200 no = (*it).first;
[2491]1201 SaveObj_P(no, (*pout), true);
[332]1202 }
[165]1203delete pout;
1204return;
1205}
1206
1207/* --Methode-- */
[331]1208void NamedObjMgr::SaveFits(string& nom, string const & flnm)
[165]1209{
[2491]1210ZSync(*myMutex);
1211
[295]1212NObjMgrAdapter* obja=NULL;
1213obja = GetObjAdapter(nom);
1214if (obja == NULL) return;
1215obja->SaveFits(flnm);
[293]1216return;
[165]1217}
1218
1219
1220
1221/* --Methode-- */
[331]1222void NamedObjMgr::PrintObj(string& nom)
[165]1223{
[2491]1224ZSync(*myMutex);
[295]1225NObjMgrAdapter* obja=NULL;
1226obja = GetObjAdapter(nom);
1227if (obja == NULL) return;
[594]1228AnyDataObj* ob = obja->GetDataObj();
1229if (ob == NULL) {
1230 cerr << "NamedObjMgr::PrintObj() / Error - NULL object ! in " << nom << endl;
1231 return;
1232 }
1233string ctyp = typeid(*ob).name();
[295]1234cout << "NamedObjMgr::PrintObj(" << nom << ") Type: " << ctyp << endl;
1235obja->Print(cout);
[165]1236
1237return;
1238}
1239
1240/* --Methode-- */
[331]1241void NamedObjMgr::DisplayObj(string& nom, string dopt)
[165]1242{
[2491]1243ZSync(*myMutex);
1244
[295]1245NObjMgrAdapter* obja=NULL;
1246obja = GetObjAdapter(nom);
1247if (obja == NULL) {
[594]1248 cout << "NamedObjMgr::DisplayObj() Error , No object with name " << nom << endl;
[165]1249 return;
1250}
[594]1251if (obja->GetDataObj() == NULL) {
1252 cerr << "NamedObjMgr::DisplayObj() / Error - NULL object ! in " << nom << endl;
1253 return;
1254 }
[165]1255if (!myImgApp) return;
1256
[295]1257PIDrawer * dr = NULL;
1258P2DArrayAdapter* arr = NULL;
1259dr = obja->GetDrawer(dopt);
1260if (!dr) arr = obja->Get2DArray(dopt);
[165]1261
[295]1262if (!dr && !arr) {
1263 string ctyp = typeid(*(obja->GetDataObj())).name();
[594]1264 cout << "NamedObjMgr::DisplayObj() Error , No display for " << ctyp << endl;
[295]1265 return;
1266 }
1267
[165]1268int wrsid = 0;
1269
[344]1270string n1,r1;
1271ParseObjectName(nom, r1, n1);
1272
[2491]1273// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1274bool fglock = (_fgimgapp) ? false : true;
1275
[295]1276if (dr) {
1277 PIDrawer3D * dr3 = dynamic_cast<PIDrawer3D *>(dr);
[2491]1278 if(dr3) wrsid = myImgApp->Disp3DDrawer(dr3, n1, dopt, "", 0, fglock);
1279 else wrsid = myImgApp->DispScDrawer( dr, n1, dopt, "", 0, fglock);
[295]1280 }
[2491]1281else if (arr) wrsid = myImgApp->DispImage(arr, n1, dopt, 0, fglock);
[165]1282
[2402]1283AddWRsId(nom, wrsid);
[295]1284return;
1285}
[165]1286
[295]1287/* --Methode-- */
[331]1288void NamedObjMgr::DisplayImage(string& nom, string dopt)
[295]1289{
[2491]1290ZSync(*myMutex);
1291
[295]1292NObjMgrAdapter* obja=NULL;
1293obja = GetObjAdapter(nom);
1294if (obja == NULL) {
[449]1295 cout << "NamedObjMgr::DisplayImage() Error , No such object " << nom << endl;
[295]1296 return;
1297}
[594]1298if (obja->GetDataObj() == NULL) {
1299 cerr << "NamedObjMgr::DisplayImage() / Error - NULL object ! in " << nom << endl;
1300 return;
1301 }
[295]1302if (!myImgApp) return;
1303
1304P2DArrayAdapter* arr = obja->Get2DArray(dopt);
[165]1305
[295]1306if (!arr) {
1307 string ctyp = typeid(*(obja->GetDataObj())).name();
[449]1308 cout << "NamedObjMgr::DisplayImage() Error , Not supported for " << ctyp << endl;
[295]1309 return;
1310 }
[165]1311
[344]1312string n1,r1;
1313ParseObjectName(nom, r1, n1);
1314
[2491]1315// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1316bool fglock = (_fgimgapp) ? false : true;
1317
[295]1318int wrsid = 0;
[2491]1319wrsid = myImgApp->DispImage(arr, n1, dopt, 0, fglock);
[165]1320
[2402]1321AddWRsId(nom, wrsid);
[295]1322return;
1323}
1324/* --Methode-- */
[331]1325void NamedObjMgr::DisplaySurf3D(string& nom, string dopt)
[295]1326{
[2491]1327ZSync(*myMutex);
1328
[295]1329NObjMgrAdapter* obja=NULL;
1330obja = GetObjAdapter(nom);
1331if (obja == NULL) {
[449]1332 cout << "NamedObjMgr::DisplaySurf3D() Error , No such object " << nom << endl;
[295]1333 return;
1334}
[594]1335if (obja->GetDataObj() == NULL) {
1336 cerr << "NamedObjMgr::DisplaySurf3D() / Error - NULL object ! in " << nom << endl;
1337 return;
1338 }
[295]1339if (!myImgApp) return;
1340
1341P2DArrayAdapter* arr = obja->Get2DArray(dopt);
[165]1342
[295]1343if (!arr) {
1344 string ctyp = typeid(*(obja->GetDataObj())).name();
[449]1345 cout << "NamedObjMgr::DisplaySurf3D() Error , Not supported " << ctyp << endl;
[295]1346 return;
1347 }
[165]1348
[295]1349if ((arr->XSize() > 250) || (arr->YSize() > 250)) {
1350 cout << "NamedObjMgr::DisplaySurf3D() Error , 2D-Array(" << arr->XSize()
[449]1351 << "x" << arr->YSize() << ") too big (max=250x250)" << endl;
[295]1352 delete arr;
1353 return;
[165]1354 }
1355
[344]1356string n1,r1;
1357ParseObjectName(nom, r1, n1);
1358
[2491]1359// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1360bool fglock = (_fgimgapp) ? false : true;
1361
[295]1362int wrsid = 0;
1363PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
[2491]1364wrsid = myImgApp->Disp3DDrawer(sdr, n1, dopt, "", 0, fglock);
[2402]1365AddWRsId(nom, wrsid);
[295]1366return;
[165]1367}
1368
1369/* --Methode-- */
[331]1370void NamedObjMgr::DisplayNT(string& nom, string& nmx, string& nmy, string& nmz,
[486]1371 string& erx, string& ery, string& erz, string& wt,
1372 string& label, string dopt, bool fg3d)
[165]1373{
[2491]1374ZSync(*myMutex);
1375
[295]1376AnyDataObj* obj=GetObj(nom);
[165]1377if (obj == NULL) {
[449]1378 cout << "NamedObjMgr::DisplayNT() Error , No such object " << nom << endl;
[165]1379 return;
1380}
1381if (!myImgApp) return;
1382
[326]1383NTupleInterface * nt = dynamic_cast<NTupleInterface *>(obj);
1384if (nt == NULL) {
1385// if (typeid(*obj) != typeid(NTupleInterface)) {
[295]1386 string ctyp = typeid(*obj).name();
[449]1387 cout << "NamedObjMgr::DisplayNT() Error , Object not an NTuple " << ctyp << endl;
[165]1388 return;
1389 }
1390
1391int wrsid = 0;
[1971]1392dopt = "defline " + dopt;
[165]1393
[344]1394string n1,r1;
1395ParseObjectName(nom, r1, n1);
1396
[2491]1397// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1398bool fglock = (_fgimgapp) ? false : true;
1399
[333]1400if ( fg3d && (nmz.length()>0) ) { // Display 3D
[326]1401 PINTuple3D* pin = new PINTuple3D(nt, false);
[165]1402 pin->SelectXYZ(nmx.c_str(), nmy.c_str(), nmz.c_str());
[486]1403 pin->SelectWt(wt.c_str());
1404 pin->SelectLabel(label.c_str());
[165]1405 pin->SelectErrBar(erx.c_str(), ery.c_str(), erz.c_str());
1406 string titre = nmz + "%" + nmy + "%" + nmz;
[2491]1407 wrsid = myImgApp->Disp3DDrawer(pin, n1, dopt, titre, 0, fglock);
[165]1408}
1409else {
[326]1410 PINTuple* pin = new PINTuple(nt, false);
[165]1411 pin->SelectXY(nmx.c_str(), nmy.c_str());
[486]1412 pin->SelectWt(wt.c_str());
1413 pin->SelectLabel(label.c_str());
[165]1414 pin->SelectErrBar(erx.c_str(), ery.c_str());
[333]1415 string titre = nmy + "%" + nmx;
[2491]1416 wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, n1, dopt, titre, 0, fglock);
[165]1417 }
1418
[2402]1419AddWRsId(nom, wrsid);
[165]1420return;
1421}
1422
[339]1423/* --Methode-- cmv 13/10/98 : Obsolete mais ne pas virer SVP */
[331]1424void NamedObjMgr::DisplayGFD(string& nom, string& numvarx, string& numvary, string& err, string dopt)
[165]1425// Pour le display 2D ou 3D d'un ``GeneralFitData''.
1426//| nom = nom de l'objet GeneralFitData a representer.
1427//| numvarx = numero (nombre entier) de la 1ere variable d'abscisse.
1428//| numvary = numero (nombre entier) de la 2sd variable d'abscisse (3D).
1429//| Pour le display 2D, numvary="" string vide.
1430//| err = qu'elles erreurs faut il representer ?
1431//| - 2D : x y xy (display y=f(x))
1432//| - 3D : x y z xy xz yz xzy (display z=f(x,y))
1433//| Ceci n'est suivi que si on a PI_NotDefLineAtt, sinon toutes
1434//| les barres d'erreurs sont representees.
1435//| opt = options generales pour le display.
1436{
[2491]1437ZSync(*myMutex);
1438
[295]1439AnyDataObj* obj=GetObj(nom);
[165]1440if(obj == NULL)
[449]1441 {cout << "NamedObjMgr::DisplayGFD() Error , No such object " << nom << endl;
[165]1442 return;}
1443if(!myImgApp) return;
[295]1444if(typeid(*obj) != typeid(GeneralFitData))
1445 {string ctyp = typeid(*obj).name();
[449]1446 cout<<"NamedObjMgr::DisplayGFD() Error , Object not a GeneralFitData "<<ctyp<<endl;
[165]1447 return;}
1448
1449// Decodage des erreurs a representer
1450bool errx=false, erry=false, errz=false;
1451if(err.length()>0) {
[2180]1452 for(int i=0;i<(int_4)err.length();i++)
[165]1453 if (err[i]=='x' || err[i]=='X') errx = true;
1454 else if(err[i]=='y' || err[i]=='Y') erry = true;
1455 else if(err[i]=='z' || err[i]=='Z') errz = true;
1456}
1457// Decodage des numeros de variables en abscisse
[339]1458 int numvx=-1, numvy=-1;
1459 if(numvarx.length()>0) numvx = atoi(numvarx.c_str());
1460 if(numvary.length()>0) numvy = atoi(numvary.c_str());
1461
[344]1462 string n1,r1;
1463 ParseObjectName(nom, r1, n1);
[2491]1464 // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1465 bool fglock = (_fgimgapp) ? false : true;
[344]1466
[339]1467 int wrsid = 0;
1468 if(numvy>=0) { // display 3D
[165]1469 PIGenFitDat3D* pigfd = new PIGenFitDat3D(((GeneralFitData*)obj),false);
1470 pigfd->SelectXY(numvx,numvy);
1471 pigfd->SelectErrBar(errx,erry,errz);
[2491]1472 wrsid = myImgApp->Disp3DDrawer(pigfd,n1,dopt,"",0,fglock);
[339]1473} else { // display 2D
[165]1474 PIGenFitDat* pigfd = new PIGenFitDat(((GeneralFitData*)obj),false);
1475 pigfd->SelectX(numvx);
1476 pigfd->SelectErrBar(errx,erry);
[2491]1477 wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,n1,dopt,"",0,fglock);
[165]1478}
1479
[2402]1480AddWRsId(nom, wrsid);
[1971]1481
[165]1482return;
1483}
1484
[1525]1485/* --Methode-- */
1486void NamedObjMgr::DisplayVector(string & nomvx, string& nomvy, string dopt)
1487// Pour l'affichage 2-D de points avec coordonnees definies par deux vecteurs
1488// nomvx et nomvy
1489{
[2491]1490ZSync(*myMutex);
1491
[1525]1492#ifdef SANS_EVOLPLANCK
1493 cerr << " NamedObjMgr::DisplayVector() Error: Not implemented with PEIDA " << endl;
1494#else
1495
1496if(!myImgApp) return;
1497
1498AnyDataObj* obj;
1499obj = GetObj(nomvx);
1500if(obj == NULL) {
1501 cout << "NamedObjMgr::DisplayVector() Error , No such object " << nomvx << endl;
1502 return;
1503}
[2263]1504//Vector * vx = dynamic_cast<Vector *>(obj);
1505BaseArray* bax = dynamic_cast<BaseArray *>(obj);
1506if (bax == NULL) {
1507 cout << "NamedObjMgr::DisplayVector() Error " << nomvx << " not a BaseArray ! " << endl;
[1525]1508 return;
1509}
1510
1511obj = GetObj(nomvy);
1512if(obj == NULL) {
1513 cout << "NamedObjMgr::DisplayVector() Error , No such object " << nomvy << endl;
1514 return;
1515}
[2263]1516BaseArray* bay = dynamic_cast<BaseArray *>(obj);
1517if (bay == NULL) {
1518 cout << "NamedObjMgr::DisplayVector() Error " << nomvy << " not a BaseArray ! " << endl;
[1525]1519 return;
1520}
1521
[2263]1522Vector vx = *bax;
1523Vector vy = *bay;
[1525]1524Vector * cvx, * cvy;
1525
[2263]1526if (vx.Size() != vy.Size()) {
[1525]1527 cout << "NamedObjMgr::DisplayVector() Warning / Vx.Size() != Vy.Size() " << endl;
[2263]1528 if (vx.Size() < vy.Size()) {
1529 cvx = new Vector(vx);
1530 cvy = new Vector(vy.SubVector(Range(0, 0, vx.Size()-1)));
[1525]1531 }
1532 else {
[2263]1533 cvx = new Vector(vx.SubVector(Range(0, 0, vy.Size()-1)));
1534 cvy = new Vector(vy);
[1525]1535 }
1536}
1537else {
[2263]1538 cvx = new Vector(vx);
1539 cvy = new Vector(vy);
[1525]1540}
1541
1542POVectorAdapter * avx = new POVectorAdapter(cvx, true);
1543POVectorAdapter * avy = new POVectorAdapter(cvy, true);
1544PIYfXDrawer * vxydrw = new PIYfXDrawer(avx, avy, true);
1545
1546string nx,rx;
1547ParseObjectName(nomvx, rx, nx);
1548string ny,ry;
1549ParseObjectName(nomvy, ry, ny);
1550
[2491]1551// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1552bool fglock = (_fgimgapp) ? false : true;
1553
[1525]1554string title = ny + " (Y) vs. " + nx + " (X)";
1555// display 2D
[2491]1556myImgApp->DispScDrawer(vxydrw, title, dopt, "", 0, fglock);
[1525]1557
1558return;
1559
1560#endif
1561}
1562
[165]1563/* --Methode--
[331]1564void NamedObjMgr::DisplayImage(string& nom, string dopt)
[165]1565{
1566 cout << "NamedObjMgr::DisplayImage() a faire ! " << endl;
1567}
1568*/
1569
1570
1571
1572
[1971]1573/* --Methode--
[165]1574void NamedObjMgr::SetGraphicAttributes(string gratt)
1575{
1576bool fg = false;
1577servnobjm->DecodeDispOption(gratt, fg);
[546]1578Services2NObjMgr::SetDefaultStatsOption(Services2NObjMgr::GetStatsOption(gratt));
[165]1579}
[333]1580
[165]1581void NamedObjMgr::SetGraphicWinZone(int nzx, int nzy, bool fcr)
1582{
1583if (!myImgApp) return;
1584if (fcr) myImgApp->CreateGraphWin(nzx, nzy);
1585else myImgApp->SetZone(nzx, nzy);
1586}
[1971]1587*/
[165]1588
1589/* --Methode-- */
[333]1590void NamedObjMgr::AddWRsId(string & nom, int wrsid)
[165]1591{
[333]1592if(wrsid != 0) {
1593 NObjList::iterator it = myObjs->find(nom);
1594 if (it == myObjs->end()) return;
1595 (*it).second.wrsid.push_back(wrsid);
[295]1596 }
[165]1597return;
1598}
1599
1600/* --Methode-- */
[333]1601void NamedObjMgr::UpdateObjMgrWindow(int did)
[165]1602{
[333]1603if (!myImgApp) return;
[2491]1604ZSync(*myMutex);
[2492]1605if ( !_fgimgapp ) myImgApp->LockMutex();
[2490]1606
[685]1607(myImgApp->ObjMgrW())->ClearObjList();
[165]1608
[333]1609NObjList::iterator it;
1610string cn;
1611for(it = myObjs->begin(); it != myObjs->end(); it++) {
1612 if ((*it).second.dirid != did) continue;
1613 cn = (*it).first.substr(1);
[1321]1614 // cn = cn.substr(cn.find('/')+1) + " (T= " + typeid(*((*it).second.obj)).name() + ")" ;
1615 cn = cn.substr(cn.find('/')+1) + " (T= " + (*it).second.obja->GetDataObjType() + ")" ;
[685]1616 (myImgApp->ObjMgrW())->AddObj(cn.c_str(), (*it).second.oid);
[165]1617 }
[2492]1618
1619if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[333]1620}
[165]1621
1622
[333]1623/* Nouvelle-Fonction */
[1207]1624void NamedObjMgr::RemoveSpacesFromName(string & nom)
[165]1625{
[333]1626// on supprime les blancs de debut et de fin
1627size_t p = nom.find_first_not_of(" ");
1628if(p>nom.length()) { nom = ""; return; }
1629nom = nom.substr(p);
1630p = nom.find(' ');
1631if(p>nom.length()) p=nom.length();
1632nom = nom.substr(0, p);
[165]1633}
1634
[333]1635/* Nouvelle-Fonction */
[1207]1636bool NamedObjMgr::CheckDirName(string & nom)
[165]1637{
[333]1638RemoveSpacesFromName(nom);
1639if (nom.length() < 1) return(false);
1640if (nom[0] == '/') nom = nom.substr(1) ;
1641size_t p = nom.find('/');
1642if (p < nom.length()) nom = nom.substr(0,p);
[2218]1643if ((nom.length() < 1) || (! isalpha(nom[0]) ) ) return(false);
[333]1644return(true);
[165]1645}
1646
[333]1647/* Nouvelle-Fonction */
[1207]1648int NamedObjMgr::ParseObjectName(string & nom, string & nomrep, string & nomobj)
[165]1649{
[333]1650RemoveSpacesFromName(nom);
1651// Si le nom ne commence pas par un slash, c'est le repertoire courant
1652if (nom[0] != '/') { nomrep = *currDir; nomobj = nom; }
[165]1653else {
[333]1654 string xx = nom.substr(1);
1655 size_t p = xx.find('/');
1656 if (p < xx.length()) {
1657 nomrep = xx.substr(0,p);
1658 nomobj = xx.substr(p+1);
[165]1659 }
[333]1660 else {
1661 nomrep = xx;
1662 nomobj = "";
[165]1663 }
1664 }
[333]1665int rc = 0;
1666NObjDirList::iterator it = myDirs->find(nomrep);
1667if (it != myDirs->end()) rc = (*it).second.id;
1668return(rc);
[165]1669}
1670
Note: See TracBrowser for help on using the repository browser.