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