GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4ObjectProxy.cxx
Go to the documentation of this file.
1 // $Id: TGo4ObjectProxy.cxx 2751 2020-04-16 10:46:36Z linev $
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 
35 Bool_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 
60  TGo4Proxy(),
61  fObject(0),
62  fOwner(kFALSE)
63 {
64 }
65 
66 TGo4ObjectProxy::TGo4ObjectProxy(TObject* obj, Bool_t owner) :
67  TGo4Proxy(),
68  fObject(obj),
69  fOwner(owner)
70 {
71  if ((fObject!=0) && fOwner && fObject->InheritsFrom(TH1::Class()))
72  ((TH1*) fObject)->SetDirectory(0);
73 }
74 
76 {
77  if (fOwner) delete fObject;
78 }
79 
81 {
82  TGo4ObjectManager* om = slot->GetOM();
83  if (om!=0) om->RegisterObjectWith(fObject, slot);
84 }
85 
87 {
88  TGo4ObjectManager* om = slot->GetOM();
89  if (om!=0) om->UnregisterObject(fObject, slot);
90 }
91 
93 {
94  if (fObject==obj) {
95  fObject = 0;
96  fOwner = kFALSE;
97  }
98  return kFALSE;
99 }
100 
102 {
103  if (fObject==0) return 0;
104  if ((name==0) || (*name==0)) return new TGo4ObjectAccess(fObject);
105  return 0;
106 }
107 
108 void TGo4ObjectProxy::WriteData(TGo4Slot* slot, TDirectory* dir, Bool_t onlyobjs)
109 {
110  const char* objname = 0;
111  if (fObject!=0)
112  objname = fObject->GetName();
113 
114  if (!onlyobjs)
115  slot->SetPar("ObjectProxy::ObjName", objname);
116 
117  if ((dir==0) || (fObject==0)) return;
118 
119  dir->cd();
120 
121  if (fObject->InheritsFrom(TH1::Class())) {
122  TH1* h1 = (TH1*) fObject;
123  TDirectory* olddir = h1->GetDirectory();
124  h1->Write(objname);
125  h1->SetDirectory(olddir);
126  } else {
127  fObject->Write(objname);
128  }
129 }
130 
131 void TGo4ObjectProxy::ReadData(TGo4Slot* slot, TDirectory* dir)
132 {
133  const char* objname = slot->GetPar("ObjectProxy::ObjName");
134  if ((objname==0) || (dir==0)) return;
135 
136  dir->cd();
137 
138  AssignObject(slot, dir->Get(objname), kTRUE);
139 }
140 
142 {
144 }
145 
147 {
148  return (fObject!=0) ? fObject->ClassName() : 0;
149 }
150 
152 {
153  return (fObject!=0) ? fObject->GetTitle() : 0;
154 }
155 
157 {
158  Int_t sz = TGo4Proxy::GetObjectSizeInfo();
159  if (fObject!=0) sz = DefineObjectSize(fObject);
160  return sz;
161 }
162 
164 {
165  return (cl!=0) && cl->InheritsFrom(TObject::Class());
166 }
167 
168 Bool_t TGo4ObjectProxy::AssignObject(TGo4Slot* slot, TObject* obj, Bool_t owner)
169 {
170  Finalize(slot);
171  if ((fObject!=0) && fOwner) delete fObject;
172  fObject = obj;
173  fOwner = owner;
174 
175  if ((fObject!=0) && fOwner && fObject->InheritsFrom(TH1::Class()))
176  ((TH1*) fObject)->SetDirectory(0);
177 
178  Initialize(slot);
179 
181 
182  return kTRUE;
183 }
184 
186 {
187  return fObject;
188 }
189 
190 
192 {
193  if (obj==0) return 0;
194 
195  Long_t sz = obj->IsA()->Size();
196 
197  if (obj->InheritsFrom(TH1::Class())) {
198  TH1* histo = dynamic_cast<TH1*> (obj);
199  Int_t nbins = histo->GetNbinsX()+2;
200  if (histo->GetDimension()>1)
201  nbins = nbins*(histo->GetNbinsY()+2);
202  if (histo->GetDimension()>2)
203  nbins = nbins * (histo->GetNbinsZ()+2);
204  Int_t binsize = 1;
205  if (strchr(histo->ClassName(),'S')!=0) binsize = sizeof(Short_t); else
206  if (strchr(histo->ClassName(),'D')!=0) binsize = sizeof(Double_t); else
207  if (strchr(histo->ClassName(),'F')!=0) binsize = sizeof(Float_t); else
208  if (strchr(histo->ClassName(),'I')!=0) binsize = sizeof(Int_t); else
209  if (strchr(histo->ClassName(),'C')!=0) binsize = sizeof(Char_t);
210  sz += binsize * nbins;
211  } else
212  if (obj->InheritsFrom(TTree::Class())) {
213  TTree* t = (TTree*) obj;
214  sz += t->GetZipBytes();
215  } else
216  if (obj->InheritsFrom(TGo4Picture::Class())) {
217  TGo4Picture* pic = (TGo4Picture*) obj;
218  sz = pic->GetTotalSize();
219  }
220 
221  return sz;
222 }
virtual Bool_t IsAcceptObject(TClass *cl)
void UnregisterObject(TObject *obj, TGo4Slot *slot)
virtual Bool_t CanGetObject() const
virtual void ReadData(TGo4Slot *slot, TDirectory *dir)
virtual const char * GetContainedClassName()
virtual Bool_t GetObject(TObject *&obj, Bool_t &owner) const
const char * GetPar(const char *name) const
Definition: TGo4Slot.cxx:617
static Long_t DefineObjectSize(TObject *obj)
virtual const char * GetObjectName() const
virtual Bool_t AssignObject(TGo4Slot *slot, TObject *obj, Bool_t owner)
void RegisterObjectWith(TObject *obj, TGo4Slot *slot)
virtual const char * GetContainedObjectInfo()
virtual void Initialize(TGo4Slot *slot)
virtual TClass * GetObjectClass() const
virtual void Finalize(TGo4Slot *slot)
virtual Int_t GetObjectSizeInfo()
virtual const char * GetObjectClassName() const
Long_t GetTotalSize()
virtual Int_t GetObjectKind()
virtual TGo4Access * ProvideAccess(const char *name)
virtual void WriteData(TGo4Slot *slot, TDirectory *dir, Bool_t onlyobjs)
void ForwardEvent(TGo4Slot *source, Int_t id, void *param=0)
Definition: TGo4Slot.cxx:581
virtual Int_t GetObjectSizeInfo()
Definition: TGo4Proxy.h:111
virtual TObject * GetAssignedObject()
virtual TGo4ObjectManager * GetOM() const
Definition: TGo4Slot.cxx:295
void SetPar(const char *name, const char *value)
Definition: TGo4Slot.cxx:605
TGo4ObjectAccess(TObject *obj)
virtual Bool_t RemoveRegisteredObject(TObject *obj)
virtual ~TGo4ObjectProxy()