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

TGo4FolderProxy.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 "TGo4FolderProxy.h"
00017 
00018 #include "TROOT.h"
00019 #include "TClass.h"
00020 #include "TTree.h"
00021 
00022 #include "TGo4ObjectProxy.h"
00023 #include "TGo4DirProxy.h"
00024 #include "TGo4TreeProxy.h"
00025 #include "TGo4CanvasProxy.h"
00026 #include "TGo4Slot.h"
00027 
00028 
00029 class TGo4FolderLevelIter : public TGo4LevelIter {
00030    public:
00031       TGo4FolderLevelIter(TFolder* folder) :
00032          TGo4LevelIter(), 
00033          fIter(0), 
00034          fCurrent(0)
00035       {
00036          fIter = folder->GetListOfFolders()->MakeIterator(); 
00037       }
00038 
00039       virtual ~TGo4FolderLevelIter()
00040       {
00041          delete fIter;
00042       }
00043 
00044       virtual Bool_t next()
00045       {
00046          fCurrent = fIter->Next();
00047          return (fCurrent!=0);
00048       }
00049 
00050       virtual Bool_t isfolder()
00051       {
00052          return (dynamic_cast<TFolder*>(fCurrent)!=0) ||
00053                 (dynamic_cast<TDirectory*>(fCurrent)!=0) ||
00054                 (dynamic_cast<TTree*>(fCurrent)!=0) ||
00055                 (dynamic_cast<TCanvas*>(fCurrent)!=0);
00056       }
00057       
00058       virtual TGo4LevelIter* subiterator()
00059       {
00060          TTree* tr = dynamic_cast<TTree*>(fCurrent);
00061          if (tr!=0) return TGo4TreeProxy::ProduceIter(tr);
00062          TDirectory* dir = dynamic_cast<TDirectory*>(fCurrent);
00063          if (dir!=0) return TGo4DirProxy::ProduceIter(dir, kFALSE);
00064          TCanvas* canv = dynamic_cast<TCanvas*>(fCurrent);
00065          if (canv!=0) return TGo4CanvasProxy::ProduceIter(canv);
00066          return new TGo4FolderLevelIter((TFolder*)fCurrent);
00067       }
00068       
00069       virtual const char* name()
00070       {
00071          return fCurrent->GetName();
00072       }
00073  
00074       virtual const char* info()
00075       {
00076          return fCurrent->ClassName();
00077       }
00078  
00079       virtual Int_t GetKind()
00080       {
00081          return isfolder() ? TGo4Access::kndFolder : TGo4Access::kndObject;
00082       }
00083  
00084       virtual const char* GetClassName()
00085       {
00086          return fCurrent->ClassName();
00087       }
00088  
00089    protected:
00090       TIterator*     fIter;     
00091       TObject*       fCurrent;  
00092 };
00093 
00094 // ****************************************************************
00095 
00096 TGo4FolderProxy::TGo4FolderProxy() : 
00097    TGo4Proxy(),
00098    fFolder(0),
00099    fOwner(kFALSE),
00100    fRootFolderName()
00101 {
00102 }
00103 
00104 TGo4FolderProxy::TGo4FolderProxy(TFolder* f, Bool_t owner, const char* rootfolder) :
00105    TGo4Proxy(),
00106    fFolder(f),
00107    fOwner(owner),
00108    fRootFolderName(rootfolder)
00109 {
00110 }
00111 
00112 TGo4FolderProxy::~TGo4FolderProxy()
00113 {
00114    if (fOwner) delete fFolder;  
00115 }
00116 
00117 Int_t TGo4FolderProxy::GetObjectKind()
00118 {
00119    return (fFolder!=0) ? TGo4Access::kndFolder : TGo4Access::kndNone; 
00120 }
00121 
00122 const char* TGo4FolderProxy::GetContainedClassName()
00123 {
00124    return fFolder ? fFolder->ClassName() : 0;
00125 }
00126 
00127 void TGo4FolderProxy::WriteData(TGo4Slot* slot, TDirectory* dir, Bool_t onlyobjs)
00128 {
00129    if (!onlyobjs) { 
00130       const char* foldername = fRootFolderName.Length()>0 ? fRootFolderName.Data() : 0;
00131       slot->SetPar("FolderProxy::RootFolder", foldername);
00132    }
00133 }
00134 
00135 void TGo4FolderProxy::ReadData(TGo4Slot* slot, TDirectory* dir)
00136 {
00137    const char* foldername = slot->GetPar("FolderProxy::RootFolder");
00138    
00139    fFolder = LocateROOTFolder(foldername);
00140    if (fFolder!=0) 
00141       fRootFolderName = foldername;
00142    fOwner = kFALSE;
00143 }
00144 
00145 TFolder* TGo4FolderProxy::LocateROOTFolder(const char* rootfolder)
00146 {
00147    TFolder* res = 0;
00148    if (rootfolder!=0){ 
00149      if (strcmp(rootfolder,"//root/")==0) 
00150         res = gROOT->GetRootFolder();
00151      else  
00152        res = dynamic_cast<TFolder*> (gROOT->GetRootFolder()->FindObject(rootfolder));
00153    }
00154    return res;    
00155 }
00156 
00157 
00158 TGo4Access* TGo4FolderProxy::ProduceProxy(TFolder* folder, const char* name)
00159 {
00160    if (folder==0) return 0; 
00161    if ((name==0) || (*name==0)) return new TGo4ObjectAccess(folder);
00162    
00163    TFolder* curfold = folder;
00164    const char* curname = name;
00165       
00166    while (curfold!=0) { 
00167       const char* slash = strchr(curname,'/');
00168       UInt_t len = (slash!=0) ? slash - curname : strlen(curname);
00169       TIter iter(curfold->GetListOfFolders());
00170       TObject* obj = 0;
00171       while ((obj = iter())!=0) 
00172          if ((strlen(obj->GetName())==len) &&
00173              (strncmp(obj->GetName(), curname, len)==0)) break;
00174       if (obj==0) return 0;
00175       
00176       if (slash==0) return new TGo4ObjectAccess(obj);
00177       
00178       curname = slash+1;
00179             
00180       TTree* tr = dynamic_cast<TTree*> (obj);
00181       if (tr!=0)
00182          return TGo4TreeProxy::ProduceProxy(tr, curname);
00183          
00184       TDirectory* dir = dynamic_cast<TDirectory*> (obj);
00185       if (dir!=0)
00186          return TGo4DirProxy::ProduceProxy(dir, kFALSE, curname);
00187             
00188       TCanvas* canv = dynamic_cast<TCanvas*> (obj);
00189       if (canv!=0)
00190          return TGo4CanvasProxy::ProduceProxy(canv, curname);
00191             
00192       curfold = dynamic_cast<TFolder*>(obj);
00193    }
00194    
00195    return 0;
00196 }
00197 
00198 TGo4LevelIter* TGo4FolderProxy::ProduceIter(TFolder* folder)
00199 {
00200    return new TGo4FolderLevelIter(folder); 
00201 }
00202 
00203 //----------------------------END OF GO4 SOURCE FILE ---------------------

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