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