00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4RootBrowserProxy.h"
00015
00016 #include "Riostream.h"
00017 #include "RVersion.h"
00018
00019 #include "TROOT.h"
00020 #include "TPad.h"
00021 #include "TCanvas.h"
00022 #include "TClass.h"
00023 #include "TH1.h"
00024 #include "TMath.h"
00025 #include "TTimer.h"
00026 #include "TBrowser.h"
00027 #include "TGMimeTypes.h"
00028
00029 #include "TGo4Log.h"
00030 #include "TGo4Slot.h"
00031 #include "TGo4Iter.h"
00032 #include "TGo4Picture.h"
00033 #include "TGo4Condition.h"
00034 #include "TGo4BrowserProxy.h"
00035 #include "TGo4AnalysisClientStatus.h"
00036 #include "TGo4BrowserItem.h"
00037
00038 #if ROOT_VERSION_CODE <= ROOT_VERSION(5,17,4)
00039 #include "TRootBrowser.h"
00040 #include "TGStatusBar.h"
00041 #endif
00042
00043 Int_t TGo4RootBrowserProxy::fCanvasCounter = 0;
00044
00045 TGo4RootBrowserProxy::TGo4RootBrowserProxy(TGo4BrowserProxy* br) :
00046 TGo4Proxy(),
00047 fBrowser(br),
00048 fLockMessage(kFALSE)
00049 {
00050 }
00051
00052 TGo4RootBrowserProxy::~TGo4RootBrowserProxy()
00053 {
00054 TGo4BrowserItem* topfold = (TGo4BrowserItem*) gROOT->GetListOfBrowsables()->FindObject("go4");
00055 if (topfold!=0) {
00056 gROOT->GetListOfBrowsables()->Remove(topfold);
00057 delete topfold;
00058 }
00059 }
00060
00061 Bool_t TGo4RootBrowserProxy::ProcessEvent(TGo4Slot* slot, TGo4Slot* source, Int_t id, void* param)
00062 {
00063 if ((id==TGo4Slot::evObjAssigned) ||
00064 (id==TGo4Slot::evObjUpdated)) {
00065 if (strcmp(source->GetName(), "Go4Browser")==0)
00066 SyncRootBrowserSlots();
00067 if (strcmp(source->GetName(), "AnalLoginfo")==0)
00068 UpdateLoginfo(source->GetAssignedObject());
00069 if (strcmp(source->GetName(), "AnalRateMeter")==0)
00070 UpdateRatemeter(source->GetAssignedObject());
00071 }
00072 else
00073 if ((id==TGo4Slot::evDelete) ||
00074 (id==TGo4Slot::evObjDeleted)) {
00075
00076 }
00077
00078 return (id==TGo4Slot::evDelete);
00079 }
00080
00081 void TGo4RootBrowserProxy::Message(const char* str1, const char* str2, Int_t blockdelay)
00082 {
00083 TIter iter(gROOT->GetListOfBrowsers());
00084 TBrowser* br = 0;
00085
00086 while ((br = dynamic_cast<TBrowser*> (iter())) !=0 ) {
00087
00088 #if ROOT_VERSION_CODE > ROOT_VERSION(5,17,4)
00089 br->SetStatusText(str1, 0);
00090 br->SetStatusText(str2, 1);
00091 #else
00092 TRootBrowser* imp = dynamic_cast<TRootBrowser*> (br->GetBrowserImp());
00093 if (imp==0) continue;
00094
00095 imp->ShowStatusBar(kTRUE);
00096
00097 TGStatusBar* status = imp->GetStatusBar();
00098 if (status!=0) {
00099 status->SetText(str1, 0);
00100 status->SetText(str2, 1);
00101 }
00102 #endif
00103 }
00104
00105 if (blockdelay>0) {
00106 fLockMessage = kTRUE;
00107 TTimer::SingleShot(blockdelay, "TGo4RootBrowserProxy", this, "UnblockStatusOutput()");
00108 }
00109 }
00110
00111 void TGo4RootBrowserProxy::UpdateRatemeter(TObject* obj)
00112 {
00113 if (fLockMessage) return;
00114
00115 TGo4AnalysisClientStatus* anal =
00116 dynamic_cast<TGo4AnalysisClientStatus*> (obj);
00117 if (anal==0) return;
00118
00119 const char* header = 0;
00120
00121 if(anal->IsAnalysisRunning())
00122 header = "Analysis running";
00123 else
00124 header = "Analysis stopped";
00125
00126 TString res;
00127
00128 if (anal->GetRate()<10)
00129 res.Form("Rate = %6.4f Events = %d Time = %d Date = %s",
00130 anal->GetRate(),
00131 TMath::Nint(TMath::Floor(anal->GetCurrentCount())),
00132 TMath::Nint(TMath::Floor(anal->GetTime())),
00133 anal->GetDateTime());
00134 else
00135 res.Form("Rate = %d Events = %d Time = %d Date = %s",
00136 TMath::Nint(TMath::Floor(anal->GetRate())),
00137 TMath::Nint(TMath::Floor(anal->GetCurrentCount())),
00138 TMath::Nint(TMath::Floor(anal->GetTime())),
00139 anal->GetDateTime());
00140
00141 Message(header, res.Data(), 0);
00142 }
00143
00144
00145 void TGo4RootBrowserProxy::UpdateLoginfo(TObject* obj)
00146 {
00147 std::cout << "Loginfo = " << obj->GetName() << std::endl;
00148
00149 Message("Message",obj->GetName(), 5000);
00150 }
00151
00152 void TGo4RootBrowserProxy::UnblockStatusOutput()
00153 {
00154 fLockMessage = kFALSE;
00155 }
00156
00157 void TGo4RootBrowserProxy::SyncRootBrowserSlots()
00158 {
00159 if (fBrowser==0) return;
00160
00161 TGo4BrowserItem* topfold = (TGo4BrowserItem*) gROOT->GetListOfBrowsables()->FindObject("go4");
00162 if (topfold==0) {
00163 topfold = new TGo4BrowserItem(0, 0, "go4","Top go4 objects folder");
00164 topfold->SetTitle("Top Go4 folder");
00165 topfold->SetItemClass("TFolder");
00166 topfold->SetIconName("Go4Logo");
00167 topfold->SetBrowser(fBrowser, this);
00168
00169 gROOT->GetListOfBrowsables()->Add(topfold);
00170
00171 TString img = TGo4Log::subGO4SYS("icons/");
00172
00173 TGMimeTypes* mt = gClient->GetMimeTypeList();
00174 mt->AddType("go4/logo", "Go4Logo", img + "go4logo2_big.png", img + "go4logo2.png", "->Draw()");
00175 mt->AddType("go4/graph", "TGraph", img + "tgraph.png", img + "tgraph.png", "->Draw()");
00176 mt->AddType("go4/multigraph", "TMultiGraph", img + "superimpose.png", img + "superimpose.png", "->Draw()");
00177 mt->AddType("go4/picture", "TGo4Picture", img + "picture.png", img + "picture.png", "->Draw()");
00178 mt->AddType("go4/param", "TGo4Parameter", img + "parameter.png", img + "parameter.png", "->Draw()");
00179 mt->AddType("go4/fitter", "TGo4Fitter", img + "fitter.png", img + "fitter.png", "->Draw()");
00180 mt->AddType("go4/wincond", "TGo4WinCond", img + "windcond.png", img + "windcond.png", "->Draw()");
00181 mt->AddType("go4/polycond", "TGo4PolyCond", img + "polycond.png", img + "polycond.png", "->Draw()");
00182 mt->AddType("go4/condarr", "TGo4CondArray", img + "windcondarray.png", img + "windcondarray.png", "->Draw()");
00183 mt->AddType("go4/tentry", "TGo4TreeHistogramEntry", img + "dynentryx.png", img + "dynentryx.png", "->Draw()");
00184 mt->AddType("go4/pentry", "TGo4HistogramEntry", img + "dynentryx.png", img + "dynentryx.png", "->Draw()");
00185 mt->AddType("go4/hserv", "TGo4HServProxy", img + "histserv.png", img + "histserv.png", "->Draw()");
00186 mt->AddType("go4/dabcserv", "TGo4DabcProxy", img + "dabc.png", img + "dabc.png", "->Draw()");
00187 mt->AddType("go4/canvas", "TCanvas", img + "canvas.png", img + "canvas.png", "->Draw()");
00188 mt->AddType("go4/analysis", "TGo4AnalysisProxy", img + "analysiswin.png", img + "analysiswin.png", "->Draw()");
00189 mt->AddType("go4/tbranch", "Go4-TreeBranch", img + "branch_t.png", img + "branch_t.png", "->Draw()");
00190 mt->AddType("go4/tleaf", "Go4-TreeLeaf", img + "leaf_t.png", img + "leaf_t.png", "->Draw()");
00191 mt->AddType("go4/datamember", "Go4-EventDataMember", img + "eventitem.png", img + "eventitem.png", "->Draw()");
00192 mt->AddType("go4/event", "Go4-EventElement", img + "eventobj.png", img + "eventobj.png", "->Draw()");
00193 }
00194
00195 TGo4BrowserItem* curfold = topfold;
00196 TGo4BrowserItem* curitem = curfold->firstChild();
00197 TGo4BrowserItem* previtem = 0;
00198
00199 TObjArray testedClasses;
00200
00201 TGo4Iter iter(fBrowser->BrowserTopSlot(), kTRUE);
00202
00203 while (true) {
00204 Bool_t res = iter.next();
00205
00206
00207 Int_t levelchange = iter.levelchange();
00208 while (levelchange++<0) {
00209
00210 while (curitem!=0) {
00211 TGo4BrowserItem* next = curfold->nextChild();
00212 curfold->deleteChild(curitem);
00213 curitem = next;
00214 }
00215
00216 if (curfold==0) break;
00217
00218 previtem = curfold;
00219 curfold = curfold->GetParent();
00220 curitem = curfold==0 ? 0 : curfold->nextChild();
00221 }
00222
00223 if (!res) break;
00224
00225
00226 while ((curitem!=0) && (strcmp(iter.getname(), curitem->GetName())!=0)) {
00227 TGo4BrowserItem* next = curfold->nextChild();
00228 curfold->deleteChild(curitem);
00229 curitem = next;
00230 }
00231
00232 TGo4Slot* curslot = iter.getslot();
00233 if (curslot==0) {
00234 std::cerr << "************* ERROR in gui slots ****************** " << std::endl;
00235 return;
00236 }
00237
00238 const char* classname = TGo4BrowserProxy::ItemClassName(curslot);
00239 const char* iteminfo = TGo4BrowserProxy::ItemInfo(curslot);
00240 Int_t itemkind = TGo4BrowserProxy::ItemKind(curslot);
00241 TClass* itemclass = 0;
00242
00243 if ((classname!=0) && (testedClasses.FindObject(classname)==0)) {
00244 itemclass = gROOT->GetClass(classname);
00245 if (itemclass==0)
00246 testedClasses.Add(new TNamed(classname,""));
00247 }
00248
00249 TString pixmap;
00250 int cando = TGo4BrowserProxy::DefineItemProperties(itemkind, itemclass, pixmap);
00251 TGo4BrowserProxy::SetItemCanDo(curslot, cando);
00252
00253 if (curitem==0)
00254 curitem = new TGo4BrowserItem(curfold, previtem, iter.getname(), classname);
00255
00256 curitem->SetBrowser(fBrowser, this);
00257 curitem->SetTitle(iteminfo);
00258 curitem->SetItemClass(classname);
00259
00260 TString iconname = classname;
00261 if (itemkind==TGo4Access::kndTreeBranch)
00262 iconname = "Go4-TreeBranch";
00263 else
00264 if (itemkind==TGo4Access::kndTreeLeaf)
00265 iconname = "Go4-TreeLeaf";
00266 else
00267 if (itemkind==TGo4Access::kndGo4Param)
00268 iconname = "TGo4Parameter";
00269 else
00270 if (itemkind==TGo4Access::kndDataMember)
00271 iconname = "Go4-EventDataMember";
00272 else
00273 if (itemkind==TGo4Access::kndEventElement)
00274 iconname = "Go4-EventElement";
00275
00276 curitem->SetIconName(iconname.Data());
00277
00278 if (iter.isfolder()) {
00279 curitem->SetIsFolder(kTRUE);
00280 curfold = curitem;
00281 curitem = curfold->firstChild();
00282 previtem = 0;
00283 } else {
00284
00285 curitem->SetIsFolder(kFALSE);
00286 curitem->deleteChilds();
00287 previtem = curitem;
00288 curitem = curfold->nextChild();
00289 }
00290 }
00291
00292 while (curitem!=0) {
00293 TGo4BrowserItem* next = curfold->nextChild();
00294 curfold->deleteChild(curitem);
00295 curitem = next;
00296 }
00297
00298 testedClasses.Delete();
00299 }
00300
00301 TCanvas* TGo4RootBrowserProxy::MakeCanvas(const char* title)
00302 {
00303 TString cname = "Canvas_";
00304 cname += fCanvasCounter++;
00305 TCanvas* c1 = 0;
00306
00307 if (title==0) c1 = new TCanvas(cname, cname+" title");
00308 else c1 = new TCanvas(cname, title);
00309 c1->cd();
00310
00311 return c1;
00312 }
00313
00314 void TGo4RootBrowserProxy::DrawPicture(const char* picitemname, TGo4Picture* pic, TPad* pad)
00315 {
00316 if ((pad==0) || (pic==0)) return;
00317
00318 pad->cd();
00319
00320 if (pic->IsDivided()) {
00321 pad->Divide(pic->GetDivX(), pic->GetDivY());
00322
00323 for(Int_t posy=0; posy<pic->GetDivY(); posy++)
00324 for(Int_t posx=0; posx<pic->GetDivX(); posx++) {
00325 TGo4Picture* sub = pic->FindPic(posy,posx);
00326 if (sub!=0)
00327 DrawPicture(picitemname, sub, (TPad*) pad->GetPad(posy*pic->GetDivX() + posx + 1));
00328 }
00329 return;
00330 }
00331
00332 pic->GetDrawAttributes(pad, TGo4Picture::PictureIndex);
00333
00334 TH1* h1 = 0;
00335
00336 for (Int_t indx=0; indx<pic->GetNumObjNames(); indx++) {
00337 Option_t* drawopt = pic->GetDrawOption(indx);
00338 const char* objname = pic->GetObjName(indx);
00339
00340 TString drawname;
00341
00342 TObject* obj = 0;
00343
00344 if (fBrowser->DefineRelatedObject(picitemname, objname, drawname))
00345 obj = fBrowser->GetBrowserObject(drawname.Data(), 5000);
00346 if (obj==0) continue;
00347
00348 if (h1==0)
00349 h1 = dynamic_cast<TH1*>(obj);
00350
00351 pic->GetDrawAttributes(obj, indx);
00352
00353 if (obj->InheritsFrom(TGo4Condition::Class())) {
00354 TGo4Condition* con = (TGo4Condition*) obj;
00355 con->SetWorkHistogram(h1);
00356 con->SetLineColor(2);
00357 con->SetFillColor(2);
00358 con->SetFillStyle(3444);
00359 }
00360
00361 obj->Draw(drawopt);
00362 }
00363
00364 pad->Modified();
00365 }
00366
00367 void TGo4RootBrowserProxy::DrawCondition(const char* itemname, TGo4Condition* con)
00368 {
00369 if ((con==0) || (fBrowser==0)) return;
00370
00371 const char* hname = con->GetLinkedHistogram();
00372 TString hitemname;
00373
00374 TH1* h1 = 0;
00375
00376 if ((hname!=0) &&
00377 fBrowser->DefineRelatedObject(itemname, hname, hitemname))
00378 h1 = dynamic_cast<TH1*> (fBrowser->GetBrowserObject(hitemname.Data(), 5000));
00379
00380 if (h1==0) return;
00381
00382 TCanvas* c1 = MakeCanvas(TString("Condition ") + con->GetName() + " on histo " + h1->GetName());
00383
00384 h1->Draw();
00385 con->SetWorkHistogram(h1);
00386 con->SetLineColor(2);
00387 con->SetFillColor(2);
00388 con->SetFillStyle(3444);
00389 con->Draw();
00390
00391 c1->Update();
00392 }
00393
00394 void TGo4RootBrowserProxy::DrawItem(const char* itemname)
00395 {
00396 if ((itemname==0) || (fBrowser==0)) return;
00397
00398 Int_t cando = fBrowser->ItemCanDo(itemname);
00399
00400 if (!TGo4BrowserProxy::CanDrawItem(cando)) {
00401 TClass* cl = fBrowser->ItemClass(itemname);
00402 if ((cl==0) || !cl->InheritsFrom(TGo4Condition::Class())) return;
00403 }
00404
00405
00406 TObject* obj = fBrowser->GetBrowserObject(itemname, 5000);
00407 if (obj==0) return;
00408
00409 if (obj->InheritsFrom(TGo4Condition::Class())) {
00410 DrawCondition(itemname, (TGo4Condition*) obj);
00411 return;
00412 }
00413
00414 TPad* pad = (TPad*) gPad;
00415 if (pad==0) pad = MakeCanvas(TString("Drawing of ") + obj->GetName());
00416 else pad->Clear();
00417
00418
00419
00420 if (obj->InheritsFrom(TGo4Picture::Class()))
00421 DrawPicture(itemname, (TGo4Picture*) obj, pad);
00422 else
00423 obj->Draw();
00424
00425 pad->Update();
00426 }