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

Last change on this file since 3279 was 3269, checked in by ansari, 18 years ago

Ajout des commandes nt2dcn et nt2dci , modifs PINtuple pour permettre l'utilisation d'une colonne pour specifier la couleur de trace de chaque marker - Reza 19/06/2007

File size: 46.0 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
[2615]11#include "sopnamsp.h"
[165]12#include "strutil.h"
13#include "datatypes.h"
14
15#include "nobjmgr.h"
16#include "servnobjm.h"
[330]17#include "nomgadapter.h"
[165]18#include "pistdimgapp.h"
19
[1164]20#include "dvlist.h"
[165]21
[293]22// EVOL-PLANCK
23#ifdef SANS_EVOLPLANCK
24#include "fitsimage.h"
[1321]25#else
[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
[2755]96static string* TmpDir = NULL; // Repertoire pour les compilations / link dynamique
[165]97
[2491]98// Pour gestion multithread
[2755]99static ZMutex* myMutex = NULL;
[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;
[2755]123 myMutex = new ZMutex;
[331]124 currDir = new string("home");
[333]125 string dirn = "home";
[2491]126 CreateDir_P(dirn);
[2132]127 SetKeepOldDirAtt(dirn, false);
[333]128 dirn = "tmp";
[2491]129 CreateDir_P(dirn);
[344]130 SetKeepOldDirAtt(dirn, false);
[466]131 dirn = "autoc";
[2491]132 CreateDir_P(dirn);
[368]133 SetKeepOldDirAtt(dirn, false);
[333]134 dirn = "old";
[2491]135 CreateDir_P(dirn);
[344]136 SetKeepOldDirAtt(dirn, false);
[333]137 dirn = "home";
138 SetCurrentDir(dirn);
139 myDirId = 50;
[165]140 char* varenv;
141 TmpDir = new string("");
[1276]142 if ( (varenv=getenv("TMPDIR")) != NULL ) (*TmpDir) = varenv;
[165]143 int l = (*TmpDir).length();
144 if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/';
[2491]145 servnobjm = new Services2NObjMgr(*TmpDir);
[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 }
[2755]231 ZSync zs(*myMutex); zs.NOp();
[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 }
[2755]249 ZSync zs(*myMutex); zs.NOp();
[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 }
[2755]267 ZSync zs(*myMutex); zs.NOp();
[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 }
[2755]282 ZSync zs(*myMutex); zs.NOp();
[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;
[2755]291 ZSync zs(*myMutex); zs.NOp();
[1164]292 return(*myVars);
293}
294
295/* --Methode-- */
[344]296bool NamedObjMgr::CreateDir(string & dirname)
[331]297{
[2755]298 ZSync zs(*myMutex); zs.NOp();
[2491]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 }
[2755]338ZSync zs(*myMutex); zs.NOp();
[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{
[2755]370ZSync zs(*myMutex); zs.NOp();
[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{
[2755]382ZSync zs(*myMutex); zs.NOp();
[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{
[2755]394ZSync zs(*myMutex); zs.NOp();
[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{
[2755]410ZSync zs(*myMutex); zs.NOp();
[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{
[2755]428ZSync zs(*myMutex); zs.NOp();
[333]429dirname = *currDir;
430}
431
432/* --Methode-- */
433void NamedObjMgr::ListDirs(string & patt)
434{
[2755]435ZSync zs(*myMutex); zs.NOp();
[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{
[2755]455ZSync zs(*myMutex); zs.NOp();
[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{
[2755]468ZSync zs(*myMutex); zs.NOp();
[2491]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;
[2757]499for(ii=odel.begin(); ii != odel.end(); ii++) DelObj_P(*ii,true);
[2762]500
501UpdateObjMgrWindow_P(did); // On met a jour la fenetre de gestion des objets
[331]502}
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{
[2755]531 ZSync zs(*myMutex); zs.NOp();
[2491]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++;
[2999]566if ( !CheckName(nobj) ) {
[333]567 sprintf(buff,"O%d", myNObj);
[2999]568 cout << "NamedObjMgr::AddObj() Name changed: " << nom << " -> " << buff << endl;
569 nom = buff;
570}
[333]571
572nom = '/' + nrep + '/' + nobj;
[344]573NObjDirList::iterator itr = myDirs->find(nrep);
574if ((*itr).second.lock) {
575 cout << "NamedObjMgr::AddObj() " << nrep << " Locked Directory " << endl;
576 return(false);
577 }
[333]578it = myObjs->find(nom);
[165]579if (it != myObjs->end()) { // l'objet existe deja
[466]580 if (nrep == "autoc") { // Dans /autoc , on garde les objets affiches, donc del. par Clean
[368]581 sprintf(buff, "%d", (*it).second.oid);
[466]582 string nomnew = "/autoc/" + nobj + buff;
[2491]583 RenameObj_P(nom, nomnew);
[368]584 }
585 else if ( (*itr).second.keepold ) { // On met l'ancien objet dans /old
[333]586 string on,od;
[335]587// ParseObjectName((*it).first, od, on);
[333]588 sprintf(buff, "%d", (*it).second.oid);
[335]589 string nomnew = "/old/" + nobj + buff;
[2491]590 RenameObj_P(nom, nomnew);
[333]591 }
[344]592 else { // Sinon, on remplace l'objet
593 cout << "NamedObjMgr::AddObj() - Replacing " << nom << endl;
[2491]594 DelObj_P(nom);
[344]595 }
[165]596 }
597
598nobj_item no;
599no.obj = obj;
[295]600no.obja = servnobjm->GetAdapter(obj); // L'adaptateur
[333]601no.oid = myNObj;
602no.dirid = did;
[331]603(*myObjs)[nom] = no;
[333]604
605(*itr).second.nobj++;
606
[2490]607if (myImgApp != NULL) {
[2492]608 if ( !_fgimgapp ) myImgApp->LockMutex();
[2490]609 if ( (myImgApp->ObjMgrW())->Visible() ) {
610 string oln = nobj + " (T= " + no.obja->GetDataObjType() + ")" ;
611 (myImgApp->ObjMgrW())->AddObjList(did, oln.c_str(), no.oid);
[685]612 }
[2492]613 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[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{
[2755]622ZSync zs(*myMutex); zs.NOp();
[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{
[2755]640 ZSync zs(*myMutex); zs.NOp();
[2491]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}
[2999]664
665if ( !CheckName(n2) ) {
[2218]666 cout << "NamedObjMgr::RenameObj() Error - bad new object name" << n2 << endl;
667 return(false);
668}
[333]669NObjList::iterator it2 = myObjs->find(nomnew);
670if (it2 != myObjs->end()) {
671 cout << "NamedObjMgr::RenameObj() Error - Object " << nomnew << " exist !" << endl;
[344]672 return(false);
[2999]673}
674
[344]675if ( (*itr1).second.lock || (*itr2).second.lock ) {
676 cout << "NamedObjMgr::RenameObj() Error - Source or destination directory locked !"
677 << endl;
678 return(false);
679 }
680
681
[333]682nobj_item no = (*it1).second;
683no.dirid = did;
684myObjs->erase(it1);
685NObjDirList::iterator itr = myDirs->find(r1);
686(*itr).second.nobj--;
687(*myObjs)[nomnew] = no;
688itr = myDirs->find(r2);
689(*itr).second.nobj++;
[685]690
[2490]691if (myImgApp != NULL) {
[2492]692 if ( !_fgimgapp ) myImgApp->LockMutex();
[2490]693 if ( (myImgApp->ObjMgrW())->Visible() ) {
694 (myImgApp->ObjMgrW())->DelObjList(dids, no.oid);
695 string oln = n2 + " (T= " + no.obja->GetDataObjType() + ")" ;
696 (myImgApp->ObjMgrW())->AddObjList(did, oln.c_str(), no.oid);
697 }
[2492]698 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[685]699}
[449]700if (verbeux)
701 cout << "NamedObjMgr::RenameObj() - Object " << nom << " renamed to " << nomnew << endl;
[344]702return(true);
[331]703}
704
705/* --Methode-- */
[463]706bool NamedObjMgr::CopyObj(string & nom, string& nomcp)
707{
[2755]708ZSync zs(*myMutex); zs.NOp();
[463]709if(nomcp.length()<=0)
710 {cout<<"NamedObjMgr::CopyObj() Error, copied obj name "<<nomcp<<" not valid"<<endl;
711 return(false);}
[2755]712NObjMgrAdapter* obnom = GetObjAdapter_P(nom);
[463]713if(obnom==NULL)
714 {cout<<"NamedObjMgr::CopyObj() Error - No "<<nom<<" object !"<<endl;
715 return(false);}
[1165]716AnyDataObj* obnomcp = obnom->CloneDataObj();
[463]717if(obnomcp==NULL) return(false);
[2491]718if(! AddObj_P(obnomcp,nomcp,false) ) {delete obnomcp; return(false);}
[463]719return true;
720}
721
722/* --Methode-- */
[344]723bool NamedObjMgr::DelObj(string & nom, bool fgd)
[331]724{
[2755]725 ZSync zs(*myMutex); zs.NOp();
[2491]726 return DelObj_P(nom, fgd);
727}
728
729/* --Methode-- */
730bool NamedObjMgr::DelObj_P(string & nom, bool fgd)
731{
[333]732string n1,r1;
[685]733int did = ParseObjectName(nom, r1, n1);
[333]734nom = '/' + r1 + '/' + n1;
[165]735NObjList::iterator it = myObjs->find(nom);
[344]736if (it == myObjs->end()) return(false);
737NObjDirList::iterator itr = myDirs->find(r1);
738if ( (*itr).second.lock ) {
739 cout << "NamedObjMgr::DelObj() Error - Locked directory " << r1 << endl;
740 return(false);
741 }
[165]742list<int>::iterator ii;
743if (myImgApp) {
744//DBG cerr << " *DBG* NamedObjMgr::DelObj Sz= " << (*it).second.wrsid.size() << endl;
[2492]745// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
746 bool fglock = (_fgimgapp) ? false : true;
747 if (fglock) myImgApp->LockMutex();
[165]748 for(ii=(*it).second.wrsid.begin(); ii != (*it).second.wrsid.end(); ii++)
749 myImgApp->DelWRsId((*ii));
[2492]750 if (fglock) myImgApp->UnlockMutex(true);
[165]751}
[314]752delete (*it).second.obja; // destruction de l'adaptateur
[165]753if (fgd) delete (*it).second.obj;
[333]754
[2490]755if (myImgApp != NULL) {
[2492]756 if ( !_fgimgapp ) myImgApp->LockMutex();
[2490]757 if ( (myImgApp->ObjMgrW())->Visible() ) {
758 int olid = (*it).second.oid;
759 (myImgApp->ObjMgrW())->DelObjList(did, olid);
760 }
[2492]761 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[685]762}
[165]763myObjs->erase(it);
[333]764(*itr).second.nobj--;
765
[685]766
[449]767if (!verbeux) return(true);
[165]768if (fgd) cout << "NamedObjMgr::DelObj() Object " << nom << " deleted (Total= " << myObjs->size() << ")" << endl;
769else cout << "NamedObjMgr::DelObj() Object " << nom << " removed (Total= " << myObjs->size() << ")" << endl;
[344]770return(true);
[165]771}
772
773/* --Methode-- */
[344]774bool NamedObjMgr::DelObj_Id(int oid)
[165]775{
[2755]776ZSync zs(*myMutex); zs.NOp();
[333]777NObjList::iterator it;
778string nom;
779bool of = false;
780for(it = myObjs->begin(); it != myObjs->end(); it++)
781 if ( (*it).second.oid == oid ) {
782 of = true; nom = (*it).first;
783 break;
784 }
[2757]785if (of) return(DelObj_P(nom, true));
[344]786else return(false);
[331]787}
788
789/* --Methode-- */
790void NamedObjMgr::DelObjects(string & patt, bool fgd)
791{
[2755]792ZSync zs(*myMutex); zs.NOp();
[333]793string n1,r1;
794ParseObjectName(patt, r1, n1);
795patt = '/' + r1 + '/' + n1;
[165]796NObjList::iterator it;
797list<string> odel;
798string cn;
799for(it = myObjs->begin(); it != myObjs->end(); it++) {
800 cn = (*it).first;
801 if (csh_parse(cn.c_str(), patt.c_str()) != 0) odel.push_back(cn);
802 }
803list<string>::iterator ii;
[2491]804for(ii=odel.begin(); ii != odel.end(); ii++) DelObj_P(*ii, fgd);
[165]805}
806
807/* --Methode-- */
[331]808AnyDataObj* NamedObjMgr::GetObj(string & nom)
[165]809{
[2755]810ZSync zs(*myMutex); zs.NOp();
811return GetObj_P(nom);
812}
813
814/* --Methode-- */
815AnyDataObj* NamedObjMgr::GetObj_P(string & nom)
816{
[333]817string n1,r1;
818ParseObjectName(nom, r1, n1);
819nom = '/' + r1 + '/' + n1;
[165]820NObjList::iterator it = myObjs->find(nom);
821if (it == myObjs->end()) return(NULL);
822return((*it).second.obj);
823}
824
825/* --Methode-- */
[331]826NObjMgrAdapter* NamedObjMgr::GetObjAdapter(string & nom)
[295]827{
[2755]828ZSync zs(*myMutex); zs.NOp();
829return GetObjAdapter_P(nom);
830}
831
832/* --Methode-- */
833NObjMgrAdapter* NamedObjMgr::GetObjAdapter_P(string & nom)
834{
[333]835string n1,r1;
836ParseObjectName(nom, r1, n1);
837nom = '/' + r1 + '/' + n1;
[295]838NObjList::iterator it = myObjs->find(nom);
839if (it == myObjs->end()) return(NULL);
840return((*it).second.obja);
841}
842
843/* --Methode-- */
[331]844void NamedObjMgr::ListObjs(string & patt)
[165]845{
[2755]846ZSync zs(*myMutex); zs.NOp();
[331]847int k;
848AnyDataObj* obj=NULL;
849string ctyp;
850char strg[256];
851
[333]852string n1,r1;
853ParseObjectName(patt, r1, n1);
854patt = '/' + r1 + '/' + n1;
855 cout << "NamedObjMgr::ListObjs( " << patt << " ) TotNObjs= " << myObjs->size() << "\n" ;
[331]856NObjList::iterator it; k = 0;
[333]857string cn;
[331]858for(it = myObjs->begin(); it != myObjs->end(); it++) {
[333]859 cn = (*it).first;
860 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
[331]861 obj = (*it).second.obj;
862 ctyp = typeid(*obj).name();
863 sprintf(strg, "%2d/ %16s : %s", k, typeid(*obj).name(), ((*it).first).c_str());
864 ctyp = strg;
865 cout << ctyp << "\n" ;
866 k++;
867}
868cout << endl;
[165]869return;
870}
871
872/* --Methode-- */
[333]873void NamedObjMgr::GetObjList(string & patt, vector<string> &lst)
[165]874{
[2755]875ZSync zs(*myMutex); zs.NOp();
[333]876string n1,r1;
877if (patt.length() < 1) return;
878bool fgr = (patt[0] == '/') ? true : false;
879ParseObjectName(patt, r1, n1);
880patt = '/' + r1 + '/' + n1;
881NObjList::iterator it;
882string cn;
883for(it = myObjs->begin(); it != myObjs->end(); it++) {
884 cn = (*it).first;
885 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
886 if (fgr) lst.push_back(cn);
887 else {
888 ParseObjectName(cn, r1, n1);
889 lst.push_back(n1);
890 }
891 }
[165]892}
893
894//++
895// Titre Entrées-Sorties (I/O) sur les objets
896//--
897//++
898// void ReadObj(PInPersist& s, int num=-1)
899// Lit l'objet à partir avec le tag numéro "num" dans le flot "PInPersist s"
900// et l'ajoute à la liste. Si "num" est négatif, tous les objets présents
901// sur le flot "s" sont créés et ajoutés à la liste.
902// void ReadObj(string const & nomppf, string nobj="")
903// Lit le premier objet à partir du fichier PPF "nomppf". L'objet est ajouté
904// à la liste avec le nom "nobj". Si "nobj" est une chaîne vide, un nom est
905// composé à partir du nom de fichier.
906//--
907
908/* --Methode-- */
[331]909void NamedObjMgr::ReadObj(string const & flnm, string & nobj)
[165]910{
[2755]911ZSync zs(*myMutex); zs.NOp();
[495]912PPersist* ppobj=NULL;
[165]913bool ok = true;
[495]914#ifdef SANS_EVOLPLANCK
[165]915TRY{
916 PInPersist pis(flnm);
[495]917 ppobj = PPersistMgr::ReadObject(pis);
918 if (ppobj == NULL) ok = false;
[165]919} CATCH(merr)
920 { printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n",
921 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
[495]922#else
923try {
924 PInPersist pis(flnm);
925 ppobj = pis.ReadObject();
926 }
927catch (IOExc iox) {
928 cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
929 ok = false;
930 }
931#endif
[165]932if (!ok) return;
933if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
[2491]934AddObj_P(ppobj->DataObj(), nobj, true);
[685]935cout << "NamedObjMgr::ReadObj(...) object " << nobj << " read from file " << endl;
[165]936return;
937}
[2645]938/* --Methode-- */
939void NamedObjMgr::ReadObj(vector<string> & flnm_objname)
940// flnm_objname[0] = nom du fichier .ppf
941// flnm_objname[1...] = nom des tags des objects a lire
942{
943if(flnm_objname.size()<2) return;
[2755]944ZSync zs(*myMutex); zs.NOp();
[2645]945int nread=0;
946try {
947 PInPersist pis(flnm_objname[0]);
948 for(int i=1;i<flnm_objname.size();i++) {
949 bool ok = pis.GotoNameTag(flnm_objname[i]);
950 if(!ok) {
951 cout<<"NamedObjMgr::ReadObj(...) Unknown object: "<<flnm_objname[i]<<endl;
952 continue;
953 }
954 PPersist *ppobj = pis.ReadObject();;
955 if(ppobj==NULL) {
956 cout<<"NamedObjMgr::ReadObj(...) impossible to read "<<flnm_objname[i]<<endl;
957 continue;
958 }
959 AddObj_P(ppobj->DataObj(),flnm_objname[i],true);
960 nread++;
961 cout<<"NamedObjMgr::ReadObj(...) object "<<flnm_objname[i]<<" read from file "<<endl;
962 }
963} catch (IOExc iox) {
964 cerr<<"NamedObjMgr::ReadObj()/Error Exception - Msg= "<<iox.Msg()<<endl;
965}
966cout<<nread<<" objects have been read"<<endl;
967return;
968}
[165]969
970/* --Methode-- */
971void NamedObjMgr::ReadObj(PInPersist& s, int num)
972{
[2755]973ZSync zs(*myMutex); zs.NOp();
974ReadObj_P(s, num);
975}
976
977/* --Methode-- */
978void NamedObjMgr::ReadObj_P(PInPersist& s, int num)
979{
[2180]980int_4 i; // $CHECK$ int -> int_4 a cause de TagKey
981#ifdef SANS_EVOLPLANCK
982int_4 cid, key, ln; // $CHECK$ int -> int_4 a cause de TagKey
983#endif
[165]984int n0, n1;
985bool ok = true;
986PPersist* obj=NULL;
987string nom;
988
[449]989int nread = 0;
[2460]990int nbtags = 0;
991#ifdef SANS_EVOLPLANCK
992nbtags = s.NbTags();
993#else
994nbtags = s.NbNameTags();
995#endif
996if ( (nbtags < 1) || (num >= nbtags) ) {
[165]997 if (num >= 0) {
[495]998 cerr << "NamedObjMgr::ReadObj(PInPersist, " << num << " Error! NbTags ="
[2460]999 << nbtags << endl;
[165]1000 return;
1001 }
[495]1002
1003#ifdef SANS_EVOLPLANCK
[165]1004 TRY {
1005 obj = PPersistMgr::ReadObject(s);
1006 if (obj == NULL) ok = false;
1007 } CATCH(merr) {
1008 printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
1009 ok = false;
1010 } ENDTRY;
[495]1011#else
1012try {
1013 obj = s.ReadObject();
1014 }
1015catch (IOExc iox) {
1016 cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
1017 ok = false;
1018 }
1019#endif
1020
[165]1021 if (!ok) return;
1022 nom = "";
[2491]1023 AddObj_P(obj->DataObj(), nom, false);
[449]1024 nread++;
[165]1025}
1026
[2460]1027if (num < 0) { n0 = 0; n1 = nbtags; }
[165]1028else { n0 = num; n1 = num+1; }
1029for(i=n0; i<n1; i++) {
[495]1030#ifdef SANS_EVOLPLANCK
[165]1031 key = s.TagKey(i, cid, ln);
1032 if (ln <= 0) nom = "";
1033 else nom = s.TagName(i);
1034 s.GotoTag(i);
1035 TRY {
1036 obj = PPersistMgr::ReadObject(s);
1037 if (obj == NULL) ok = false;
1038 } CATCH(merr) {
1039 printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
1040 ok = false;
1041 } ENDTRY;
[495]1042#else
[2460]1043 s.GotoNameTagNum(i);
[584]1044 nom = s.GetTagName(i);
[495]1045 try {
1046 obj = s.ReadObject();
1047 }
1048 catch (IOExc iox) {
1049 cerr << "NamedObjMgr::ReadObj()/Error Exception - Msg= " << iox.Msg() << endl;
1050 ok = false;
1051 }
1052#endif
[2491]1053 if (ok) { AddObj_P(obj->DataObj(), nom, true); nread++; }
[165]1054}
1055
[449]1056cout << "NamedObjMgr::ReadObj(...) " << nread << " Objects read " << endl;
[165]1057return;
1058}
1059/* --Methode-- */
1060void NamedObjMgr::ReadAll(string const & flnm)
1061{
[2755]1062ZSync zs(*myMutex); zs.NOp();
[2701]1063#ifdef SANS_EVOLPLANCK
[165]1064bool ok = true;
1065PPersist* obj=NULL;
1066
[2180]1067PInPersist* ppin=NULL;
[165]1068TRY{
1069 ppin = new PInPersist(flnm);
1070 if (ppin->NbTags() < 1) obj = PPersistMgr::ReadObject((*ppin));
1071 else obj = NULL;
1072} CATCH(merr)
1073 { printf("NamedObjMgr::ReadAll()/Error Exception= %ld (%s) \n",
[2701]1074 (long)merr, PeidaExc(merr)); ok = false; }
1075ENDTRY;
[165]1076if (!ok) return;
1077if (obj) {
1078 string nom = servnobjm->FileName2Name(flnm);
[2491]1079 AddObj_P(obj->DataObj(), nom, false);
[165]1080 }
[2755]1081else ReadObj_P((*ppin), -1);
[165]1082delete ppin;
[2701]1083#else
1084try {
1085 PInPersist pis(flnm);
1086 if (pis.NbNameTags() >= 1) {
1087 if (pis.NbNameTags() < pis.NbTopLevelObjects()) {
1088 cout << "NamedObjMgr::ReadAll()/Warning File " << flnm << " NbNameTags="
1089 << pis.NbNameTags() << " < NbTopLevelObjects= "
1090 << pis.NbTopLevelObjects() << endl;
1091 cout << " ... Reading " << pis.NbNameTags() << " objects at NameTags " ;
1092 }
[2755]1093 ReadObj_P(pis, -1);
[2701]1094 return;
1095 }
1096
1097 string nom = servnobjm->FileName2Name(flnm);
1098 int kn = 1;
1099 for(int ii=0; ii<pis.NbTopLevelObjects(); ii++) {
1100 PPersist* obj = pis.ReadObject();
1101 if (!obj) continue;
1102 AddObj_P(obj->DataObj(), nom, false);
1103 kn++;
1104 nom += (string)MuTyV(kn);
1105 }
1106}
1107catch (IOExc& iox) {
1108 cerr << "NamedObjMgr::ReadAll()/Error Exception - Msg= " << iox.Msg() << endl;
1109}
1110#endif
[165]1111return;
1112}
1113
[709]1114
[2491]1115/* --Methode-- */
1116void NamedObjMgr::SaveObj(string & nom, POutPersist& s, bool keeppath)
1117{
[2755]1118 ZSync zs(*myMutex); zs.NOp();
[2491]1119 SaveObj_P(nom, s, keeppath);
1120}
[165]1121
1122static int key_for_write = 5000;
1123/* --Methode-- */
[2491]1124void NamedObjMgr::SaveObj_P(string & nom, POutPersist& s, bool keeppath)
[165]1125{
[333]1126if (nom.length() < 1) return;
1127string nob,rep;
1128ParseObjectName(nom, rep, nob);
1129nom = '/' + rep + '/' + nob;
[295]1130NObjMgrAdapter* obja=NULL;
[333]1131string nomf = (keeppath) ? nom : nob;
[2755]1132obja = GetObjAdapter_P(nom);
[295]1133if (obja == NULL) return;
[165]1134printf("NamedObjMgr::SaveObj(%s, ) (Type=%s) \n",
[295]1135 nom.c_str(), typeid(*(obja->GetDataObj())).name());
[333]1136obja->SavePPF(s, nomf);
[165]1137return;
1138}
1139
1140/* --Methode-- */
[333]1141void NamedObjMgr::SaveObjects(string & patt, string const& flnm)
1142{
[2755]1143ZSync zs(*myMutex); zs.NOp();
[333]1144string n1,r1;
1145if (patt.length() < 1) return;
1146bool keeppath = (patt[0] == '/') ? true : false;
1147ParseObjectName(patt, r1, n1);
1148patt = '/' + r1 + '/' + n1;
1149
1150bool ok = true;
[2180]1151POutPersist* pout=NULL;
[495]1152#ifdef SANS_EVOLPLANCK
[333]1153TRY{
1154 pout = new POutPersist(flnm);
1155} CATCH(merr)
1156 { printf("NamedObjMgr::SaveObjects()/Error Exception= %ld (%s) \n",
1157 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
[495]1158#else
1159try {
1160 pout = new POutPersist(flnm);
1161}
1162catch (IOExc iox) {
1163 cerr << "NamedObjMgr::SaveObjects()/Error Exception - Msg= " << iox.Msg() << endl;
1164 ok = false;
1165}
1166#endif
[333]1167if (!ok) return;
1168NObjList::iterator it;
1169string cn;
1170for(it = myObjs->begin(); it != myObjs->end(); it++) {
1171 cn = (*it).first;
1172 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
[2491]1173 SaveObj_P(cn, (*pout), keeppath);
[333]1174 }
1175delete pout;
1176return;
1177}
1178
1179/* --Methode-- */
[2669]1180void NamedObjMgr::SaveListObjects(vector<string> &liste)
1181// Les n-1 premiers elements (liste[0 -> n-2]) contiennent
1182// les noms des objects a mettre dans le fichier ppf
1183// dont le nom est le dernier argument (liste[n-1])
1184{
[2755]1185 ZSync zs(*myMutex); zs.NOp();
[2669]1186
1187 if(liste.size()<2) {
1188 cerr<<"NamedObjMgr::SaveListObjects()/Error not enough argument"<<endl;
1189 return;
1190 }
1191
1192 // open ppf file
1193 string ppfname = liste[liste.size()-1];
1194 POutPersist* pout=NULL;
1195 try {
1196 pout = new POutPersist(ppfname);
1197 } catch(IOExc iox) {
1198 cerr<<"NamedObjMgr::SaveObjects()/Error Exception - Msg= "<<iox.Msg()<<endl;
1199 return;
1200 }
1201
1202 // put objects in ppf file
1203 for(int i=0;i<liste.size()-1;i++) {
1204 bool keeppath = (liste[i][0] == '/') ? true : false;
1205 SaveObj_P(liste[i], (*pout), keeppath);
1206 }
1207
1208 // close ppf file
1209 delete pout;
1210
1211 return;
1212}
1213
1214/* --Methode-- */
[165]1215void NamedObjMgr::SaveAll(string const& flnm)
1216{
[2755]1217ZSync zs(*myMutex); zs.NOp();
[165]1218bool ok = true;
1219
[2180]1220POutPersist* pout=NULL;
[495]1221#ifdef SANS_EVOLPLANCK
[165]1222TRY{
1223 pout = new POutPersist(flnm);
1224} CATCH(merr)
1225 { printf("NamedObjMgr::SaveAll()/Error Exception= %ld (%s) \n",
1226 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
[495]1227#else
1228try {
1229 pout = new POutPersist(flnm);
1230}
1231catch (IOExc iox) {
1232 cerr << "NamedObjMgr::SaveAll()/Error Exception - Msg= " << iox.Msg() << endl;
1233 ok = false;
1234}
1235#endif
[165]1236if (!ok) return;
[332]1237NObjList::iterator it;
1238string no;
1239for(it = myObjs->begin(); it != myObjs->end(); it++) {
1240 no = (*it).first;
[2491]1241 SaveObj_P(no, (*pout), true);
[332]1242 }
[165]1243delete pout;
1244return;
1245}
1246
[2491]1247
[165]1248
1249/* --Methode-- */
[2975]1250void NamedObjMgr::PrintObj(string& nom, int lev)
[165]1251{
[2755]1252ZSync zs(*myMutex); zs.NOp();
[295]1253NObjMgrAdapter* obja=NULL;
[2755]1254obja = GetObjAdapter_P(nom);
[295]1255if (obja == NULL) return;
[594]1256AnyDataObj* ob = obja->GetDataObj();
1257if (ob == NULL) {
1258 cerr << "NamedObjMgr::PrintObj() / Error - NULL object ! in " << nom << endl;
1259 return;
1260 }
1261string ctyp = typeid(*ob).name();
[295]1262cout << "NamedObjMgr::PrintObj(" << nom << ") Type: " << ctyp << endl;
[2975]1263obja->Print(cout, lev);
[165]1264
1265return;
1266}
1267
1268/* --Methode-- */
[331]1269void NamedObjMgr::DisplayObj(string& nom, string dopt)
[165]1270{
[2677]1271// Pas de display si option dopt = nodisp
1272if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
1273
[2755]1274ZSync zs(*myMutex); zs.NOp();
[2491]1275
[295]1276NObjMgrAdapter* obja=NULL;
[2755]1277obja = GetObjAdapter_P(nom);
[295]1278if (obja == NULL) {
[594]1279 cout << "NamedObjMgr::DisplayObj() Error , No object with name " << nom << endl;
[165]1280 return;
1281}
[594]1282if (obja->GetDataObj() == NULL) {
1283 cerr << "NamedObjMgr::DisplayObj() / Error - NULL object ! in " << nom << endl;
1284 return;
1285 }
[165]1286if (!myImgApp) return;
1287
[295]1288PIDrawer * dr = NULL;
1289P2DArrayAdapter* arr = NULL;
1290dr = obja->GetDrawer(dopt);
1291if (!dr) arr = obja->Get2DArray(dopt);
[165]1292
[295]1293if (!dr && !arr) {
1294 string ctyp = typeid(*(obja->GetDataObj())).name();
[594]1295 cout << "NamedObjMgr::DisplayObj() Error , No display for " << ctyp << endl;
[295]1296 return;
1297 }
1298
[165]1299int wrsid = 0;
1300
[344]1301string n1,r1;
1302ParseObjectName(nom, r1, n1);
1303
[2491]1304// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1305bool fglock = (_fgimgapp) ? false : true;
1306
[295]1307if (dr) {
1308 PIDrawer3D * dr3 = dynamic_cast<PIDrawer3D *>(dr);
[2491]1309 if(dr3) wrsid = myImgApp->Disp3DDrawer(dr3, n1, dopt, "", 0, fglock);
1310 else wrsid = myImgApp->DispScDrawer( dr, n1, dopt, "", 0, fglock);
[295]1311 }
[2651]1312else if (arr) wrsid = myImgApp->DispImage(arr, n1, dopt, false, 0, fglock);
[165]1313
[2762]1314AddWRsId_P(nom, wrsid);
[295]1315return;
1316}
[165]1317
[295]1318/* --Methode-- */
[2651]1319void NamedObjMgr::DisplayImage(string& nom, string dopt, bool fgimagnav)
[295]1320{
[2677]1321// Pas de display si option dopt = nodisp
1322if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
1323
[2755]1324ZSync zs(*myMutex); zs.NOp();
[2491]1325
[295]1326NObjMgrAdapter* obja=NULL;
[2755]1327obja = GetObjAdapter_P(nom);
[295]1328if (obja == NULL) {
[449]1329 cout << "NamedObjMgr::DisplayImage() Error , No such object " << nom << endl;
[295]1330 return;
1331}
[594]1332if (obja->GetDataObj() == NULL) {
1333 cerr << "NamedObjMgr::DisplayImage() / Error - NULL object ! in " << nom << endl;
1334 return;
1335 }
[295]1336if (!myImgApp) return;
1337
1338P2DArrayAdapter* arr = obja->Get2DArray(dopt);
[165]1339
[295]1340if (!arr) {
1341 string ctyp = typeid(*(obja->GetDataObj())).name();
[449]1342 cout << "NamedObjMgr::DisplayImage() Error , Not supported for " << ctyp << endl;
[295]1343 return;
1344 }
[165]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;
[2651]1353wrsid = myImgApp->DispImage(arr, n1, dopt, fgimagnav, 0, fglock);
[165]1354
[2762]1355AddWRsId_P(nom, wrsid);
[295]1356return;
1357}
1358/* --Methode-- */
[331]1359void NamedObjMgr::DisplaySurf3D(string& nom, string dopt)
[295]1360{
[2677]1361// Pas de display si option dopt = nodisp
1362if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
1363
[2755]1364ZSync zs(*myMutex); zs.NOp();
[2491]1365
[295]1366NObjMgrAdapter* obja=NULL;
[2755]1367obja = GetObjAdapter_P(nom);
[295]1368if (obja == NULL) {
[449]1369 cout << "NamedObjMgr::DisplaySurf3D() Error , No such object " << nom << endl;
[295]1370 return;
1371}
[594]1372if (obja->GetDataObj() == NULL) {
1373 cerr << "NamedObjMgr::DisplaySurf3D() / Error - NULL object ! in " << nom << endl;
1374 return;
1375 }
[295]1376if (!myImgApp) return;
1377
1378P2DArrayAdapter* arr = obja->Get2DArray(dopt);
[165]1379
[295]1380if (!arr) {
1381 string ctyp = typeid(*(obja->GetDataObj())).name();
[449]1382 cout << "NamedObjMgr::DisplaySurf3D() Error , Not supported " << ctyp << endl;
[295]1383 return;
1384 }
[165]1385
[295]1386if ((arr->XSize() > 250) || (arr->YSize() > 250)) {
1387 cout << "NamedObjMgr::DisplaySurf3D() Error , 2D-Array(" << arr->XSize()
[449]1388 << "x" << arr->YSize() << ") too big (max=250x250)" << endl;
[295]1389 delete arr;
1390 return;
[165]1391 }
1392
[344]1393string n1,r1;
1394ParseObjectName(nom, r1, n1);
1395
[2491]1396// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1397bool fglock = (_fgimgapp) ? false : true;
1398
[295]1399int wrsid = 0;
1400PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
[2491]1401wrsid = myImgApp->Disp3DDrawer(sdr, n1, dopt, "", 0, fglock);
[2762]1402AddWRsId_P(nom, wrsid);
[295]1403return;
[165]1404}
1405
1406/* --Methode-- */
[331]1407void NamedObjMgr::DisplayNT(string& nom, string& nmx, string& nmy, string& nmz,
[486]1408 string& erx, string& ery, string& erz, string& wt,
[3269]1409 string& label, string& colornm, bool coloridx, string dopt, bool fg3d)
[165]1410{
[2677]1411// Pas de display si option dopt = nodisp
1412if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
1413
[2755]1414ZSync zs(*myMutex); zs.NOp();
[2491]1415
[2755]1416AnyDataObj* obj=GetObj_P(nom);
[165]1417if (obj == NULL) {
[449]1418 cout << "NamedObjMgr::DisplayNT() Error , No such object " << nom << endl;
[165]1419 return;
1420}
1421if (!myImgApp) return;
1422
[326]1423NTupleInterface * nt = dynamic_cast<NTupleInterface *>(obj);
1424if (nt == NULL) {
1425// if (typeid(*obj) != typeid(NTupleInterface)) {
[295]1426 string ctyp = typeid(*obj).name();
[449]1427 cout << "NamedObjMgr::DisplayNT() Error , Object not an NTuple " << ctyp << endl;
[165]1428 return;
1429 }
1430
1431int wrsid = 0;
[1971]1432dopt = "defline " + dopt;
[165]1433
[344]1434string n1,r1;
1435ParseObjectName(nom, r1, n1);
1436
[2491]1437// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1438bool fglock = (_fgimgapp) ? false : true;
1439
[333]1440if ( fg3d && (nmz.length()>0) ) { // Display 3D
[326]1441 PINTuple3D* pin = new PINTuple3D(nt, false);
[165]1442 pin->SelectXYZ(nmx.c_str(), nmy.c_str(), nmz.c_str());
[486]1443 pin->SelectWt(wt.c_str());
1444 pin->SelectLabel(label.c_str());
[165]1445 pin->SelectErrBar(erx.c_str(), ery.c_str(), erz.c_str());
1446 string titre = nmz + "%" + nmy + "%" + nmz;
[2491]1447 wrsid = myImgApp->Disp3DDrawer(pin, n1, dopt, titre, 0, fglock);
[165]1448}
1449else {
[326]1450 PINTuple* pin = new PINTuple(nt, false);
[165]1451 pin->SelectXY(nmx.c_str(), nmy.c_str());
[486]1452 pin->SelectWt(wt.c_str());
1453 pin->SelectLabel(label.c_str());
[165]1454 pin->SelectErrBar(erx.c_str(), ery.c_str());
[3269]1455 if (colornm.length() > 0) { // Juin 2007 : gestion de nom de colonne pour la couleur
1456 if (coloridx) pin->SelectColorByIndex(colornm.c_str());
1457 else pin->SelectColorByName(colornm.c_str());
1458 }
[333]1459 string titre = nmy + "%" + nmx;
[2491]1460 wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, n1, dopt, titre, 0, fglock);
[165]1461 }
1462
[2762]1463AddWRsId_P(nom, wrsid);
[165]1464return;
1465}
1466
[339]1467/* --Methode-- cmv 13/10/98 : Obsolete mais ne pas virer SVP */
[331]1468void NamedObjMgr::DisplayGFD(string& nom, string& numvarx, string& numvary, string& err, string dopt)
[165]1469// Pour le display 2D ou 3D d'un ``GeneralFitData''.
1470//| nom = nom de l'objet GeneralFitData a representer.
1471//| numvarx = numero (nombre entier) de la 1ere variable d'abscisse.
1472//| numvary = numero (nombre entier) de la 2sd variable d'abscisse (3D).
1473//| Pour le display 2D, numvary="" string vide.
1474//| err = qu'elles erreurs faut il representer ?
1475//| - 2D : x y xy (display y=f(x))
1476//| - 3D : x y z xy xz yz xzy (display z=f(x,y))
1477//| Ceci n'est suivi que si on a PI_NotDefLineAtt, sinon toutes
1478//| les barres d'erreurs sont representees.
1479//| opt = options generales pour le display.
1480{
[2677]1481// Pas de display si option dopt = nodisp
1482if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
1483
[2755]1484ZSync zs(*myMutex); zs.NOp();
[2491]1485
[2755]1486AnyDataObj* obj=GetObj_P(nom);
[165]1487if(obj == NULL)
[449]1488 {cout << "NamedObjMgr::DisplayGFD() Error , No such object " << nom << endl;
[165]1489 return;}
1490if(!myImgApp) return;
[295]1491if(typeid(*obj) != typeid(GeneralFitData))
1492 {string ctyp = typeid(*obj).name();
[449]1493 cout<<"NamedObjMgr::DisplayGFD() Error , Object not a GeneralFitData "<<ctyp<<endl;
[165]1494 return;}
1495
1496// Decodage des erreurs a representer
1497bool errx=false, erry=false, errz=false;
1498if(err.length()>0) {
[2180]1499 for(int i=0;i<(int_4)err.length();i++)
[165]1500 if (err[i]=='x' || err[i]=='X') errx = true;
1501 else if(err[i]=='y' || err[i]=='Y') erry = true;
1502 else if(err[i]=='z' || err[i]=='Z') errz = true;
1503}
1504// Decodage des numeros de variables en abscisse
[339]1505 int numvx=-1, numvy=-1;
1506 if(numvarx.length()>0) numvx = atoi(numvarx.c_str());
1507 if(numvary.length()>0) numvy = atoi(numvary.c_str());
1508
[344]1509 string n1,r1;
1510 ParseObjectName(nom, r1, n1);
[2491]1511 // Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1512 bool fglock = (_fgimgapp) ? false : true;
[344]1513
[339]1514 int wrsid = 0;
1515 if(numvy>=0) { // display 3D
[165]1516 PIGenFitDat3D* pigfd = new PIGenFitDat3D(((GeneralFitData*)obj),false);
1517 pigfd->SelectXY(numvx,numvy);
1518 pigfd->SelectErrBar(errx,erry,errz);
[2491]1519 wrsid = myImgApp->Disp3DDrawer(pigfd,n1,dopt,"",0,fglock);
[339]1520} else { // display 2D
[165]1521 PIGenFitDat* pigfd = new PIGenFitDat(((GeneralFitData*)obj),false);
1522 pigfd->SelectX(numvx);
1523 pigfd->SelectErrBar(errx,erry);
[2491]1524 wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,n1,dopt,"",0,fglock);
[165]1525}
1526
[2762]1527AddWRsId_P(nom, wrsid);
[1971]1528
[165]1529return;
1530}
1531
[1525]1532/* --Methode-- */
1533void NamedObjMgr::DisplayVector(string & nomvx, string& nomvy, string dopt)
1534// Pour l'affichage 2-D de points avec coordonnees definies par deux vecteurs
1535// nomvx et nomvy
1536{
[2677]1537// Pas de display si option dopt = nodisp
1538if ( (dopt == "nodisp") || (dopt == "nodisplay") ) return;
1539
[2755]1540ZSync zs(*myMutex); zs.NOp();
[2491]1541
[1525]1542#ifdef SANS_EVOLPLANCK
1543 cerr << " NamedObjMgr::DisplayVector() Error: Not implemented with PEIDA " << endl;
1544#else
1545
1546if(!myImgApp) return;
1547
1548AnyDataObj* obj;
[2755]1549obj = GetObj_P(nomvx);
[1525]1550if(obj == NULL) {
1551 cout << "NamedObjMgr::DisplayVector() Error , No such object " << nomvx << endl;
1552 return;
1553}
[2263]1554//Vector * vx = dynamic_cast<Vector *>(obj);
1555BaseArray* bax = dynamic_cast<BaseArray *>(obj);
1556if (bax == NULL) {
1557 cout << "NamedObjMgr::DisplayVector() Error " << nomvx << " not a BaseArray ! " << endl;
[1525]1558 return;
1559}
1560
[2755]1561obj = GetObj_P(nomvy);
[1525]1562if(obj == NULL) {
1563 cout << "NamedObjMgr::DisplayVector() Error , No such object " << nomvy << endl;
1564 return;
1565}
[2263]1566BaseArray* bay = dynamic_cast<BaseArray *>(obj);
1567if (bay == NULL) {
1568 cout << "NamedObjMgr::DisplayVector() Error " << nomvy << " not a BaseArray ! " << endl;
[1525]1569 return;
1570}
1571
[2263]1572Vector vx = *bax;
1573Vector vy = *bay;
[1525]1574Vector * cvx, * cvy;
1575
[2263]1576if (vx.Size() != vy.Size()) {
[1525]1577 cout << "NamedObjMgr::DisplayVector() Warning / Vx.Size() != Vy.Size() " << endl;
[2263]1578 if (vx.Size() < vy.Size()) {
1579 cvx = new Vector(vx);
1580 cvy = new Vector(vy.SubVector(Range(0, 0, vx.Size()-1)));
[1525]1581 }
1582 else {
[2263]1583 cvx = new Vector(vx.SubVector(Range(0, 0, vy.Size()-1)));
1584 cvy = new Vector(vy);
[1525]1585 }
1586}
1587else {
[2263]1588 cvx = new Vector(vx);
1589 cvy = new Vector(vy);
[1525]1590}
1591
1592POVectorAdapter * avx = new POVectorAdapter(cvx, true);
1593POVectorAdapter * avy = new POVectorAdapter(cvy, true);
1594PIYfXDrawer * vxydrw = new PIYfXDrawer(avx, avy, true);
1595
1596string nx,rx;
1597ParseObjectName(nomvx, rx, nx);
1598string ny,ry;
1599ParseObjectName(nomvy, ry, ny);
1600
[2491]1601// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
1602bool fglock = (_fgimgapp) ? false : true;
1603
[1525]1604string title = ny + " (Y) vs. " + nx + " (X)";
1605// display 2D
[2491]1606myImgApp->DispScDrawer(vxydrw, title, dopt, "", 0, fglock);
[1525]1607
1608return;
1609
1610#endif
1611}
1612
[165]1613/* --Methode--
[331]1614void NamedObjMgr::DisplayImage(string& nom, string dopt)
[165]1615{
1616 cout << "NamedObjMgr::DisplayImage() a faire ! " << endl;
1617}
1618*/
1619
1620
1621
1622
[1971]1623/* --Methode--
[165]1624void NamedObjMgr::SetGraphicAttributes(string gratt)
1625{
1626bool fg = false;
1627servnobjm->DecodeDispOption(gratt, fg);
[546]1628Services2NObjMgr::SetDefaultStatsOption(Services2NObjMgr::GetStatsOption(gratt));
[165]1629}
[333]1630
[165]1631void NamedObjMgr::SetGraphicWinZone(int nzx, int nzy, bool fcr)
1632{
1633if (!myImgApp) return;
1634if (fcr) myImgApp->CreateGraphWin(nzx, nzy);
1635else myImgApp->SetZone(nzx, nzy);
1636}
[1971]1637*/
[165]1638
1639/* --Methode-- */
[333]1640void NamedObjMgr::AddWRsId(string & nom, int wrsid)
[165]1641{
[2762]1642ZSync zs(*myMutex); zs.NOp();
1643AddWRsId_P(nom, wrsid);
1644}
1645
1646/* --Methode-- */
1647void NamedObjMgr::AddWRsId_P(string & nom, int wrsid)
1648{
[333]1649if(wrsid != 0) {
1650 NObjList::iterator it = myObjs->find(nom);
1651 if (it == myObjs->end()) return;
1652 (*it).second.wrsid.push_back(wrsid);
[295]1653 }
[165]1654return;
1655}
1656
1657/* --Methode-- */
[333]1658void NamedObjMgr::UpdateObjMgrWindow(int did)
[165]1659{
[333]1660if (!myImgApp) return;
[2762]1661ZSync zs(*myMutex); zs.NOp();
1662UpdateObjMgrWindow_P(did);
1663}
1664
1665/* --Methode-- */
1666void NamedObjMgr::UpdateObjMgrWindow_P(int did)
1667{
1668if (!myImgApp) return;
[2492]1669if ( !_fgimgapp ) myImgApp->LockMutex();
[2762]1670if ( !(myImgApp->ObjMgrW())->Visible() ||
1671 ( (myImgApp->ObjMgrW())->GetCurDirId() != did) ) {
1672 if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
1673 return;
1674 }
[2490]1675
[685]1676(myImgApp->ObjMgrW())->ClearObjList();
[165]1677
[333]1678NObjList::iterator it;
1679string cn;
1680for(it = myObjs->begin(); it != myObjs->end(); it++) {
1681 if ((*it).second.dirid != did) continue;
1682 cn = (*it).first.substr(1);
[1321]1683 // cn = cn.substr(cn.find('/')+1) + " (T= " + typeid(*((*it).second.obj)).name() + ")" ;
1684 cn = cn.substr(cn.find('/')+1) + " (T= " + (*it).second.obja->GetDataObjType() + ")" ;
[685]1685 (myImgApp->ObjMgrW())->AddObj(cn.c_str(), (*it).second.oid);
[165]1686 }
[2492]1687if ( !_fgimgapp ) myImgApp->UnlockMutex(true);
[2762]1688return;
[333]1689}
[165]1690
1691
[333]1692/* Nouvelle-Fonction */
[1207]1693void NamedObjMgr::RemoveSpacesFromName(string & nom)
[165]1694{
[333]1695// on supprime les blancs de debut et de fin
1696size_t p = nom.find_first_not_of(" ");
1697if(p>nom.length()) { nom = ""; return; }
1698nom = nom.substr(p);
1699p = nom.find(' ');
1700if(p>nom.length()) p=nom.length();
1701nom = nom.substr(0, p);
[165]1702}
1703
[333]1704/* Nouvelle-Fonction */
[1207]1705bool NamedObjMgr::CheckDirName(string & nom)
[165]1706{
[333]1707RemoveSpacesFromName(nom);
1708if (nom.length() < 1) return(false);
1709if (nom[0] == '/') nom = nom.substr(1) ;
1710size_t p = nom.find('/');
1711if (p < nom.length()) nom = nom.substr(0,p);
[2218]1712if ((nom.length() < 1) || (! isalpha(nom[0]) ) ) return(false);
[333]1713return(true);
[165]1714}
1715
[333]1716/* Nouvelle-Fonction */
[1207]1717int NamedObjMgr::ParseObjectName(string & nom, string & nomrep, string & nomobj)
[165]1718{
[333]1719RemoveSpacesFromName(nom);
1720// Si le nom ne commence pas par un slash, c'est le repertoire courant
1721if (nom[0] != '/') { nomrep = *currDir; nomobj = nom; }
[165]1722else {
[333]1723 string xx = nom.substr(1);
1724 size_t p = xx.find('/');
1725 if (p < xx.length()) {
1726 nomrep = xx.substr(0,p);
1727 nomobj = xx.substr(p+1);
[165]1728 }
[333]1729 else {
1730 nomrep = xx;
1731 nomobj = "";
[165]1732 }
1733 }
[333]1734int rc = 0;
1735NObjDirList::iterator it = myDirs->find(nomrep);
1736if (it != myDirs->end()) rc = (*it).second.id;
1737return(rc);
[165]1738}
1739
[2999]1740/* Nouvelle-Fonction */
1741bool NamedObjMgr::CheckName(string const & nom)
1742{
1743if (nom.length() < 1) return false;
1744if (! isalpha(nom[0]) ) return false;
1745for(int k=0; k<nom.length(); k++)
1746 if ((!isalnum(nom[k])) && (nom[k] != '_')) return false;
1747return true;
1748}
Note: See TracBrowser for help on using the repository browser.