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

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

Suite des modifs pour piapp multi-threads
1) Ajout Mutex de synchronisation ds ls classe NamedObjMgr
2) Suite controle de gestion d'appel aux methodes de PIStdImgApp depuis
la classe elle-meme, a travers le NamedObjMgr
3) Modification de la boucle d'evenements, avec un thread de reveil
periodique

Reza, 4 Janvier 2004

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