TProofStartupDialog.cxx

Go to the documentation of this file.
00001 // @(#)root/peac:$Id: TProofStartupDialog.cxx 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: Maarten Ballintijn    21/10/2004
00003 // Author: Kris Gulbrandsen      21/10/2004
00004 
00005 /*************************************************************************
00006  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers.               *
00007  * All rights reserved.                                                  *
00008  *                                                                       *
00009  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00010  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00011  *************************************************************************/
00012 
00013 //////////////////////////////////////////////////////////////////////////
00014 //                                                                      //
00015 // TProofStartupDialog                                                  //
00016 //                                                                      //
00017 // This class provides a query progress bar for data being staged.      //
00018 //                                                                      //
00019 //////////////////////////////////////////////////////////////////////////
00020 
00021 #include "TProofStartupDialog.h"
00022 #include "TGLabel.h"
00023 #include "TGButton.h"
00024 #include "TGProgressBar.h"
00025 #include "TSystem.h"
00026 #include "TTimer.h"
00027 #include "TProof.h"
00028 
00029 
00030 ClassImp(TProofStartupDialog)
00031 
00032 //______________________________________________________________________________
00033 TProofStartupDialog::TProofStartupDialog(TProof *proof,
00034                                          const Char_t *dataset,
00035                                          Int_t nfiles,
00036                                          Long64_t totalbytes)
00037 {
00038    // Create data staging progress dialog.
00039 
00040    fProof = proof;
00041    fPrevStaged = 0;
00042    fFiles = nfiles;
00043    fTotalBytes = totalbytes;
00044 
00045    const TGWindow *main = gClient->GetRoot();
00046    fDialog = new TGTransientFrame(main, main, 10, 10);
00047    fDialog->Connect("CloseWindow()", "TProofStartupDialog", this, "DoClose()");
00048    fDialog->DontCallClose();
00049 
00050    // title label
00051    char buf[256];
00052    sprintf(buf, "Staging files for data set '%s'", dataset);
00053    fDialog->AddFrame(new TGLabel(fDialog, buf),
00054                      new TGLayoutHints(kLHintsNormal, 10, 10, 20, 0));
00055    sprintf(buf, "%d files, number of bytes %lld", fFiles, fTotalBytes);
00056    fFilesBytes = new TGLabel(fDialog, buf);
00057    fDialog->AddFrame(fFilesBytes, new TGLayoutHints(kLHintsNormal, 10, 10, 5, 0));
00058 
00059    // progress bar
00060    fBar = new TGHProgressBar(fDialog, TGProgressBar::kFancy, 450);
00061    fBar->SetBarColor("green");
00062    fDialog->AddFrame(fBar, new TGLayoutHints(kLHintsTop | kLHintsLeft |
00063                      kLHintsExpandX, 10, 10, 20, 20));
00064 
00065    // status labels
00066    TGHorizontalFrame *hf1 = new TGHorizontalFrame(fDialog, 0, 0);
00067    TGCompositeFrame *cf1 = new TGCompositeFrame(hf1, 110, 0, kFixedWidth);
00068    fStaged = new TGLabel(cf1, "Estimated time left:");
00069    cf1->AddFrame(fStaged);
00070    hf1->AddFrame(cf1);
00071    fTotal= new TGLabel(hf1, "- sec (- bytes of - staged)");
00072    hf1->AddFrame(fTotal, new TGLayoutHints(kLHintsNormal, 10, 10, 0, 0));
00073    fDialog->AddFrame(hf1, new TGLayoutHints(kLHintsNormal, 10, 10, 5, 0));
00074 
00075    TGHorizontalFrame *hf2 = new TGHorizontalFrame(fDialog, 0, 0);
00076    TGCompositeFrame *cf2 = new TGCompositeFrame(hf2, 110, 0, kFixedWidth);
00077    cf2->AddFrame(new TGLabel(cf2, "Staging rate:"));
00078    hf2->AddFrame(cf2);
00079    fRate = new TGLabel(hf2, "- bytes/sec");
00080    hf2->AddFrame(fRate, new TGLayoutHints(kLHintsNormal, 10, 10, 0, 0));
00081    fDialog->AddFrame(hf2, new TGLayoutHints(kLHintsNormal, 10, 10, 5, 0));
00082 
00083    // stop and close buttons
00084    TGHorizontalFrame *hf3 = new TGHorizontalFrame(fDialog, 60, 20, kFixedWidth);
00085 
00086    UInt_t  nb = 0, width = 0, height = 0;
00087 
00088    // place button frame (hf3) at the bottom
00089    fDialog->AddFrame(hf3, new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 10, 10, 20, 10));
00090 
00091    // keep buttons centered and with the same width
00092    hf3->Resize((width + 40) * nb, height);
00093 
00094    // connect slot to proof progress signal
00095    if (fProof)
00096       fProof->Connect("IsDataReady(Long64_t,Long64_t)", "TProofStartupDialog",
00097                       this, "Progress(Long64_t,Long64_t)");
00098 
00099    // set dialog title
00100    fDialog->SetWindowName("Data Staging Progress");
00101 
00102    // map all widgets and calculate size of dialog
00103    fDialog->MapSubwindows();
00104 
00105    width  = fDialog->GetDefaultWidth();
00106    height = fDialog->GetDefaultHeight();
00107 
00108    fDialog->Resize(width, height);
00109 
00110    // position relative to the parent window (which is the root window)
00111    Window_t wdum;
00112    int      ax, ay;
00113 
00114    gVirtualX->TranslateCoordinates(main->GetId(), main->GetId(),
00115                           (((TGFrame *) main)->GetWidth() - width) >> 1,
00116                           (((TGFrame *) main)->GetHeight() - height) >> 1,
00117                           ax, ay, wdum);
00118    fDialog->Move(ax, ay);
00119    fDialog->SetWMPosition(ax, ay);
00120 
00121    // make the message box non-resizable
00122    fDialog->SetWMSize(width, height);
00123    fDialog->SetWMSizeHints(width, height, width, height, 0, 0);
00124 
00125    fDialog->SetMWMHints(kMWMDecorAll | kMWMDecorResizeH  | kMWMDecorMaximize |
00126                                        kMWMDecorMinimize | kMWMDecorMenu,
00127                         kMWMFuncAll  | kMWMFuncResize    | kMWMFuncMaximize |
00128                                        kMWMFuncMinimize,
00129                         kMWMInputModeless);
00130 
00131    // popup dialog and wait till user replies
00132    fDialog->MapWindow();
00133 
00134    fStartTime = gSystem->Now();
00135 }
00136 
00137 //______________________________________________________________________________
00138 void TProofStartupDialog::Progress(Long64_t totalbytes, Long64_t bytesready)
00139 {
00140    // Update progress bar and status labels.
00141 
00142    if (fPrevStaged == bytesready)
00143       return;
00144 
00145    char buf[256];
00146    if (fTotalBytes != totalbytes) {
00147       fTotalBytes = totalbytes;
00148       sprintf(buf, "%d files, number of bytes %lld", fFiles, fTotalBytes);
00149       fFilesBytes->SetText(buf);
00150    }
00151 
00152    Float_t pos = Float_t(Double_t(bytesready * 100)/Double_t(totalbytes));
00153    fBar->SetPosition(pos);
00154 
00155    // get current time
00156    fEndTime = gSystem->Now();
00157    TTime tdiff = fEndTime - fStartTime;
00158    Float_t eta = 0;
00159    if (bytesready)
00160       eta = ((Float_t)((Long_t)tdiff)*totalbytes/Float_t(bytesready) - Long_t(tdiff))/1000.;
00161 
00162    if (bytesready == totalbytes) {
00163       fStaged->SetText("Staged:");
00164       sprintf(buf, "%lld bytes in %.1f sec", totalbytes, Long_t(tdiff)/1000.);
00165       fTotal->SetText(buf);
00166 
00167       if (fProof) {
00168          fProof->Disconnect("IsDataReady(Long64_t,Long64_t)", this,
00169                             "Progress(Long64_t,Long64_t)");
00170          fProof = 0;
00171       }
00172 
00173       DoClose();
00174    } else {
00175       sprintf(buf, "%.1f sec (%lld bytes of %lld staged)", eta, bytesready,
00176               totalbytes);
00177       fTotal->SetText(buf);
00178       sprintf(buf, "%.1f bytes/sec", Float_t(bytesready)/Long_t(tdiff)*1000.);
00179       fRate->SetText(buf);
00180    }
00181    fPrevStaged = bytesready;
00182 
00183    fDialog->Layout();
00184 }
00185 
00186 //______________________________________________________________________________
00187 TProofStartupDialog::~TProofStartupDialog()
00188 {
00189    // Cleanup dialog.
00190 
00191    if (fProof)
00192       fProof->Disconnect("IsDataReady(Long64_t,Long64_t)", this,
00193                          "Progress(Long64_t,Long64_t)");
00194 
00195    fDialog->Cleanup();
00196    delete fDialog;
00197 }
00198 
00199 //______________________________________________________________________________
00200 void TProofStartupDialog::CloseWindow()
00201 {
00202    // Called when dialog is closed.
00203 
00204    delete this;
00205 }
00206 
00207 //______________________________________________________________________________
00208 void TProofStartupDialog::DoClose()
00209 {
00210    // Close dialog.
00211 
00212    TTimer::SingleShot(500, "TProofStartupDialog", this, "CloseWindow()");
00213 }

Generated on Tue Jul 5 14:50:52 2011 for ROOT_528-00b_version by  doxygen 1.5.1