00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4ObjectProxy.h"
00017
00018 #include "TH1.h"
00019 #include "TDirectory.h"
00020 #include "TClass.h"
00021
00022 #include "TGo4Slot.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) {
00163 sz = fObject->IsA()->Size();
00164
00165 TH1* histo = dynamic_cast<TH1*> (fObject);
00166 if (histo!=0) {
00167 Int_t nbins = histo->GetNbinsX()+2;
00168 if (histo->GetDimension()>1)
00169 nbins = nbins*(histo->GetNbinsY()+2);
00170 if (histo->GetDimension()>2)
00171 nbins = nbins * (histo->GetNbinsZ()+2);
00172 Int_t binsize = 1;
00173 if (strchr(histo->ClassName(),'S')!=0) binsize = sizeof(Short_t); else
00174 if (strchr(histo->ClassName(),'D')!=0) binsize = sizeof(Double_t); else
00175 if (strchr(histo->ClassName(),'F')!=0) binsize = sizeof(Float_t); else
00176 if (strchr(histo->ClassName(),'I')!=0) binsize = sizeof(Int_t); else
00177 if (strchr(histo->ClassName(),'C')!=0) binsize = sizeof(Char_t);
00178 sz += binsize * nbins;
00179 }
00180 }
00181
00182 return sz;
00183 }
00184
00185 Bool_t TGo4ObjectProxy::IsAcceptObject(TClass* cl)
00186 {
00187 return (cl!=0) && cl->InheritsFrom(TObject::Class());
00188 }
00189
00190 Bool_t TGo4ObjectProxy::AssignObject(TGo4Slot* slot, TObject* obj, Bool_t owner)
00191 {
00192 Finalize(slot);
00193 if ((fObject!=0) && fOwner) delete fObject;
00194 fObject = obj;
00195 fOwner = owner;
00196
00197 if ((fObject!=0) && fOwner && fObject->InheritsFrom(TH1::Class()))
00198 ((TH1*) fObject)->SetDirectory(0);
00199
00200 Initialize(slot);
00201
00202
00203
00204 slot->ForwardEvent(slot, TGo4Slot::evObjAssigned);
00205
00206 return kTRUE;
00207 }
00208
00209 TObject* TGo4ObjectProxy::GetAssignedObject()
00210 {
00211 return fObject;
00212 }
00213
00214