GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4DrawCloneProxy.cxx
Go to the documentation of this file.
1// $Id$
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 "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(nullptr),
31 fPanel(panel),
32 fParentSlot(nullptr)
33{
34}
35
40
41Bool_t TGo4DrawCloneProxy::AssignClone(TObject *obj, TGo4Slot *slot)
42{
43 TGo4LockGuard lock;
44
45 CleanupClone(slot);
46 if (!obj) 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(nullptr);
54 TGo4ObjectManager *om = slot->GetOM();
55 if (om && fClone)
56 om->RegisterObjectWith(fClone, slot);
57
58 return kTRUE;
59}
60
62{
63 if (!fClone) return;
64 TGo4ObjectManager *om = slot->GetOM();
65 if (om) {
67 om->UnregisterObject(fClone, slot);
68 }
69 delete fClone;
70 fClone = nullptr;
71}
72
74{
75 TNamed *src = dynamic_cast<TNamed*> (obj);
76 TNamed *tgt = dynamic_cast<TNamed*> (fClone);
77
78 TGo4Picture *padopt = fPanel->GetPadOptions(fParentSlot->GetParent());
79
80 if (!tgt || !src || !padopt) 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 && padopt->IsTitleTime()) {
88 title+= " ";
89 title+=stime;
90 }
91 if (sdate && padopt->IsTitleDate()) {
92 title+= " ";
93 title+=sdate;
94 }
95 if (itemname && padopt->IsTitleItem()) {
96 title+= " ";
97 title+=itemname;
98 }
99 title.ReplaceAll(";","#semicolon");
100 tgt->SetTitle(title.Data());
101}
102
108
110{
111 if (obj==fClone) fClone = nullptr;
112 return kFALSE;
113}
114
116{
118 if (fClone) {
119 delete fClone;
120 Error("Initialize"," Problem in TGo4DrawCloneProxy");
121 }
122 fClone = nullptr;
123 fParentSlot = slot;
124
125 if (GetLink()) {
126 TObject *obj = GetLink()->GetAssignedObject();
127 if (obj) AssignClone(obj, slot);
128 }
129}
130
132{
133 CleanupClone(slot);
135 fParentSlot = nullptr;
136}
137
142
143Bool_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 if ((id==TGo4Slot::evObjUpdated) || (id==TGo4Slot::evContAssigned)) {
150 bool res = kFALSE;
151 TObject *obj = GetLink()->GetAssignedObject();
152 if (obj) {
153 Int_t rebinx = 0, rebiny = 0;
154 if (fClone)
155 res = TGo4BrowserProxy::UpdateObjectContent(fClone, obj, &rebinx, &rebiny);
156 if (!res) {
157 res = AssignClone(obj, slot);
158 } else {
159 if (rebinx>1) fParentSlot->SetIntPar("::HasRebinX",rebinx);
160 else fParentSlot->RemovePar("::HasRebinX");
161 if (rebiny>1) fParentSlot->SetIntPar("::HasRebinY",rebiny);
162 else fParentSlot->RemovePar("::HasRebinY");
163 }
164 }
165
166 if (!res) CleanupClone(slot);
167 else ChangeTitle(obj);
168 }
169
170 return TGo4LinkProxy::ProcessEvent(slot, source, id, param);
171}
172
174{
175 if (!fClone) return;
176
177 Int_t rebinx = 0, rebiny = 0;
178 fParentSlot->GetIntPar("::DoRebinX", rebinx);
179 fParentSlot->RemovePar("::DoRebinX");
180 fParentSlot->GetIntPar("::DoRebinY", rebiny);
181 fParentSlot->RemovePar("::DoRebinY");
182
183 if ((rebinx<2) && (rebiny<2)) return;
184
185 if (rebinx == 0) rebinx = 1;
186 if (rebiny == 0) rebiny = 1;
187
188 TH2 *h2 = dynamic_cast<TH2 *> (fClone);
189 if (h2) {
190 h2->Rebin2D(rebinx, rebiny);
191 return;
192 }
193
194 TH1 *h1 = dynamic_cast<TH1 *> (fClone);
195 if (h1) h1->Rebin(rebinx);
196}
197
#define TGo4LockGuard
static const char * ItemTime(TGo4Slot *slot)
static Bool_t UpdateObjectContent(TObject *obj, TObject *newobj, Int_t *hasrebinx=nullptr, Int_t *hasrebiny=nullptr)
static const char * GetLinkedName(TGo4Slot *slot)
static const char * ItemDate(TGo4Slot *slot)
void ChangeTitle(TObject *obj)
Bool_t RemoveRegisteredObject(TObject *obj) override
void CleanupClone(TGo4Slot *slot)
Bool_t AssignClone(TObject *obj, TGo4Slot *slot)
Bool_t ProcessEvent(TGo4Slot *slot, TGo4Slot *source, Int_t id, void *param) override
void Initialize(TGo4Slot *slot) override
TGo4ViewPanel * fPanel
void Finalize(TGo4Slot *slot) override
TObject * GetAssignedObject() override
TGo4DrawCloneProxy(TGo4Slot *slot, TGo4ViewPanel *panel)
TGo4Slot * GetLink() const
void Finalize(TGo4Slot *slot) override
TObject * GetAssignedObject() override
void Initialize(TGo4Slot *slot) override
Bool_t ProcessEvent(TGo4Slot *slot, TGo4Slot *source, Int_t id, void *param) override
void RegisterObjectWith(TObject *obj, TGo4Slot *slot)
void UnregisterObject(TObject *obj, TGo4Slot *slot)
void RecursiveRemove(TObject *obj) override
Picture cconfiguration in Go4.
Definition TGo4Picture.h:40
Bool_t IsTitleDate() const
Bool_t IsTitleItem() const
Bool_t IsTitleTime() const
virtual TGo4ObjectManager * GetOM() const
Definition TGo4Slot.cxx:282
@ evObjUpdated
Definition TGo4Slot.h:49
@ evObjAssigned
Definition TGo4Slot.h:47
@ evContAssigned
Definition TGo4Slot.h:48
TObject * GetAssignedObject()
Definition TGo4Slot.cxx:356