GSI Object Oriented Online Offline (Go4) GO4-6.4.0
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
77
79{
80 auto om = slot->GetOM();
81 if (om) om->RegisterObjectWith(fObject, slot);
82}
83
85{
86 auto om = slot->GetOM();
87 if (om) om->UnregisterObject(fObject, slot);
88}
89
91{
92 if (fObject == obj) {
93 fObject = nullptr;
94 fOwner = kFALSE;
95 }
96 return kFALSE;
97}
98
99std::unique_ptr<TGo4Access> TGo4ObjectProxy::ProvideAccess(const char *name)
100{
101 if (!fObject) return nullptr;
102 if (!name || !*name)
103 return std::make_unique<TGo4ObjectAccess>(fObject);
104 return nullptr;
105}
106
107void TGo4ObjectProxy::WriteData(TGo4Slot *slot, TDirectory *dir, Bool_t onlyobjs)
108{
109 const char *objname = fObject ? fObject->GetName() : nullptr;
110
111 if (!onlyobjs)
112 slot->SetPar("ObjectProxy::ObjName", objname);
113
114 if (!dir || !fObject) return;
115
116 dir->cd();
117
118 if (fObject->InheritsFrom(TH1::Class())) {
119 TH1 *h1 = (TH1 *) fObject;
120 TDirectory *olddir = h1->GetDirectory();
121 h1->Write(objname);
122 h1->SetDirectory(olddir);
123 } else {
124 fObject->Write(objname);
125 }
126}
127
128void TGo4ObjectProxy::ReadData(TGo4Slot *slot, TDirectory *dir)
129{
130 const char *objname = slot ? slot->GetPar("ObjectProxy::ObjName") : nullptr;
131 if (!objname || !dir) return;
132
133 dir->cd();
134
135 AssignObject(slot, dir->Get(objname), kTRUE);
136}
137
142
144{
145 return fObject ? fObject->ClassName() : nullptr;
146}
147
149{
150 return fObject ? fObject->GetTitle() : nullptr;
151}
152
154{
155 Int_t sz = TGo4Proxy::GetObjectSizeInfo();
157 return sz;
158}
159
160Bool_t TGo4ObjectProxy::IsAcceptObject(TClass *cl) const
161{
162 return cl && cl->InheritsFrom(TObject::Class());
163}
164
165Bool_t TGo4ObjectProxy::AssignObject(TGo4Slot *slot, TObject *obj, Bool_t owner)
166{
167 Finalize(slot);
168 if (fObject && fOwner) delete fObject;
169 fObject = obj;
170 fOwner = owner;
171
172 if (fObject && fOwner && fObject->InheritsFrom(TH1::Class()))
173 ((TH1 *) fObject)->SetDirectory(nullptr);
174
175 Initialize(slot);
176
178
179 return kTRUE;
180}
181
183{
184 return fObject;
185}
186
188{
189 if (!obj) return 0;
190
191 Long_t sz = obj->IsA()->Size();
192
193 if (obj->InheritsFrom(TH1::Class())) {
194 TH1 *histo = dynamic_cast<TH1 *> (obj);
195 Int_t nbins = histo->GetNbinsX()+2;
196 if (histo->GetDimension()>1)
197 nbins = nbins*(histo->GetNbinsY()+2);
198 if (histo->GetDimension()>2)
199 nbins = nbins * (histo->GetNbinsZ()+2);
200 Int_t binsize = 1;
201 if (strchr(histo->ClassName(),'S')) binsize = sizeof(Short_t); else
202 if (strchr(histo->ClassName(),'D')) binsize = sizeof(Double_t); else
203 if (strchr(histo->ClassName(),'F')) binsize = sizeof(Float_t); else
204 if (strchr(histo->ClassName(),'I')) binsize = sizeof(Int_t); else
205 if (strchr(histo->ClassName(),'C')) binsize = sizeof(Char_t);
206 sz += binsize * nbins;
207 } else if (obj->InheritsFrom(TTree::Class())) {
208 TTree *t = (TTree *) obj;
209 sz += t->GetZipBytes();
210 } else if (obj->InheritsFrom(TGo4Picture::Class())) {
211 TGo4Picture *pic = (TGo4Picture *) obj;
212 sz = pic->GetTotalSize();
213 }
214
215 return sz;
216}
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
@ evObjAssigned
Definition TGo4Slot.h:47
void ForwardEvent(TGo4Slot *source, Int_t id, void *param=nullptr)
Definition TGo4Slot.cxx:565
void SetPar(const char *name, const char *value)
Definition TGo4Slot.cxx:586
const char * GetPar(const char *name) const
Definition TGo4Slot.cxx:598