GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4RootBrowserProxy.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
15
16#include "TROOT.h"
17#include "TCanvas.h"
18#include "TClass.h"
19#include "TH1.h"
20#include "TMath.h"
21#include "TTimer.h"
22#include "TBrowser.h"
23#include "TGMimeTypes.h"
24
25#include "TGo4Log.h"
26#include "TGo4Slot.h"
27#include "TGo4Iter.h"
28#include "TGo4Picture.h"
29#include "TGo4Condition.h"
30#include "TGo4BrowserProxy.h"
32#include "TGo4BrowserItem.h"
33
35
42
44{
45 TGo4BrowserItem *topfold = (TGo4BrowserItem *) gROOT->GetListOfBrowsables()->FindObject("go4");
46 if (topfold) {
47 gROOT->GetListOfBrowsables()->Remove(topfold);
48 delete topfold;
49 }
50}
51
52Bool_t TGo4RootBrowserProxy::ProcessEvent(TGo4Slot *slot, TGo4Slot *source, Int_t id, void *param)
53{
54 if ((id == TGo4Slot::evObjAssigned) || (id == TGo4Slot::evObjUpdated)) {
55 if (strcmp(source->GetName(), "Go4Browser") == 0)
57 if (strcmp(source->GetName(), "AnalLoginfo") == 0)
59 if (strcmp(source->GetName(), "AnalRateMeter") == 0)
61 } else if ((id == TGo4Slot::evDelete) || (id == TGo4Slot::evObjDeleted)) {
62 // Slot deleted
63 }
64
65 return id == TGo4Slot::evDelete;
66}
67
68void TGo4RootBrowserProxy::Message(const char *str1, const char *str2, Int_t blockdelay)
69{
70 TIter iter(gROOT->GetListOfBrowsers());
71
72 while (auto br = dynamic_cast<TBrowser*> (iter())) {
73 br->SetStatusText(str1, 0);
74 br->SetStatusText(str2, 1);
75 }
76
77 if (blockdelay > 0) {
78 fLockMessage = kTRUE;
79 TTimer::SingleShot(blockdelay, "TGo4RootBrowserProxy", this, "UnblockStatusOutput()");
80 }
81}
82
84{
85 if (fLockMessage) return;
86
88 dynamic_cast<TGo4AnalysisClientStatus*> (obj);
89 if (!anal) return;
90
91 const char *header = nullptr;
92
93 if(anal->IsAnalysisRunning())
94 header = "Analysis running";
95 else
96 header = "Analysis stopped";
97
98 TString res;
99
100 if (anal->GetRate() < 10)
101 res.Form("Rate = %6.4f Events = %d Time = %d Date = %s",
102 anal->GetRate(),
103 TMath::Nint(TMath::Floor(anal->GetCurrentCount())),
104 TMath::Nint(TMath::Floor(anal->GetTime())),
105 anal->GetDateTime());
106 else
107 res.Form("Rate = %d Events = %d Time = %d Date = %s",
108 TMath::Nint(TMath::Floor(anal->GetRate())),
109 TMath::Nint(TMath::Floor(anal->GetCurrentCount())),
110 TMath::Nint(TMath::Floor(anal->GetTime())),
111 anal->GetDateTime());
112
113 Message(header, res.Data(), 0);
114}
115
116
118{
119 std::cout << "Loginfo = " << obj->GetName() << std::endl;
120
121 Message("Message",obj->GetName(), 5000);
122}
123
128
130{
131 if (!fBrowser) return;
132
133 TGo4BrowserItem *topfold = (TGo4BrowserItem *) gROOT->GetListOfBrowsables()->FindObject("go4");
134 if (!topfold) {
135 topfold = new TGo4BrowserItem(nullptr, nullptr, "go4","Top go4 objects folder");
136 topfold->SetTitle("Top Go4 folder");
137 topfold->SetItemClass("TFolder");
138 topfold->SetIconName("Go4Logo");
139 topfold->SetBrowser(fBrowser, this);
140
141 gROOT->GetListOfBrowsables()->Add(topfold);
142
143 TString img = TGo4Log::subGO4SYS("icons/");
144
145 TGMimeTypes* mt = gClient->GetMimeTypeList();
146 mt->AddType("go4/logo", "Go4Logo", img + "go4logo2_big.png", img + "go4logo2.png", "->Draw()");
147 mt->AddType("go4/graph", "TGraph", img + "tgraph.png", img + "tgraph.png", "->Draw()");
148 mt->AddType("go4/multigraph", "TMultiGraph", img + "superimpose.png", img + "superimpose.png", "->Draw()");
149 mt->AddType("go4/picture", "TGo4Picture", img + "picture.png", img + "picture.png", "->Draw()");
150 mt->AddType("go4/param", "TGo4Parameter", img + "parameter.png", img + "parameter.png", "->Draw()");
151 mt->AddType("go4/fitter", "TGo4Fitter", img + "fitter.png", img + "fitter.png", "->Draw()");
152 mt->AddType("go4/wincond", "TGo4WinCond", img + "windcond.png", img + "windcond.png", "->Draw()");
153 mt->AddType("go4/polycond", "TGo4PolyCond", img + "polycond.png", img + "polycond.png", "->Draw()");
154 mt->AddType("go4/condarr", "TGo4CondArray", img + "windcondarray.png", img + "windcondarray.png", "->Draw()");
155 mt->AddType("go4/tentry", "TGo4TreeHistogramEntry", img + "dynentryx.png", img + "dynentryx.png", "->Draw()");
156 mt->AddType("go4/pentry", "TGo4HistogramEntry", img + "dynentryx.png", img + "dynentryx.png", "->Draw()");
157 mt->AddType("go4/hserv", "TGo4HServProxy", img + "histserv.png", img + "histserv.png", "->Draw()");
158 mt->AddType("go4/dabcserv", "TGo4DabcProxy", img + "dabc.png", img + "dabc.png", "->Draw()");
159 mt->AddType("go4/analysis", "TGo4AnalysisProxy", img + "analysiswin.png", img + "analysiswin.png", "->Draw()");
161 //mt->AddType("go4/httpserv", "TGo4HttpProxy", img + "http.png", img + "http.png", "->Draw()");
162 mt->AddType("go4/canvas", "TCanvas", img + "canvas.png", img + "canvas.png", "->Draw()");
163 mt->AddType("go4/tbranch", "Go4-TreeBranch", img + "branch_t.png", img + "branch_t.png", "->Draw()");
164 mt->AddType("go4/tleaf", "Go4-TreeLeaf", img + "leaf_t.png", img + "leaf_t.png", "->Draw()");
165 mt->AddType("go4/datamember", "Go4-EventDataMember", img + "eventitem.png", img + "eventitem.png", "->Draw()");
166 mt->AddType("go4/event", "Go4-EventElement", img + "eventobj.png", img + "eventobj.png", "->Draw()");
167 }
168
169 TGo4BrowserItem *curfold = topfold;
170 TGo4BrowserItem *curitem = curfold->firstChild();
171 TGo4BrowserItem *previtem = nullptr;
172
173 TObjArray testedClasses;
174
175 TGo4Iter iter(fBrowser->BrowserTopSlot(), kTRUE);
176
177 while (true) {
178 Bool_t res = iter.next();
179
180 // go to top folders and remove rest items
181 Int_t levelchange = iter.levelchange();
182 while (levelchange++ < 0) {
183
184 while (curitem) {
185 TGo4BrowserItem *next = curfold->nextChild();
186 curfold->deleteChild(curitem);
187 curitem = next;
188 }
189
190 if (!curfold) break;
191
192 previtem = curfold;
193 curfold = curfold->GetParent();
194 curitem = !curfold ? nullptr : curfold->nextChild();
195 }
196
197 if (!res) break;
198
199 // delete all slots in folder, which has another name
200 while (curitem && (strcmp(iter.getname(), curitem->GetName()) != 0)) {
201 TGo4BrowserItem *next = curfold->nextChild();
202 curfold->deleteChild(curitem);
203 curitem = next;
204 }
205
206 TGo4Slot *curslot = iter.getslot();
207 if (!curslot) {
208 std::cerr << "************* ERROR in gui slots ****************** " << std::endl;
209 return;
210 }
211
212 const char *classname = TGo4BrowserProxy::ItemClassName(curslot);
213 const char *iteminfo = TGo4BrowserProxy::ItemInfo(curslot);
214 Int_t itemkind = TGo4BrowserProxy::ItemKind(curslot);
215 TClass *itemclass = nullptr;
216
217 if (classname && !testedClasses.FindObject(classname)) {
218 itemclass = gROOT->GetClass(classname);
219 if (!itemclass)
220 testedClasses.Add(new TNamed(classname,""));
221 }
222
223 TString pixmap;
224 int cando = TGo4BrowserProxy::DefineItemProperties(itemkind, itemclass, pixmap);
225 TGo4BrowserProxy::SetItemCanDo(curslot, cando);
226
227 if (!curitem)
228 curitem = new TGo4BrowserItem(curfold, previtem, iter.getname(), classname);
229
230 curitem->SetBrowser(fBrowser, this);
231 curitem->SetTitle(iteminfo);
232 curitem->SetItemClass(classname);
233
234 TString iconname = classname;
235 if (itemkind == TGo4Access::kndTreeBranch)
236 iconname = "Go4-TreeBranch";
237 else if (itemkind == TGo4Access::kndTreeLeaf)
238 iconname = "Go4-TreeLeaf";
239 else if (itemkind == TGo4Access::kndGo4Param)
240 iconname = "TGo4Parameter";
241 else if (itemkind == TGo4Access::kndDataMember)
242 iconname = "Go4-EventDataMember";
243 else if (itemkind == TGo4Access::kndEventElement)
244 iconname = "Go4-EventElement";
245
246 curitem->SetIconName(iconname.Data());
247
248 if (iter.isfolder()) {
249 curitem->SetIsFolder(kTRUE);
250 curfold = curitem;
251 curitem = curfold->firstChild();
252 previtem = nullptr;
253 } else {
254 // remove any substructures if any
255 curitem->SetIsFolder(kFALSE);
256 curitem->deleteChilds();
257 previtem = curitem;
258 curitem = curfold->nextChild();
259 }
260 }
261
262 while (curitem) {
263 TGo4BrowserItem *next = curfold->nextChild();
264 curfold->deleteChild(curitem);
265 curitem = next;
266 }
267
268 testedClasses.Delete();
269}
270
271TCanvas *TGo4RootBrowserProxy::MakeCanvas(const char *title)
272{
273 TString cname = "Canvas_";
274 cname += fCanvasCounter++;
275 TCanvas *c1 = nullptr;
276
277 if (!title) c1 = new TCanvas(cname, cname+" title");
278 else c1 = new TCanvas(cname, title);
279 c1->cd();
280
281 return c1;
282}
283
284void TGo4RootBrowserProxy::DrawPicture(const char *picitemname, TGo4Picture *pic, TPad *pad)
285{
286 if (!pad || !pic) return;
287
288 pad->cd();
289
290 if (pic->IsDivided()) {
291 pad->Divide(pic->GetDivX(), pic->GetDivY());
292
293 for (Int_t posy = 0; posy < pic->GetDivY(); posy++)
294 for (Int_t posx = 0; posx < pic->GetDivX(); posx++) {
295 TGo4Picture *sub = pic->FindPic(posy, posx);
296 if (sub)
297 DrawPicture(picitemname, sub, (TPad *)pad->GetPad(posy * pic->GetDivX() + posx + 1));
298 }
299 return;
300 }
301
303
304 TH1 *h1 = nullptr;
305
306 for (Int_t indx = 0; indx < pic->GetNumObjNames(); indx++) {
307 Option_t *drawopt = pic->GetDrawOption(indx);
308 const char *objname = pic->GetObjName(indx);
309
310 TString drawname;
311
312 TObject *obj = nullptr;
313
314 if (fBrowser->DefineRelatedObject(picitemname, objname, drawname))
315 obj = fBrowser->GetBrowserObject(drawname.Data(), 5000);
316 if (!obj) continue;
317
318 if (!h1)
319 h1 = dynamic_cast<TH1 *>(obj);
320
321 pic->GetDrawAttributes(obj, indx);
322
323 if (obj->InheritsFrom(TGo4Condition::Class())) {
324 TGo4Condition *con = (TGo4Condition *) obj;
325 con->SetWorkHistogram(h1);
326 con->SetLineColor(2);
327 con->SetFillColor(2);
328 con->SetFillStyle(3444);
329 }
330
331 obj->Draw(drawopt);
332 }
333
334 pad->Modified();
335}
336
338{
339 if (!con || !fBrowser) return;
340
341 const char *hname = con->GetLinkedHistogram();
342 TString hitemname;
343
344 TH1 *h1 = nullptr;
345
346 if (hname && fBrowser->DefineRelatedObject(itemname, hname, hitemname))
347 h1 = dynamic_cast<TH1 *>(fBrowser->GetBrowserObject(hitemname.Data(), 5000));
348
349 if (!h1) return;
350
351 TCanvas *c1 = MakeCanvas(TString("Condition ") + con->GetName() + " on histo " + h1->GetName());
352
353 h1->Draw();
354 con->SetWorkHistogram(h1);
355 con->SetLineColor(2);
356 con->SetFillColor(2);
357 con->SetFillStyle(3444);
358 con->Draw();
359
360 c1->Update();
361}
362
363void TGo4RootBrowserProxy::DrawItem(const char *itemname)
364{
365 if (!itemname || !fBrowser) return;
366
367 Int_t cando = fBrowser->ItemCanDo(itemname);
368
369 if (!TGo4BrowserProxy::CanDrawItem(cando)) {
370 TClass *cl = fBrowser->ItemClass(itemname);
371 if (!cl || !cl->InheritsFrom(TGo4Condition::Class())) return;
372 }
373
374 TObject *obj = fBrowser->GetBrowserObject(itemname, 5000);
375 if (!obj) return;
376
377 if (obj->InheritsFrom(TGo4Condition::Class())) {
378 DrawCondition(itemname, (TGo4Condition *) obj);
379 return;
380 }
381
382 TPad *pad = (TPad *) gPad;
383 if (!pad) pad = MakeCanvas(TString("Drawing of ") + obj->GetName());
384 else pad->Clear();
385
386 if (obj->InheritsFrom(TGo4Picture::Class()))
387 DrawPicture(itemname, (TGo4Picture *) obj, pad);
388 else
389 obj->Draw();
390
391 pad->Update();
392}
@ kndTreeBranch
Definition TGo4Proxy.h:37
@ kndEventElement
Definition TGo4Proxy.h:41
@ kndDataMember
Definition TGo4Proxy.h:40
void SetIsFolder(Bool_t b)
TGo4BrowserItem * nextChild()
void SetTitle(const char *title="") override
void SetBrowser(TGo4BrowserProxy *br, TGo4RootBrowserProxy *br2)
void deleteChild(TGo4BrowserItem *item)
void SetItemClass(const char *name)
TGo4BrowserItem * GetParent() const
void SetIconName(const char *name)
TGo4BrowserItem * firstChild()
static void SetItemCanDo(TGo4Slot *slot, Int_t cando)
Int_t ItemKind(const char *name)
static const char * ItemInfo(TGo4Slot *slot)
static Int_t DefineItemProperties(Int_t kind, TClass *cl, TString &pixmap)
static bool CanDrawItem(int cando)
const char * ItemClassName(const char *name)
Go4 condition class.
const char * GetLinkedHistogram() const
Access name of the associated histogram.
void Draw(Option_t *opt="") override
Draw this condition on current pad.
virtual void SetWorkHistogram(TH1 *histo)
Set reference to work histogram for statistics functions.
Bool_t isfolder()
Definition TGo4Iter.cxx:109
Bool_t next(Bool_t goesinto=kTRUE)
Definition TGo4Iter.cxx:44
const char * getname()
Definition TGo4Iter.cxx:115
TGo4Slot * getslot() const
Definition TGo4Iter.cxx:166
Int_t levelchange() const
Definition TGo4Iter.h:41
static TString subGO4SYS(const char *subdir)
Return subdirectory in the GO4SYS.
Definition TGo4Log.cxx:189
Picture cconfiguration in Go4.
Definition TGo4Picture.h:40
Int_t GetNumObjNames() const
Int_t GetDivY() const
Definition TGo4Picture.h:57
Bool_t IsDivided() const
Definition TGo4Picture.h:58
Option_t * GetDrawOption() const override
void GetDrawAttributes(TObject *obj, Int_t index=UndefIndex) const
const char * GetObjName(Int_t n) const
TGo4Picture * FindPic(Int_t posy, Int_t posx)
Int_t GetDivX() const
Definition TGo4Picture.h:56
void DrawCondition(const char *itemname, TGo4Condition *con)
TCanvas * MakeCanvas(const char *title=nullptr)
TGo4BrowserProxy * fBrowser
Bool_t ProcessEvent(TGo4Slot *slot, TGo4Slot *source, Int_t id, void *param) override
void DrawPicture(const char *itemname, TGo4Picture *pic, TPad *pad)
void Message(const char *str1, const char *str2, Int_t blockdelay)
TGo4RootBrowserProxy(TGo4BrowserProxy *br=nullptr)
void UpdateLoginfo(TObject *obj)
void DrawItem(const char *itemname)
void UpdateRatemeter(TObject *obj)
@ evObjUpdated
Definition TGo4Slot.h:49
@ evObjAssigned
Definition TGo4Slot.h:47
@ evObjDeleted
Definition TGo4Slot.h:51
@ evDelete
Definition TGo4Slot.h:45
TObject * GetAssignedObject()
Definition TGo4Slot.cxx:356