Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4HStackProxy.h"
00015
00016 #include "TROOT.h"
00017 #include "TObjArray.h"
00018 #include "TClass.h"
00019 #include "TFrame.h"
00020 #include "TPaveText.h"
00021 #include "TObjString.h"
00022 #include "THStack.h"
00023 #include "TH1.h"
00024
00025 #include "TGo4Slot.h"
00026 #include "TGo4ObjectProxy.h"
00027 #include "TGo4ObjectManager.h"
00028
00029 class TGo4HStackLevelIter : public TGo4LevelIter {
00030 protected:
00031 TIterator* fIter;
00032 TObject* fCurrent;
00033 public:
00034 TGo4HStackLevelIter(THStack* hs) :
00035 TGo4LevelIter(),
00036 fIter(0),
00037 fCurrent(0)
00038 {
00039 fIter = hs->GetHists()->MakeIterator();
00040 }
00041
00042 virtual ~TGo4HStackLevelIter()
00043 {
00044 delete fIter;
00045 }
00046
00047 virtual Bool_t next()
00048 {
00049 fCurrent = fIter->Next();
00050 return (fCurrent!=0);
00051 }
00052
00053 virtual Bool_t isfolder()
00054 {
00055 return kFALSE;
00056 }
00057
00058 virtual TGo4LevelIter* subiterator()
00059 {
00060 return 0;
00061 }
00062
00063 virtual const char* name()
00064 {
00065 return fCurrent->GetName();
00066 }
00067
00068 virtual const char* info()
00069 {
00070 return fCurrent->ClassName();
00071 }
00072
00073 virtual Int_t GetKind()
00074 {
00075 return TGo4Access::kndObject;
00076 }
00077
00078 virtual const char* GetClassName()
00079 {
00080 return fCurrent->ClassName();
00081 }
00082 };
00083
00084
00085
00086 TGo4HStackProxy::TGo4HStackProxy() :
00087 TGo4Proxy(),
00088 fHS(0),
00089 fOwner(kFALSE)
00090 {
00091 }
00092
00093 TGo4HStackProxy::TGo4HStackProxy(THStack* hs, Bool_t owner) :
00094 TGo4Proxy(),
00095 fHS(hs),
00096 fOwner(owner)
00097 {
00098 }
00099
00100 TGo4HStackProxy::~TGo4HStackProxy()
00101 {
00102 if (fOwner) delete fHS;
00103 }
00104
00105 Int_t TGo4HStackProxy::GetObjectKind()
00106 {
00107 return (fHS!=0) ? TGo4Access::kndFolder : TGo4Access::kndNone;
00108 }
00109
00110 const char* TGo4HStackProxy::GetContainedClassName()
00111 {
00112 return fHS ? fHS->ClassName() : 0;
00113 }
00114
00115 void TGo4HStackProxy::Initialize(TGo4Slot* slot)
00116 {
00117 TGo4ObjectManager* om = slot->GetOM();
00118 if (om!=0) om->RegisterObjectWith(fHS, slot);
00119 }
00120
00121 void TGo4HStackProxy::Finalize(TGo4Slot* slot)
00122 {
00123 TGo4ObjectManager* om = slot->GetOM();
00124 if (om!=0) om->UnregisterObject(fHS, slot);
00125 }
00126
00127 Bool_t TGo4HStackProxy::RemoveRegisteredObject(TObject* obj)
00128 {
00129 if (obj==fHS) {
00130 fHS = 0;
00131 fOwner = kFALSE;
00132 }
00133 return kFALSE;
00134 }
00135
00136 void TGo4HStackProxy::WriteData(TGo4Slot* slot, TDirectory* dir, Bool_t onlyobjs)
00137 {
00138 const char* objname = 0;
00139 if (fHS!=0)
00140 objname = fHS->GetName();
00141
00142 if (!onlyobjs)
00143 slot->SetPar("HStackProxy::StackName", objname);
00144
00145 if ((dir==0) || (fHS==0)) return;
00146
00147 dir->cd();
00148
00149 fHS->Write(objname);
00150 }
00151
00152 void TGo4HStackProxy::ReadData(TGo4Slot* slot, TDirectory* dir)
00153 {
00154 const char* objname = slot->GetPar("HStackProxy::StackName");
00155 if ((objname==0) || (dir==0)) return;
00156
00157 dir->cd();
00158
00159 AssignObject(slot, dir->Get(objname), kTRUE);
00160 }
00161
00162 Bool_t TGo4HStackProxy::IsAcceptObject(TClass* cl)
00163 {
00164 return (cl!=0) && cl->InheritsFrom(THStack::Class());
00165 }
00166
00167 Bool_t TGo4HStackProxy::AssignObject(TGo4Slot* slot, TObject* obj, Bool_t owner)
00168 {
00169 Finalize(slot);
00170 if ((fHS!=0) && fOwner) delete fHS;
00171
00172 fHS = dynamic_cast<THStack*> (obj);
00173 fOwner = owner && (fHS!=0);
00174
00175 if ((fHS==0) && (obj!=0) && owner) delete obj;
00176
00177 Initialize(slot);
00178
00179 slot->ForwardEvent(slot, TGo4Slot::evObjAssigned);
00180
00181 return fHS!=0;
00182 }
00183
00184 TObject* TGo4HStackProxy::GetAssignedObject()
00185 {
00186 return fHS;
00187 }
00188
00189 TGo4Access* TGo4HStackProxy::ProduceProxy(THStack* hs, const char* name)
00190 {
00191 if (hs==0) return 0;
00192 if ((name==0) || (*name==0)) return new TGo4ObjectAccess(hs);
00193
00194 TObject* obj = hs->GetHists()->FindObject(name);
00195
00196 return obj ? new TGo4ObjectAccess(obj) : 0;
00197 }
00198
00199 TGo4LevelIter* TGo4HStackProxy::ProduceIter(THStack* hs)
00200 {
00201 return new TGo4HStackLevelIter(hs);
00202 }