Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4TreeProxy.cxx

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

Generated on Fri Nov 28 12:59:27 2008 for Go4-v3.04-1 by  doxygen 1.4.2