GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4HStackProxy.cxx
Go to the documentation of this file.
1 // $Id: TGo4HStackProxy.cxx 2759 2020-04-16 13:00:41Z 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 "TGo4HStackProxy.h"
15 
16 #include "TROOT.h"
17 #include "TList.h"
18 #include "TClass.h"
19 #include "THStack.h"
20 
21 #include "TGo4ObjectProxy.h"
22 #include "TGo4ObjectManager.h"
23 
25  protected:
26  TIterator* fIter;
27  TObject* fCurrent;
28  public:
29  TGo4HStackLevelIter(THStack* hs) :
30  TGo4LevelIter(),
31  fIter(0),
32  fCurrent(0)
33  {
34  fIter = hs->GetHists()->MakeIterator();
35  }
36 
38  {
39  delete fIter;
40  }
41 
42  virtual Bool_t next()
43  {
44  fCurrent = fIter->Next();
45  return (fCurrent!=0);
46  }
47 
48  virtual Bool_t isfolder()
49  {
50  return kFALSE;
51  }
52 
54  {
55  return 0;
56  }
57 
58  virtual const char* name()
59  {
60  return fCurrent->GetName();
61  }
62 
63  virtual const char* info()
64  {
65  return fCurrent->ClassName();
66  }
67 
68  virtual Int_t GetKind()
69  {
70  return TGo4Access::kndObject;
71  }
72 
73  virtual const char* GetClassName()
74  {
75  return fCurrent->ClassName();
76  }
77 };
78 
79 // ****************************************************************
80 
82  TGo4Proxy(),
83  fHS(0),
84  fOwner(kFALSE)
85 {
86 }
87 
88 TGo4HStackProxy::TGo4HStackProxy(THStack* hs, Bool_t owner) :
89  TGo4Proxy(),
90  fHS(hs),
91  fOwner(owner)
92 {
93 }
94 
96 {
97  if (fOwner) delete fHS;
98 }
99 
101 {
103 }
104 
106 {
107  return fHS ? fHS->ClassName() : 0;
108 }
109 
111 {
112  TGo4ObjectManager* om = slot->GetOM();
113  if (om!=0) om->RegisterObjectWith(fHS, slot);
114 }
115 
117 {
118  TGo4ObjectManager* om = slot->GetOM();
119  if (om!=0) om->UnregisterObject(fHS, slot);
120 }
121 
123 {
124  if (obj==fHS) {
125  fHS = 0;
126  fOwner = kFALSE;
127  }
128  return kFALSE;
129 }
130 
131 void TGo4HStackProxy::WriteData(TGo4Slot* slot, TDirectory* dir, Bool_t onlyobjs)
132 {
133  const char* objname = 0;
134  if (fHS!=0)
135  objname = fHS->GetName();
136 
137  if (!onlyobjs)
138  slot->SetPar("HStackProxy::StackName", objname);
139 
140  if ((dir==0) || (fHS==0)) return;
141 
142  dir->cd();
143 
144  fHS->Write(objname);
145 }
146 
147 void TGo4HStackProxy::ReadData(TGo4Slot* slot, TDirectory* dir)
148 {
149  const char* objname = slot->GetPar("HStackProxy::StackName");
150  if ((objname==0) || (dir==0)) return;
151 
152  dir->cd();
153 
154  AssignObject(slot, dir->Get(objname), kTRUE);
155 }
156 
158 {
159  return (cl!=0) && cl->InheritsFrom(THStack::Class());
160 }
161 
162 Bool_t TGo4HStackProxy::AssignObject(TGo4Slot* slot, TObject* obj, Bool_t owner)
163 {
164  Finalize(slot);
165  if ((fHS!=0) && fOwner) delete fHS;
166 
167  fHS = dynamic_cast<THStack*> (obj);
168  fOwner = owner && (fHS!=0);
169 
170  if ((fHS==0) && (obj!=0) && owner) delete obj;
171 
172  Initialize(slot);
173 
175 
176  return fHS!=0;
177 }
178 
180 {
181  return fHS;
182 }
183 
184 TGo4Access* TGo4HStackProxy::CreateAccess(THStack* hs, const char* name)
185 {
186  if (hs==0) return 0;
187  if ((name==0) || (*name==0)) return new TGo4ObjectAccess(hs);
188 
189  TObject* obj = hs->GetHists()->FindObject(name);
190 
191  return obj ? new TGo4ObjectAccess(obj) : 0;
192 }
193 
195 {
196  return new TGo4HStackLevelIter(hs);
197 }
virtual const char * name()
virtual void Finalize(TGo4Slot *slot)
virtual Int_t GetKind()
TGo4HStackLevelIter(THStack *hs)
void UnregisterObject(TObject *obj, TGo4Slot *slot)
virtual TObject * GetAssignedObject()
virtual void WriteData(TGo4Slot *slot, TDirectory *dir, Bool_t onlyobjs)
virtual const char * GetContainedClassName()
virtual ~TGo4HStackProxy()
static TGo4LevelIter * ProduceIter(THStack *canv)
const char * GetPar(const char *name) const
Definition: TGo4Slot.cxx:617
virtual Bool_t isfolder()
void RegisterObjectWith(TObject *obj, TGo4Slot *slot)
virtual Bool_t RemoveRegisteredObject(TObject *obj)
virtual const char * GetClassName()
virtual void Initialize(TGo4Slot *slot)
virtual Bool_t next()
virtual TGo4LevelIter * subiterator()
virtual const char * info()
static TGo4Access * CreateAccess(THStack *canv, const char *name)
virtual void ReadData(TGo4Slot *slot, TDirectory *dir)
void ForwardEvent(TGo4Slot *source, Int_t id, void *param=0)
Definition: TGo4Slot.cxx:581
virtual Bool_t IsAcceptObject(TClass *cl)
virtual Bool_t AssignObject(TGo4Slot *slot, TObject *obj, Bool_t owner)
virtual ~TGo4HStackLevelIter()
virtual TGo4ObjectManager * GetOM() const
Definition: TGo4Slot.cxx:295
void SetPar(const char *name, const char *value)
Definition: TGo4Slot.cxx:605
virtual Int_t GetObjectKind()