GSI Object Oriented Online Offline (Go4) GO4-6.4.5
Loading...
Searching...
No Matches
TGo4ObjectProxy.cxx
Go to the documentation of this file.
1// $Id$
2//-----------------------------------------------------------------------
3// The GSI Online Offline Object Oriented (Go4) Project
4// Experiment Data Processing at EE department, GSI
5//-----------------------------------------------------------------------
6// Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7// Planckstr. 1, 64291 Darmstadt, Germany
8// Contact: http://go4.gsi.de
9//-----------------------------------------------------------------------
10// This software can be used under the license agreements as stated
11// in Go4License.txt file which is part of the distribution.
12//-----------------------------------------------------------------------
13
14#include "TGo4ObjectProxy.h"
15
16#include "TH1.h"
17#include "TDirectory.h"
18#include "TClass.h"
19#include "TTree.h"
20
21#include "TGo4Picture.h"
22#include "TGo4ObjectManager.h"
23
25 TGo4Access(),
26 fObject(obj)
27{
28}
29
31{
32 return kTRUE;
33}
34
35Bool_t TGo4ObjectAccess::GetObject(TObject *&obj, Bool_t &owner) const
36{
37 obj = fObject;
38 owner = kFALSE;
39 return kTRUE;
40}
41
43{
44 return fObject->IsA();
45}
46
48{
49 return fObject->GetName();
50}
51
53{
54 return fObject->ClassName();
55}
56
57// ********************************************************************
58
63
64TGo4ObjectProxy::TGo4ObjectProxy(TObject *obj, Bool_t owner) :
65 TGo4Proxy(),
66 fObject(obj),
67 fOwner(owner)
68{
69 if (fObject && fOwner && fObject->InheritsFrom(TH1::Class()))
70 ((TH1 *) fObject)->SetDirectory(nullptr);
71}
72
78
80{
81 auto om = slot->GetOM();
82 if (om) om->RegisterObjectWith(fObject, slot);
83}
84
86{
87 auto om = slot->GetOM();
88 if (om) om->UnregisterObject(fObject, slot);
89}
90
92{
93 if (fObject == obj) {
94 fObject = nullptr;
95 fOwner = kFALSE;
96 }
97 return kFALSE;
98}
99
100std::unique_ptr<TGo4Access> TGo4ObjectProxy::ProvideAccess(const char *name)
101{
102 if (!fObject) return nullptr;
103 if (!name || !*name)
104 return std::make_unique<TGo4ObjectAccess>(fObject);
105 return nullptr;
106}
107
108void TGo4ObjectProxy::WriteData(TGo4Slot *slot, TDirectory *dir, Bool_t onlyobjs)
109{
110 const char *objname = fObject ? fObject->GetName() : nullptr;
111
112 if (!onlyobjs)
113 slot->SetPar("ObjectProxy::ObjName", objname);
114
115 if (!dir || !fObject) return;
116
117 dir->cd();
118
119 if (fObject->InheritsFrom(TH1::Class())) {
120 TH1 *h1 = (TH1 *) fObject;
121 TDirectory *olddir = h1->GetDirectory();
122 h1->Write(objname);
123 h1->SetDirectory(olddir);
124 } else {
125 fObject->Write(objname);
126 }
127}
128
129void TGo4ObjectProxy::ReadData(TGo4Slot *slot, TDirectory *dir)
130{
131 const char *objname = slot ? slot->GetPar("ObjectProxy::ObjName") : nullptr;
132 if (!objname || !dir) return;
133
134 dir->cd();
135
136 AssignObject(slot, dir->Get(objname), kTRUE);
137}
138
143
145{
146 return fObject ? fObject->ClassName() : nullptr;
147}
148
150{
151 return fObject ? fObject->GetTitle() : nullptr;
152}
153
155{
156 Int_t sz = TGo4Proxy::GetObjectSizeInfo();
158 return sz;
159}
160
161Bool_t TGo4ObjectProxy::IsAcceptObject(TClass *cl) const
162{
163 return cl && cl->InheritsFrom(TObject::Class());
164}
165
166Bool_t TGo4ObjectProxy::AssignObject(TGo4Slot *slot, TObject *obj, Bool_t owner)
167{
168 Finalize(slot);
169 if (fObject && fOwner) delete fObject;
170 fObject = obj;
171 fOwner = owner;
172
173 if (fObject && fOwner && fObject->InheritsFrom(TH1::Class()))
174 ((TH1 *) fObject)->SetDirectory(nullptr);
175
176 Initialize(slot);
177
179
180 return kTRUE;
181}
182
184{
185 return fObject;
186}
187
189{
190 if (!obj) return 0;
191
192 Long_t sz = obj->IsA()->Size();
193
194 if (obj->InheritsFrom(TH1::Class())) {
195 TH1 *histo = dynamic_cast<TH1 *> (obj);
196 Int_t nbins = histo->GetNbinsX()+2;
197 if (histo->GetDimension()>1)
198 nbins = nbins*(histo->GetNbinsY()+2);
199 if (histo->GetDimension()>2)
200 nbins = nbins * (histo->GetNbinsZ()+2);
201 Int_t binsize = 1;
202 if (strchr(histo->ClassName(),'S')) binsize = sizeof(Short_t); else
203 if (strchr(histo->ClassName(),'D')) binsize = sizeof(Double_t); else
204 if (strchr(histo->ClassName(),'F')) binsize = sizeof(Float_t); else
205 if (strchr(histo->ClassName(),'I')) binsize = sizeof(Int_t); else
206 if (strchr(histo->ClassName(),'C')) binsize = sizeof(Char_t);
207 sz += binsize * nbins;
208 } else if (obj->InheritsFrom(TTree::Class())) {
209 TTree *t = (TTree *) obj;
210 sz += t->GetZipBytes();
211 } else if (obj->InheritsFrom(TGo4Picture::Class())) {
212 TGo4Picture *pic = (TGo4Picture *) obj;
213 sz = pic->GetTotalSize();
214 }
215
216 return sz;
217}
TClass * GetObjectClass() const override
Bool_t GetObject(TObject *&obj, Bool_t &owner) const override
TGo4ObjectAccess(TObject *obj)
const char * GetObjectClassName() const override
const char * GetObjectName() const override
Bool_t CanGetObject() const override
Returns kTRUE, when object can be directly obtained with GetObject() method.
void RegisterObjectWith(TObject *obj, TGo4Slot *slot)
void UnregisterObject(TObject *obj, TGo4Slot *slot)
Int_t GetObjectKind() const override
void ReadData(TGo4Slot *slot, TDirectory *dir) override
const char * GetContainedClassName() const override
void WriteData(TGo4Slot *slot, TDirectory *dir, Bool_t onlyobjs) override
Int_t GetObjectSizeInfo() const override
void Finalize(TGo4Slot *slot) override
void Initialize(TGo4Slot *slot) override
static Long_t DefineObjectSize(TObject *obj)
const char * GetContainedObjectInfo() override
TObject * GetAssignedObject() override
virtual ~TGo4ObjectProxy()
Bool_t RemoveRegisteredObject(TObject *obj) override
std::unique_ptr< TGo4Access > ProvideAccess(const char *name) override
Bool_t IsAcceptObject(TClass *cl) const override
Bool_t AssignObject(TGo4Slot *slot, TObject *obj, Bool_t owner) override
Picture cconfiguration in Go4.
Definition TGo4Picture.h:40
Long_t GetTotalSize()
Returns total size, used by picture in memory.
virtual Int_t GetObjectSizeInfo() const
Definition TGo4Proxy.h:117
virtual TGo4ObjectManager * GetOM() const
Definition TGo4Slot.cxx:282
void ForwardEvent(TGo4Slot *source, Int_t id, void *param=nullptr)
Definition TGo4Slot.cxx:566
@ evObjAssigned
Definition TGo4Slot.h:47
void SetPar(const char *name, const char *value)
Definition TGo4Slot.cxx:587
const char * GetPar(const char *name) const
Definition TGo4Slot.cxx:599