GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4FolderProxy.cxx
Go to the documentation of this file.
1 // $Id: TGo4FolderProxy.cxx 2740 2020-04-15 21:02:30Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4FolderProxy.h"
15 
16 #include "TROOT.h"
17 #include "TTree.h"
18 #include "TFolder.h"
19 #include "TCanvas.h"
20 #include "THStack.h"
21 
22 #include "TGo4ObjectProxy.h"
23 #include "TGo4DirProxy.h"
24 #include "TGo4TreeProxy.h"
25 #include "TGo4CanvasProxy.h"
26 #include "TGo4HStackProxy.h"
27 #include "TGo4Slot.h"
28 
29 
31  public:
32  TGo4FolderLevelIter(TFolder* folder) :
33  TGo4LevelIter(),
34  fIter(0),
35  fCurrent(0)
36  {
37  fIter = folder->GetListOfFolders()->MakeIterator();
38  }
39 
41  {
42  delete fIter;
43  }
44 
45  virtual Bool_t next()
46  {
47  fCurrent = fIter->Next();
48  return (fCurrent!=0);
49  }
50 
51  virtual Bool_t isfolder()
52  {
53  return (dynamic_cast<TFolder*>(fCurrent)!=0) ||
54  (dynamic_cast<TDirectory*>(fCurrent)!=0) ||
55  (dynamic_cast<TTree*>(fCurrent)!=0) ||
56  (dynamic_cast<TCanvas*>(fCurrent)!=0) ||
57  (dynamic_cast<THStack*>(fCurrent)!=0);
58  }
59 
61  {
62  TTree* tr = dynamic_cast<TTree*>(fCurrent);
63  if (tr!=0) return TGo4TreeProxy::ProduceIter(tr);
64  TDirectory* dir = dynamic_cast<TDirectory*>(fCurrent);
65  if (dir!=0) return TGo4DirProxy::ProduceIter(dir, kFALSE);
66  TCanvas* canv = dynamic_cast<TCanvas*>(fCurrent);
67  if (canv!=0) return TGo4CanvasProxy::ProduceIter(canv);
68  THStack* hs = dynamic_cast<THStack*> (fCurrent);
69  if (hs!=0) return TGo4HStackProxy::ProduceIter(hs);
70  return new TGo4FolderLevelIter((TFolder*)fCurrent);
71  }
72 
73  virtual const char* name()
74  {
75  return fCurrent->GetName();
76  }
77 
78  virtual const char* info()
79  {
80  return fCurrent->ClassName();
81  }
82 
83  virtual Int_t GetKind()
84  {
86  }
87 
88  virtual const char* GetClassName()
89  {
90  return fCurrent->ClassName();
91  }
92 
93  protected:
94  TIterator* fIter;
95  TObject* fCurrent;
96 };
97 
98 // ****************************************************************
99 
101  TGo4Proxy(),
102  fFolder(0),
103  fOwner(kFALSE),
104  fRootFolderName()
105 {
106 }
107 
108 TGo4FolderProxy::TGo4FolderProxy(TFolder* f, Bool_t owner, const char* rootfolder) :
109  TGo4Proxy(),
110  fFolder(f),
111  fOwner(owner),
112  fRootFolderName(rootfolder)
113 {
114 }
115 
117 {
118  if (fOwner) delete fFolder;
119 }
120 
122 {
124 }
125 
127 {
128  return fFolder ? fFolder->ClassName() : 0;
129 }
130 
131 void TGo4FolderProxy::WriteData(TGo4Slot* slot, TDirectory* dir, Bool_t onlyobjs)
132 {
133  if (!onlyobjs) {
134  const char* foldername = fRootFolderName.Length()>0 ? fRootFolderName.Data() : 0;
135  slot->SetPar("FolderProxy::RootFolder", foldername);
136  }
137 }
138 
139 void TGo4FolderProxy::ReadData(TGo4Slot* slot, TDirectory* dir)
140 {
141  const char* foldername = slot->GetPar("FolderProxy::RootFolder");
142 
143  fFolder = LocateROOTFolder(foldername);
144  if (fFolder!=0)
145  fRootFolderName = foldername;
146  fOwner = kFALSE;
147 }
148 
149 TFolder* TGo4FolderProxy::LocateROOTFolder(const char* rootfolder)
150 {
151  TFolder* res = 0;
152  if (rootfolder!=0){
153  if (strcmp(rootfolder,"//root/")==0)
154  res = gROOT->GetRootFolder();
155  else
156  res = dynamic_cast<TFolder*> (gROOT->GetRootFolder()->FindObject(rootfolder));
157  }
158  return res;
159 }
160 
161 
162 TGo4Access* TGo4FolderProxy::CreateAccess(TFolder* folder, const char* name)
163 {
164  if (folder==0) return 0;
165  if ((name==0) || (*name==0)) return new TGo4ObjectAccess(folder);
166 
167  TFolder* curfold = folder;
168  const char* curname = name;
169 
170  while (curfold!=0) {
171  const char* slash = strchr(curname,'/');
172  UInt_t len = (slash!=0) ? slash - curname : strlen(curname);
173  TIter iter(curfold->GetListOfFolders());
174  TObject* obj = 0;
175  while ((obj = iter())!=0)
176  if ((strlen(obj->GetName())==len) &&
177  (strncmp(obj->GetName(), curname, len)==0)) break;
178  if (obj==0) return 0;
179 
180  if (slash==0) return new TGo4ObjectAccess(obj);
181 
182  curname = slash+1;
183 
184  TTree* tr = dynamic_cast<TTree*> (obj);
185  if (tr!=0)
186  return TGo4TreeProxy::CreateAccess(tr, curname);
187 
188  TDirectory* dir = dynamic_cast<TDirectory*> (obj);
189  if (dir!=0)
190  return TGo4DirProxy::CreateAccess(dir, kFALSE, curname);
191 
192  TCanvas* canv = dynamic_cast<TCanvas*> (obj);
193  if (canv!=0)
194  return TGo4CanvasProxy::CreateAccess(canv, curname);
195 
196  THStack* hs = dynamic_cast<THStack*> (obj);
197  if (hs!=0)
198  return TGo4HStackProxy::CreateAccess(hs, curname);
199 
200  curfold = dynamic_cast<TFolder*>(obj);
201  }
202 
203  return 0;
204 }
205 
207 {
208  return new TGo4FolderLevelIter(folder);
209 }
virtual void ReadData(TGo4Slot *slot, TDirectory *dir)
TGo4FolderLevelIter(TFolder *folder)
TString fRootFolderName
static TGo4LevelIter * ProduceIter(TTree *tree)
static TGo4LevelIter * ProduceIter(THStack *canv)
static TGo4Access * CreateAccess(TCanvas *canv, const char *name)
const char * GetPar(const char *name) const
Definition: TGo4Slot.cxx:617
virtual ~TGo4FolderLevelIter()
virtual Bool_t isfolder()
virtual const char * name()
static TGo4LevelIter * ProduceIter(TCanvas *canv)
static TGo4LevelIter * ProduceIter(TDirectory *dir, Bool_t readright)
virtual Int_t GetKind()
virtual Bool_t next()
static TFolder * LocateROOTFolder(const char *rootfolder)
virtual TGo4LevelIter * subiterator()
static TGo4Access * CreateAccess(TFolder *folder, const char *name)
virtual const char * GetContainedClassName()
static TGo4Access * CreateAccess(THStack *canv, const char *name)
virtual const char * GetClassName()
virtual Int_t GetObjectKind()
virtual const char * info()
static TGo4Access * CreateAccess(TTree *tree, const char *name)
virtual ~TGo4FolderProxy()
virtual void WriteData(TGo4Slot *slot, TDirectory *dir, Bool_t onlyobjs)
static TGo4LevelIter * ProduceIter(TFolder *folder)
void SetPar(const char *name, const char *value)
Definition: TGo4Slot.cxx:605
static TGo4Access * CreateAccess(TDirectory *dir, Bool_t readright, const char *name, TGo4Slot *browser_slot=0)