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
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <ctype.h>
4
5#include <typeinfo>
6#include <iostream>
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"
16#include "nomgadapter.h"
17#include "pistdimgapp.h"
18
19#include "dvlist.h"
20
21// EVOL-PLANCK
22#ifdef SANS_EVOLPLANCK
23#include "fitsimage.h"
24#else
25#include "fitsautoreader.h"
26#include "tvector.h"
27#include "pitvmaad.h"
28#include "piyfxdrw.h"
29#endif
30
31#include "pisurfdr.h"
32#include "pipodrw.h"
33
34#include "pintuple.h"
35#include "pintup3d.h"
36#include "pigfd1.h"
37#include "pigfd2.h"
38
39#include "zthread.h"
40
41
42//++
43// Class NamedObjMgr
44// Lib PI
45// include nobjmgr.h
46//
47// Cette classe fournit les services nécéssaires à la gestion des objets
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 ............
62struct nobj_diritem {
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
67};
68
69typedef map<string, nobj_diritem, less<string> > NObjDirList;
70
71struct nobj_item {
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)
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
84static NObjDirList* myDirs = NULL;
85static NObjList* myObjs = NULL;
86static int fgOInit = 0;
87static int myNObj = 0;
88static int myDirId = 0;
89static string* currDir;
90
91static PIStdImgApp* myImgApp=NULL;
92static Services2NObjMgr* servnobjm=NULL;
93
94static DVList* myVars = NULL; // Pour stocker les variables
95
96static string* TmpDir; // Repertoire pour les compilations / link dynamique
97
98// Pour gestion multithread
99static ZMutex* myMutex;
100// ..................................................................
101
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-- */
114NamedObjMgr::NamedObjMgr(bool fgimgapp)
115{
116_fgimgapp = fgimgapp;
117if (fgOInit == 0) {
118 myNObj = 0;
119 myDirId = 0;
120 myDirs = new NObjDirList;
121 myObjs = new NObjList;
122 myVars = new DVList;
123 currDir = new string("home");
124 string dirn = "home";
125 CreateDir_P(dirn);
126 SetKeepOldDirAtt(dirn, false);
127 dirn = "tmp";
128 CreateDir_P(dirn);
129 SetKeepOldDirAtt(dirn, false);
130 dirn = "autoc";
131 CreateDir_P(dirn);
132 SetKeepOldDirAtt(dirn, false);
133 dirn = "old";
134 CreateDir_P(dirn);
135 SetKeepOldDirAtt(dirn, false);
136 dirn = "home";
137 SetCurrentDir(dirn);
138 myDirId = 50;
139 char* varenv;
140 TmpDir = new string("");
141 if ( (varenv=getenv("TMPDIR")) != NULL ) (*TmpDir) = varenv;
142 int l = (*TmpDir).length();
143 if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/';
144 servnobjm = new Services2NObjMgr(*TmpDir);
145 myMutex = new ZMutex;
146 }
147fgOInit++;
148}
149
150
151/* --Methode-- */
152NamedObjMgr::~NamedObjMgr()
153{
154fgOInit--;
155if (fgOInit == 0) {
156 string patt = "/*/*";
157 DelObjects(patt, true);
158 delete myObjs;
159 delete myDirs;
160 delete myVars;
161 delete myMutex;
162}
163}
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);
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 }
187}
188
189
190static bool verbeux = false; // true -> plus de message (creation/suppression d'objets)
191void NamedObjMgr::SetVerbose(bool fg)
192{
193verbeux = fg;
194}
195
196/* --Methode-- */
197PIStdImgApp* NamedObjMgr::GetImgApp()
198{
199return(myImgApp);
200}
201
202/* --Methode-- */
203Services2NObjMgr* NamedObjMgr::GetServiceObj()
204{
205return(servnobjm);
206}
207
208/* --Methode-- */
209string const& NamedObjMgr::GetTmpDir()
210{
211return *TmpDir;
212}
213
214/* --Methode-- */
215void NamedObjMgr::SetTmpDir(string const& tmpdir)
216{
217if(tmpdir.length()<1) return;
218*TmpDir = tmpdir;
219int l = (*TmpDir).length();
220if ( (l>0) && ((*TmpDir)[l-1] != '/') ) (*TmpDir) += '/';
221servnobjm->SetTmpDir(*TmpDir);
222}
223
224/* --Methode-- */
225bool NamedObjMgr::SetVar(string const & key, string const & val)
226{
227 if ((key.length() < 1) || (! isalpha(key[0])) ) {
228 cout << "NamedObjMgr::SetVar( " << key << " ...) Bad VarName " << endl;
229 return(false);
230 }
231 ZSync(*myMutex);
232#ifdef SANS_EVOLPLANCK
233 bool fg = true;
234#else
235 bool fg = myVars->HasKey(key);
236#endif
237 myVars->SetS(key, val);
238 // cout << " DEBUG::SetVar " << *myVars << endl;
239 return(fg);
240}
241
242/* --Methode-- */
243bool NamedObjMgr::HasVar(string const & key)
244{
245 if ((key.length() < 1) || (! isalpha(key[0])) ) {
246 cout << "NamedObjMgr::HasVar( " << key << ") Bad VarName " << endl;
247 return(false);
248 }
249 ZSync(*myMutex);
250#ifdef SANS_EVOLPLANCK
251 DVList::ValList::const_iterator it;
252 for(it=myVars->Begin(); it!= myVars->End(); it++)
253 if ((*it).first == key) return true;
254 return(false);
255#else
256 return(myVars->HasKey(key));
257#endif
258}
259
260/* --Methode-- */
261bool NamedObjMgr::DeleteVar(string const & key)
262{
263 if ((key.length() < 1) || (! isalpha(key[0])) ) {
264 cout << "NamedObjMgr::DeleteVar( " << key << ") Bad VarName " << endl;
265 return(false);
266 }
267 ZSync(*myMutex);
268#ifdef SANS_EVOLPLANCK
269 return(false);
270#else
271 return(myVars->DeleteKey(key));
272#endif
273}
274
275/* --Methode-- */
276string NamedObjMgr::GetVar(string const & key)
277{
278 if ((key.length() < 1) || (! isalpha(key[0])) ) {
279 cout << "NamedObjMgr::GetVar( " << key << ") Bad VarName " << endl;
280 return("");
281 }
282 ZSync(*myMutex);
283 // cout << " DEBUG::GetVar " << *myVars << endl;
284 return(myVars->GetS(key));
285}
286
287/* --Methode-- */
288DVList& NamedObjMgr::GetVarList()
289{
290 // cout << " DEBUG::GetVarList " << *myVars << endl;
291 ZSync(*myMutex);
292 return(*myVars);
293}
294
295/* --Methode-- */
296bool NamedObjMgr::CreateDir(string & dirname)
297{
298 ZSync(*myMutex);
299 return CreateDir_P(dirname);
300}
301
302/* --Methode-- */
303bool NamedObjMgr::CreateDir_P(string & dirname)
304{
305if ( !CheckDirName(dirname) ) {
306 cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Invalid name !" << endl;
307 return(false);
308 }
309NObjDirList::iterator it = myDirs->find(dirname);
310if (it != myDirs->end()) {
311 cout << "NamedObjMgr::CreateDir( " << dirname << ") Error - Existing directory !" << endl;
312 return(false);
313 }
314myDirId++;
315nobj_diritem di;
316di.id = myDirId;
317di.nobj = 0;
318di.lock = false;
319di.keepold = false;
320(*myDirs)[dirname] = di;
321if (myImgApp) {
322 string str = '/' + dirname;
323 if ( !_fgimgapp ) ZSync(myImgApp->getMutex(),2);
324 (myImgApp->ObjMgrW())->AddDirectory(str.c_str(), myDirId);
325 }
326if (verbeux) cout << "NamedObjMgr::CreateDir() " << dirname << " Created " << endl;
327return(true);
328}
329
330/* --Methode-- */
331bool NamedObjMgr::DeleteDir(string & dirname)
332{
333if ( !CheckDirName(dirname) ) {
334 cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - Invalid name !" << endl;
335 return(false);
336 }
337ZSync(*myMutex);
338NObjDirList::iterator it = myDirs->find(dirname);
339if (it == myDirs->end()) {
340 cout << "NamedObjMgr::DeleteDir( " << dirname << ") Error - No such directory !" << endl;
341 return(false);
342 }
343if ((*it).second.nobj > 0) {
344 cout << "NamedObjMgr::DeleteDir() " << dirname << " not empty ! " << endl;
345 return(false);
346 }
347if ((*it).second.lock ) {
348 cout << "NamedObjMgr::DeleteDir() " << dirname << " locked ! " << endl;
349 return(false);
350 }
351if ((*it).second.id < 50) {
352 cout << "NamedObjMgr::DeleteDir() " << dirname << " cannot be deleted ! " << endl;
353 return(false);
354 }
355
356if (myImgApp) {
357 if ( !_fgimgapp ) ZSync(myImgApp->getMutex(),2);
358 (myImgApp->ObjMgrW())->DelDirectory((*it).second.id);
359}
360myDirs->erase(it);
361if (verbeux) cout << "NamedObjMgr::DeleteDir() " << dirname << " deleted " << endl;
362return(true);
363}
364
365/* --Methode-- */
366void NamedObjMgr::LockDir(string & dirname)
367{
368ZSync(*myMutex);
369if ( !CheckDirName(dirname) ) return;
370NObjDirList::iterator it = myDirs->find(dirname);
371if (it == myDirs->end()) return;
372(*it).second.lock = true;
373if (verbeux) cout << "NamedObjMgr::LockDir() " << dirname << " Locked " << endl;
374return;
375}
376
377/* --Methode-- */
378void NamedObjMgr::UnlockDir(string & dirname)
379{
380ZSync(*myMutex);
381if ( !CheckDirName(dirname) ) return;
382NObjDirList::iterator it = myDirs->find(dirname);
383if (it == myDirs->end()) return;
384(*it).second.lock = true;
385if (verbeux) cout << "NamedObjMgr::UnlockDir() " << dirname << " Unlocked " << endl;
386return;
387}
388
389/* --Methode-- */
390void NamedObjMgr::SetKeepOldDirAtt(string & dirname, bool keepold)
391{
392ZSync(*myMutex);
393if ( !CheckDirName(dirname) ) return;
394NObjDirList::iterator it = myDirs->find(dirname);
395if (it == myDirs->end()) return;
396(*it).second.keepold = keepold;
397if (!verbeux) return;
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{
408ZSync(*myMutex);
409if ( !CheckDirName(dirname) ) {
410 cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - Invalid name !" << endl;
411 return(false);
412 }
413NObjDirList::iterator it = myDirs->find(dirname);
414if (it == myDirs->end()) {
415 cout << "NamedObjMgr::SetCurrentDir( " << dirname << ") Error - No such directory !" << endl;
416 return(false);
417 }
418*currDir = dirname;
419if (verbeux) cout << "NamedObjMgr::SetCurrentDir() -> " << dirname << endl;
420return(true);
421}
422
423/* --Methode-- */
424void NamedObjMgr::GetCurrentDir(string & dirname)
425{
426ZSync(*myMutex);
427dirname = *currDir;
428}
429
430/* --Methode-- */
431void NamedObjMgr::ListDirs(string & patt)
432{
433ZSync(*myMutex);
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++;
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
447 }
448}
449
450/* --Methode-- */
451void NamedObjMgr::GetDirList(string & patt, vector<string>& lstd)
452{
453ZSync(*myMutex);
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-- */
464void NamedObjMgr::CleanDir(string & dirname)
465{
466ZSync(*myMutex);
467CleanDir_P(dirname);
468}
469
470/* --Methode-- */
471void NamedObjMgr::CleanDir_P(string & dirname)
472{
473if ( !CheckDirName(dirname) ) {
474 cout << "NamedObjMgr::CleanDir( " << dirname << ") Error - Invalid name !" << endl;
475 // return(false); $CHECK$ illegal return value in void function
476 }
477NObjDirList::iterator itr = myDirs->find(dirname);
478if (itr == myDirs->end()) {
479 cout << "NamedObjMgr::CleanDir( " << dirname << ") Error - No such directory !" << endl;
480 // return(false); $CHECK$ illegal return value in void function
481 }
482
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);
498if (myImgApp) {
499 if ( !_fgimgapp ) ZSync(myImgApp->getMutex(),2);
500 (myImgApp->ObjMgrW())->UpdateList(did);
501}
502}
503
504
505
506//++
507// Titre Gestion de la liste des objets
508//--
509//++
510// void AddObj(AnyDataObj* obj, string& nom)
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"
519// AnyDataObj* GetObj(string const& nom)
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.
524// void CopyObj(string const& nom, string& nomcp)
525// Copy l'objet "nom" de la liste dans l'objet "nomcp" de la liste.
526//--
527
528/* --Methode-- */
529bool NamedObjMgr::AddObj(AnyDataObj* obj, string & nom, bool crd)
530{
531 ZSync(*myMutex);
532 return AddObj_P(obj, nom, crd);
533}
534
535/* --Methode-- */
536bool NamedObjMgr::AddObj_P(AnyDataObj* obj, string & nom, bool crd)
537{
538
539if (obj == NULL) return(false);
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;
545 return(false);
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;
555 return(false);
556 }
557 else { CreateDir_P(nrep); did = myDirId; }
558 }
559
560// Si c'est le repertoire /autoc, on nettoie
561if (nrep == "autoc") {
562 CleanDir_P(nrep);
563 }
564
565myNObj++;
566if ((nobj.length() < 1) || (! isalpha(nobj[0]) ) ) {
567 cout << "NamedObjMgr::AddObj() bad object name " << nobj ;
568 sprintf(buff,"O%d", myNObj);
569 nobj = buff;
570 cout << " changed to " << nobj << endl;
571 }
572
573nom = '/' + nrep + '/' + nobj;
574NObjDirList::iterator itr = myDirs->find(nrep);
575if ((*itr).second.lock) {
576 cout << "NamedObjMgr::AddObj() " << nrep << " Locked Directory " << endl;
577 return(false);
578 }
579it = myObjs->find(nom);
580if (it != myObjs->end()) { // l'objet existe deja
581 if (nrep == "autoc") { // Dans /autoc , on garde les objets affiches, donc del. par Clean
582 sprintf(buff, "%d", (*it).second.oid);
583 string nomnew = "/autoc/" + nobj + buff;
584 RenameObj_P(nom, nomnew);
585 }
586 else if ( (*itr).second.keepold ) { // On met l'ancien objet dans /old
587 string on,od;
588// ParseObjectName((*it).first, od, on);
589 sprintf(buff, "%d", (*it).second.oid);
590 string nomnew = "/old/" + nobj + buff;
591 RenameObj_P(nom, nomnew);
592 }
593 else { // Sinon, on remplace l'objet
594 cout << "NamedObjMgr::AddObj() - Replacing " << nom << endl;
595 DelObj_P(nom);
596 }
597 }
598
599nobj_item no;
600no.obj = obj;
601no.obja = servnobjm->GetAdapter(obj); // L'adaptateur
602no.oid = myNObj;
603no.dirid = did;
604(*myObjs)[nom] = no;
605
606(*itr).second.nobj++;
607
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);
613 }
614}
615if (verbeux) cout << "NamedObjMgr::AddObj() Object " << nom << " ( "
616 << typeid(*obj).name() << " ) added (Total= " << myObjs->size() << ")" << endl;
617return(true);
618}
619
620bool NamedObjMgr::AddObj(AnyDataObj& obj, string & nom, bool crd)
621{
622ZSync(*myMutex);
623NObjMgrAdapter* adap = GetServiceObj()->GetAdapter(&obj);
624if (adap == NULL) {
625 cout << "NamedObjMgr::AddObj() No Adapter ! " << nom << endl;
626 return(false);
627}
628AnyDataObj * cloneobj = adap->CloneDataObj(true);
629delete adap;
630if (cloneobj == NULL) {
631 cout << "NamedObjMgr::AddObj() Pb cloning object ! " << nom << endl;
632 return(false);
633}
634return ( AddObj_P(cloneobj , nom, crd) );
635}
636
637/* --Methode-- */
638bool NamedObjMgr::RenameObj(string & nom, string& nomnew)
639{
640 ZSync(*myMutex);
641 return RenameObj_P(nom, nomnew);
642}
643
644/* --Methode-- */
645bool NamedObjMgr::RenameObj_P(string & nom, string& nomnew)
646{
647string n1,r1,n2,r2;
648int dids = ParseObjectName(nom, r1, n1);
649NObjDirList::iterator itr1 = myDirs->find(r1);
650int did = ParseObjectName(nomnew, r2, n2);
651NObjDirList::iterator itr2 = myDirs->find(r2);
652
653if (did == 0) {
654 cout << "NamedObjMgr::RenameObj() Error - No " << r2 << " directory !" << endl;
655 return(false);
656}
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;
662 return(false);
663}
664if ((n2.length() < 1) || (! isalpha(n2[0])) ) {
665 cout << "NamedObjMgr::RenameObj() Error - bad new object name" << n2 << endl;
666 return(false);
667}
668NObjList::iterator it2 = myObjs->find(nomnew);
669if (it2 != myObjs->end()) {
670 cout << "NamedObjMgr::RenameObj() Error - Object " << nomnew << " exist !" << endl;
671 return(false);
672 }
673
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
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++;
689
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 }
697}
698if (verbeux)
699 cout << "NamedObjMgr::RenameObj() - Object " << nom << " renamed to " << nomnew << endl;
700return(true);
701}
702
703/* --Methode-- */
704bool NamedObjMgr::CopyObj(string & nom, string& nomcp)
705{
706ZSync(*myMutex);
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);}
714AnyDataObj* obnomcp = obnom->CloneDataObj();
715if(obnomcp==NULL) return(false);
716if(! AddObj_P(obnomcp,nomcp,false) ) {delete obnomcp; return(false);}
717return true;
718}
719
720/* --Methode-- */
721bool NamedObjMgr::DelObj(string & nom, bool fgd)
722{
723 ZSync(*myMutex);
724 return DelObj_P(nom, fgd);
725}
726
727/* --Methode-- */
728bool NamedObjMgr::DelObj_P(string & nom, bool fgd)
729{
730string n1,r1;
731int did = ParseObjectName(nom, r1, n1);
732nom = '/' + r1 + '/' + n1;
733NObjList::iterator it = myObjs->find(nom);
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 }
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}
746delete (*it).second.obja; // destruction de l'adaptateur
747if (fgd) delete (*it).second.obj;
748
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 }
755}
756myObjs->erase(it);
757(*itr).second.nobj--;
758
759
760if (!verbeux) return(true);
761if (fgd) cout << "NamedObjMgr::DelObj() Object " << nom << " deleted (Total= " << myObjs->size() << ")" << endl;
762else cout << "NamedObjMgr::DelObj() Object " << nom << " removed (Total= " << myObjs->size() << ")" << endl;
763return(true);
764}
765
766/* --Methode-- */
767bool NamedObjMgr::DelObj_Id(int oid)
768{
769ZSync(*myMutex);
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 }
778if (of) return(DelObj(nom, true));
779else return(false);
780}
781
782/* --Methode-- */
783void NamedObjMgr::DelObjects(string & patt, bool fgd)
784{
785ZSync(*myMutex);
786string n1,r1;
787ParseObjectName(patt, r1, n1);
788patt = '/' + r1 + '/' + n1;
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;
797for(ii=odel.begin(); ii != odel.end(); ii++) DelObj_P(*ii, fgd);
798}
799
800/* --Methode-- */
801AnyDataObj* NamedObjMgr::GetObj(string & nom)
802{
803ZSync(*myMutex);
804string n1,r1;
805ParseObjectName(nom, r1, n1);
806nom = '/' + r1 + '/' + n1;
807NObjList::iterator it = myObjs->find(nom);
808if (it == myObjs->end()) return(NULL);
809return((*it).second.obj);
810}
811
812/* --Methode-- */
813NObjMgrAdapter* NamedObjMgr::GetObjAdapter(string & nom)
814{
815ZSync(*myMutex);
816string n1,r1;
817ParseObjectName(nom, r1, n1);
818nom = '/' + r1 + '/' + n1;
819NObjList::iterator it = myObjs->find(nom);
820if (it == myObjs->end()) return(NULL);
821return((*it).second.obja);
822}
823
824/* --Methode-- */
825void NamedObjMgr::ListObjs(string & patt)
826{
827ZSync(*myMutex);
828int k;
829AnyDataObj* obj=NULL;
830string ctyp;
831char strg[256];
832
833string n1,r1;
834ParseObjectName(patt, r1, n1);
835patt = '/' + r1 + '/' + n1;
836 cout << "NamedObjMgr::ListObjs( " << patt << " ) TotNObjs= " << myObjs->size() << "\n" ;
837NObjList::iterator it; k = 0;
838string cn;
839for(it = myObjs->begin(); it != myObjs->end(); it++) {
840 cn = (*it).first;
841 if (csh_parse(cn.c_str(), patt.c_str()) == 0) continue;
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;
850return;
851}
852
853/* --Methode-- */
854void NamedObjMgr::GetObjList(string & patt, vector<string> &lst)
855{
856ZSync(*myMutex);
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 }
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-- */
890void NamedObjMgr::ReadObj(string const & flnm, string & nobj)
891{
892ZSync(*myMutex);
893PPersist* ppobj=NULL;
894bool ok = true;
895#ifdef SANS_EVOLPLANCK
896TRY{
897 PInPersist pis(flnm);
898 ppobj = PPersistMgr::ReadObject(pis);
899 if (ppobj == NULL) ok = false;
900} CATCH(merr)
901 { printf("NamedObjMgr::ReadObj()/Error Exception= %ld (%s) \n",
902 (long)merr, PeidaExc(merr)); ok = false; } ENDTRY;
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
913if (!ok) return;
914if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
915AddObj_P(ppobj->DataObj(), nobj, true);
916cout << "NamedObjMgr::ReadObj(...) object " << nobj << " read from file " << endl;
917return;
918}
919
920/* --Methode-- */
921void NamedObjMgr::ReadObj(PInPersist& s, int num)
922{
923ZSync(*myMutex);
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
928int n0, n1;
929bool ok = true;
930PPersist* obj=NULL;
931string nom;
932
933int nread = 0;
934int nbtags = 0;
935#ifdef SANS_EVOLPLANCK
936nbtags = s.NbTags();
937#else
938nbtags = s.NbNameTags();
939#endif
940if ( (nbtags < 1) || (num >= nbtags) ) {
941 if (num >= 0) {
942 cerr << "NamedObjMgr::ReadObj(PInPersist, " << num << " Error! NbTags ="
943 << nbtags << endl;
944 return;
945 }
946
947#ifdef SANS_EVOLPLANCK
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;
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
965 if (!ok) return;
966 nom = "";
967 AddObj_P(obj->DataObj(), nom, false);
968 nread++;
969}
970
971if (num < 0) { n0 = 0; n1 = nbtags; }
972else { n0 = num; n1 = num+1; }
973for(i=n0; i<n1; i++) {
974#ifdef SANS_EVOLPLANCK
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;
986#else
987 s.GotoNameTagNum(i);
988 nom = s.GetTagName(i);
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
997 if (ok) { AddObj_P(obj->DataObj(), nom, true); nread++; }
998}
999
1000cout << "NamedObjMgr::ReadObj(...) " << nread << " Objects read " << endl;
1001return;
1002}
1003/* --Methode-- */
1004void NamedObjMgr::ReadAll(string const & flnm)
1005{
1006ZSync(*myMutex);
1007bool ok = true;
1008PPersist* obj=NULL;
1009
1010PInPersist* ppin=NULL;
1011#ifdef SANS_EVOLPLANCK
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;
1019#else
1020try {
1021 ppin = new PInPersist(flnm);
1022 if (ppin->NbNameTags() < 1) obj = ppin->ReadObject();
1023 else obj = NULL;
1024}
1025catch (IOExc iox) {
1026 cerr << "NamedObjMgr::ReadAll()/Error Exception - Msg= " << iox.Msg() << endl;
1027 ok = false;
1028}
1029#endif
1030if (!ok) return;
1031if (obj) {
1032 string nom = servnobjm->FileName2Name(flnm);
1033 AddObj_P(obj->DataObj(), nom, false);
1034 }
1035else ReadObj((*ppin), -1);
1036delete ppin;
1037return;
1038}
1039
1040/* --Methode-- */
1041void NamedObjMgr::ReadFits(string const & flnm, string & nobj)
1042{
1043ZSync(*myMutex);
1044#ifdef SANS_EVOLPLANCK
1045bool ok = false;
1046RzImage* obj=NULL;
1047TRY{
1048 obj = RzReadFits((char*)flnm.c_str());
1049 if (obj == NULL) ok = false;
1050 else ok = true;
1051} CATCH(merr) {
1052 printf("NamedObjMgr::ReadFITS(_Error Exception= %ld (%s) \n", (long)merr, PeidaExc(merr));
1053 ok = false;
1054} ENDTRY;
1055
1056if (ok && (obj != NULL)) {
1057 if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
1058 AddObj_P((AnyDataObj*)obj, nobj);
1059}
1060#else
1061 try {
1062 FITS_AutoReader fiar(flnm);
1063 char bun[16];
1064 int nhdu = fiar.NbBlocks();
1065 if (nobj.length()<1) nobj = servnobjm->FileName2Name(flnm);
1066 string name;
1067 AnyDataObj* obj;
1068 int kon = 1;
1069 for(int k=1; k<=nhdu; k++) {
1070 obj = fiar.ReadObject(k);
1071 if (obj) {
1072 cout << " NamedObjMgr::ReadFits() " << (string)typeid(*obj).name()
1073 << " read From HDU " << k << endl;
1074 if (typeid(*obj) == typeid(DVList)) {
1075 delete obj;
1076 continue;
1077 }
1078 if (kon > 1) {
1079 sprintf(bun, "%d", kon);
1080 name = nobj + bun;
1081 }
1082 else name = nobj;
1083 AddObj_P(obj, name, false);
1084 kon++;
1085 }
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 }
1095#endif
1096
1097return;
1098}
1099
1100/* --Methode-- */
1101void NamedObjMgr::SaveObj(string & nom, POutPersist& s, bool keeppath)
1102{
1103 ZSync(*myMutex);
1104 SaveObj_P(nom, s, keeppath);
1105}
1106
1107static int key_for_write = 5000;
1108/* --Methode-- */
1109void NamedObjMgr::SaveObj_P(string & nom, POutPersist& s, bool keeppath)
1110{
1111if (nom.length() < 1) return;
1112string nob,rep;
1113ParseObjectName(nom, rep, nob);
1114nom = '/' + rep + '/' + nob;
1115NObjMgrAdapter* obja=NULL;
1116string nomf = (keeppath) ? nom : nob;
1117obja = GetObjAdapter(nom);
1118if (obja == NULL) return;
1119printf("NamedObjMgr::SaveObj(%s, ) (Type=%s) \n",
1120 nom.c_str(), typeid(*(obja->GetDataObj())).name());
1121obja->SavePPF(s, nomf);
1122return;
1123}
1124
1125/* --Methode-- */
1126void NamedObjMgr::SaveObjects(string & patt, string const& flnm)
1127{
1128ZSync(*myMutex);
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;
1136POutPersist* pout=NULL;
1137#ifdef SANS_EVOLPLANCK
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;
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
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;
1158 SaveObj_P(cn, (*pout), keeppath);
1159 }
1160delete pout;
1161return;
1162}
1163
1164/* --Methode-- */
1165void NamedObjMgr::SaveAll(string const& flnm)
1166{
1167ZSync(*myMutex);
1168bool ok = true;
1169
1170POutPersist* pout=NULL;
1171#ifdef SANS_EVOLPLANCK
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;
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
1186if (!ok) return;
1187NObjList::iterator it;
1188string no;
1189for(it = myObjs->begin(); it != myObjs->end(); it++) {
1190 no = (*it).first;
1191 SaveObj_P(no, (*pout), true);
1192 }
1193delete pout;
1194return;
1195}
1196
1197/* --Methode-- */
1198void NamedObjMgr::SaveFits(string& nom, string const & flnm)
1199{
1200ZSync(*myMutex);
1201
1202NObjMgrAdapter* obja=NULL;
1203obja = GetObjAdapter(nom);
1204if (obja == NULL) return;
1205obja->SaveFits(flnm);
1206return;
1207}
1208
1209
1210
1211/* --Methode-- */
1212void NamedObjMgr::PrintObj(string& nom)
1213{
1214ZSync(*myMutex);
1215NObjMgrAdapter* obja=NULL;
1216obja = GetObjAdapter(nom);
1217if (obja == NULL) return;
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();
1224cout << "NamedObjMgr::PrintObj(" << nom << ") Type: " << ctyp << endl;
1225obja->Print(cout);
1226
1227return;
1228}
1229
1230/* --Methode-- */
1231void NamedObjMgr::DisplayObj(string& nom, string dopt)
1232{
1233ZSync(*myMutex);
1234
1235NObjMgrAdapter* obja=NULL;
1236obja = GetObjAdapter(nom);
1237if (obja == NULL) {
1238 cout << "NamedObjMgr::DisplayObj() Error , No object with name " << nom << endl;
1239 return;
1240}
1241if (obja->GetDataObj() == NULL) {
1242 cerr << "NamedObjMgr::DisplayObj() / Error - NULL object ! in " << nom << endl;
1243 return;
1244 }
1245if (!myImgApp) return;
1246
1247PIDrawer * dr = NULL;
1248P2DArrayAdapter* arr = NULL;
1249dr = obja->GetDrawer(dopt);
1250if (!dr) arr = obja->Get2DArray(dopt);
1251
1252if (!dr && !arr) {
1253 string ctyp = typeid(*(obja->GetDataObj())).name();
1254 cout << "NamedObjMgr::DisplayObj() Error , No display for " << ctyp << endl;
1255 return;
1256 }
1257
1258int wrsid = 0;
1259
1260string n1,r1;
1261ParseObjectName(nom, r1, n1);
1262
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
1266if (dr) {
1267 PIDrawer3D * dr3 = dynamic_cast<PIDrawer3D *>(dr);
1268 if(dr3) wrsid = myImgApp->Disp3DDrawer(dr3, n1, dopt, "", 0, fglock);
1269 else wrsid = myImgApp->DispScDrawer( dr, n1, dopt, "", 0, fglock);
1270 }
1271else if (arr) wrsid = myImgApp->DispImage(arr, n1, dopt, 0, fglock);
1272
1273AddWRsId(nom, wrsid);
1274return;
1275}
1276
1277/* --Methode-- */
1278void NamedObjMgr::DisplayImage(string& nom, string dopt)
1279{
1280ZSync(*myMutex);
1281
1282NObjMgrAdapter* obja=NULL;
1283obja = GetObjAdapter(nom);
1284if (obja == NULL) {
1285 cout << "NamedObjMgr::DisplayImage() Error , No such object " << nom << endl;
1286 return;
1287}
1288if (obja->GetDataObj() == NULL) {
1289 cerr << "NamedObjMgr::DisplayImage() / Error - NULL object ! in " << nom << endl;
1290 return;
1291 }
1292if (!myImgApp) return;
1293
1294P2DArrayAdapter* arr = obja->Get2DArray(dopt);
1295
1296if (!arr) {
1297 string ctyp = typeid(*(obja->GetDataObj())).name();
1298 cout << "NamedObjMgr::DisplayImage() Error , Not supported for " << ctyp << endl;
1299 return;
1300 }
1301
1302string n1,r1;
1303ParseObjectName(nom, r1, n1);
1304
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
1308int wrsid = 0;
1309wrsid = myImgApp->DispImage(arr, n1, dopt, 0, fglock);
1310
1311AddWRsId(nom, wrsid);
1312return;
1313}
1314/* --Methode-- */
1315void NamedObjMgr::DisplaySurf3D(string& nom, string dopt)
1316{
1317ZSync(*myMutex);
1318
1319NObjMgrAdapter* obja=NULL;
1320obja = GetObjAdapter(nom);
1321if (obja == NULL) {
1322 cout << "NamedObjMgr::DisplaySurf3D() Error , No such object " << nom << endl;
1323 return;
1324}
1325if (obja->GetDataObj() == NULL) {
1326 cerr << "NamedObjMgr::DisplaySurf3D() / Error - NULL object ! in " << nom << endl;
1327 return;
1328 }
1329if (!myImgApp) return;
1330
1331P2DArrayAdapter* arr = obja->Get2DArray(dopt);
1332
1333if (!arr) {
1334 string ctyp = typeid(*(obja->GetDataObj())).name();
1335 cout << "NamedObjMgr::DisplaySurf3D() Error , Not supported " << ctyp << endl;
1336 return;
1337 }
1338
1339if ((arr->XSize() > 250) || (arr->YSize() > 250)) {
1340 cout << "NamedObjMgr::DisplaySurf3D() Error , 2D-Array(" << arr->XSize()
1341 << "x" << arr->YSize() << ") too big (max=250x250)" << endl;
1342 delete arr;
1343 return;
1344 }
1345
1346string n1,r1;
1347ParseObjectName(nom, r1, n1);
1348
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
1352int wrsid = 0;
1353PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
1354wrsid = myImgApp->Disp3DDrawer(sdr, n1, dopt, "", 0, fglock);
1355AddWRsId(nom, wrsid);
1356return;
1357}
1358
1359/* --Methode-- */
1360void NamedObjMgr::DisplayNT(string& nom, string& nmx, string& nmy, string& nmz,
1361 string& erx, string& ery, string& erz, string& wt,
1362 string& label, string dopt, bool fg3d)
1363{
1364ZSync(*myMutex);
1365
1366AnyDataObj* obj=GetObj(nom);
1367if (obj == NULL) {
1368 cout << "NamedObjMgr::DisplayNT() Error , No such object " << nom << endl;
1369 return;
1370}
1371if (!myImgApp) return;
1372
1373NTupleInterface * nt = dynamic_cast<NTupleInterface *>(obj);
1374if (nt == NULL) {
1375// if (typeid(*obj) != typeid(NTupleInterface)) {
1376 string ctyp = typeid(*obj).name();
1377 cout << "NamedObjMgr::DisplayNT() Error , Object not an NTuple " << ctyp << endl;
1378 return;
1379 }
1380
1381int wrsid = 0;
1382dopt = "defline " + dopt;
1383
1384string n1,r1;
1385ParseObjectName(nom, r1, n1);
1386
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
1390if ( fg3d && (nmz.length()>0) ) { // Display 3D
1391 PINTuple3D* pin = new PINTuple3D(nt, false);
1392 pin->SelectXYZ(nmx.c_str(), nmy.c_str(), nmz.c_str());
1393 pin->SelectWt(wt.c_str());
1394 pin->SelectLabel(label.c_str());
1395 pin->SelectErrBar(erx.c_str(), ery.c_str(), erz.c_str());
1396 string titre = nmz + "%" + nmy + "%" + nmz;
1397 wrsid = myImgApp->Disp3DDrawer(pin, n1, dopt, titre, 0, fglock);
1398}
1399else {
1400 PINTuple* pin = new PINTuple(nt, false);
1401 pin->SelectXY(nmx.c_str(), nmy.c_str());
1402 pin->SelectWt(wt.c_str());
1403 pin->SelectLabel(label.c_str());
1404 pin->SelectErrBar(erx.c_str(), ery.c_str());
1405 string titre = nmy + "%" + nmx;
1406 wrsid = myImgApp->DispScDrawer( (PIDrawer*)pin, n1, dopt, titre, 0, fglock);
1407 }
1408
1409AddWRsId(nom, wrsid);
1410return;
1411}
1412
1413/* --Methode-- cmv 13/10/98 : Obsolete mais ne pas virer SVP */
1414void NamedObjMgr::DisplayGFD(string& nom, string& numvarx, string& numvary, string& err, string dopt)
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{
1427ZSync(*myMutex);
1428
1429AnyDataObj* obj=GetObj(nom);
1430if(obj == NULL)
1431 {cout << "NamedObjMgr::DisplayGFD() Error , No such object " << nom << endl;
1432 return;}
1433if(!myImgApp) return;
1434if(typeid(*obj) != typeid(GeneralFitData))
1435 {string ctyp = typeid(*obj).name();
1436 cout<<"NamedObjMgr::DisplayGFD() Error , Object not a GeneralFitData "<<ctyp<<endl;
1437 return;}
1438
1439// Decodage des erreurs a representer
1440bool errx=false, erry=false, errz=false;
1441if(err.length()>0) {
1442 for(int i=0;i<(int_4)err.length();i++)
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
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
1452 string n1,r1;
1453 ParseObjectName(nom, r1, n1);
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;
1456
1457 int wrsid = 0;
1458 if(numvy>=0) { // display 3D
1459 PIGenFitDat3D* pigfd = new PIGenFitDat3D(((GeneralFitData*)obj),false);
1460 pigfd->SelectXY(numvx,numvy);
1461 pigfd->SelectErrBar(errx,erry,errz);
1462 wrsid = myImgApp->Disp3DDrawer(pigfd,n1,dopt,"",0,fglock);
1463} else { // display 2D
1464 PIGenFitDat* pigfd = new PIGenFitDat(((GeneralFitData*)obj),false);
1465 pigfd->SelectX(numvx);
1466 pigfd->SelectErrBar(errx,erry);
1467 wrsid = myImgApp->DispScDrawer((PIDrawer*)pigfd,n1,dopt,"",0,fglock);
1468}
1469
1470AddWRsId(nom, wrsid);
1471
1472return;
1473}
1474
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{
1480ZSync(*myMutex);
1481
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}
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;
1498 return;
1499}
1500
1501obj = GetObj(nomvy);
1502if(obj == NULL) {
1503 cout << "NamedObjMgr::DisplayVector() Error , No such object " << nomvy << endl;
1504 return;
1505}
1506BaseArray* bay = dynamic_cast<BaseArray *>(obj);
1507if (bay == NULL) {
1508 cout << "NamedObjMgr::DisplayVector() Error " << nomvy << " not a BaseArray ! " << endl;
1509 return;
1510}
1511
1512Vector vx = *bax;
1513Vector vy = *bay;
1514Vector * cvx, * cvy;
1515
1516if (vx.Size() != vy.Size()) {
1517 cout << "NamedObjMgr::DisplayVector() Warning / Vx.Size() != Vy.Size() " << endl;
1518 if (vx.Size() < vy.Size()) {
1519 cvx = new Vector(vx);
1520 cvy = new Vector(vy.SubVector(Range(0, 0, vx.Size()-1)));
1521 }
1522 else {
1523 cvx = new Vector(vx.SubVector(Range(0, 0, vy.Size()-1)));
1524 cvy = new Vector(vy);
1525 }
1526}
1527else {
1528 cvx = new Vector(vx);
1529 cvy = new Vector(vy);
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
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
1544string title = ny + " (Y) vs. " + nx + " (X)";
1545// display 2D
1546myImgApp->DispScDrawer(vxydrw, title, dopt, "", 0, fglock);
1547
1548return;
1549
1550#endif
1551}
1552
1553/* --Methode--
1554void NamedObjMgr::DisplayImage(string& nom, string dopt)
1555{
1556 cout << "NamedObjMgr::DisplayImage() a faire ! " << endl;
1557}
1558*/
1559
1560
1561
1562
1563/* --Methode--
1564void NamedObjMgr::SetGraphicAttributes(string gratt)
1565{
1566bool fg = false;
1567servnobjm->DecodeDispOption(gratt, fg);
1568Services2NObjMgr::SetDefaultStatsOption(Services2NObjMgr::GetStatsOption(gratt));
1569}
1570
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}
1577*/
1578
1579/* --Methode-- */
1580void NamedObjMgr::AddWRsId(string & nom, int wrsid)
1581{
1582if(wrsid != 0) {
1583 NObjList::iterator it = myObjs->find(nom);
1584 if (it == myObjs->end()) return;
1585 (*it).second.wrsid.push_back(wrsid);
1586 }
1587return;
1588}
1589
1590/* --Methode-- */
1591void NamedObjMgr::UpdateObjMgrWindow(int did)
1592{
1593if (!myImgApp) return;
1594ZSync(*myMutex);
1595if ( !_fgimgapp ) ZSync(myImgApp->getMutex(),2);
1596
1597(myImgApp->ObjMgrW())->ClearObjList();
1598
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);
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() + ")" ;
1606 (myImgApp->ObjMgrW())->AddObj(cn.c_str(), (*it).second.oid);
1607 }
1608}
1609
1610
1611/* Nouvelle-Fonction */
1612void NamedObjMgr::RemoveSpacesFromName(string & nom)
1613{
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);
1621}
1622
1623/* Nouvelle-Fonction */
1624bool NamedObjMgr::CheckDirName(string & nom)
1625{
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);
1631if ((nom.length() < 1) || (! isalpha(nom[0]) ) ) return(false);
1632return(true);
1633}
1634
1635/* Nouvelle-Fonction */
1636int NamedObjMgr::ParseObjectName(string & nom, string & nomrep, string & nomobj)
1637{
1638RemoveSpacesFromName(nom);
1639// Si le nom ne commence pas par un slash, c'est le repertoire courant
1640if (nom[0] != '/') { nomrep = *currDir; nomobj = nom; }
1641else {
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);
1647 }
1648 else {
1649 nomrep = xx;
1650 nomobj = "";
1651 }
1652 }
1653int rc = 0;
1654NObjDirList::iterator it = myDirs->find(nomrep);
1655if (it != myDirs->end()) rc = (*it).second.id;
1656return(rc);
1657}
1658
Note: See TracBrowser for help on using the repository browser.