GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4ObjectProxy.cxx
Go to the documentation of this file.
1 // $Id: TGo4ObjectProxy.cxx 1456 2015-05-28 14:34:10Z 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 für 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 "TGo4Slot.h"
22 #include "TGo4Picture.h"
23 #include "TGo4ObjectManager.h"
24 
26  TGo4Access(),
27  fObject(obj)
28 {
29 }
30 
32 {
33  return kTRUE;
34 }
35 
36 Bool_t TGo4ObjectAccess::GetObject(TObject* &obj, Bool_t &owner) const
37 {
38  obj = fObject;
39  owner = kFALSE;
40  return kTRUE;
41 }
42 
44 {
45  return fObject->IsA();
46 }
47 
49 {
50  return fObject->GetName();
51 }
52 
54 {
55  return fObject->ClassName();
56 }
57 
58 // ********************************************************************
59 
61  TGo4Proxy(),
62  fObject(0),
63  fOwner(kFALSE)
64 {
65 }
66 
67 TGo4ObjectProxy::TGo4ObjectProxy(TObject* obj, Bool_t owner) :
68  TGo4Proxy(),
69  fObject(obj),
70  fOwner(owner)
71 {
72  if ((fObject!=0) && fOwner && fObject->InheritsFrom(TH1::Class()))
73  ((TH1*) fObject)->SetDirectory(0);
74 }
75 
77 {
78  if (fOwner) delete fObject;
79 }
80 
82 {
83  TGo4ObjectManager* om = slot->GetOM();
84  if (om!=0) om->RegisterObjectWith(fObject, slot);
85 }
86 
88 {
89  TGo4ObjectManager* om = slot->GetOM();
90  if (om!=0) om->UnregisterObject(fObject, slot);
91 }
92 
94 {
95  if (fObject==obj) {
96  fObject = 0;
97  fOwner = kFALSE;
98  }
99  return kFALSE;
100 }
101 
103 {
104  if (fObject==0) return 0;
105  if ((name==0) || (*name==0)) return new TGo4ObjectAccess(fObject);
106  return 0;
107 }
108 
109 void TGo4ObjectProxy::WriteData(TGo4Slot* slot, TDirectory* dir, Bool_t onlyobjs)
110 {
111  const char* objname = 0;
112  if (fObject!=0)
113  objname = fObject->GetName();
114 
115  if (!onlyobjs)
116  slot->SetPar("ObjectProxy::ObjName", objname);
117 
118  if ((dir==0) || (fObject==0)) return;
119 
120  dir->cd();
121 
122  if (fObject->InheritsFrom(TH1::Class())) {
123  TH1* h1 = (TH1*) fObject;
124  TDirectory* olddir = h1->GetDirectory();
125  h1->Write(objname);
126  h1->SetDirectory(olddir);
127  } else {
128  fObject->Write(objname);
129  }
130 }
131 
132 void TGo4ObjectProxy::ReadData(TGo4Slot* slot, TDirectory* dir)
133 {
134  const char* objname = slot->GetPar("ObjectProxy::ObjName");
135  if ((objname==0) || (dir==0)) return;
136 
137  dir->cd();
138 
139  AssignObject(slot, dir->Get(objname), kTRUE);
140 }
141 
143 {
145 }
146 
148 {
149  return (fObject!=0) ? fObject->ClassName() : 0;
150 }
151 
153 {
154  return (fObject!=0) ? fObject->GetTitle() : 0;
155 }
156 
158 {
159  Int_t sz = TGo4Proxy::GetObjectSizeInfo();
160  if (fObject!=0) sz = DefineObjectSize(fObject);
161  return sz;
162 }
163 
165 {
166  return (cl!=0) && cl->InheritsFrom(TObject::Class());
167 }
168 
169 Bool_t TGo4ObjectProxy::AssignObject(TGo4Slot* slot, TObject* obj, Bool_t owner)
170 {
171  Finalize(slot);
172  if ((fObject!=0) && fOwner) delete fObject;
173  fObject = obj;
174  fOwner = owner;
175 
176  if ((fObject!=0) && fOwner && fObject->InheritsFrom(TH1::Class()))
177  ((TH1*) fObject)->SetDirectory(0);
178 
179  Initialize(slot);
180 
182 
183  return kTRUE;
184 }
185 
187 {
188  return fObject;
189 }
190 
191 
193 {
194  if (obj==0) return 0;
195 
196  Long_t sz = obj->IsA()->Size();
197 
198  if (obj->InheritsFrom(TH1::Class())) {
199  TH1* histo = dynamic_cast<TH1*> (obj);
200  Int_t nbins = histo->GetNbinsX()+2;
201  if (histo->GetDimension()>1)
202  nbins = nbins*(histo->GetNbinsY()+2);
203  if (histo->GetDimension()>2)
204  nbins = nbins * (histo->GetNbinsZ()+2);
205  Int_t binsize = 1;
206  if (strchr(histo->ClassName(),'S')!=0) binsize = sizeof(Short_t); else
207  if (strchr(histo->ClassName(),'D')!=0) binsize = sizeof(Double_t); else
208  if (strchr(histo->ClassName(),'F')!=0) binsize = sizeof(Float_t); else
209  if (strchr(histo->ClassName(),'I')!=0) binsize = sizeof(Int_t); else
210  if (strchr(histo->ClassName(),'C')!=0) binsize = sizeof(Char_t);
211  sz += binsize * nbins;
212  } else
213  if (obj->InheritsFrom(TTree::Class())) {
214  TTree* t = (TTree*) obj;
215  sz += t->GetZipBytes();
216  } else
217  if (obj->InheritsFrom(TGo4Picture::Class())) {
218  TGo4Picture* pic = (TGo4Picture*) obj;
219  sz = pic->GetTotalSize();
220  }
221 
222  return sz;
223 }
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:621
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:585
virtual Int_t GetObjectSizeInfo()
Definition: TGo4Proxy.h:111
virtual TObject * GetAssignedObject()
virtual TGo4ObjectManager * GetOM() const
Definition: TGo4Slot.cxx:298
void SetPar(const char *name, const char *value)
Definition: TGo4Slot.cxx:609
TGo4ObjectAccess(TObject *obj)
virtual Bool_t RemoveRegisteredObject(TObject *obj)
virtual ~TGo4ObjectProxy()