GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4CanvasProxy.cxx
Go to the documentation of this file.
1 // $Id: TGo4CanvasProxy.cxx 1352 2015-01-27 10:03:25Z 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 "TGo4CanvasProxy.h"
15 
16 #include "TROOT.h"
17 #include "TObjArray.h"
18 #include "TClass.h"
19 #include "TFrame.h"
20 #include "TPaveText.h"
21 #include "TObjString.h"
22 #include "THStack.h"
23 #include "TH1.h"
24 
25 #include "TGo4Slot.h"
26 #include "TGo4ObjectProxy.h"
27 #include "TGo4HStackProxy.h"
28 #include "TGo4ObjectManager.h"
29 
31  protected:
32  TIterator* fIter;
33  TObject* fCurrent;
34  TObjArray fStacks;
35  public:
36  TGo4CanvasLevelIter(TPad* pad) :
37  TGo4LevelIter(),
38  fIter(0),
39  fCurrent(0),
40  fStacks()
41  {
42  fIter = pad->GetListOfPrimitives()->MakeIterator();
43  fStacks.SetOwner(kTRUE);
44  }
45 
47  {
48  delete fIter;
49  }
50 
51  virtual Bool_t next()
52  {
53  bool skip = false;
54  do {
55  skip = false;
56  fCurrent = fIter->Next();
57 
58  if (fCurrent==0) break;
59 
60  TFrame* fr = dynamic_cast<TFrame*>(fCurrent);
61  if (fr!=0) { skip = true; continue; }
62 
63  TPaveText* ptxt = dynamic_cast<TPaveText*> (fCurrent);
64  if ((ptxt!=0) && (strcmp(ptxt->GetName(),"title")==0)) { skip = true; continue; }
65 
66  if (dynamic_cast<TPave*>(fCurrent) != 0) { skip = true; continue; }
67 
68  if (fCurrent->GetName()==0) { skip = true; continue; }
69 
70  if (strlen(fCurrent->GetName())==0) { skip = true; continue; }
71 
72  if (strcmp(fCurrent->GetName(), fCurrent->ClassName())==0) { skip = true; continue; }
73 
74  // this is axis object for drawing THStack in the canvas
75  if (fStacks.FindObject(fCurrent->GetName()) && fCurrent->InheritsFrom(TH1F::Class())) { skip = true; continue; }
76 
77  } while(skip);
78 
79  if (fCurrent && fCurrent->InheritsFrom(THStack::Class()))
80  fStacks.Add(new TObjString(fCurrent->GetName()));
81 
82  return (fCurrent!=0);
83  }
84 
85  virtual Bool_t isfolder()
86  {
87  return (dynamic_cast<TPad*>(fCurrent)!=0) ||
88  (dynamic_cast<THStack*>(fCurrent)!=0);
89  }
90 
92  {
93  TPad* subpad = dynamic_cast<TPad*>(fCurrent);
94  if (subpad!=0) return new TGo4CanvasLevelIter(subpad);
95  THStack* hs = dynamic_cast<THStack*> (fCurrent);
96  if (hs!=0) return TGo4HStackProxy::ProduceIter(hs);
97  return 0;
98  }
99 
100  virtual const char* name()
101  {
102  return fCurrent->GetName();
103  }
104 
105  virtual const char* info()
106  {
107  return fCurrent->ClassName();
108  }
109 
110  virtual Int_t GetKind()
111  {
113  }
114 
115  virtual const char* GetClassName()
116  {
117  return fCurrent->ClassName();
118  }
119 };
120 
121 // ****************************************************************
122 
124  TGo4Proxy(),
125  fCanvas(0),
126  fOwner(kFALSE)
127 {
128 }
129 
130 TGo4CanvasProxy::TGo4CanvasProxy(TCanvas* c, Bool_t owner) :
131  TGo4Proxy(),
132  fCanvas(c),
133  fOwner(owner)
134 {
135 }
136 
138 {
139  if (fOwner) delete fCanvas;
140 }
141 
143 {
145 }
146 
148 {
149  return fCanvas ? fCanvas->ClassName() : 0;
150 }
151 
153 {
154  TGo4ObjectManager* om = slot->GetOM();
155  if (om!=0) om->RegisterObjectWith(fCanvas, slot);
156 }
157 
159 {
160  TGo4ObjectManager* om = slot->GetOM();
161  if (om!=0) om->UnregisterObject(fCanvas, slot);
162 }
163 
165 {
166  if (obj==fCanvas) {
167  fCanvas = 0;
168  fOwner = kFALSE;
169  }
170  return kFALSE;
171 }
172 
173 void TGo4CanvasProxy::WriteData(TGo4Slot* slot, TDirectory* dir, Bool_t onlyobjs)
174 {
175  const char* objname = 0;
176  if (fCanvas!=0)
177  objname = fCanvas->GetName();
178 
179  if (!onlyobjs)
180  slot->SetPar("CanvasProxy::CanvasName", objname);
181 
182  if ((dir==0) || (fCanvas==0)) return;
183 
184  dir->cd();
185 
186  fCanvas->Write(objname);
187 }
188 
189 void TGo4CanvasProxy::ReadData(TGo4Slot* slot, TDirectory* dir)
190 {
191  const char* objname = slot->GetPar("CanvasProxy::CanvasName");
192  if ((objname==0) || (dir==0)) return;
193 
194  dir->cd();
195 
196  AssignObject(slot, dir->Get(objname), kTRUE);
197 }
198 
200 {
201  return (cl!=0) && cl->InheritsFrom(TCanvas::Class());
202 }
203 
204 Bool_t TGo4CanvasProxy::AssignObject(TGo4Slot* slot, TObject* obj, Bool_t owner)
205 {
206  Finalize(slot);
207  if ((fCanvas!=0) && fOwner) delete fCanvas;
208 
209  fCanvas = dynamic_cast<TCanvas*> (obj);
210  fOwner = owner && (fCanvas!=0);
211 
212  if ((fCanvas==0) && (obj!=0) && owner) delete obj;
213 
214  Initialize(slot);
215 
217 
218  return fCanvas!=0;
219 }
220 
222 {
223  return fCanvas;
224 }
225 
226 TGo4Access* TGo4CanvasProxy::CreateAccess(TCanvas* canv, const char* name)
227 {
228  if (canv==0) return 0;
229  if ((name==0) || (*name==0)) return new TGo4ObjectAccess(canv);
230 
231  TPad* curpad = canv;
232  const char* curname = name;
233 
234  while (curpad!=0) {
235  const char* slash = strchr(curname,'/');
236  UInt_t len = (slash!=0) ? slash - curname : strlen(curname);
237  TIter iter(curpad->GetListOfPrimitives());
238  TObject* obj = 0;
239  while ((obj = iter())!=0)
240  if ((strlen(obj->GetName())==len) &&
241  (strncmp(obj->GetName(), curname, len)==0)) break;
242  if (obj==0) return 0;
243 
244 // std::cout << "Object class = " << obj->ClassName() << std::endl;
245 
246  if (slash==0) return new TGo4ObjectAccess(obj);
247 
248  curname = slash+1;
249 
250  curpad = dynamic_cast<TPad*>(obj);
251 
252  if (curpad==0) {
253  THStack* hs = dynamic_cast<THStack*> (obj);
254  if (hs!=0)
255  return TGo4HStackProxy::CreateAccess(hs, curname);
256  }
257  }
258 
259  return 0;
260 }
261 
263 {
264  return new TGo4CanvasLevelIter(canv);
265 }
virtual void Initialize(TGo4Slot *slot)
virtual void ReadData(TGo4Slot *slot, TDirectory *dir)
virtual void Finalize(TGo4Slot *slot)
void UnregisterObject(TObject *obj, TGo4Slot *slot)
virtual Bool_t isfolder()
virtual const char * name()
static TGo4LevelIter * ProduceIter(THStack *canv)
virtual ~TGo4CanvasLevelIter()
static TGo4Access * CreateAccess(TCanvas *canv, const char *name)
const char * GetPar(const char *name) const
Definition: TGo4Slot.cxx:621
void RegisterObjectWith(TObject *obj, TGo4Slot *slot)
virtual const char * info()
virtual Bool_t next()
static TGo4LevelIter * ProduceIter(TCanvas *canv)
virtual Int_t GetObjectKind()
virtual ~TGo4CanvasProxy()
virtual void WriteData(TGo4Slot *slot, TDirectory *dir, Bool_t onlyobjs)
virtual Bool_t RemoveRegisteredObject(TObject *obj)
virtual TObject * GetAssignedObject()
virtual Bool_t IsAcceptObject(TClass *cl)
virtual TGo4LevelIter * subiterator()
static TGo4Access * CreateAccess(THStack *canv, const char *name)
void ForwardEvent(TGo4Slot *source, Int_t id, void *param=0)
Definition: TGo4Slot.cxx:585
virtual const char * GetContainedClassName()
virtual TGo4ObjectManager * GetOM() const
Definition: TGo4Slot.cxx:298
void SetPar(const char *name, const char *value)
Definition: TGo4Slot.cxx:609
virtual const char * GetClassName()
virtual Bool_t AssignObject(TGo4Slot *slot, TObject *obj, Bool_t owner)
TGo4CanvasLevelIter(TPad *pad)
virtual Int_t GetKind()