Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4RootBrowserProxy.cxx

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

Generated on Fri Nov 28 12:59:28 2008 for Go4-v3.04-1 by  doxygen 1.4.2