GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4DrawCloneProxy.cxx
Go to the documentation of this file.
1 // $Id: TGo4DrawCloneProxy.cxx 1483 2015-06-03 14:19:49Z 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 "TGo4DrawCloneProxy.h"
15 
16 #include "TH1.h"
17 #include "TH2.h"
18 #include "TGraph.h"
19 #include "TString.h"
20 
21 #include "TGo4LockGuard.h"
22 #include "TGo4ObjectManager.h"
23 #include "TGo4Picture.h"
24 #include "TGo4BrowserProxy.h"
25 #include "TGo4ViewPanel.h"
26 
27 
29  TGo4LinkProxy(slot),
30  fClone(0),
31  fPanel(panel),
32  fParentSlot(0)
33 {
34 }
35 
37 {
38  if (fClone!=0) delete fClone;
39 }
40 
41 Bool_t TGo4DrawCloneProxy::AssignClone(TObject* obj, TGo4Slot* slot)
42 {
43  TGo4LockGuard lock;
44 
45  CleanupClone(slot);
46  if (obj==0) return kFALSE;
47 
48  if (!obj->InheritsFrom(TH1::Class()) &&
49  !obj->InheritsFrom(TGraph::Class())) return kFALSE;
50 
51  fClone = obj->Clone();
52  if (fClone->InheritsFrom(TH1::Class()))
53  ((TH1*) fClone)->SetDirectory(0);
54  TGo4ObjectManager* om = slot->GetOM();
55  if ((om!=0) && (fClone!=0))
56  om->RegisterObjectWith(fClone, slot);
57 
58  return kTRUE;
59 }
60 
62 {
63  if (fClone==0) return;
64  TGo4ObjectManager* om = slot->GetOM();
65  if (om!=0) {
67  om->UnregisterObject(fClone, slot);
68  }
69  delete fClone;
70  fClone = 0;
71 }
72 
74 {
75  TNamed* src = dynamic_cast<TNamed*> (obj);
76  TNamed* tgt = dynamic_cast<TNamed*> (fClone);
77 
79 
80  if ((tgt==0) || (src==0) || (padopt==0)) return;
81  TString title = src->GetTitle();
82 
83  const char* stime = TGo4BrowserProxy::ItemTime(GetLink());
84  const char* sdate = TGo4BrowserProxy::ItemDate(GetLink());
85  const char* itemname = TGo4BrowserProxy::GetLinkedName(fParentSlot);
86 
87  if ((stime!=0) && padopt->IsTitleTime()) {
88  title+= " ";
89  title+=stime;
90  }
91  if ((sdate!=0) && padopt->IsTitleDate()) {
92  title+= " ";
93  title+=sdate;
94  }
95  if ((itemname!=0) && padopt->IsTitleItem()) {
96  title+= " ";
97  title+=itemname;
98  }
99  title.ReplaceAll(";","#semicolon");
100  tgt->SetTitle(title.Data());
101 }
102 
104 {
105  if (GetLink()!=0)
107 }
108 
110 {
111  if (obj==fClone) fClone = 0;
112  return kFALSE;
113 }
114 
116 {
118  if (fClone!=0) {
119  delete fClone;
120  Error("Initialize"," Problem in TGo4DrawCloneProxy");
121  }
122  fClone = 0;
123  fParentSlot = slot;
124 
125  if (GetLink()!=0) {
126  TObject* obj = GetLink()->GetAssignedObject();
127  if (obj!=0) AssignClone(obj, slot);
128  }
129 }
130 
132 {
133  CleanupClone(slot);
135  fParentSlot = 0;
136 }
137 
139 {
141 }
142 
143 Bool_t TGo4DrawCloneProxy::ProcessEvent(TGo4Slot* slot, TGo4Slot* source, Int_t id, void* param)
144 {
145  if (id==TGo4Slot::evObjAssigned) {
146  TObject* obj = GetLink()->GetAssignedObject();
147  AssignClone(obj, slot);
148  ChangeTitle(obj);
149  } else
151  bool res = kFALSE;
152  TObject* obj = GetLink()->GetAssignedObject();
153  if (obj!=0) {
154  Int_t rebinx(0), rebiny(0);
155  if (fClone!=0)
156  res = TGo4BrowserProxy::UpdateObjectContent(fClone, obj, &rebinx, &rebiny);
157  if (!res)
158  res = AssignClone(obj, slot);
159  else {
160  if (rebinx>1) fParentSlot->SetIntPar("::HasRebinX",rebinx);
161  else fParentSlot->RemovePar("::HasRebinX");
162  if (rebiny>1) fParentSlot->SetIntPar("::HasRebinY",rebiny);
163  else fParentSlot->RemovePar("::HasRebinY");
164  }
165  }
166 
167  if (!res) CleanupClone(slot);
168  else ChangeTitle(obj);
169  }
170 
171  return TGo4LinkProxy::ProcessEvent(slot, source, id, param);
172 }
173 
175 {
176  if (fClone==0) return;
177 
178  Int_t rebinx(0), rebiny(0);
179  fParentSlot->GetIntPar("::DoRebinX", rebinx);
180  fParentSlot->RemovePar("::DoRebinX");
181  fParentSlot->GetIntPar("::DoRebinY", rebiny);
182  fParentSlot->RemovePar("::DoRebinY");
183 
184  if ((rebinx<2) && (rebiny<2)) return;
185 
186  if (rebinx==0) rebinx = 1;
187  if (rebiny==0) rebiny = 1;
188 
189  TH2* h2 = dynamic_cast<TH2*> (fClone);
190  if (h2!=0) {
191  h2->Rebin2D(rebinx, rebiny);
192  return;
193  }
194 
195  TH1* h1 = dynamic_cast<TH1*> (fClone);
196  if (h1!=0) h1->Rebin(rebinx);
197 }
198 
virtual Bool_t ProcessEvent(TGo4Slot *slot, TGo4Slot *source, Int_t id, void *param)
Bool_t GetIntPar(const char *name, Int_t &value)
Definition: TGo4Slot.cxx:646
Bool_t AssignClone(TObject *obj, TGo4Slot *slot)
void UnregisterObject(TObject *obj, TGo4Slot *slot)
void SetIntPar(const char *name, Int_t value)
Definition: TGo4Slot.cxx:639
void CleanupClone(TGo4Slot *slot)
virtual void Finalize(TGo4Slot *slot)
static Bool_t UpdateObjectContent(TObject *obj, TObject *newobj, Int_t *hasrebinx=0, Int_t *hasrebiny=0)
virtual void Initialize(TGo4Slot *slot)
void RegisterObjectWith(TObject *obj, TGo4Slot *slot)
TObject * GetAssignedObject()
Definition: TGo4Slot.cxx:373
virtual TObject * GetAssignedObject()
TGo4Slot * GetParent() const
Definition: TGo4Slot.h:58
TGo4ViewPanel * fPanel
static const char * ItemDate(TGo4Slot *slot)
virtual void Finalize(TGo4Slot *slot)
void ChangeTitle(TObject *obj)
void RemovePar(const char *name)
Definition: TGo4Slot.cxx:628
TGo4DrawCloneProxy(TGo4Slot *slot, TGo4ViewPanel *panel)
virtual TGo4Picture * GetPadOptions(TPad *pad)
static const char * GetLinkedName(TGo4Slot *slot)
virtual void Initialize(TGo4Slot *slot)
virtual TObject * GetAssignedObject()
virtual void RecursiveRemove(TObject *obj)
TGo4Slot * GetLink() const
Definition: TGo4LinkProxy.h:45
virtual Bool_t ProcessEvent(TGo4Slot *slot, TGo4Slot *source, Int_t id, void *param)
Bool_t IsTitleDate() const
virtual Bool_t RemoveRegisteredObject(TObject *obj)
virtual TGo4ObjectManager * GetOM() const
Definition: TGo4Slot.cxx:298
Bool_t IsTitleItem() const
Bool_t IsTitleTime() const
static const char * ItemTime(TGo4Slot *slot)