Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4TreeProxy.h"
00015
00016 #include "TTree.h"
00017 #include "TBranch.h"
00018 #include "TIterator.h"
00019 #include "TObjArray.h"
00020
00021 #include "TGo4ObjectProxy.h"
00022
00023 class TGo4BranchAccess : public TGo4Access {
00024 public:
00025 TGo4BranchAccess(TBranch* br) : TGo4Access(), fBranch(br) {}
00026
00027 virtual const char* GetObjectName() const
00028 { return fBranch->GetName(); }
00029
00030 virtual const char* GetObjectClassName() const
00031 { return fBranch->ClassName(); }
00032
00033 private:
00034 TBranch* fBranch;
00035 };
00036
00037
00038
00039 class TGo4TreeLevelIter : public TGo4LevelIter {
00040 public:
00041 TGo4TreeLevelIter(TTree* tree) :
00042 TGo4LevelIter(),
00043 fIter(0),
00044 fCurrent(0)
00045 {
00046 fIter = tree->GetListOfBranches()->MakeIterator();
00047 }
00048
00049 TGo4TreeLevelIter(TBranch* branch) :
00050 TGo4LevelIter(),
00051 fIter(0),
00052 fCurrent(0)
00053 {
00054 fIter = branch->GetListOfBranches()->MakeIterator();
00055 }
00056
00057 virtual ~TGo4TreeLevelIter()
00058 {
00059 delete fIter;
00060 }
00061
00062 virtual Bool_t next()
00063 {
00064 do {
00065 TObject* res = fIter->Next();
00066 if (res==0) return kFALSE;
00067 fCurrent = dynamic_cast<TBranch*> (res);
00068 } while (fCurrent==0);
00069 return kTRUE;
00070 }
00071
00072 virtual Bool_t isfolder()
00073 {
00074 return fCurrent->GetListOfBranches()->GetEntries() > 0;
00075 }
00076
00077 virtual TGo4LevelIter* subiterator()
00078 {
00079 return new TGo4TreeLevelIter(fCurrent);
00080 }
00081
00082 virtual const char* name()
00083 {
00084 return fCurrent->GetName();
00085 }
00086
00087 virtual const char* info()
00088 {
00089 return fCurrent->GetClassName();
00090 }
00091
00092 virtual Int_t GetKind()
00093 {
00094 return isfolder() ? TGo4Access::kndTreeBranch : TGo4Access::kndTreeLeaf;
00095 }
00096
00097 virtual const char* GetClassName()
00098 {
00099 return fCurrent->ClassName();
00100 }
00101
00102 protected:
00103 TIterator* fIter;
00104 TBranch* fCurrent;
00105 };
00106
00107
00108
00109 TGo4TreeProxy::TGo4TreeProxy() :
00110 TGo4Proxy(),
00111 fTree(0),
00112 fOwner(0)
00113 {
00114 }
00115
00116 TGo4TreeProxy::TGo4TreeProxy(TTree* tree, Bool_t owner) :
00117 TGo4Proxy(),
00118 fTree(tree),
00119 fOwner(owner)
00120 {
00121 }
00122
00123 TGo4TreeProxy::~TGo4TreeProxy()
00124 {
00125 if (fOwner) delete fTree;
00126 }
00127
00128 Int_t TGo4TreeProxy::GetObjectKind()
00129 {
00130 return (fTree!=0) ? TGo4Access::kndFolder : TGo4Access::kndNone;
00131 }
00132
00133
00134 const char* TGo4TreeProxy::GetContainedClassName()
00135 {
00136 return (fTree!=0) ? fTree->ClassName() : 0;
00137 }
00138
00139 TGo4Access* TGo4TreeProxy::ProduceProxy(TTree* tree, const char* name)
00140 {
00141 if (tree==0) return 0;
00142
00143 if ((name==0) || (*name==0)) return new TGo4ObjectAccess(tree);
00144
00145 TObjArray* list = tree->GetListOfBranches();
00146 const char* curname = name;
00147
00148 while (list!=0) {
00149 const char* slash = strchr(curname,'/');
00150 UInt_t len = (slash!=0) ? slash - curname : strlen(curname);
00151 TIter iter(list);
00152 TObject* obj = 0;
00153 while ((obj = iter())!=0)
00154 if ((strlen(obj->GetName())==len) &&
00155 (strncmp(obj->GetName(), curname, len)==0)) break;
00156 TBranch* br = dynamic_cast<TBranch*> (obj);
00157 if (br==0) return 0;
00158
00159 if (slash!=0) {
00160 list = br->GetListOfBranches();
00161 curname = slash+1;
00162 } else
00163 return new TGo4BranchAccess(br);
00164 }
00165 return 0;
00166 }
00167
00168 TGo4LevelIter* TGo4TreeProxy::ProduceIter(TTree* tree)
00169 {
00170 return new TGo4TreeLevelIter(tree);
00171 }