GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4FolderProxy.cxx
Go to the documentation of this file.
1 // $Id: TGo4FolderProxy.cxx 1352 2015-01-27 10:03:25Z 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 für 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 "TClass.h"
18 #include "TTree.h"
19 
20 #include "TGo4ObjectProxy.h"
21 #include "TGo4DirProxy.h"
22 #include "TGo4TreeProxy.h"
23 #include "TGo4CanvasProxy.h"
24 #include "TGo4HStackProxy.h"
25 #include "TGo4Slot.h"
26 
27 
29  public:
30  TGo4FolderLevelIter(TFolder* folder) :
31  TGo4LevelIter(),
32  fIter(0),
33  fCurrent(0)
34  {
35  fIter = folder->GetListOfFolders()->MakeIterator();
36  }
37 
39  {
40  delete fIter;
41  }
42 
43  virtual Bool_t next()
44  {
45  fCurrent = fIter->Next();
46  return (fCurrent!=0);
47  }
48 
49  virtual Bool_t isfolder()
50  {
51  return (dynamic_cast<TFolder*>(fCurrent)!=0) ||
52  (dynamic_cast<TDirectory*>(fCurrent)!=0) ||
53  (dynamic_cast<TTree*>(fCurrent)!=0) ||
54  (dynamic_cast<TCanvas*>(fCurrent)!=0) ||
55  (dynamic_cast<THStack*>(fCurrent)!=0);
56  }
57 
59  {
60  TTree* tr = dynamic_cast<TTree*>(fCurrent);
61  if (tr!=0) return TGo4TreeProxy::ProduceIter(tr);
62  TDirectory* dir = dynamic_cast<TDirectory*>(fCurrent);
63  if (dir!=0) return TGo4DirProxy::ProduceIter(dir, kFALSE);
64  TCanvas* canv = dynamic_cast<TCanvas*>(fCurrent);
65  if (canv!=0) return TGo4CanvasProxy::ProduceIter(canv);
66  THStack* hs = dynamic_cast<THStack*> (fCurrent);
67  if (hs!=0) return TGo4HStackProxy::ProduceIter(hs);
68  return new TGo4FolderLevelIter((TFolder*)fCurrent);
69  }
70 
71  virtual const char* name()
72  {
73  return fCurrent->GetName();
74  }
75 
76  virtual const char* info()
77  {
78  return fCurrent->ClassName();
79  }
80 
81  virtual Int_t GetKind()
82  {
84  }
85 
86  virtual const char* GetClassName()
87  {
88  return fCurrent->ClassName();
89  }
90 
91  protected:
92  TIterator* fIter;
93  TObject* fCurrent;
94 };
95 
96 // ****************************************************************
97 
99  TGo4Proxy(),
100  fFolder(0),
101  fOwner(kFALSE),
102  fRootFolderName()
103 {
104 }
105 
106 TGo4FolderProxy::TGo4FolderProxy(TFolder* f, Bool_t owner, const char* rootfolder) :
107  TGo4Proxy(),
108  fFolder(f),
109  fOwner(owner),
110  fRootFolderName(rootfolder)
111 {
112 }
113 
115 {
116  if (fOwner) delete fFolder;
117 }
118 
120 {
122 }
123 
125 {
126  return fFolder ? fFolder->ClassName() : 0;
127 }
128 
129 void TGo4FolderProxy::WriteData(TGo4Slot* slot, TDirectory* dir, Bool_t onlyobjs)
130 {
131  if (!onlyobjs) {
132  const char* foldername = fRootFolderName.Length()>0 ? fRootFolderName.Data() : 0;
133  slot->SetPar("FolderProxy::RootFolder", foldername);
134  }
135 }
136 
137 void TGo4FolderProxy::ReadData(TGo4Slot* slot, TDirectory* dir)
138 {
139  const char* foldername = slot->GetPar("FolderProxy::RootFolder");
140 
141  fFolder = LocateROOTFolder(foldername);
142  if (fFolder!=0)
143  fRootFolderName = foldername;
144  fOwner = kFALSE;
145 }
146 
147 TFolder* TGo4FolderProxy::LocateROOTFolder(const char* rootfolder)
148 {
149  TFolder* res = 0;
150  if (rootfolder!=0){
151  if (strcmp(rootfolder,"//root/")==0)
152  res = gROOT->GetRootFolder();
153  else
154  res = dynamic_cast<TFolder*> (gROOT->GetRootFolder()->FindObject(rootfolder));
155  }
156  return res;
157 }
158 
159 
160 TGo4Access* TGo4FolderProxy::CreateAccess(TFolder* folder, const char* name)
161 {
162  if (folder==0) return 0;
163  if ((name==0) || (*name==0)) return new TGo4ObjectAccess(folder);
164 
165  TFolder* curfold = folder;
166  const char* curname = name;
167 
168  while (curfold!=0) {
169  const char* slash = strchr(curname,'/');
170  UInt_t len = (slash!=0) ? slash - curname : strlen(curname);
171  TIter iter(curfold->GetListOfFolders());
172  TObject* obj = 0;
173  while ((obj = iter())!=0)
174  if ((strlen(obj->GetName())==len) &&
175  (strncmp(obj->GetName(), curname, len)==0)) break;
176  if (obj==0) return 0;
177 
178  if (slash==0) return new TGo4ObjectAccess(obj);
179 
180  curname = slash+1;
181 
182  TTree* tr = dynamic_cast<TTree*> (obj);
183  if (tr!=0)
184  return TGo4TreeProxy::CreateAccess(tr, curname);
185 
186  TDirectory* dir = dynamic_cast<TDirectory*> (obj);
187  if (dir!=0)
188  return TGo4DirProxy::CreateAccess(dir, kFALSE, curname);
189 
190  TCanvas* canv = dynamic_cast<TCanvas*> (obj);
191  if (canv!=0)
192  return TGo4CanvasProxy::CreateAccess(canv, curname);
193 
194  THStack* hs = dynamic_cast<THStack*> (obj);
195  if (hs!=0)
196  return TGo4HStackProxy::CreateAccess(hs, curname);
197 
198  curfold = dynamic_cast<TFolder*>(obj);
199  }
200 
201  return 0;
202 }
203 
205 {
206  return new TGo4FolderLevelIter(folder);
207 }
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:621
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:609
static TGo4Access * CreateAccess(TDirectory *dir, Bool_t readright, const char *name, TGo4Slot *browser_slot=0)