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