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