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