Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4ObjectProxy.h"
00015
00016 #include "TH1.h"
00017 #include "TDirectory.h"
00018 #include "TClass.h"
00019 #include "TTree.h"
00020
00021 #include "TGo4Slot.h"
00022 #include "TGo4Picture.h"
00023 #include "TGo4ObjectManager.h"
00024
00025 TGo4ObjectAccess::TGo4ObjectAccess(TObject* obj) :
00026 TGo4Access(),
00027 fObject(obj)
00028 {
00029 }
00030
00031 Bool_t TGo4ObjectAccess::CanGetObject() const
00032 {
00033 return kTRUE;
00034 }
00035
00036 Bool_t TGo4ObjectAccess::GetObject(TObject* &obj, Bool_t &owner) const
00037 {
00038 obj = fObject;
00039 owner = kFALSE;
00040 return kTRUE;
00041 }
00042
00043 TClass* TGo4ObjectAccess::GetObjectClass() const
00044 {
00045 return fObject->IsA();
00046 }
00047
00048 const char* TGo4ObjectAccess::GetObjectName() const
00049 {
00050 return fObject->GetName();
00051 }
00052
00053 const char* TGo4ObjectAccess::GetObjectClassName() const
00054 {
00055 return fObject->ClassName();
00056 }
00057
00058
00059
00060 TGo4ObjectProxy::TGo4ObjectProxy() :
00061 TGo4Proxy(),
00062 fObject(0),
00063 fOwner(kFALSE)
00064 {
00065 }
00066
00067 TGo4ObjectProxy::TGo4ObjectProxy(TObject* obj, Bool_t owner) :
00068 TGo4Proxy(),
00069 fObject(obj),
00070 fOwner(owner)
00071 {
00072 if ((fObject!=0) && fOwner && fObject->InheritsFrom(TH1::Class()))
00073 ((TH1*) fObject)->SetDirectory(0);
00074 }
00075
00076 TGo4ObjectProxy::~TGo4ObjectProxy()
00077 {
00078 if (fOwner) delete fObject;
00079 }
00080
00081 void TGo4ObjectProxy::Initialize(TGo4Slot* slot)
00082 {
00083 TGo4ObjectManager* om = slot->GetOM();
00084 if (om!=0) om->RegisterObjectWith(fObject, slot);
00085 }
00086
00087 void TGo4ObjectProxy::Finalize(TGo4Slot* slot)
00088 {
00089 TGo4ObjectManager* om = slot->GetOM();
00090 if (om!=0) om->UnregisterObject(fObject, slot);
00091 }
00092
00093 Bool_t TGo4ObjectProxy::RemoveRegisteredObject(TObject* obj)
00094 {
00095 if (fObject==obj) {
00096
00097
00098 fObject = 0;
00099 fOwner = kFALSE;
00100 }
00101 return kFALSE;
00102 }
00103
00104 TGo4Access* TGo4ObjectProxy::MakeProxy(const char* name)
00105 {
00106 if (fObject==0) return 0;
00107 if ((name==0) || (*name==0)) return new TGo4ObjectAccess(fObject);
00108 return 0;
00109 }
00110
00111 void TGo4ObjectProxy::WriteData(TGo4Slot* slot, TDirectory* dir, Bool_t onlyobjs)
00112 {
00113 const char* objname = 0;
00114 if (fObject!=0)
00115 objname = fObject->GetName();
00116
00117 if (!onlyobjs)
00118 slot->SetPar("ObjectProxy::ObjName", objname);
00119
00120 if ((dir==0) || (fObject==0)) return;
00121
00122 dir->cd();
00123
00124 if (fObject->InheritsFrom(TH1::Class())) {
00125 TH1* h1 = (TH1*) fObject;
00126 TDirectory* olddir = h1->GetDirectory();
00127 h1->Write(objname);
00128 h1->SetDirectory(olddir);
00129 } else {
00130 fObject->Write(objname);
00131 }
00132 }
00133
00134 void TGo4ObjectProxy::ReadData(TGo4Slot* slot, TDirectory* dir)
00135 {
00136 const char* objname = slot->GetPar("ObjectProxy::ObjName");
00137 if ((objname==0) || (dir==0)) return;
00138
00139 dir->cd();
00140
00141 AssignObject(slot, dir->Get(objname), kTRUE);
00142 }
00143
00144 Int_t TGo4ObjectProxy::GetObjectKind()
00145 {
00146 return (fObject!=0) ? TGo4Access::kndObject : TGo4Access::kndNone;
00147 }
00148
00149 const char* TGo4ObjectProxy::GetContainedClassName()
00150 {
00151 return (fObject!=0) ? fObject->ClassName() : 0;
00152 }
00153
00154 const char* TGo4ObjectProxy::GetContainedObjectInfo()
00155 {
00156 return (fObject!=0) ? fObject->GetTitle() : 0;
00157 }
00158
00159 Int_t TGo4ObjectProxy::GetObjectSizeInfo()
00160 {
00161 Int_t sz = TGo4Proxy::GetObjectSizeInfo();
00162 if (fObject!=0) sz = DefineObjectSize(fObject);
00163 return sz;
00164 }
00165
00166 Bool_t TGo4ObjectProxy::IsAcceptObject(TClass* cl)
00167 {
00168 return (cl!=0) && cl->InheritsFrom(TObject::Class());
00169 }
00170
00171 Bool_t TGo4ObjectProxy::AssignObject(TGo4Slot* slot, TObject* obj, Bool_t owner)
00172 {
00173 Finalize(slot);
00174 if ((fObject!=0) && fOwner) delete fObject;
00175 fObject = obj;
00176 fOwner = owner;
00177
00178 if ((fObject!=0) && fOwner && fObject->InheritsFrom(TH1::Class()))
00179 ((TH1*) fObject)->SetDirectory(0);
00180
00181 Initialize(slot);
00182
00183 slot->ForwardEvent(slot, TGo4Slot::evObjAssigned);
00184
00185 return kTRUE;
00186 }
00187
00188 TObject* TGo4ObjectProxy::GetAssignedObject()
00189 {
00190 return fObject;
00191 }
00192
00193
00194 Long_t TGo4ObjectProxy::DefineObjectSize(TObject* obj)
00195 {
00196 if (obj==0) return 0;
00197
00198 Long_t sz = obj->IsA()->Size();
00199
00200 if (obj->InheritsFrom(TH1::Class())) {
00201 TH1* histo = dynamic_cast<TH1*> (obj);
00202 Int_t nbins = histo->GetNbinsX()+2;
00203 if (histo->GetDimension()>1)
00204 nbins = nbins*(histo->GetNbinsY()+2);
00205 if (histo->GetDimension()>2)
00206 nbins = nbins * (histo->GetNbinsZ()+2);
00207 Int_t binsize = 1;
00208 if (strchr(histo->ClassName(),'S')!=0) binsize = sizeof(Short_t); else
00209 if (strchr(histo->ClassName(),'D')!=0) binsize = sizeof(Double_t); else
00210 if (strchr(histo->ClassName(),'F')!=0) binsize = sizeof(Float_t); else
00211 if (strchr(histo->ClassName(),'I')!=0) binsize = sizeof(Int_t); else
00212 if (strchr(histo->ClassName(),'C')!=0) binsize = sizeof(Char_t);
00213 sz += binsize * nbins;
00214 } else
00215 if (obj->InheritsFrom(TTree::Class())) {
00216 TTree* t = (TTree*) obj;
00217 sz += t->GetZipBytes();
00218 } else
00219 if (obj->InheritsFrom(TGo4Picture::Class())) {
00220 TGo4Picture* pic = (TGo4Picture*) obj;
00221 sz = pic->GetTotalSize();
00222 }
00223
00224 return sz;
00225
00226 }