GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4TreeProxy.cxx
Go to the documentation of this file.
1 // $Id: TGo4TreeProxy.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 "TGo4TreeProxy.h"
15 
16 #include "TTree.h"
17 #include "TBranch.h"
18 #include "TIterator.h"
19 
20 #include "TGo4ObjectProxy.h"
21 
22 class TGo4BranchAccess : public TGo4Access {
23  public:
24  TGo4BranchAccess(TBranch* br) : TGo4Access(), fBranch(br) {}
25 
26  virtual const char* GetObjectName() const
27  { return fBranch->GetName(); }
28 
29  virtual const char* GetObjectClassName() const
30  { return fBranch->ClassName(); }
31 
32  private:
33  TBranch* fBranch;
34 };
35 
36 // ****************************************************************
37 
39  public:
40  TGo4TreeLevelIter(TTree* tree) :
41  TGo4LevelIter(),
42  fIter(0),
43  fCurrent(0)
44  {
45  fIter = tree->GetListOfBranches()->MakeIterator();
46  }
47 
48  TGo4TreeLevelIter(TBranch* branch) :
49  TGo4LevelIter(),
50  fIter(0),
51  fCurrent(0)
52  {
53  fIter = branch->GetListOfBranches()->MakeIterator();
54  }
55 
57  {
58  delete fIter;
59  }
60 
61  virtual Bool_t next()
62  {
63  do {
64  TObject* res = fIter->Next();
65  if (res==0) return kFALSE;
66  fCurrent = dynamic_cast<TBranch*> (res);
67  } while (fCurrent==0);
68  return kTRUE;
69  }
70 
71  virtual Bool_t isfolder()
72  {
73  return fCurrent->GetListOfBranches()->GetEntries() > 0;
74  }
75 
77  {
78  return new TGo4TreeLevelIter(fCurrent);
79  }
80 
81  virtual const char* name()
82  {
83  return fCurrent->GetName();
84  }
85 
86  virtual const char* info()
87  {
88  return fCurrent->GetClassName();
89  }
90 
91  virtual Int_t GetKind()
92  {
94  }
95 
96  virtual const char* GetClassName()
97  {
98  return fCurrent->ClassName();
99  }
100 
101  protected:
102  TIterator* fIter;
103  TBranch* fCurrent;
104 };
105 
106 // ***********************************************************************
107 
109  TGo4Proxy(),
110  fTree(0),
111  fOwner(0)
112 {
113 }
114 
115 TGo4TreeProxy::TGo4TreeProxy(TTree* tree, Bool_t owner) :
116  TGo4Proxy(),
117  fTree(tree),
118  fOwner(owner)
119 {
120 }
121 
123 {
124  if (fOwner) delete fTree;
125 }
126 
128 {
130 }
131 
132 
134 {
135  return (fTree!=0) ? fTree->ClassName() : 0;
136 }
137 
138 TGo4Access* TGo4TreeProxy::CreateAccess(TTree* tree, const char* name)
139 {
140  if (tree==0) return 0;
141 
142  if ((name==0) || (*name==0)) return new TGo4ObjectAccess(tree);
143 
144  TObjArray* list = tree->GetListOfBranches();
145  const char* curname = name;
146 
147  while (list!=0) {
148  const char* slash = strchr(curname,'/');
149  UInt_t len = (slash!=0) ? slash - curname : strlen(curname);
150  TIter iter(list);
151  TObject* obj = 0;
152  while ((obj = iter())!=0)
153  if ((strlen(obj->GetName())==len) &&
154  (strncmp(obj->GetName(), curname, len)==0)) break;
155  TBranch* br = dynamic_cast<TBranch*> (obj);
156  if (br==0) return 0;
157 
158  if (slash!=0) {
159  list = br->GetListOfBranches();
160  curname = slash+1;
161  } else
162  return new TGo4BranchAccess(br);
163  }
164  return 0;
165 }
166 
168 {
169  return new TGo4TreeLevelIter(tree);
170 }
static TGo4LevelIter * ProduceIter(TTree *tree)
virtual Int_t GetObjectKind()
TGo4TreeLevelIter(TTree *tree)
TGo4BranchAccess(TBranch *br)
virtual const char * GetObjectName() const
virtual const char * GetContainedClassName()
virtual const char * GetClassName()
virtual Bool_t next()
virtual ~TGo4TreeProxy()
virtual TGo4LevelIter * subiterator()
virtual const char * info()
virtual Bool_t isfolder()
static TGo4Access * CreateAccess(TTree *tree, const char *name)
virtual const char * GetObjectClassName() const
TGo4TreeLevelIter(TBranch *branch)
virtual const char * name()
virtual Int_t GetKind()
virtual ~TGo4TreeLevelIter()