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