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

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

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

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