TSessionViewer.cxx

Go to the documentation of this file.
00001 // @(#)root/sessionviewer:$Id: TSessionViewer.cxx 35627 2010-09-23 08:33:09Z bellenot $
00002 // Author: Marek Biskup, Jakub Madejczyk, Bertrand Bellenot 10/08/2005
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // TSessionViewer                                                       //
00015 //                                                                      //
00016 // Widget used to manage PROOF or local sessions, PROOF connections,    //
00017 // queries construction and results handling.                           //
00018 //                                                                      //
00019 //////////////////////////////////////////////////////////////////////////
00020 
00021 #include "TApplication.h"
00022 #include "TROOT.h"
00023 #include "THashList.h"
00024 #include "TClass.h"
00025 #include "TSystem.h"
00026 #include "TGFileDialog.h"
00027 #include "TBrowser.h"
00028 #include "TGButton.h"
00029 #include "TGLayout.h"
00030 #include "TGListTree.h"
00031 #include "TGCanvas.h"
00032 #include "TGLabel.h"
00033 #include "TGTextEntry.h"
00034 #include "TGNumberEntry.h"
00035 #include "TGTableLayout.h"
00036 #include "TGComboBox.h"
00037 #include "TGSplitter.h"
00038 #include "TGProgressBar.h"
00039 #include "TGListView.h"
00040 #include "TGMsgBox.h"
00041 #include "TGMenu.h"
00042 #include "TGStatusBar.h"
00043 #include "TGIcon.h"
00044 #include "TChain.h"
00045 #include "TDSet.h"
00046 #include "TFileInfo.h"
00047 #include "TProof.h"
00048 #include "TRandom.h"
00049 #include "TSessionViewer.h"
00050 #include "TSessionLogView.h"
00051 #include "TQueryResult.h"
00052 #include "TGTextView.h"
00053 #include "TGMenu.h"
00054 #include "TGToolBar.h"
00055 #include "TGTab.h"
00056 #include "TRootEmbeddedCanvas.h"
00057 #include "TCanvas.h"
00058 #include "TGMimeTypes.h"
00059 #include "TInterpreter.h"
00060 #include "TContextMenu.h"
00061 #include "TG3DLine.h"
00062 #include "TSessionDialogs.h"
00063 #include "TEnv.h"
00064 #include "TH2.h"
00065 #include "TTreePlayer.h"
00066 #include "TFileCollection.h"
00067 #ifdef WIN32
00068 #include "TWin32SplashThread.h"
00069 #endif
00070 #include <stdlib.h>
00071 
00072 TSessionViewer *gSessionViewer = 0;
00073 
00074 const char *kConfigFile = ".proofgui.conf";
00075 
00076 ClassImp(TQueryDescription)
00077 ClassImp(TSessionDescription)
00078 ClassImp(TSessionServerFrame)
00079 ClassImp(TSessionFrame)
00080 ClassImp(TSessionQueryFrame)
00081 ClassImp(TSessionOutputFrame)
00082 ClassImp(TSessionInputFrame)
00083 ClassImp(TSessionViewer)
00084 
00085 const char *xpm_names[] = {
00086     "monitor01.xpm",
00087     "monitor02.xpm",
00088     "monitor03.xpm",
00089     "monitor04.xpm",
00090     0
00091 };
00092 
00093 const char *conftypes[] = {
00094    "Config files",  "*.conf",
00095    "All files",     "*.*",
00096     0,               0
00097 };
00098 
00099 const char *pkgtypes[] = {
00100    "Package files", "*.par",
00101    "All files",     "*.*",
00102     0,               0
00103 };
00104 
00105 const char *macrotypes[] = {
00106    "C files",       "*.[C|c]*",
00107    "All files",     "*",
00108    0,               0
00109 };
00110 
00111 
00112 const char *kFeedbackHistos[] = {
00113    "PROOF_PacketsHist",
00114    "PROOF_EventsHist",
00115    "PROOF_NodeHist",
00116    "PROOF_LatencyHist",
00117    "PROOF_ProcTimeHist",
00118    "PROOF_CpuTimeHist",
00119    0
00120 };
00121 
00122 const char* const kSession_RedirectFile = ".templog";
00123 const char* const kSession_RedirectCmd = ".tempcmd";
00124 
00125 // Menu command id's
00126 enum ESessionViewerCommands {
00127    kFileLoadConfig,
00128    kFileSaveConfig,
00129    kFileCloseViewer,
00130    kFileQuit,
00131 
00132    kSessionNew,
00133    kSessionAdd,
00134    kSessionDelete,
00135    kSessionGetQueries,
00136 
00137    kSessionConnect,
00138    kSessionDisconnect,
00139    kSessionShutdown,
00140    kSessionCleanup,
00141    kSessionBrowse,
00142    kSessionShowStatus,
00143    kSessionReset,
00144 
00145    kQueryNew,
00146    kQueryEdit,
00147    kQueryDelete,
00148    kQuerySubmit,
00149    kQueryStartViewer,
00150 
00151    kOptionsAutoSave,
00152    kOptionsStatsHist,
00153    kOptionsStatsTrace,
00154    kOptionsSlaveStatsTrace,
00155    kOptionsFeedback,
00156 
00157    kHelpAbout
00158 };
00159 
00160 const char *xpm_toolbar[] = {
00161     "fileopen.xpm",
00162     "filesaveas.xpm",
00163     "",
00164     "connect.xpm",
00165     "disconnect.xpm",
00166     "",
00167     "query_new.xpm",
00168     "query_submit.xpm",
00169     "",
00170     "about.xpm",
00171     "",
00172     "quit.xpm",
00173     0
00174 };
00175 
00176 ToolBarData_t tb_data[] = {
00177   { "", "Open Config File",     kFALSE, kFileLoadConfig,    0 },
00178   { "", "Save Config File",     kFALSE, kFileSaveConfig,    0 },
00179   { "", 0,                      0,      -1,                 0 },
00180   { "", "Connect",              kFALSE, kSessionConnect,    0 },
00181   { "", "Disconnect",           kFALSE, kSessionDisconnect, 0 },
00182   { "", 0,                      0,      -1,                 0 },
00183   { "", "New Query",            kFALSE, kQueryNew,          0 },
00184   { "", "Submit Query",         kFALSE, kQuerySubmit,       0 },
00185   { "", 0,                      0,      -1,                 0 },
00186   { "", "About Root",           kFALSE, kHelpAbout,         0 },
00187   { "", 0,                      0,      -1,                 0 },
00188   { "", "Exit Root",            kFALSE, kFileQuit,          0 },
00189   { 0,  0,                      0,      0,                  0 }
00190 };
00191 
00192 
00193 ////////////////////////////////////////////////////////////////////////////////
00194 // Server Frame
00195 
00196 //______________________________________________________________________________
00197 TSessionServerFrame::TSessionServerFrame(TGWindow* p, Int_t w, Int_t h) :
00198    TGCompositeFrame(p, w, h), fFrmNewServer(0), fTxtName(0), fTxtAddress(0),
00199       fTxtConfig(0), fTxtUsrName(0), fViewer(0)
00200 {
00201    // Constructor.
00202 }
00203 
00204 //______________________________________________________________________________
00205 TSessionServerFrame::~TSessionServerFrame()
00206 {
00207    // Destructor.
00208    Cleanup();
00209 }
00210 
00211 //______________________________________________________________________________
00212 void TSessionServerFrame::Build(TSessionViewer *gui)
00213 {
00214    // Build server configuration frame.
00215 
00216    SetLayoutManager(new TGVerticalLayout(this));
00217 
00218    SetCleanup(kDeepCleanup);
00219 
00220    fViewer = gui;
00221    fFrmNewServer = new TGGroupFrame(this, "New Session");
00222    fFrmNewServer->SetCleanup(kDeepCleanup);
00223 
00224    AddFrame(fFrmNewServer, new TGLayoutHints(kLHintsExpandX, 2, 2, 2, 2));
00225 
00226    fFrmNewServer->SetLayoutManager(new TGMatrixLayout(fFrmNewServer, 0, 2, 8));
00227 
00228    fFrmNewServer->AddFrame(new TGLabel(fFrmNewServer, "Session Name:"),
00229                            new TGLayoutHints(kLHintsLeft, 3, 3, 3, 3));
00230    fFrmNewServer->AddFrame(fTxtName = new TGTextEntry(fFrmNewServer,
00231                            (const char *)0, 1), new TGLayoutHints());
00232    fTxtName->Resize(156, fTxtName->GetDefaultHeight());
00233    fTxtName->Associate(this);
00234    fFrmNewServer->AddFrame(new TGLabel(fFrmNewServer, "Server name:"),
00235                            new TGLayoutHints(kLHintsLeft, 3, 3, 3, 3));
00236    fFrmNewServer->AddFrame(fTxtAddress = new TGTextEntry(fFrmNewServer,
00237                            (const char *)0, 2), new TGLayoutHints());
00238    fTxtAddress->Resize(156, fTxtAddress->GetDefaultHeight());
00239    fTxtAddress->Associate(this);
00240    fFrmNewServer->AddFrame(new TGLabel(fFrmNewServer, "Port (default: 1093):"),
00241                            new TGLayoutHints(kLHintsLeft, 3, 3, 3, 3));
00242    fFrmNewServer->AddFrame(fNumPort = new TGNumberEntry(fFrmNewServer, 1093, 5,
00243             3, TGNumberFormat::kNESInteger,TGNumberFormat::kNEANonNegative,
00244             TGNumberFormat::kNELLimitMinMax, 0, 65535),new TGLayoutHints());
00245    fNumPort->Associate(this);
00246    fFrmNewServer->AddFrame(new TGLabel(fFrmNewServer, "Configuration File:"),
00247                            new TGLayoutHints(kLHintsLeft, 3, 3, 3, 3));
00248    fFrmNewServer->AddFrame(fTxtConfig = new TGTextEntry(fFrmNewServer,
00249                            (const char *)0, 4), new TGLayoutHints());
00250    fTxtConfig->Resize(156, fTxtConfig->GetDefaultHeight());
00251    fTxtConfig->Associate(this);
00252    fFrmNewServer->AddFrame(new TGLabel(fFrmNewServer, "Log Level:"),
00253                            new TGLayoutHints(kLHintsLeft, 3, 3, 3, 3));
00254 
00255    fFrmNewServer->AddFrame(fLogLevel = new TGNumberEntry(fFrmNewServer, 0, 5, 5,
00256                            TGNumberFormat::kNESInteger,
00257                            TGNumberFormat::kNEANonNegative,
00258                            TGNumberFormat::kNELLimitMinMax, 0, 5),
00259                            new TGLayoutHints(kLHintsLeft, 3, 3, 3, 3));
00260    fLogLevel->Associate(this);
00261 
00262    fFrmNewServer->AddFrame(new TGLabel(fFrmNewServer, "User Name:"),
00263             new TGLayoutHints(kLHintsLeft, 3, 3, 3, 3));
00264    fFrmNewServer->AddFrame(fTxtUsrName = new TGTextEntry(fFrmNewServer,
00265                            (const char *)0, 6), new TGLayoutHints());
00266    fTxtUsrName->Resize(156, fTxtUsrName->GetDefaultHeight());
00267    fTxtUsrName->Associate(this);
00268 
00269    fFrmNewServer->AddFrame(new TGLabel(fFrmNewServer, "Process mode :"),
00270             new TGLayoutHints(kLHintsLeft | kLHintsBottom | kLHintsExpandX,
00271             3, 3, 3, 3));
00272    fFrmNewServer->AddFrame(fSync = new TGCheckButton(fFrmNewServer,
00273       "&Synchronous"), new TGLayoutHints(kLHintsLeft | kLHintsBottom |
00274       kLHintsExpandX, 3, 3, 3, 3));
00275    fSync->SetToolTipText("Default Process Mode");
00276    fSync->SetState(kButtonDown);
00277 
00278    AddFrame(fBtnAdd = new TGTextButton(this, "             Save             "),
00279             new TGLayoutHints(kLHintsTop | kLHintsCenterX, 5, 5, 15, 5));
00280    fBtnAdd->SetToolTipText("Add server to the list");
00281    fBtnAdd->Connect("Clicked()", "TSessionServerFrame", this,
00282                     "OnBtnAddClicked()");
00283    AddFrame(fBtnConnect = new TGTextButton(this, "          Connect          "),
00284                  new TGLayoutHints(kLHintsTop | kLHintsCenterX, 5, 5, 15, 5));
00285    fBtnConnect->Connect("Clicked()", "TSessionServerFrame", this,
00286                         "OnBtnConnectClicked()");
00287    fBtnConnect->SetToolTipText("Connect to the selected server");
00288 
00289    fTxtConfig->Connect("DoubleClicked()", "TSessionServerFrame", this,
00290                        "OnConfigFileClicked()");
00291 
00292    fTxtName->Connect("TextChanged(char*)", "TSessionServerFrame", this,
00293                      "SettingsChanged()");
00294    fTxtAddress->Connect("TextChanged(char*)", "TSessionServerFrame", this,
00295                        "SettingsChanged()");
00296    fTxtConfig->Connect("TextChanged(char*)", "TSessionServerFrame", this,
00297                        "SettingsChanged()");
00298    fTxtUsrName->Connect("TextChanged(char*)", "TSessionServerFrame", this,
00299                         "SettingsChanged()");
00300    fSync->Connect("Clicked()", "TSessionServerFrame", this,
00301                   "SettingsChanged()");
00302    fLogLevel->Connect("ValueChanged(Long_t)", "TSessionServerFrame", this,
00303                       "SettingsChanged()");
00304    fLogLevel->Connect("ValueSet(Long_t)", "TSessionServerFrame", this,
00305                       "SettingsChanged()");
00306    fNumPort->Connect("ValueChanged(Long_t)", "TSessionServerFrame", this,
00307                      "SettingsChanged()");
00308    fNumPort->Connect("ValueSet(Long_t)", "TSessionServerFrame", this,
00309                      "SettingsChanged()");
00310 
00311 }
00312 
00313 //______________________________________________________________________________
00314 void TSessionServerFrame::SettingsChanged()
00315 {
00316    // Settings have changed, update GUI accordingly.
00317 
00318    TGTextEntry *sender = dynamic_cast<TGTextEntry*>((TQObject*)gTQSender);
00319    Bool_t issync = (fSync->GetState() == kButtonDown);
00320    if ((fViewer->GetActDesc()->fLocal) ||
00321        (strcmp(fViewer->GetActDesc()->GetName(), fTxtName->GetText())) ||
00322        (strcmp(fViewer->GetActDesc()->fAddress.Data(), fTxtAddress->GetText())) ||
00323        (strcmp(fViewer->GetActDesc()->fConfigFile.Data(), fTxtConfig->GetText())) ||
00324        (strcmp(fViewer->GetActDesc()->fUserName.Data(), fTxtUsrName->GetText())) ||
00325        (fViewer->GetActDesc()->fLogLevel != fLogLevel->GetIntNumber()) ||
00326        (fViewer->GetActDesc()->fPort != fNumPort->GetIntNumber()) ||
00327        (fViewer->GetActDesc()->fSync != issync)) {
00328       ShowFrame(fBtnAdd);
00329       HideFrame(fBtnConnect);
00330    }
00331    else {
00332       HideFrame(fBtnAdd);
00333       ShowFrame(fBtnConnect);
00334    }
00335    if (sender) {
00336       sender->SetFocus();
00337    }
00338 }
00339 
00340 
00341 //______________________________________________________________________________
00342 Bool_t TSessionServerFrame::HandleExpose(Event_t * /*event*/)
00343 {
00344    // Handle expose event in server frame.
00345 
00346    //fTxtName->SelectAll();
00347    //fTxtName->SetFocus();
00348    return kTRUE;
00349 }
00350 
00351 //______________________________________________________________________________
00352 void TSessionServerFrame::OnConfigFileClicked()
00353 {
00354    // Browse configuration files.
00355 
00356    // do nothing if connection in progress
00357    if (fViewer->IsBusy())
00358       return;
00359    TGFileInfo fi;
00360    fi.fFileTypes = conftypes;
00361    new TGFileDialog(fClient->GetRoot(), fViewer, kFDOpen, &fi);
00362    if (!fi.fFilename) return;
00363    fTxtConfig->SetText(gSystem->BaseName(fi.fFilename));
00364 }
00365 
00366 //______________________________________________________________________________
00367 void TSessionServerFrame::OnBtnDeleteClicked()
00368 {
00369    // Delete selected session configuration (remove it from the list).
00370 
00371    // do nothing if connection in progress
00372    if (fViewer->IsBusy())
00373       return;
00374    TString name(fTxtName->GetText());
00375    TIter next(fViewer->GetSessions());
00376    TSessionDescription *desc = fViewer->GetActDesc();
00377 
00378    if (desc->fLocal) {
00379       Int_t retval;
00380       new TGMsgBox(fClient->GetRoot(), this, "Error Deleting Session",
00381                    "Deleting Local Sessions is not allowed !",
00382                     kMBIconExclamation,kMBOk,&retval);
00383       return;
00384    }
00385    // ask for confirmation
00386    TString m;
00387    m.Form("Are you sure to delete the server \"%s\"",
00388           desc->fName.Data());
00389    Int_t result;
00390    new TGMsgBox(fClient->GetRoot(), this, "", m.Data(), 0,
00391                 kMBOk | kMBCancel, &result);
00392    // if confirmed, delete it
00393    if (result == kMBOk) {
00394       // remove the Proof session from gROOT list of Proofs
00395       if (desc->fConnected && desc->fAttached && desc->fProof) {
00396          desc->fProof->Detach("S");
00397       }
00398       // remove it from our sessions list
00399       fViewer->GetSessions()->Remove((TObject *)desc);
00400       // update configuration file
00401       TGListTreeItem *item = fViewer->GetSessionHierarchy()->GetSelected();
00402       fViewer->GetSessionHierarchy()->DeleteItem(item);
00403 
00404       TObject *obj = fViewer->GetSessions()->Last();
00405       item = fViewer->GetSessionHierarchy()->FindChildByData(
00406                fViewer->GetSessionItem(), (void *)obj);
00407       if (item) {
00408          fViewer->GetSessionHierarchy()->ClearHighlighted();
00409          fViewer->GetSessionHierarchy()->OpenItem(item);
00410          fViewer->GetSessionHierarchy()->HighlightItem(item);
00411          fViewer->GetSessionHierarchy()->SetSelected(item);
00412          fViewer->GetSessionHierarchy()->ClearViewPort();
00413          fClient->NeedRedraw(fViewer->GetSessionHierarchy());
00414          fViewer->OnListTreeClicked(item, 1, 0, 0);
00415       }
00416    }
00417    if (fViewer->IsAutoSave())
00418       fViewer->WriteConfiguration();
00419 }
00420 
00421 //______________________________________________________________________________
00422 void TSessionServerFrame::OnBtnConnectClicked()
00423 {
00424    // Connect to selected server.
00425 
00426    // do nothing if connection in progress
00427    if (fViewer->IsBusy())
00428       return;
00429 
00430    if (!fViewer->GetSessions()->FindObject(fTxtName->GetText())) {
00431       OnBtnAddClicked();
00432    }
00433    else {
00434       fViewer->GetActDesc()->fAddress = fTxtAddress->GetText();
00435       fViewer->GetActDesc()->fPort = fNumPort->GetIntNumber();
00436       if (strlen(fTxtConfig->GetText()) > 1)
00437          fViewer->GetActDesc()->fConfigFile = TString(fTxtConfig->GetText());
00438       else
00439          fViewer->GetActDesc()->fConfigFile = "";
00440       fViewer->GetActDesc()->fLogLevel = fLogLevel->GetIntNumber();
00441       fViewer->GetActDesc()->fUserName = fTxtUsrName->GetText();
00442       fViewer->GetActDesc()->fSync = (fSync->GetState() == kButtonDown);
00443       if (fViewer->IsAutoSave())
00444          fViewer->WriteConfiguration();
00445    }
00446    // set flag busy
00447    fViewer->SetBusy();
00448    // avoid input events in list tree while connecting
00449    fViewer->GetSessionHierarchy()->RemoveInput(kPointerMotionMask |
00450          kEnterWindowMask | kLeaveWindowMask | kKeyPressMask);
00451    gVirtualX->GrabButton(fViewer->GetSessionHierarchy()->GetId(), kAnyButton,
00452          kAnyModifier, kButtonPressMask | kButtonReleaseMask, kNone, kNone, kFALSE);
00453    // set watch cursor to indicate connection in progress
00454    gVirtualX->SetCursor(fViewer->GetSessionHierarchy()->GetId(),
00455          gVirtualX->CreateCursor(kWatch));
00456    gVirtualX->SetCursor(GetId(),gVirtualX->CreateCursor(kWatch));
00457    // display connection progress bar in first part of status bar
00458    fViewer->GetStatusBar()->GetBarPart(0)->ShowFrame(fViewer->GetConnectProg());
00459    // connect to proof startup message (to update progress bar)
00460    TQObject::Connect("TProof", "StartupMessage(char *,Bool_t,Int_t,Int_t)",
00461          "TSessionViewer", fViewer, "StartupMessage(char *,Bool_t,Int_t,Int_t)");
00462    // collect and set-up configuration
00463    TString url = fTxtUsrName->GetText();
00464    url += "@"; url += fTxtAddress->GetText();
00465    if (fNumPort->GetIntNumber() > 0) {
00466       url += ":";
00467       url += fNumPort->GetIntNumber();
00468    }
00469 
00470    TProofDesc *desc;
00471    fViewer->GetActDesc()->fProofMgr = TProofMgr::Create(url);
00472    if (!fViewer->GetActDesc()->fProofMgr ||
00473        !fViewer->GetActDesc()->fProofMgr->IsValid()) {
00474       // hide connection progress bar from status bar
00475       fViewer->GetStatusBar()->GetBarPart(0)->HideFrame(fViewer->GetConnectProg());
00476       // release busy flag
00477       fViewer->SetBusy(kFALSE);
00478       // restore cursors and input
00479       gVirtualX->SetCursor(GetId(), 0);
00480       gVirtualX->GrabButton(fViewer->GetSessionHierarchy()->GetId(), kAnyButton,
00481             kAnyModifier, kButtonPressMask | kButtonReleaseMask, kNone, kNone);
00482       fViewer->GetSessionHierarchy()->AddInput(kPointerMotionMask |
00483             kEnterWindowMask | kLeaveWindowMask | kKeyPressMask);
00484       gVirtualX->SetCursor(fViewer->GetSessionHierarchy()->GetId(), 0);
00485       return;
00486    }
00487    fViewer->UpdateListOfSessions();
00488    // check if the session already exist before to recreate it
00489    TList *sessions = fViewer->GetActDesc()->fProofMgr->QuerySessions("");
00490    if (sessions) {
00491       TIter nextp(sessions);
00492       // loop over existing Proof sessions
00493       while ((desc = (TProofDesc *)nextp())) {
00494          if ((desc->GetName() == fViewer->GetActDesc()->fTag) ||
00495              (desc->GetTitle() == fViewer->GetActDesc()->fName)) {
00496             fViewer->GetActDesc()->fProof =
00497                fViewer->GetActDesc()->fProofMgr->AttachSession(desc->GetLocalId(), kTRUE);
00498             fViewer->GetActDesc()->fTag = desc->GetName();
00499             fViewer->GetActDesc()->fProof->SetAlias(fViewer->GetActDesc()->fName);
00500             fViewer->GetActDesc()->fConnected = kTRUE;
00501             fViewer->GetActDesc()->fAttached = kTRUE;
00502 
00503             if (fViewer->GetOptionsMenu()->IsEntryChecked(kOptionsFeedback)) {
00504                Int_t i = 0;
00505                // browse list of feedback histos and check user's selected ones
00506                while (kFeedbackHistos[i]) {
00507                   if (fViewer->GetCascadeMenu()->IsEntryChecked(41+i)) {
00508                      fViewer->GetActDesc()->fProof->AddFeedback(kFeedbackHistos[i]);
00509                      fViewer->GetActDesc()->fNbHistos++;
00510                   }
00511                   i++;
00512                }
00513                // connect feedback signal
00514                fViewer->GetActDesc()->fProof->Connect("Feedback(TList *objs)",
00515                            "TSessionQueryFrame", fViewer->GetQueryFrame(),
00516                            "Feedback(TList *objs)");
00517                gROOT->Time();
00518             }
00519             else {
00520                // if feedback option not selected, clear Proof's feedback option
00521                fViewer->GetActDesc()->fProof->ClearFeedback();
00522             }
00523 
00524             break;
00525          }
00526       }
00527    }
00528    if (fViewer->GetActDesc()->fProof == 0) {
00529       if (fViewer->GetActDesc()->fProofMgr->IsValid()) {
00530          fViewer->GetActDesc()->fProof = fViewer->GetActDesc()->fProofMgr->CreateSession(
00531          fViewer->GetActDesc()->fConfigFile);
00532          sessions = fViewer->GetActDesc()->fProofMgr->QuerySessions("");
00533          desc = (TProofDesc *)sessions->Last();
00534          if (desc) {
00535             fViewer->GetActDesc()->fProof->SetAlias(fViewer->GetActDesc()->fName);
00536             fViewer->GetActDesc()->fTag = desc->GetName();
00537             fViewer->GetActDesc()->fConnected = kTRUE;
00538             fViewer->GetActDesc()->fAttached = kTRUE;
00539          }
00540       }
00541    }
00542    if (fViewer->GetActDesc()->fProof) {
00543       fViewer->GetActDesc()->fConfigFile = fViewer->GetActDesc()->fProof->GetConfFile();
00544       fViewer->GetActDesc()->fUserName   = fViewer->GetActDesc()->fProof->GetUser();
00545       fViewer->GetActDesc()->fPort       = fViewer->GetActDesc()->fProof->GetPort();
00546       fViewer->GetActDesc()->fLogLevel   = fViewer->GetActDesc()->fProof->GetLogLevel();
00547       if (fViewer->GetActDesc()->fLogLevel < 0)
00548          fViewer->GetActDesc()->fLogLevel = 0;
00549       if (fViewer->GetActDesc()->fProof->IsLite())
00550          fViewer->GetActDesc()->fAddress = "lite";
00551       else
00552          fViewer->GetActDesc()->fAddress = fViewer->GetActDesc()->fProof->GetMaster();
00553       fViewer->GetActDesc()->fConnected = kTRUE;
00554       fViewer->GetActDesc()->fProof->SetBit(TProof::kUsingSessionGui);
00555    }
00556    fViewer->UpdateListOfSessions();
00557 
00558    // check if connected and valid
00559    if (fViewer->GetActDesc()->fProof &&
00560        fViewer->GetActDesc()->fProof->IsValid()) {
00561       // set log level
00562       fViewer->GetActDesc()->fProof->SetLogLevel(fViewer->GetActDesc()->fLogLevel);
00563       // set query type (synch / asynch)
00564       fViewer->GetActDesc()->fProof->SetQueryMode(fViewer->GetActDesc()->fSync ?
00565                              TProof::kSync : TProof::kAsync);
00566       // set connected flag
00567       fViewer->GetActDesc()->fConnected = kTRUE;
00568       // change list tree item picture to connected pixmap
00569       TGListTreeItem *item = fViewer->GetSessionHierarchy()->FindChildByData(
00570                               fViewer->GetSessionItem(),fViewer->GetActDesc());
00571       item->SetPictures(fViewer->GetProofConPict(), fViewer->GetProofConPict());
00572       // update viewer
00573       fViewer->OnListTreeClicked(item, 1, 0, 0);
00574       fViewer->GetSessionHierarchy()->ClearViewPort();
00575       fClient->NeedRedraw(fViewer->GetSessionHierarchy());
00576       // connect to progress related signals
00577       fViewer->GetActDesc()->fProof->Connect("Progress(Long64_t,Long64_t)",
00578                  "TSessionQueryFrame", fViewer->GetQueryFrame(),
00579                  "Progress(Long64_t,Long64_t)");
00580       fViewer->GetActDesc()->fProof->Connect("Progress(Long64_t,Long64_t,Long64_t,Float_t,Float_t,Float_t,Float_t)",
00581                  "TSessionQueryFrame", fViewer->GetQueryFrame(),
00582                  "Progress(Long64_t,Long64_t,Long64_t,Float_t,Float_t,Float_t,Float_t)");
00583       fViewer->GetActDesc()->fProof->Connect("StopProcess(Bool_t)",
00584                  "TSessionQueryFrame", fViewer->GetQueryFrame(),
00585                  "IndicateStop(Bool_t)");
00586       fViewer->GetActDesc()->fProof->Connect(
00587                   "ResetProgressDialog(const char*,Int_t,Long64_t,Long64_t)",
00588                   "TSessionQueryFrame", fViewer->GetQueryFrame(),
00589                   "ResetProgressDialog(const char*,Int_t,Long64_t,Long64_t)");
00590       // enable timer used for status bar icon's animation
00591       fViewer->EnableTimer();
00592       // change status bar right icon to connected pixmap
00593       fViewer->ChangeRightLogo("monitor01.xpm");
00594       // do not animate yet
00595       fViewer->SetChangePic(kFALSE);
00596       // connect to signal "query result ready"
00597       fViewer->GetActDesc()->fProof->Connect("QueryResultReady(char *)",
00598                        "TSessionViewer", fViewer, "QueryResultReady(char *)");
00599       // display connection information on status bar
00600       TString msg;
00601       msg.Form("PROOF Cluster %s ready", fViewer->GetActDesc()->fName.Data());
00602       fViewer->GetStatusBar()->SetText(msg.Data(), 1);
00603       fViewer->GetSessionFrame()->ProofInfos();
00604       fViewer->UpdateListOfPackages();
00605       fViewer->GetSessionFrame()->UpdateListOfDataSets();
00606       // Enable previously uploaded packages if in auto-enable mode
00607       if (fViewer->GetActDesc()->fAutoEnable) {
00608          TPackageDescription *package;
00609          TIter next(fViewer->GetActDesc()->fPackages);
00610          while ((package = (TPackageDescription *)next())) {
00611             if (!package->fEnabled) {
00612                if (fViewer->GetActDesc()->fProof->EnablePackage(package->fName) != 0)
00613                   Error("Submit", "Enable package failed");
00614                else {
00615                   package->fEnabled = kTRUE;
00616                   fViewer->GetSessionFrame()->UpdatePackages();
00617                }
00618             }
00619          }
00620       }
00621    }
00622    // hide connection progress bar from status bar
00623    fViewer->GetStatusBar()->GetBarPart(0)->HideFrame(fViewer->GetConnectProg());
00624    // release busy flag
00625    fViewer->SetBusy(kFALSE);
00626    // restore cursors and input
00627    gVirtualX->SetCursor(GetId(), 0);
00628    gVirtualX->GrabButton(fViewer->GetSessionHierarchy()->GetId(), kAnyButton,
00629          kAnyModifier, kButtonPressMask | kButtonReleaseMask, kNone, kNone);
00630    fViewer->GetSessionHierarchy()->AddInput(kPointerMotionMask |
00631          kEnterWindowMask | kLeaveWindowMask | kKeyPressMask);
00632    gVirtualX->SetCursor(fViewer->GetSessionHierarchy()->GetId(), 0);
00633 }
00634 
00635 //______________________________________________________________________________
00636 void TSessionServerFrame::OnBtnNewServerClicked()
00637 {
00638    // Reset server configuration fields.
00639 
00640    // do nothing if connection in progress
00641    if (fViewer->IsBusy())
00642       return;
00643    fViewer->GetSessionHierarchy()->ClearHighlighted();
00644    fViewer->GetSessionHierarchy()->OpenItem(fViewer->GetSessionItem());
00645    fViewer->GetSessionHierarchy()->HighlightItem(fViewer->GetSessionItem());
00646    fViewer->GetSessionHierarchy()->SetSelected(fViewer->GetSessionItem());
00647    fViewer->OnListTreeClicked(fViewer->GetSessionItem(), 1, 0, 0);
00648    fViewer->GetSessionHierarchy()->ClearViewPort();
00649    fClient->NeedRedraw(fViewer->GetSessionHierarchy());
00650    fTxtName->SetText("");
00651    fTxtAddress->SetText("");
00652    fTxtConfig->SetText("");
00653    fNumPort->SetIntNumber(1093);
00654    fLogLevel->SetIntNumber(0);
00655    fTxtUsrName->SetText("");
00656 }
00657 
00658 //______________________________________________________________________________
00659 void TSessionServerFrame::OnBtnAddClicked()
00660 {
00661    // Add newly created session configuration in the list of sessions.
00662 
00663    Int_t retval;
00664    Bool_t newSession = kTRUE;
00665    TSessionDescription* desc = 0;
00666    // do nothing if connection in progress
00667    if (fViewer->IsBusy())
00668       return;
00669 
00670    if ((!fTxtName->GetBuffer()->GetTextLength()) ||
00671        (!fTxtAddress->GetBuffer()->GetTextLength()) ||
00672        (!fTxtUsrName->GetBuffer()->GetTextLength())) {
00673       new TGMsgBox(fClient->GetRoot(), fViewer, "Error Adding Session",
00674                    "At least one required field is empty !",
00675                     kMBIconExclamation, kMBOk, &retval);
00676       return;
00677    }
00678    TObject *obj = fViewer->GetSessions()->FindObject(fTxtName->GetText());
00679    if (obj)
00680       desc = dynamic_cast<TSessionDescription*>(obj);
00681    if (desc) {
00682       new TGMsgBox(fClient->GetRoot(), fViewer, "Adding Session",
00683                    TString::Format("The session \"%s\" already exists ! Overwrite ?",
00684                    fTxtName->GetText()), kMBIconQuestion, kMBYes | kMBNo |
00685                    kMBCancel, &retval);
00686       if (retval != kMBYes)
00687          return;
00688       newSession = kFALSE;
00689    }
00690    if (newSession) {
00691       desc = new TSessionDescription();
00692       desc->fName = fTxtName->GetText();
00693       desc->fTag = "";
00694       desc->fQueries = new TList();
00695       desc->fPackages = new TList();
00696       desc->fActQuery = 0;
00697       desc->fProof = 0;
00698       desc->fProofMgr = 0;
00699       desc->fAutoEnable = kFALSE;
00700       desc->fAddress = fTxtAddress->GetText();
00701       desc->fPort = fNumPort->GetIntNumber();
00702       desc->fConnected = kFALSE;
00703       desc->fAttached = kFALSE;
00704       desc->fLocal = kFALSE;
00705       if (strlen(fTxtConfig->GetText()) > 1)
00706          desc->fConfigFile = TString(fTxtConfig->GetText());
00707       else
00708          desc->fConfigFile = "";
00709       desc->fLogLevel = fLogLevel->GetIntNumber();
00710       desc->fUserName = fTxtUsrName->GetText();
00711       desc->fSync = (fSync->GetState() == kButtonDown);
00712       // add newly created session config to our session list
00713       fViewer->GetSessions()->Add((TObject *)desc);
00714       // save into configuration file
00715       TGListTreeItem *item = fViewer->GetSessionHierarchy()->AddItem(
00716             fViewer->GetSessionItem(), desc->fName.Data(),
00717             fViewer->GetProofDisconPict(), fViewer->GetProofDisconPict());
00718       fViewer->GetSessionHierarchy()->SetToolTipItem(item, "Proof Session");
00719       item->SetUserData(desc);
00720       fViewer->GetSessionHierarchy()->ClearHighlighted();
00721       fViewer->GetSessionHierarchy()->OpenItem(fViewer->GetSessionItem());
00722       fViewer->GetSessionHierarchy()->OpenItem(item);
00723       fViewer->GetSessionHierarchy()->HighlightItem(item);
00724       fViewer->GetSessionHierarchy()->SetSelected(item);
00725       fViewer->GetSessionHierarchy()->ClearViewPort();
00726       fClient->NeedRedraw(fViewer->GetSessionHierarchy());
00727       fViewer->OnListTreeClicked(item, 1, 0, 0);
00728    }
00729    else {
00730       fViewer->GetActDesc()->fName = fTxtName->GetText();
00731       fViewer->GetActDesc()->fAddress = fTxtAddress->GetText();
00732       fViewer->GetActDesc()->fPort = fNumPort->GetIntNumber();
00733       if (strlen(fTxtConfig->GetText()) > 1)
00734          fViewer->GetActDesc()->fConfigFile = TString(fTxtConfig->GetText());
00735       fViewer->GetActDesc()->fLogLevel = fLogLevel->GetIntNumber();
00736       fViewer->GetActDesc()->fUserName = fTxtUsrName->GetText();
00737       fViewer->GetActDesc()->fSync = (fSync->GetState() == kButtonDown);
00738       TGListTreeItem *item2 = fViewer->GetSessionHierarchy()->GetSelected();
00739       item2->SetUserData(fViewer->GetActDesc());
00740       fViewer->OnListTreeClicked(fViewer->GetSessionHierarchy()->GetSelected(),
00741                                  1, 0, 0);
00742    }
00743    HideFrame(fBtnAdd);
00744    ShowFrame(fBtnConnect);
00745    if (fViewer->IsAutoSave())
00746       fViewer->WriteConfiguration();
00747 }
00748 
00749 //______________________________________________________________________________
00750 void TSessionServerFrame::Update(TSessionDescription* desc)
00751 {
00752    // Update fields with values from session description desc.
00753 
00754    if (desc->fLocal) {
00755       fTxtName->SetText("");
00756       fTxtAddress->SetText("");
00757       fNumPort->SetIntNumber(1093);
00758       fTxtConfig->SetText("");
00759       fTxtUsrName->SetText("");
00760       fLogLevel->SetIntNumber(0);
00761       return;
00762    }
00763 
00764    fTxtName->SetText(desc->fName);
00765    fTxtAddress->SetText(desc->fAddress);
00766    fNumPort->SetIntNumber(desc->fPort);
00767    fLogLevel->SetIntNumber(desc->fLogLevel);
00768 
00769    if (desc->fConfigFile.Length() > 1) {
00770       fTxtConfig->SetText(desc->fConfigFile);
00771    }
00772    else {
00773       fTxtConfig->SetText("");
00774    }
00775    fTxtUsrName->SetText(desc->fUserName);
00776 }
00777 
00778 //______________________________________________________________________________
00779 Bool_t TSessionServerFrame::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
00780 {
00781    // Process messages for session server frame.
00782    // Used to navigate between text entry fields.
00783 
00784    switch (GET_MSG(msg)) {
00785       case kC_TEXTENTRY:
00786          switch (GET_SUBMSG(msg)) {
00787             case kTE_ENTER:
00788             case kTE_TAB:
00789                switch (parm1) {
00790                   case 1: // session name
00791                      fTxtAddress->SelectAll();
00792                      fTxtAddress->SetFocus();
00793                      break;
00794                   case 2: // server address
00795                      fNumPort->GetNumberEntry()->SelectAll();
00796                      fNumPort->GetNumberEntry()->SetFocus();
00797                      break;
00798                   case 3: // port number
00799                      fTxtConfig->SelectAll();
00800                      fTxtConfig->SetFocus();
00801                      break;
00802                   case 4: // configuration file
00803                      fLogLevel->GetNumberEntry()->SelectAll();
00804                      fLogLevel->GetNumberEntry()->SetFocus();
00805                      break;
00806                   case 5: // log level
00807                      fTxtUsrName->SelectAll();
00808                      fTxtUsrName->SetFocus();
00809                      break;
00810                   case 6: // user name
00811                      fTxtName->SelectAll();
00812                      fTxtName->SetFocus();
00813                      break;
00814                }
00815                break;
00816 
00817             default:
00818                break;
00819          }
00820          break;
00821 
00822       default:
00823          break;
00824    }
00825    return kTRUE;
00826 }
00827 
00828 ////////////////////////////////////////////////////////////////////////////////
00829 // Session Frame
00830 
00831 //______________________________________________________________________________
00832 TSessionFrame::TSessionFrame(TGWindow* p, Int_t w, Int_t h) :
00833    TGCompositeFrame(p, w, h)
00834 {
00835    // Constructor.
00836 }
00837 
00838 //______________________________________________________________________________
00839 TSessionFrame::~TSessionFrame()
00840 {
00841    // Destructor.
00842 
00843    Cleanup();
00844 }
00845 
00846 //______________________________________________________________________________
00847 void TSessionFrame::Build(TSessionViewer *gui)
00848 {
00849    // Build session frame.
00850 
00851    SetLayoutManager(new TGVerticalLayout(this));
00852    SetCleanup(kDeepCleanup);
00853    fViewer  = gui;
00854    Int_t i,j;
00855 
00856    // main session tab
00857    fTab = new TGTab(this, 200, 200);
00858    AddFrame(fTab, new TGLayoutHints(kLHintsTop | kLHintsExpandX |
00859          kLHintsExpandY, 2, 2, 2, 2));
00860 
00861    // add "Status" tab element
00862    TGCompositeFrame *tf = fTab->AddTab("Status");
00863    fFA = new TGCompositeFrame(tf, 100, 100, kVerticalFrame);
00864    tf->AddFrame(fFA, new TGLayoutHints(kLHintsTop | kLHintsLeft |
00865          kLHintsExpandX | kLHintsExpandY));
00866 
00867    // add first session information line
00868    fInfoLine[0] = new TGLabel(fFA, " ");
00869    fFA->AddFrame(fInfoLine[0], new TGLayoutHints(kLHintsCenterX |
00870          kLHintsExpandX, 5, 5, 15, 5));
00871 
00872    TGCompositeFrame* frmInfos = new TGHorizontalFrame(fFA, 350, 100);
00873    frmInfos->SetLayoutManager(new TGTableLayout(frmInfos, 9, 2));
00874 
00875    // add session information lines
00876    j = 0;
00877    for (i=0;i<17;i+=2) {
00878       fInfoLine[i+1] = new TGLabel(frmInfos, " ");
00879       frmInfos->AddFrame(fInfoLine[i+1], new TGTableLayoutHints(0, 1, j, j+1,
00880             kLHintsLeft | kLHintsCenterY, 5, 5, 2, 2));
00881       fInfoLine[i+2] = new TGLabel(frmInfos, " ");
00882       frmInfos->AddFrame(fInfoLine[i+2], new TGTableLayoutHints(1, 2, j, j+1,
00883             kLHintsLeft | kLHintsCenterY, 5, 5, 2, 2));
00884       j++;
00885    }
00886    fFA->AddFrame(frmInfos, new TGLayoutHints(kLHintsLeft | kLHintsTop |
00887          kLHintsExpandX  | kLHintsExpandY, 5, 5, 5, 5));
00888 
00889    // add "new query" and "get queries" buttons
00890    TGCompositeFrame* frmBut1 = new TGHorizontalFrame(fFA, 350, 100);
00891    frmBut1->SetCleanup(kDeepCleanup);
00892    frmBut1->AddFrame(fBtnNewQuery = new TGTextButton(frmBut1, "New Query..."),
00893          new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5));
00894    fBtnNewQuery->SetToolTipText("Open New Query Dialog");
00895    frmBut1->AddFrame(fBtnGetQueries = new TGTextButton(frmBut1, " Get Queries "),
00896          new TGLayoutHints(kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5));
00897    fBtnGetQueries->SetToolTipText("Get List of Queries from the server");
00898    fBtnShowLog = new TGTextButton(frmBut1, "Show log...");
00899    fBtnShowLog->SetToolTipText("Show Session log (opens log window)");
00900    frmBut1->AddFrame(fBtnShowLog, new TGLayoutHints(kLHintsLeft |
00901          kLHintsExpandX, 5, 5, 5, 5));
00902    fFA->AddFrame(frmBut1, new TGLayoutHints(kLHintsLeft | kLHintsBottom |
00903          kLHintsExpandX));
00904 
00905    // add "Commands" tab element
00906    tf = fTab->AddTab("Commands");
00907    fFC = new TGCompositeFrame(tf, 100, 100, kVerticalFrame);
00908    tf->AddFrame(fFC, new TGLayoutHints(kLHintsTop | kLHintsLeft |
00909          kLHintsExpandX | kLHintsExpandY));
00910 
00911    // add comand line label and text entry
00912    TGCompositeFrame* frmCmd = new TGHorizontalFrame(fFC, 350, 100);
00913    frmCmd->SetCleanup(kDeepCleanup);
00914    frmCmd->AddFrame(new TGLabel(frmCmd, "Command Line :"),
00915          new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 5, 5, 15, 5));
00916    fCommandBuf = new TGTextBuffer(120);
00917    frmCmd->AddFrame(fCommandTxt = new TGTextEntry(frmCmd,
00918          fCommandBuf ),new TGLayoutHints(kLHintsLeft | kLHintsCenterY |
00919          kLHintsExpandX, 5, 5, 15, 5));
00920    fFC->AddFrame(frmCmd, new TGLayoutHints(kLHintsExpandX, 5, 5, 10, 5));
00921    // connect command line text entry to "return pressed" signal
00922    fCommandTxt->Connect("ReturnPressed()", "TSessionFrame", this,
00923          "OnCommandLine()");
00924 
00925    // check box for option "clear view"
00926    fClearCheck = new TGCheckButton(fFC, "Clear view after each command");
00927    fFC->AddFrame(fClearCheck,new TGLayoutHints(kLHintsLeft | kLHintsTop,
00928          10, 5, 5, 5));
00929    fClearCheck->SetState(kButtonUp);
00930    // add text view for redirected output
00931    fFC->AddFrame(new TGLabel(fFC, "Output :"),
00932       new TGLayoutHints(kLHintsLeft | kLHintsTop, 10, 5, 5, 5));
00933    fInfoTextView = new TGTextView(fFC, 330, 150, "", kSunkenFrame |
00934          kDoubleBorder);
00935    fFC->AddFrame(fInfoTextView, new TGLayoutHints(kLHintsLeft |
00936          kLHintsTop | kLHintsExpandX | kLHintsExpandY, 10, 10, 5, 5));
00937 
00938    // add "Packages" tab element
00939    tf = fTab->AddTab("Packages");
00940    fFB = new TGCompositeFrame(tf, 100, 100, kVerticalFrame);
00941    tf->AddFrame(fFB, new TGLayoutHints(kLHintsTop | kLHintsLeft |
00942          kLHintsExpandX | kLHintsExpandY));
00943 
00944    // new frame containing packages listbox and control buttons
00945    TGCompositeFrame* frmcanvas = new TGHorizontalFrame(fFB, 350, 100);
00946 
00947    // packages listbox
00948    fLBPackages = new TGListBox(frmcanvas);
00949    fLBPackages->Resize(80,150);
00950    fLBPackages->SetMultipleSelections(kFALSE);
00951    frmcanvas->AddFrame(fLBPackages, new TGLayoutHints(kLHintsExpandX |
00952          kLHintsExpandY, 5, 5, 5, 5));
00953    // control buttons frame
00954    TGCompositeFrame* frmBut2 = new TGVerticalFrame(frmcanvas, 150, 100);
00955 
00956    fChkMulti = new TGCheckButton(frmBut2, "Multiple Selection");
00957    fChkMulti->SetToolTipText("Enable multiple selection in the package list");
00958    frmBut2->AddFrame(fChkMulti, new TGLayoutHints(kLHintsLeft, 5, 5, 5, 5));
00959 
00960    fBtnAdd = new TGTextButton(frmBut2, "     Add...     ");
00961    fBtnAdd->SetToolTipText("Add a package to the list");
00962    frmBut2->AddFrame(fBtnAdd,new TGLayoutHints(kLHintsTop | kLHintsLeft |
00963          kLHintsExpandX, 5, 5, 5, 5));
00964    fBtnRemove = new TGTextButton(frmBut2, "Remove");
00965    fBtnRemove->SetToolTipText("Remove package from the list");
00966    frmBut2->AddFrame(fBtnRemove,new TGLayoutHints(kLHintsTop | kLHintsLeft |
00967          kLHintsExpandX, 5, 5, 5, 5));
00968    fBtnUp = new TGTextButton(frmBut2, "Move Up");
00969    fBtnUp->SetToolTipText("Move package one step upward in the list");
00970    frmBut2->AddFrame(fBtnUp,new TGLayoutHints(kLHintsTop | kLHintsLeft |
00971          kLHintsExpandX, 5, 5, 5, 5));
00972    fBtnDown = new TGTextButton(frmBut2, "Move Down");
00973    fBtnDown->SetToolTipText("Move package one step downward in the list");
00974    frmBut2->AddFrame(fBtnDown,new TGLayoutHints(kLHintsTop | kLHintsLeft |
00975          kLHintsExpandX, 5, 5, 5, 5));
00976    frmcanvas->AddFrame(frmBut2, new TGLayoutHints(kLHintsLeft | kLHintsCenterY |
00977          kLHintsExpandY));
00978    fFB->AddFrame(frmcanvas, new TGLayoutHints(kLHintsLeft | kLHintsTop |
00979          kLHintsExpandX | kLHintsExpandY));
00980 
00981    TGCompositeFrame* frmLeg = new TGHorizontalFrame(fFB, 300, 100);
00982    frmLeg->SetCleanup(kDeepCleanup);
00983    TGPicture *pic1 = (TGPicture *)fClient->GetPicture("package.xpm");
00984    TGIcon *icn1 = new TGIcon(frmLeg, pic1, pic1->GetWidth(), pic1->GetHeight());
00985    frmLeg->AddFrame(icn1, new TGLayoutHints(kLHintsLeft | kLHintsTop,
00986          5, 5, 0, 5));
00987    frmLeg->AddFrame(new TGLabel(frmLeg, ": Local"),
00988          new TGLayoutHints(kLHintsLeft | kLHintsTop, 0, 10, 0, 5));
00989 
00990    TGPicture *pic2 = (TGPicture *)fClient->GetPicture("package_delete.xpm");
00991    TGIcon *icn2 = new TGIcon(frmLeg, pic2, pic2->GetWidth(), pic2->GetHeight());
00992    frmLeg->AddFrame(icn2, new TGLayoutHints(kLHintsLeft | kLHintsTop,
00993          5, 5, 0, 5));
00994    frmLeg->AddFrame(new TGLabel(frmLeg, ": Uploaded"),
00995          new TGLayoutHints(kLHintsLeft | kLHintsTop, 0, 10, 0, 5));
00996 
00997    TGPicture *pic3 = (TGPicture *)fClient->GetPicture("package_add.xpm");
00998    TGIcon *icn3 = new TGIcon(frmLeg, pic3, pic3->GetWidth(), pic3->GetHeight());
00999    frmLeg->AddFrame(icn3, new TGLayoutHints(kLHintsLeft | kLHintsTop,
01000          5, 5, 0, 5));
01001    frmLeg->AddFrame(new TGLabel(frmLeg, ": Enabled"),
01002          new TGLayoutHints(kLHintsLeft | kLHintsTop, 0, 10, 0, 5));
01003    fFB->AddFrame(frmLeg, new TGLayoutHints(kLHintsLeft | kLHintsTop |
01004          kLHintsExpandX, 0, 0, 0, 0));
01005 
01006    TGCompositeFrame* frmBtn = new TGHorizontalFrame(fFB, 300, 100);
01007    frmBtn->SetCleanup(kDeepCleanup);
01008    frmBtn->AddFrame(fBtnUpload = new TGTextButton(frmBtn,
01009          " Upload "), new TGLayoutHints(kLHintsLeft | kLHintsExpandX |
01010          kLHintsCenterY, 5, 5, 5, 5));
01011    fBtnUpload->SetToolTipText("Upload selected package(s) to the server");
01012    frmBtn->AddFrame(fBtnEnable = new TGTextButton(frmBtn,
01013          " Enable "), new TGLayoutHints(kLHintsLeft | kLHintsExpandX |
01014          kLHintsCenterY, 5, 5, 5, 5));
01015    fBtnEnable->SetToolTipText("Enable selected package(s) on the server");
01016    frmBtn->AddFrame(fBtnDisable = new TGTextButton(frmBtn,
01017          " Disable "), new TGLayoutHints(kLHintsLeft | kLHintsExpandX |
01018          kLHintsCenterY, 5, 5, 5, 5));
01019    fBtnDisable->SetToolTipText("Disable selected package(s) on the server");
01020    frmBtn->AddFrame(fBtnClear = new TGTextButton(frmBtn,
01021          " Clear "), new TGLayoutHints(kLHintsLeft | kLHintsExpandX |
01022          kLHintsCenterY, 5, 5, 5, 5));
01023    fBtnClear->SetToolTipText("Clear all packages on the server");
01024    fFB->AddFrame(frmBtn, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
01025 
01026    fBtnClear->SetEnabled(kFALSE);
01027 
01028    TGCompositeFrame* frmBtn3 = new TGHorizontalFrame(fFB, 300, 100);
01029    frmBtn3->SetCleanup(kDeepCleanup);
01030    fBtnShow = new TGTextButton(frmBtn3, "Show packages");
01031    fBtnShow->SetToolTipText("Show (list) available packages on the server");
01032    frmBtn3->AddFrame(fBtnShow,new TGLayoutHints(kLHintsCenterY | kLHintsLeft |
01033          kLHintsExpandX, 5, 5, 5, 5));
01034    fBtnShowEnabled = new TGTextButton(frmBtn3, "Show Enabled");
01035    fBtnShowEnabled->SetToolTipText("Show (list) enabled packages on the server");
01036    frmBtn3->AddFrame(fBtnShowEnabled,new TGLayoutHints(kLHintsCenterY | kLHintsLeft |
01037          kLHintsExpandX, 5, 5, 5, 5));
01038    fFB->AddFrame(frmBtn3, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 0));
01039 
01040    fChkEnable = new TGCheckButton(fFB, "Enable at session startup");
01041    fChkEnable->SetToolTipText("Enable packages on the server at startup time");
01042    fFB->AddFrame(fChkEnable, new TGLayoutHints(kLHintsLeft, 5, 5, 5, 5));
01043 
01044    // add "DataSets" tab element
01045    tf = fTab->AddTab("DataSets");
01046    fFE = new TGCompositeFrame(tf, 100, 100, kVerticalFrame);
01047    tf->AddFrame(fFE, new TGLayoutHints(kLHintsTop | kLHintsLeft |
01048          kLHintsExpandX | kLHintsExpandY));
01049 
01050    // new frame containing datasets treeview and control buttons
01051    TGCompositeFrame* frmdataset = new TGHorizontalFrame(fFE, 350, 100);
01052 
01053    // datasets list tree
01054    fDSetView = new TGCanvas(frmdataset, 200, 200, kSunkenFrame | kDoubleBorder);
01055    frmdataset->AddFrame(fDSetView, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
01056          5, 5, 5, 5));
01057    fDataSetTree = new TGListTree(fDSetView, kHorizontalFrame);
01058    fDataSetTree->AddItem(0, "DataSets");
01059 
01060    // control buttons frame
01061    TGCompositeFrame* frmBut3 = new TGVerticalFrame(frmdataset, 150, 100);
01062 
01063    fBtnUploadDSet = new TGTextButton(frmBut3, "     Upload...     ");
01064    fBtnUploadDSet->SetToolTipText("Upload a dataset to the cluster");
01065    frmBut3->AddFrame(fBtnUploadDSet, new TGLayoutHints(kLHintsTop | kLHintsLeft |
01066          kLHintsExpandX, 5, 5, 5, 5));
01067    fBtnRemoveDSet = new TGTextButton(frmBut3, "Remove");
01068    fBtnRemoveDSet->SetToolTipText("Remove dataset from the cluster");
01069    frmBut3->AddFrame(fBtnRemoveDSet,new TGLayoutHints(kLHintsTop | kLHintsLeft |
01070          kLHintsExpandX, 5, 5, 5, 5));
01071    fBtnVerifyDSet = new TGTextButton(frmBut3, "Verify");
01072    fBtnVerifyDSet->SetToolTipText("Verify dataset on the cluster");
01073    frmBut3->AddFrame(fBtnVerifyDSet,new TGLayoutHints(kLHintsTop | kLHintsLeft |
01074          kLHintsExpandX, 5, 5, 5, 5));
01075    fBtnRefresh = new TGTextButton(frmBut3, "Refresh List");
01076    fBtnRefresh->SetToolTipText("Refresh List of DataSet/Files present on the cluster");
01077    frmBut3->AddFrame(fBtnRefresh,new TGLayoutHints(kLHintsTop | kLHintsLeft |
01078          kLHintsExpandX, 5, 5, 15, 5));
01079 
01080    frmdataset->AddFrame(frmBut3, new TGLayoutHints(kLHintsLeft | kLHintsCenterY |
01081          kLHintsExpandY, 5, 5, 5, 0));
01082 
01083    fFE->AddFrame(frmdataset, new TGLayoutHints(kLHintsLeft | kLHintsTop |
01084          kLHintsExpandX | kLHintsExpandY));
01085 
01086    // add "Options" tab element
01087    tf = fTab->AddTab("Options");
01088    fFD = new TGCompositeFrame(tf, 100, 100, kVerticalFrame);
01089    tf->AddFrame(fFD, new TGLayoutHints(kLHintsTop | kLHintsLeft |
01090          kLHintsExpandX | kLHintsExpandY));
01091 
01092    // add Log Level label and text entry
01093    TGCompositeFrame* frmLog = new TGHorizontalFrame(fFD, 310, 100, kFixedWidth);
01094    frmLog->SetCleanup(kDeepCleanup);
01095    frmLog->AddFrame(fApplyLogLevel = new TGTextButton(frmLog,
01096          "        Apply        "), new TGLayoutHints(kLHintsRight |
01097          kLHintsCenterY, 10, 5, 5, 5));
01098    fApplyLogLevel->SetToolTipText("Apply currently selected log level");
01099    fLogLevel = new TGNumberEntry(frmLog, 0, 5, 5, TGNumberFormat::kNESInteger,
01100          TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 0, 5);
01101    frmLog->AddFrame(fLogLevel, new TGLayoutHints(kLHintsRight |
01102          kLHintsCenterY, 5, 5, 5, 5));
01103    frmLog->AddFrame(new TGLabel(frmLog, "Log Level :"),
01104          new TGLayoutHints(kLHintsRight | kLHintsCenterY, 5, 5, 5, 5));
01105    fFD->AddFrame(frmLog, new TGLayoutHints(kLHintsLeft, 5, 5, 15, 5));
01106 
01107    // add Parallel Nodes label and text entry
01108    TGCompositeFrame* frmPar = new TGHorizontalFrame(fFD, 310, 100, kFixedWidth);
01109    frmPar->SetCleanup(kDeepCleanup);
01110    frmPar->AddFrame(fApplyParallel = new TGTextButton(frmPar,
01111          "        Apply        "), new TGLayoutHints(kLHintsRight |
01112          kLHintsCenterY, 10, 5, 5, 5));
01113    fApplyParallel->SetToolTipText("Apply currently selected parallel nodes");
01114    fTxtParallel = new TGTextEntry(frmPar);
01115    fTxtParallel->SetAlignment(kTextRight);
01116    fTxtParallel->SetText("99999");
01117    fTxtParallel->Resize(fLogLevel->GetDefaultWidth(), fTxtParallel->GetDefaultHeight());
01118    frmPar->AddFrame(fTxtParallel, new TGLayoutHints(kLHintsRight |
01119          kLHintsCenterY, 5, 5, 5, 5));
01120    frmPar->AddFrame(new TGLabel(frmPar, "Set Parallel Nodes :"),
01121          new TGLayoutHints(kLHintsRight | kLHintsCenterY, 5, 5, 5, 5));
01122    fFD->AddFrame(frmPar, new TGLayoutHints(kLHintsLeft, 5, 5, 5, 5));
01123 
01124    // connect button actions to functions
01125    fBtnShowLog->Connect("Clicked()", "TSessionFrame", this,
01126          "OnBtnShowLogClicked()");
01127    fBtnNewQuery->Connect("Clicked()", "TSessionFrame", this,
01128          "OnBtnNewQueryClicked()");
01129    fBtnGetQueries->Connect("Clicked()", "TSessionFrame", this,
01130          "OnBtnGetQueriesClicked()");
01131 
01132    fChkEnable->Connect("Toggled(Bool_t)", "TSessionFrame", this,
01133          "OnStartupEnable(Bool_t)");
01134    fChkMulti->Connect("Toggled(Bool_t)", "TSessionFrame", this,
01135          "OnMultipleSelection(Bool_t)");
01136    fBtnAdd->Connect("Clicked()", "TSessionFrame", this,
01137          "OnBtnAddClicked()");
01138    fBtnRemove->Connect("Clicked()", "TSessionFrame", this,
01139          "OnBtnRemoveClicked()");
01140    fBtnUp->Connect("Clicked()", "TSessionFrame", this,
01141          "OnBtnUpClicked()");
01142    fBtnDown->Connect("Clicked()", "TSessionFrame", this,
01143          "OnBtnDownClicked()");
01144    fApplyLogLevel->Connect("Clicked()", "TSessionFrame", this,
01145          "OnApplyLogLevel()");
01146    fApplyParallel->Connect("Clicked()", "TSessionFrame", this,
01147          "OnApplyParallel()");
01148    fBtnUpload->Connect("Clicked()", "TSessionFrame", this,
01149          "OnUploadPackages()");
01150    fBtnEnable->Connect("Clicked()", "TSessionFrame", this,
01151          "OnEnablePackages()");
01152    fBtnDisable->Connect("Clicked()", "TSessionFrame", this,
01153          "OnDisablePackages()");
01154    fBtnClear->Connect("Clicked()", "TSessionFrame", this,
01155          "OnClearPackages()");
01156    fBtnShowEnabled->Connect("Clicked()", "TSessionViewer", fViewer,
01157          "ShowEnabledPackages()");
01158    fBtnShow->Connect("Clicked()", "TSessionViewer", fViewer,
01159          "ShowPackages()");
01160 
01161    fBtnUploadDSet->Connect("Clicked()", "TSessionFrame", this,
01162          "OnBtnUploadDSet()");
01163    fBtnRemoveDSet->Connect("Clicked()", "TSessionFrame", this,
01164          "OnBtnRemoveDSet()");
01165    fBtnVerifyDSet->Connect("Clicked()", "TSessionFrame", this,
01166          "OnBtnVerifyDSet()");
01167    fBtnRefresh->Connect("Clicked()", "TSessionFrame", this,
01168          "UpdateListOfDataSets()");
01169 }
01170 
01171 //______________________________________________________________________________
01172 void TSessionFrame::ProofInfos()
01173 {
01174    // Display informations on current session.
01175 
01176    TString buf;
01177 
01178    // if local session
01179    if (fViewer->GetActDesc()->fLocal) {
01180       buf.Form("*** Local Session on %s ***", gSystem->HostName());
01181       fInfoLine[0]->SetText(buf.Data());
01182       UserGroup_t *userGroup = gSystem->GetUserInfo();
01183       fInfoLine[1]->SetText("User :");
01184       buf.Form("%s", userGroup->fRealName.Data());
01185       fInfoLine[2]->SetText(buf.Data());
01186       fInfoLine[3]->SetText("Working directory :");
01187       buf.Form("%s", gSystem->WorkingDirectory());
01188       fInfoLine[4]->SetText(buf.Data());
01189       fInfoLine[5]->SetText(" ");
01190       fInfoLine[6]->SetText(" ");
01191       fInfoLine[7]->SetText(" ");
01192       fInfoLine[8]->SetText(" ");
01193       fInfoLine[9]->SetText(" ");
01194       fInfoLine[10]->SetText(" ");
01195       fInfoLine[11]->SetText(" ");
01196       fInfoLine[12]->SetText(" ");
01197       fInfoLine[13]->SetText(" ");
01198       fInfoLine[14]->SetText(" ");
01199       fInfoLine[15]->SetText(" ");
01200       fInfoLine[16]->SetText(" ");
01201       fInfoLine[17]->SetText(" ");
01202       fInfoLine[18]->SetText(" ");
01203       delete userGroup;
01204       Layout();
01205       Resize(GetDefaultSize());
01206       return;
01207    }
01208    // return if not a valid Proof session
01209    if (!fViewer->GetActDesc()->fConnected ||
01210        !fViewer->GetActDesc()->fAttached ||
01211        !fViewer->GetActDesc()->fProof ||
01212        !fViewer->GetActDesc()->fProof->IsValid())
01213       return;
01214 
01215    if (!fViewer->GetActDesc()->fProof->IsMaster()) {
01216       if (fViewer->GetActDesc()->fProof->IsParallel())
01217          buf.Form("*** Connected to %s (parallel mode, %d workers) ***",
01218                fViewer->GetActDesc()->fProof->GetMaster(),
01219                fViewer->GetActDesc()->fProof->GetParallel());
01220       else
01221          buf.Form("*** Connected to %s (sequential mode) ***",
01222                fViewer->GetActDesc()->fProof->GetMaster());
01223       fInfoLine[0]->SetText(buf.Data());
01224       fInfoLine[1]->SetText("Port number : ");
01225       buf.Form("%d", fViewer->GetActDesc()->fProof->GetPort());
01226       fInfoLine[2]->SetText(buf.Data());
01227       fInfoLine[3]->SetText("User : ");
01228       buf.Form("%s", fViewer->GetActDesc()->fProof->GetUser());
01229       fInfoLine[4]->SetText(buf.Data());
01230       fInfoLine[5]->SetText("Client protocol version : ");
01231       buf.Form("%d", fViewer->GetActDesc()->fProof->GetClientProtocol());
01232       fInfoLine[6]->SetText(buf.Data());
01233       fInfoLine[7]->SetText("Remote protocol version : ");
01234       buf.Form("%d", fViewer->GetActDesc()->fProof->GetRemoteProtocol());
01235       fInfoLine[8]->SetText(buf.Data());
01236       fInfoLine[9]->SetText("Log level : ");
01237       buf.Form("%d", fViewer->GetActDesc()->fProof->GetLogLevel());
01238       fInfoLine[10]->SetText(buf.Data());
01239       fInfoLine[11]->SetText("Session unique tag : ");
01240       buf.Form("%s", fViewer->GetActDesc()->fProof->IsValid() ?
01241             fViewer->GetActDesc()->fProof->GetSessionTag() : " ");
01242       fInfoLine[12]->SetText(buf.Data());
01243       fInfoLine[13]->SetText("Total MB's processed :");
01244       buf.Form("%.2f", float(fViewer->GetActDesc()->fProof->GetBytesRead())/(1024*1024));
01245       fInfoLine[14]->SetText(buf.Data());
01246       fInfoLine[15]->SetText("Total real time used (s) :");
01247       buf.Form("%.3f", fViewer->GetActDesc()->fProof->GetRealTime());
01248       fInfoLine[16]->SetText(buf.Data());
01249       fInfoLine[17]->SetText("Total CPU time used (s) :");
01250       buf.Form("%.3f", fViewer->GetActDesc()->fProof->GetCpuTime());
01251       fInfoLine[18]->SetText(buf.Data());
01252    }
01253    else {
01254       if (fViewer->GetActDesc()->fProof->IsParallel())
01255          buf.Form("*** Master server %s (parallel mode, %d workers) ***",
01256                fViewer->GetActDesc()->fProof->GetMaster(),
01257                fViewer->GetActDesc()->fProof->GetParallel());
01258       else
01259          buf.Form("*** Master server %s (sequential mode) ***",
01260                fViewer->GetActDesc()->fProof->GetMaster());
01261       fInfoLine[0]->SetText(buf.Data());
01262       fInfoLine[1]->SetText("Port number : ");
01263       buf.Form("%d", fViewer->GetActDesc()->fProof->GetPort());
01264       fInfoLine[2]->SetText(buf.Data());
01265       fInfoLine[3]->SetText("User : ");
01266       buf.Form("%s", fViewer->GetActDesc()->fProof->GetUser());
01267       fInfoLine[4]->SetText(buf.Data());
01268       fInfoLine[5]->SetText("Protocol version : ");
01269       buf.Form("%d", fViewer->GetActDesc()->fProof->GetClientProtocol());
01270       fInfoLine[6]->SetText(buf.Data());
01271       fInfoLine[7]->SetText("Image name : ");
01272       buf.Form("%s",fViewer->GetActDesc()->fProof->GetImage());
01273       fInfoLine[8]->SetText(buf.Data());
01274       fInfoLine[9]->SetText("Config directory : ");
01275       buf.Form("%s", fViewer->GetActDesc()->fProof->GetConfDir());
01276       fInfoLine[10]->SetText(buf.Data());
01277       fInfoLine[11]->SetText("Config file : ");
01278       buf.Form("%s", fViewer->GetActDesc()->fProof->GetConfFile());
01279       fInfoLine[12]->SetText(buf.Data());
01280       fInfoLine[13]->SetText("Total MB's processed :");
01281       buf.Form("%.2f", float(fViewer->GetActDesc()->fProof->GetBytesRead())/(1024*1024));
01282       fInfoLine[14]->SetText(buf.Data());
01283       fInfoLine[15]->SetText("Total real time used (s) :");
01284       buf.Form("%.3f", fViewer->GetActDesc()->fProof->GetRealTime());
01285       fInfoLine[16]->SetText(buf.Data());
01286       fInfoLine[17]->SetText("Total CPU time used (s) :");
01287       buf.Form("%.3f", fViewer->GetActDesc()->fProof->GetCpuTime());
01288       fInfoLine[18]->SetText(buf.Data());
01289    }
01290    Layout();
01291    Resize(GetDefaultSize());
01292 }
01293 
01294 //______________________________________________________________________________
01295 void TSessionFrame::OnBtnUploadDSet()
01296 {
01297    // Open Upload Dataset dialog.
01298 
01299    if (fViewer->IsBusy())
01300       return;
01301    if (fViewer->GetActDesc()->fLocal) return;
01302    new TUploadDataSetDlg(fViewer, 450, 360);
01303 }
01304 
01305 //______________________________________________________________________________
01306 void TSessionFrame::UpdateListOfDataSets()
01307 {
01308    // Update list of dataset present on the cluster.
01309 
01310    TObjString *dsetname;
01311    TFileInfo  *dsetfilename;
01312    // cleanup the list
01313    fDataSetTree->DeleteChildren(fDataSetTree->GetFirstItem());
01314    if (fViewer->GetActDesc()->fConnected && fViewer->GetActDesc()->fAttached &&
01315        fViewer->GetActDesc()->fProof && fViewer->GetActDesc()->fProof->IsValid() &&
01316        fViewer->GetActDesc()->fProof->IsParallel()) {
01317 
01318       const TGPicture *dseticon = fClient->GetPicture("rootdb_t.xpm");
01319       // ask for the list of datasets
01320 
01321       // TODO: is now returning a TMap; viewer has to be adapted
01322       TList *dsetlist = 0; //fViewer->GetActDesc()->fProof->GetDataSets();
01323       if(dsetlist) {
01324          TGListTreeItem *dsetitem;
01325          fDataSetTree->OpenItem(fDataSetTree->GetFirstItem());
01326          TIter nextdset(dsetlist);
01327          while ((dsetname = (TObjString *)nextdset())) {
01328             if (!fDataSetTree->FindItemByObj(fDataSetTree->GetFirstItem(), dsetname)) {
01329                // add the dataset in the tree
01330                dsetitem = fDataSetTree->AddItem(fDataSetTree->GetFirstItem(),
01331                                         dsetname->GetName(), dsetname);
01332                // ask for the list of files in the dataset
01333                TList *dsetfilelist = fViewer->GetActDesc()->fProof->GetDataSet(
01334                                                             dsetname->GetName())->GetList();
01335                if(dsetfilelist) {
01336                   TIter nextdsetfile(dsetfilelist);
01337                   while ((dsetfilename = (TFileInfo *)nextdsetfile())) {
01338                      if (! fDataSetTree->FindItemByObj(dsetitem, dsetfilename)) {
01339                         // if not already in, add the file name in the tree
01340                         fDataSetTree->AddItem(dsetitem,
01341                            dsetfilename->GetFirstUrl()->GetUrl(),
01342                            dsetfilename, dseticon, dseticon);
01343                      }
01344                   }
01345                   // open the dataset item in order to show the files
01346                   fDataSetTree->OpenItem(dsetitem);
01347                }
01348             }
01349          }
01350       }
01351    }
01352    // refresh list tree
01353    fClient->NeedRedraw(fDataSetTree);
01354 }
01355 
01356 //______________________________________________________________________________
01357 void TSessionFrame::OnBtnRemoveDSet()
01358 {
01359    // Remove dataset from the list and from the cluster.
01360 
01361    TGListTreeItem *item;
01362    TObjString *obj = 0;
01363    if (fViewer->GetActDesc()->fLocal) return;
01364 
01365    item = fDataSetTree->GetSelected();
01366    if (!item) return;
01367    if (item->GetParent() == 0) return;
01368    if (item->GetParent() == fDataSetTree->GetFirstItem()) {
01369       // Dataset itself
01370       obj = (TObjString *)item->GetUserData();
01371    }
01372    else if (item->GetParent()->GetParent() == fDataSetTree->GetFirstItem()) {
01373       // One file of the dataset
01374       obj = (TObjString *)item->GetParent()->GetUserData();
01375    }
01376 
01377    // if valid Proof session, set parallel slaves
01378    if (obj && fViewer->GetActDesc()->fProof &&
01379       fViewer->GetActDesc()->fProof->IsValid()) {
01380       fViewer->GetActDesc()->fProof->RemoveDataSet(obj->GetName());
01381       UpdateListOfDataSets();
01382    }
01383 }
01384 
01385 //______________________________________________________________________________
01386 void TSessionFrame::OnBtnVerifyDSet()
01387 {
01388    // Verify that the files in the selected dataset are present on the cluster.
01389 
01390    TGListTreeItem *item;
01391    TObjString *obj = 0;
01392    if (fViewer->GetActDesc()->fLocal) return;
01393 
01394    item = fDataSetTree->GetSelected();
01395    if (!item) return;
01396    if (item->GetParent() == 0) return;
01397    if (item->GetParent() == fDataSetTree->GetFirstItem()) {
01398       // Dataset itself
01399       obj = (TObjString *)item->GetUserData();
01400    }
01401    else if (item->GetParent()->GetParent() == fDataSetTree->GetFirstItem()) {
01402       // One file of the dataset
01403       obj = (TObjString *)item->GetParent()->GetUserData();
01404    }
01405 
01406    // if valid Proof session, set parallel slaves
01407    if (obj && fViewer->GetActDesc()->fProof &&
01408       fViewer->GetActDesc()->fProof->IsValid()) {
01409       fViewer->GetActDesc()->fProof->VerifyDataSet(obj->GetName());
01410    }
01411 }
01412 
01413 //______________________________________________________________________________
01414 void TSessionFrame::OnApplyLogLevel()
01415 {
01416    // Apply selected log level on current session.
01417 
01418    // if local session, do nothing
01419    if (fViewer->GetActDesc()->fLocal) return;
01420    // if valid Proof session, set log level
01421    if (fViewer->GetActDesc()->fProof &&
01422       fViewer->GetActDesc()->fProof->IsValid()) {
01423       fViewer->GetActDesc()->fLogLevel = fLogLevel->GetIntNumber();
01424       fViewer->GetActDesc()->fProof->SetLogLevel(fViewer->GetActDesc()->fLogLevel);
01425    }
01426    fViewer->GetSessionFrame()->ProofInfos();
01427 }
01428 
01429 //______________________________________________________________________________
01430 void TSessionFrame::OnApplyParallel()
01431 {
01432    // Apply selected number of workers on current Proof session.
01433 
01434    // if local session, do nothing
01435    if (fViewer->GetActDesc()->fLocal) return;
01436    // if valid Proof session, set parallel slaves
01437    if (fViewer->GetActDesc()->fProof &&
01438       fViewer->GetActDesc()->fProof->IsValid()) {
01439       Int_t nodes = atoi(fTxtParallel->GetText());
01440       fViewer->GetActDesc()->fProof->SetParallel(nodes);
01441    }
01442    fViewer->GetSessionFrame()->ProofInfos();
01443 }
01444 
01445 //______________________________________________________________________________
01446 void TSessionFrame::OnMultipleSelection(Bool_t on)
01447 {
01448    // Handle multiple selection check button.
01449 
01450    fLBPackages->SetMultipleSelections(on);
01451 }
01452 
01453 //______________________________________________________________________________
01454 void TSessionFrame::OnStartupEnable(Bool_t on)
01455 {
01456    // Handle multiple selection check button.
01457 
01458    if (fViewer->GetActDesc())
01459       fViewer->GetActDesc()->fAutoEnable = on;
01460 }
01461 
01462 //______________________________________________________________________________
01463 void TSessionFrame::UpdatePackages()
01464 {
01465    // Update list of packages.
01466 
01467    TPackageDescription *package;
01468    const TGPicture *pict;
01469    fLBPackages->RemoveEntries(0, fLBPackages->GetNumberOfEntries());
01470    TIter next(fViewer->GetActDesc()->fPackages);
01471    while ((package = (TPackageDescription *)next())) {
01472       if (package->fEnabled)
01473          pict = fClient->GetPicture("package_add.xpm");
01474       else if (package->fUploaded)
01475          pict = fClient->GetPicture("package_delete.xpm");
01476       else
01477          pict = fClient->GetPicture("package.xpm");
01478       TGIconLBEntry *entry = new TGIconLBEntry(fLBPackages->GetContainer(),
01479                                     package->fId, package->fPathName, pict);
01480       fLBPackages->AddEntry(entry, new TGLayoutHints(kLHintsExpandX | kLHintsTop));
01481    }
01482    fLBPackages->Layout();
01483    fClient->NeedRedraw(fLBPackages->GetContainer());
01484 }
01485 
01486 //______________________________________________________________________________
01487 void TSessionFrame::OnUploadPackages()
01488 {
01489    // Upload selected package(s) to the current session.
01490 
01491    // if local session, do nothing
01492    if (fViewer->GetActDesc()->fLocal) return;
01493    // if valid Proof session, upload packages
01494    if (fViewer->GetActDesc()->fProof &&
01495       fViewer->GetActDesc()->fProof->IsValid()) {
01496       TObject *obj;
01497       TList selected;
01498       fLBPackages->GetSelectedEntries(&selected);
01499       TIter next(&selected);
01500       while ((obj = next())) {
01501          TString name = obj->GetTitle();
01502          if (fViewer->GetActDesc()->fProof->UploadPackage(name.Data()) != 0)
01503             Error("Submit", "Upload package failed");
01504          else {
01505             TObject *o = fViewer->GetActDesc()->fPackages->FindObject(gSystem->BaseName(name));
01506             if (!o) continue;
01507             TPackageDescription *package =
01508                dynamic_cast<TPackageDescription *>(o);
01509             if (package) {
01510                package->fUploaded = kTRUE;
01511                ((TGIconLBEntry *)obj)->SetPicture(
01512                      fClient->GetPicture("package_delete.xpm"));
01513             }
01514          }
01515       }
01516       UpdatePackages();
01517    }
01518    fLBPackages->Layout();
01519    fClient->NeedRedraw(fLBPackages->GetContainer());
01520 }
01521 
01522 //______________________________________________________________________________
01523 void TSessionFrame::OnEnablePackages()
01524 {
01525    // Enable selected package(s) in the current session.
01526 
01527    // if local session, do nothing
01528    if (fViewer->GetActDesc()->fLocal) return;
01529    // if valid Proof session, enable packages
01530    if (fViewer->GetActDesc()->fProof &&
01531       fViewer->GetActDesc()->fProof->IsValid()) {
01532       TObject *obj;
01533       TList selected;
01534       fBtnEnable->SetState(kButtonDisabled);
01535       fLBPackages->GetSelectedEntries(&selected);
01536       TIter next(&selected);
01537       while ((obj = next())) {
01538          TString name = obj->GetTitle();
01539          TObject *o = fViewer->GetActDesc()->fPackages->FindObject(gSystem->BaseName(name));
01540          if (!o) continue;
01541          TPackageDescription *package =
01542             dynamic_cast<TPackageDescription *>(o);
01543          if (package) {
01544             if (!package->fUploaded) {
01545                if (fViewer->GetActDesc()->fProof->UploadPackage(name.Data()) != 0)
01546                   Error("Submit", "Upload package failed");
01547                else {
01548                   package->fUploaded = kTRUE;
01549                   ((TGIconLBEntry *)obj)->SetPicture(
01550                         fClient->GetPicture("package_delete.xpm"));
01551                }
01552             }
01553          }
01554          if (fViewer->GetActDesc()->fProof->EnablePackage(name) != 0)
01555             Error("Submit", "Enable package failed");
01556          else {
01557             package->fEnabled = kTRUE;
01558             ((TGIconLBEntry *)obj)->SetPicture(fClient->GetPicture("package_add.xpm"));
01559          }
01560       }
01561       UpdatePackages();
01562       fBtnEnable->SetState(kButtonUp);
01563    }
01564    fLBPackages->Layout();
01565    fClient->NeedRedraw(fLBPackages->GetContainer());
01566 }
01567 
01568 //______________________________________________________________________________
01569 void TSessionFrame::OnDisablePackages()
01570 {
01571    // Disable selected package(s) in the current session.
01572 
01573    // if local session, do nothing
01574    if (fViewer->GetActDesc()->fLocal) return;
01575    // if valid Proof session, disable (clear) packages
01576    if (fViewer->GetActDesc()->fProof &&
01577       fViewer->GetActDesc()->fProof->IsValid()) {
01578       TObject *obj;
01579       TList selected;
01580       fLBPackages->GetSelectedEntries(&selected);
01581       TIter next(&selected);
01582       while ((obj = next())) {
01583          TString name = obj->GetTitle();
01584          if (fViewer->GetActDesc()->fProof->ClearPackage(name) != 0)
01585             Error("Submit", "Clear package failed");
01586          else {
01587             TObject *o = fViewer->GetActDesc()->fPackages->FindObject(gSystem->BaseName(name));
01588             if (!o) continue;
01589             TPackageDescription *package =
01590                dynamic_cast<TPackageDescription *>(o);
01591             if (package) {
01592                package->fEnabled = kFALSE;
01593                package->fUploaded = kFALSE;
01594                ((TGIconLBEntry *)obj)->SetPicture(fClient->GetPicture("package.xpm"));
01595             }
01596          }
01597       }
01598       UpdatePackages();
01599    }
01600    fLBPackages->Layout();
01601    fClient->NeedRedraw(fLBPackages->GetContainer());
01602 }
01603 
01604 //______________________________________________________________________________
01605 void TSessionFrame::OnClearPackages()
01606 {
01607    // Clear (disable) all packages in the current session.
01608 
01609    TPackageDescription *package;
01610    // if local session, do nothing
01611    if (fViewer->GetActDesc()->fLocal) return;
01612    // if valid Proof session, clear packages
01613    if (fViewer->GetActDesc()->fProof &&
01614       fViewer->GetActDesc()->fProof->IsValid()) {
01615       if (fViewer->GetActDesc()->fProof->ClearPackages() != 0)
01616          Error("Submit", "Clear packages failed");
01617       else {
01618          TIter next(fViewer->GetActDesc()->fPackages);
01619          while ((package = (TPackageDescription *)next())) {
01620             package->fEnabled = kFALSE;
01621          }
01622       }
01623    }
01624    fLBPackages->Layout();
01625    fClient->NeedRedraw(fLBPackages->GetContainer());
01626 }
01627 
01628 //______________________________________________________________________________
01629 void TSessionFrame::OnBtnAddClicked()
01630 {
01631    // Open file dialog and add selected package file to the list.
01632 
01633    if (fViewer->IsBusy())
01634       return;
01635    TGFileInfo fi;
01636    TPackageDescription *package;
01637    TGIconLBEntry *entry;
01638    fi.fFileTypes = pkgtypes;
01639    new TGFileDialog(fClient->GetRoot(), fViewer, kFDOpen, &fi);
01640    if (fi.fMultipleSelection && fi.fFileNamesList) {
01641       TObjString *el;
01642       TIter next(fi.fFileNamesList);
01643       while ((el = (TObjString *) next())) {
01644          package = new TPackageDescription;
01645          package->fName = gSystem->BaseName(gSystem->UnixPathName(el->GetString()));
01646          package->fPathName = gSystem->UnixPathName(el->GetString());
01647          package->fId   = fViewer->GetActDesc()->fPackages->GetEntries();
01648          package->fUploaded = kFALSE;
01649          package->fEnabled = kFALSE;
01650          fViewer->GetActDesc()->fPackages->Add((TObject *)package);
01651          entry = new TGIconLBEntry(fLBPackages->GetContainer(),
01652                                    package->fId, package->fPathName,
01653                                    fClient->GetPicture("package.xpm"));
01654          fLBPackages->AddEntry(entry, new TGLayoutHints(kLHintsExpandX | kLHintsTop));
01655       }
01656    }
01657    else if (fi.fFilename) {
01658       package = new TPackageDescription;
01659       package->fName = gSystem->BaseName(gSystem->UnixPathName(fi.fFilename));
01660       package->fPathName = gSystem->UnixPathName(fi.fFilename);
01661       package->fId   = fViewer->GetActDesc()->fPackages->GetEntries();
01662       package->fUploaded = kFALSE;
01663       package->fEnabled = kFALSE;
01664       fViewer->GetActDesc()->fPackages->Add((TObject *)package);
01665       entry = new TGIconLBEntry(fLBPackages->GetContainer(),
01666                                 package->fId, package->fPathName,
01667                                 fClient->GetPicture("package.xpm"));
01668       fLBPackages->AddEntry(entry, new TGLayoutHints(kLHintsExpandX | kLHintsTop));
01669    }
01670    fLBPackages->Layout();
01671    fClient->NeedRedraw(fLBPackages->GetContainer());
01672 }
01673 
01674 //______________________________________________________________________________
01675 void TSessionFrame::OnBtnRemoveClicked()
01676 {
01677    // Remove selected package from the list.
01678 
01679    TPackageDescription *package;
01680    const TGPicture *pict;
01681    Int_t pos = fLBPackages->GetSelected();
01682    fLBPackages->RemoveEntries(0, fLBPackages->GetNumberOfEntries());
01683    fViewer->GetActDesc()->fPackages->Remove(
01684          fViewer->GetActDesc()->fPackages->At(pos));
01685    Int_t id = 0;
01686    TIter next(fViewer->GetActDesc()->fPackages);
01687    while ((package = (TPackageDescription *)next())) {
01688       package->fId = id;
01689       id++;
01690       if (package->fEnabled)
01691          pict = fClient->GetPicture("package_add.xpm");
01692       else if (package->fUploaded)
01693          pict = fClient->GetPicture("package_delete.xpm");
01694       else
01695          pict = fClient->GetPicture("package.xpm");
01696       TGIconLBEntry *entry = new TGIconLBEntry(fLBPackages->GetContainer(),
01697                                     package->fId, package->fPathName, pict);
01698       fLBPackages->AddEntry(entry, new TGLayoutHints(kLHintsExpandX | kLHintsTop));
01699    }
01700    fLBPackages->Layout();
01701    fClient->NeedRedraw(fLBPackages->GetContainer());
01702 }
01703 
01704 //______________________________________________________________________________
01705 void TSessionFrame::OnBtnUpClicked()
01706 {
01707    // Move selected package entry one position up in the list.
01708 
01709    TPackageDescription *package;
01710    const TGPicture *pict;
01711    Int_t pos = fLBPackages->GetSelected();
01712    if (pos <= 0) return;
01713    fLBPackages->RemoveEntries(0, fLBPackages->GetNumberOfEntries());
01714    package = (TPackageDescription *)fViewer->GetActDesc()->fPackages->At(pos);
01715    fViewer->GetActDesc()->fPackages->Remove(
01716          fViewer->GetActDesc()->fPackages->At(pos));
01717    package->fId -= 1;
01718    fViewer->GetActDesc()->fPackages->AddAt(package, package->fId);
01719    Int_t id = 0;
01720    TIter next(fViewer->GetActDesc()->fPackages);
01721    while ((package = (TPackageDescription *)next())) {
01722       package->fId = id;
01723       id++;
01724       if (package->fEnabled)
01725          pict = fClient->GetPicture("package_add.xpm");
01726       else if (package->fUploaded)
01727          pict = fClient->GetPicture("package_delete.xpm");
01728       else
01729          pict = fClient->GetPicture("package.xpm");
01730       TGIconLBEntry *entry = new TGIconLBEntry(fLBPackages->GetContainer(),
01731                                     package->fId, package->fPathName, pict);
01732       fLBPackages->AddEntry(entry, new TGLayoutHints(kLHintsExpandX | kLHintsTop));
01733    }
01734    fLBPackages->Select(pos-1);
01735    fLBPackages->Layout();
01736    fClient->NeedRedraw(fLBPackages->GetContainer());
01737 }
01738 
01739 //______________________________________________________________________________
01740 void TSessionFrame::OnBtnDownClicked()
01741 {
01742    // Move selected package entry one position down in the list.
01743 
01744    TPackageDescription *package;
01745    const TGPicture *pict;
01746    Int_t pos = fLBPackages->GetSelected();
01747    if (pos == -1 || pos == fViewer->GetActDesc()->fPackages->GetEntries()-1)
01748       return;
01749    fLBPackages->RemoveEntries(0, fLBPackages->GetNumberOfEntries());
01750    package = (TPackageDescription *)fViewer->GetActDesc()->fPackages->At(pos);
01751    fViewer->GetActDesc()->fPackages->Remove(
01752          fViewer->GetActDesc()->fPackages->At(pos));
01753    package->fId += 1;
01754    fViewer->GetActDesc()->fPackages->AddAt(package, package->fId);
01755    Int_t id = 0;
01756    TIter next(fViewer->GetActDesc()->fPackages);
01757    while ((package = (TPackageDescription *)next())) {
01758       package->fId = id;
01759       id++;
01760       if (package->fEnabled)
01761          pict = fClient->GetPicture("package_add.xpm");
01762       else if (package->fUploaded)
01763          pict = fClient->GetPicture("package_delete.xpm");
01764       else
01765          pict = fClient->GetPicture("package.xpm");
01766       TGIconLBEntry *entry = new TGIconLBEntry(fLBPackages->GetContainer(),
01767                                     package->fId, package->fPathName, pict);
01768       fLBPackages->AddEntry(entry, new TGLayoutHints(kLHintsExpandX | kLHintsTop));
01769    }
01770    fLBPackages->Select(pos+1);
01771    fLBPackages->Layout();
01772    fClient->NeedRedraw(fLBPackages->GetContainer());
01773 }
01774 
01775 //______________________________________________________________________________
01776 void TSessionFrame::OnBtnDisconnectClicked()
01777 {
01778    // Disconnect from current Proof session.
01779 
01780    // if local session, do nothing
01781    if (fViewer->GetActDesc()->fLocal) return;
01782    // if valid Proof session, disconnect (close)
01783    if (fViewer->GetActDesc()->fAttached &&
01784        fViewer->GetActDesc()->fProof &&
01785        fViewer->GetActDesc()->fProof->IsValid()) {
01786       fViewer->GetActDesc()->fProof->Detach();
01787    }
01788    // reset connected flag
01789    fViewer->GetActDesc()->fAttached = kFALSE;
01790    fViewer->GetActDesc()->fProof = 0;
01791    // disable animation timer
01792    fViewer->DisableTimer();
01793    // change list tree item picture to disconnected pixmap
01794    TGListTreeItem *item = fViewer->GetSessionHierarchy()->FindChildByData(
01795                            fViewer->GetSessionItem(), fViewer->GetActDesc());
01796    item->SetPictures(fViewer->GetProofDisconPict(),
01797                      fViewer->GetProofDisconPict());
01798 
01799    // update viewer
01800    fViewer->OnListTreeClicked(fViewer->GetSessionHierarchy()->GetSelected(),
01801                               1, 0, 0);
01802    fViewer->GetSessionHierarchy()->ClearViewPort();
01803    fClient->NeedRedraw(fViewer->GetSessionHierarchy());
01804    fViewer->GetStatusBar()->SetText("", 1);
01805 }
01806 
01807 //______________________________________________________________________________
01808 void TSessionFrame::OnBtnShowLogClicked()
01809 {
01810    // Show session log.
01811 
01812    fViewer->ShowLog(0);
01813 }
01814 
01815 //______________________________________________________________________________
01816 void TSessionFrame::OnBtnNewQueryClicked()
01817 {
01818    // Call "New Query" Dialog.
01819 
01820    TNewQueryDlg *dlg = new TNewQueryDlg(fViewer, 350, 310);
01821    dlg->Popup();
01822 }
01823 
01824 //______________________________________________________________________________
01825 void TSessionFrame::OnBtnGetQueriesClicked()
01826 {
01827    // Get list of queries from current Proof server and populate the list tree.
01828 
01829    TList *lqueries = 0;
01830    TQueryResult *query = 0;
01831    TQueryDescription *newquery = 0, *lquery = 0;
01832    if (fViewer->GetActDesc()->fProof &&
01833        fViewer->GetActDesc()->fProof->IsValid()) {
01834       lqueries = fViewer->GetActDesc()->fProof->GetListOfQueries();
01835    }
01836    if (lqueries) {
01837       TIter nextp(lqueries);
01838       // loop over list of queries received from Proof server
01839       while ((query = (TQueryResult *)nextp())) {
01840          // create new query description
01841          newquery = new TQueryDescription();
01842          newquery->fReference = TString::Format("%s:%s", query->GetTitle(),
01843                                                 query->GetName());
01844          // check in our tree if it is already there
01845          TGListTreeItem *item =
01846             fViewer->GetSessionHierarchy()->FindChildByData(
01847                   fViewer->GetSessionItem(), fViewer->GetActDesc());
01848          // if already there, skip
01849          if (fViewer->GetSessionHierarchy()->FindChildByName(item,
01850              newquery->fReference.Data()))
01851             continue;
01852          // check also in our query description list
01853          Bool_t found = kFALSE;
01854          TIter nextp2(fViewer->GetActDesc()->fQueries);
01855          while ((lquery = (TQueryDescription *)nextp2())) {
01856             if (lquery->fReference.CompareTo(newquery->fReference) == 0) {
01857                found = kTRUE;
01858                break;
01859             }
01860          }
01861          if (found) continue;
01862          // build new query description with infos from Proof
01863          newquery->fStatus = query->IsFinalized() ?
01864                TQueryDescription::kSessionQueryFinalized :
01865                (TQueryDescription::ESessionQueryStatus)query->GetStatus();
01866          newquery->fSelectorString  = query->GetSelecImp()->GetName();
01867          newquery->fQueryName       = TString::Format("%s:%s", query->GetTitle(),
01868                                                       query->GetName());
01869          newquery->fOptions         = query->GetOptions();
01870          newquery->fEventList       = "";
01871          newquery->fNbFiles         = 0;
01872          newquery->fNoEntries       = query->GetEntries();
01873          newquery->fFirstEntry      = query->GetFirst();
01874          newquery->fResult          = query;
01875          newquery->fChain           = 0;
01876          fViewer->GetActDesc()->fQueries->Add((TObject *)newquery);
01877          TGListTreeItem *item2 = fViewer->GetSessionHierarchy()->AddItem(item,
01878                   newquery->fQueryName, fViewer->GetQueryConPict(),
01879                   fViewer->GetQueryConPict());
01880          item2->SetUserData(newquery);
01881          if (query->GetInputList())
01882             fViewer->GetSessionHierarchy()->AddItem(item2, "InputList");
01883          if (query->GetOutputList())
01884             fViewer->GetSessionHierarchy()->AddItem(item2, "OutputList");
01885       }
01886    }
01887    // at the end, update list tree
01888    fViewer->GetSessionHierarchy()->ClearViewPort();
01889    fClient->NeedRedraw(fViewer->GetSessionHierarchy());
01890 }
01891 
01892 //______________________________________________________________________________
01893 void TSessionFrame::OnCommandLine()
01894 {
01895    // Command line handling.
01896 
01897    // get command string
01898    const char *cmd = fCommandTxt->GetText();
01899    char opt[2];
01900    // form temporary file path
01901    TString pathtmp = TString::Format("%s/%s", gSystem->TempDirectory(),
01902                                      kSession_RedirectCmd);
01903    // if check box "clear view" is checked, open temp file in write mode
01904    // (overwrite), in append mode otherwise.
01905    if (fClearCheck->IsOn())
01906       snprintf(opt, 2, "w");
01907    else
01908       snprintf(opt, 2, "a");
01909 
01910    // if valid Proof session, pass the command to Proof
01911    if (fViewer->GetActDesc()->fProof &&
01912        fViewer->GetActDesc()->fProof->IsValid()) {
01913       // redirect stdout/stderr to temp file
01914       if (gSystem->RedirectOutput(pathtmp.Data(), opt) != 0) {
01915          Error("ShowStatus", "stdout/stderr redirection failed; skipping");
01916          return;
01917       }
01918       // execute command line
01919       fViewer->GetActDesc()->fProof->Exec(cmd);
01920       // restore back stdout/stderr
01921       if (gSystem->RedirectOutput(0) != 0) {
01922          Error("ShowStatus", "stdout/stderr retore failed; skipping");
01923          return;
01924       }
01925       // if check box "clear view" is checked, clear text view
01926       if (fClearCheck->IsOn())
01927          fInfoTextView->Clear();
01928       // load (display) temp file in text view
01929       fInfoTextView->LoadFile(pathtmp.Data());
01930       // set focus to "command line" text entry
01931       fCommandTxt->SetFocus();
01932    }
01933    else {
01934       // if no Proof session, or Proof session not valid,
01935       // lets execute command line by TApplication
01936 
01937       // redirect stdout/stderr to temp file
01938       if (gSystem->RedirectOutput(pathtmp.Data(), opt) != 0) {
01939          Error("ShowStatus", "stdout/stderr redirection failed; skipping");
01940       }
01941       // execute command line
01942       gApplication->ProcessLine(cmd);
01943       // restore back stdout/stderr
01944       if (gSystem->RedirectOutput(0) != 0) {
01945          Error("ShowStatus", "stdout/stderr retore failed; skipping");
01946       }
01947       // if check box "clear view" is checked, clear text view
01948       if (fClearCheck->IsOn())
01949          fInfoTextView->Clear();
01950       // load (display) temp file in text view
01951       fInfoTextView->LoadFile(pathtmp.Data());
01952       // set focus to "command line" text entry
01953       fCommandTxt->SetFocus();
01954    }
01955    // display bottom of text view
01956    fInfoTextView->ShowBottom();
01957 }
01958 
01959 //______________________________________________________________________________
01960 void TSessionFrame::SetLocal(Bool_t local)
01961 {
01962    // Switch widgets status/visibility for local/remote sessions.
01963 
01964    if (local) {
01965       fBtnGetQueries->SetState(kButtonDisabled);
01966       fBtnShowLog->SetState(kButtonDisabled);
01967       fTab->HideFrame(fTab->GetTabTab("Options"));
01968       fTab->HideFrame(fTab->GetTabTab("Packages"));
01969       fTab->HideFrame(fTab->GetTabTab("DataSets"));
01970    }
01971    else {
01972       fBtnGetQueries->SetState(kButtonUp);
01973       fBtnShowLog->SetState(kButtonUp);
01974       fTab->ShowFrame(fTab->GetTabTab("Options"));
01975       fTab->ShowFrame(fTab->GetTabTab("Packages"));
01976       fTab->ShowFrame(fTab->GetTabTab("DataSets"));
01977    }
01978 }
01979 
01980 //______________________________________________________________________________
01981 void TSessionFrame::ShutdownSession()
01982 {
01983    // Shutdown current session.
01984 
01985    // do nothing if connection in progress
01986    if (fViewer->IsBusy())
01987       return;
01988 
01989    if (fViewer->GetActDesc()->fLocal) {
01990       Int_t retval;
01991       new TGMsgBox(fClient->GetRoot(), this, "Error Shutting down Session",
01992                    "Shutting down Local Sessions is not allowed !",
01993                     kMBIconExclamation,kMBOk,&retval);
01994       return;
01995    }
01996    if (!fViewer->GetActDesc()->fAttached ||
01997        !fViewer->GetActDesc()->fProof ||
01998        !fViewer->GetActDesc()->fProof->IsValid())
01999       return;
02000    // ask for confirmation
02001    TString m;
02002    m.Form("Are you sure to shutdown the session \"%s\"",
02003           fViewer->GetActDesc()->fName.Data());
02004    Int_t result;
02005    new TGMsgBox(fClient->GetRoot(), this, "", m.Data(), 0,
02006                 kMBOk | kMBCancel, &result);
02007    // if confirmed, delete it
02008    if (result != kMBOk)
02009       return;
02010    // remove the Proof session from gROOT list of Proofs
02011    fViewer->GetActDesc()->fProof->Detach("S");
02012    // reset connected flag
02013    fViewer->GetActDesc()->fAttached = kFALSE;
02014    fViewer->GetActDesc()->fProof = 0;
02015    // disable animation timer
02016    fViewer->DisableTimer();
02017    // change list tree item picture to disconnected pixmap
02018    TGListTreeItem *item = fViewer->GetSessionHierarchy()->FindChildByData(
02019                           fViewer->GetSessionItem(), fViewer->GetActDesc());
02020    item->SetPictures(fViewer->GetProofDisconPict(),
02021                      fViewer->GetProofDisconPict());
02022     // update viewer
02023    fViewer->OnListTreeClicked(fViewer->GetSessionHierarchy()->GetSelected(),
02024                               1, 0, 0);
02025    fViewer->GetSessionHierarchy()->ClearViewPort();
02026    fClient->NeedRedraw(fViewer->GetSessionHierarchy());
02027    fViewer->GetStatusBar()->SetText("", 1);
02028 }
02029 
02030 //////////////////////////////////////////////////////////////////////////
02031 // Edit Query Frame
02032 //////////////////////////////////////////////////////////////////////////
02033 
02034 //______________________________________________________________________________
02035 TEditQueryFrame::TEditQueryFrame(TGWindow* p, Int_t w, Int_t h) :
02036    TGCompositeFrame(p, w, h, kVerticalFrame)
02037 {
02038    // Create a new Query dialog, used by the Session Viewer, to Edit a Query if
02039    // the editmode flag is set, or to create a new one if not set.
02040 
02041 }
02042 
02043 //______________________________________________________________________________
02044 TEditQueryFrame::~TEditQueryFrame()
02045 {
02046    // Delete query dialog.
02047 
02048    Cleanup();
02049 }
02050 
02051 //______________________________________________________________________________
02052 void TEditQueryFrame::Build(TSessionViewer *gui)
02053 {
02054    // Build the "new query" dialog.
02055 
02056    TGButton *btnTmp;
02057    fViewer = gui;
02058    SetCleanup(kDeepCleanup);
02059    SetLayoutManager(new TGTableLayout(this, 6, 5));
02060 
02061    // add "Query Name" label and text entry
02062    AddFrame(new TGLabel(this, "Query Name :"),
02063          new TGTableLayoutHints(0, 1, 0, 1, kLHintsCenterY, 5, 5, 4, 0));
02064    AddFrame(fTxtQueryName = new TGTextEntry(this,
02065          (const char *)0, 1), new TGTableLayoutHints(1, 2, 0, 1,
02066          kLHintsCenterY, 5, 5, 4, 0));
02067 
02068    // add "TChain" label and text entry
02069    AddFrame(new TGLabel(this, "TChain :"),
02070          new TGTableLayoutHints(0, 1, 1, 2, kLHintsCenterY, 5, 5, 4, 0));
02071    AddFrame(fTxtChain = new TGTextEntry(this,
02072          (const char *)0, 2), new TGTableLayoutHints(1, 2, 1, 2,
02073          kLHintsCenterY, 5, 5, 4, 0));
02074    fTxtChain->SetToolTipText("Specify TChain or TDSet from memory or file");
02075    fTxtChain->SetEnabled(kFALSE);
02076    // add "Browse" button
02077    AddFrame(btnTmp = new TGTextButton(this, "Browse..."),
02078          new TGTableLayoutHints(2, 3, 1, 2, kLHintsCenterY, 5, 0, 4, 8));
02079    btnTmp->Connect("Clicked()", "TEditQueryFrame", this, "OnBrowseChain()");
02080 
02081    // add "Selector" label and text entry
02082    AddFrame(new TGLabel(this, "Selector :"),
02083          new TGTableLayoutHints(0, 1, 2, 3, kLHintsCenterY, 5, 5, 0, 0));
02084    AddFrame(fTxtSelector = new TGTextEntry(this,
02085          (const char *)0, 3), new TGTableLayoutHints(1, 2, 2, 3,
02086          kLHintsCenterY, 5, 5, 0, 0));
02087    // add "Browse" button
02088    AddFrame(btnTmp = new TGTextButton(this, "Browse..."),
02089          new TGTableLayoutHints(2, 3, 2, 3, kLHintsCenterY, 5, 0, 0, 8));
02090    btnTmp->Connect("Clicked()", "TEditQueryFrame", this, "OnBrowseSelector()");
02091 
02092    // add "Less <<" ("More >>") button
02093    AddFrame(fBtnMore = new TGTextButton(this, " Less << "),
02094          new TGTableLayoutHints(2, 3, 4, 5, kLHintsCenterY, 5, 5, 4, 0));
02095    fBtnMore->Connect("Clicked()", "TEditQueryFrame", this, "OnNewQueryMore()");
02096 
02097    // add (initially hidden) options frame
02098    fFrmMore = new TGCompositeFrame(this, 200, 200);
02099    fFrmMore->SetCleanup(kDeepCleanup);
02100 
02101    AddFrame(fFrmMore, new TGTableLayoutHints(0, 3, 5, 6,
02102          kLHintsExpandX | kLHintsExpandY));
02103    fFrmMore->SetLayoutManager(new TGTableLayout(fFrmMore, 4, 3));
02104 
02105    // add "Options" label and text entry
02106    fFrmMore->AddFrame(new TGLabel(fFrmMore, "Options :"),
02107          new TGTableLayoutHints(0, 1, 0, 1, kLHintsCenterY, 5, 5, 0, 0));
02108    fFrmMore->AddFrame(fTxtOptions = new TGTextEntry(fFrmMore,
02109          (const char *)0, 4), new TGTableLayoutHints(1, 2, 0, 1, 0, 17,
02110          0, 0, 8));
02111    //fTxtOptions->SetText("ASYN");
02112    fTxtOptions->SetText("");
02113 
02114    // add "Nb Entries" label and number entry
02115    fFrmMore->AddFrame(new TGLabel(fFrmMore, "Nb Entries :"),
02116          new TGTableLayoutHints(0, 1, 1, 2, kLHintsCenterY, 5, 5, 0, 0));
02117    fFrmMore->AddFrame(fNumEntries = new TGNumberEntry(fFrmMore, 0, 5, -1,
02118          TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber,
02119          TGNumberFormat::kNELNoLimits), new TGTableLayoutHints(1, 2, 1, 2,
02120          0, 17, 0, 0, 8));
02121    fNumEntries->SetIntNumber(-1);
02122    // add "First Entry" label and number entry
02123    fFrmMore->AddFrame(new TGLabel(fFrmMore, "First entry :"),
02124          new TGTableLayoutHints(0, 1, 2, 3, kLHintsCenterY, 5, 5, 0, 0));
02125    fFrmMore->AddFrame(fNumFirstEntry = new TGNumberEntry(fFrmMore, 0, 5, -1,
02126          TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative,
02127          TGNumberFormat::kNELNoLimits), new TGTableLayoutHints(1, 2, 2, 3, 0,
02128          17, 0, 0, 8));
02129 
02130    // add "Event list" label and text entry
02131    fFrmMore->AddFrame(new TGLabel(fFrmMore, "Event list :"),
02132          new TGTableLayoutHints(0, 1, 3, 4, kLHintsCenterY, 5, 5, 0, 0));
02133    fFrmMore->AddFrame(fTxtEventList = new TGTextEntry(fFrmMore,
02134          (const char *)0, 6), new TGTableLayoutHints(1, 2, 3, 4, 0, 17,
02135          5, 0, 0));
02136    // add "Browse" button
02137    fFrmMore->AddFrame(btnTmp = new TGTextButton(fFrmMore, "Browse..."),
02138          new TGTableLayoutHints(2, 3, 3, 4, 0, 6, 0, 0, 8));
02139    btnTmp->Connect("Clicked()", "TEditQueryFrame", this, "OnBrowseEventList()");
02140 
02141    fTxtQueryName->Associate(this);
02142    fTxtChain->Associate(this);
02143    fTxtSelector->Associate(this);
02144    fTxtOptions->Associate(this);
02145    fNumEntries->Associate(this);
02146    fNumFirstEntry->Associate(this);
02147    fTxtEventList->Associate(this);
02148 
02149    fTxtQueryName->Connect("TextChanged(char*)", "TEditQueryFrame", this,
02150                         "SettingsChanged()");
02151    fTxtChain->Connect("TextChanged(char*)", "TEditQueryFrame", this,
02152                         "SettingsChanged()");
02153    fTxtSelector->Connect("TextChanged(char*)", "TEditQueryFrame", this,
02154                         "SettingsChanged()");
02155    fTxtOptions->Connect("TextChanged(char*)", "TEditQueryFrame", this,
02156                         "SettingsChanged()");
02157    fNumEntries->Connect("ValueChanged(Long_t)", "TEditQueryFrame", this,
02158                         "SettingsChanged()");
02159    fNumFirstEntry->Connect("ValueChanged(Long_t)", "TEditQueryFrame", this,
02160                         "SettingsChanged()");
02161    fTxtEventList->Connect("TextChanged(char*)", "TEditQueryFrame", this,
02162                         "SettingsChanged()");
02163 }
02164 
02165 //______________________________________________________________________________
02166 void TEditQueryFrame::OnNewQueryMore()
02167 {
02168    // Show/hide options frame and update button text accordingly.
02169 
02170    if (IsVisible(fFrmMore)) {
02171       HideFrame(fFrmMore);
02172       fBtnMore->SetText(" More >> ");
02173    }
02174    else {
02175       ShowFrame(fFrmMore);
02176       fBtnMore->SetText(" Less << ");
02177    }
02178 }
02179 
02180 //______________________________________________________________________________
02181 void TEditQueryFrame::OnBrowseChain()
02182 {
02183    // Call new chain dialog.
02184 
02185    TNewChainDlg *dlg = new TNewChainDlg(fClient->GetRoot(), this);
02186    dlg->Connect("OnElementSelected(TObject *)", "TEditQueryFrame",
02187          this, "OnElementSelected(TObject *)");
02188 }
02189 
02190 //____________________________________________________________________________
02191 void TEditQueryFrame::OnElementSelected(TObject *obj)
02192 {
02193    // Handle OnElementSelected signal coming from new chain dialog.
02194 
02195    if (obj) {
02196       fChain = obj;
02197       if (obj->IsA() == TChain::Class())
02198          fTxtChain->SetText(((TChain *)fChain)->GetName());
02199       else if (obj->IsA() == TDSet::Class())
02200          fTxtChain->SetText(((TDSet *)fChain)->GetObjName());
02201    }
02202 }
02203 
02204 //______________________________________________________________________________
02205 void TEditQueryFrame::OnBrowseSelector()
02206 {
02207    // Open file browser to choose selector macro.
02208 
02209    TGFileInfo fi;
02210    fi.fFileTypes = macrotypes;
02211    new TGFileDialog(fClient->GetRoot(), this, kFDOpen, &fi);
02212    if (!fi.fFilename) return;
02213    fTxtSelector->SetText(gSystem->UnixPathName(fi.fFilename));
02214 }
02215 
02216 //______________________________________________________________________________
02217 void TEditQueryFrame::OnBrowseEventList()
02218 {
02219    //Browse event list
02220 
02221 }
02222 
02223 //______________________________________________________________________________
02224 void TEditQueryFrame::OnBtnSave()
02225 {
02226    // Save current settings in main session viewer.
02227 
02228    // if we are in edition mode and query description is valid,
02229    // use it, otherwise create a new one
02230    TQueryDescription *newquery;
02231    if (fQuery)
02232       newquery = fQuery;
02233    else
02234       newquery = new TQueryDescription();
02235 
02236    // update query description fields
02237    newquery->fSelectorString  = fTxtSelector->GetText();
02238    if (fChain) {
02239       newquery->fTDSetString  = fChain->GetName();
02240       newquery->fChain        = fChain;
02241    }
02242    else {
02243       newquery->fTDSetString = "";
02244       newquery->fChain       = 0;
02245    }
02246    newquery->fQueryName      = fTxtQueryName->GetText();
02247    newquery->fOptions        = fTxtOptions->GetText();
02248    newquery->fNoEntries      = fNumEntries->GetIntNumber();
02249    newquery->fFirstEntry     = fNumFirstEntry->GetIntNumber();
02250    newquery->fNbFiles        = 0;
02251    newquery->fResult         = 0;
02252 
02253    if (newquery->fChain) {
02254       if (newquery->fChain->IsA() == TChain::Class())
02255          newquery->fNbFiles = ((TChain *)newquery->fChain)->GetListOfFiles()->GetEntriesFast();
02256       else if (newquery->fChain->IsA() == TDSet::Class())
02257          newquery->fNbFiles = ((TDSet *)newquery->fChain)->GetListOfElements()->GetSize();
02258    }
02259    // update user data with modified query description
02260    TGListTreeItem *item = fViewer->GetSessionHierarchy()->GetSelected();
02261    fViewer->GetSessionHierarchy()->RenameItem(item, newquery->fQueryName);
02262    item->SetUserData(newquery);
02263    // update list tree
02264    fViewer->GetSessionHierarchy()->ClearViewPort();
02265    fClient->NeedRedraw(fViewer->GetSessionHierarchy());
02266    fTxtQueryName->SelectAll();
02267    fTxtQueryName->SetFocus();
02268    fViewer->WriteConfiguration();
02269    fViewer->GetQueryFrame()->Modified(kFALSE);
02270    if (fViewer->GetActDesc()->fLocal ||
02271       (fViewer->GetActDesc()->fConnected &&
02272        fViewer->GetActDesc()->fAttached &&
02273        fViewer->GetActDesc()->fProof &&
02274        fViewer->GetActDesc()->fProof->IsValid())) {
02275       fViewer->GetQueryFrame()->GetTab()->SetTab("Status");
02276       fViewer->GetQueryFrame()->OnBtnSubmit();
02277    }
02278 }
02279 
02280 //______________________________________________________________________________
02281 void TEditQueryFrame::SettingsChanged()
02282 {
02283    // Settings have changed, update GUI accordingly.
02284 
02285    if (fQuery) {
02286       if ((strcmp(fQuery->fSelectorString.Data(), fTxtSelector->GetText())) ||
02287           (strcmp(fQuery->fQueryName.Data(), fTxtQueryName->GetText())) ||
02288           (strcmp(fQuery->fOptions.Data(), fTxtOptions->GetText())) ||
02289           (fQuery->fNoEntries  != fNumEntries->GetIntNumber()) ||
02290           (fQuery->fFirstEntry != fNumFirstEntry->GetIntNumber()) ||
02291           (fQuery->fChain != fChain)) {
02292          fViewer->GetQueryFrame()->Modified(kTRUE);
02293       }
02294       else {
02295          fViewer->GetQueryFrame()->Modified(kFALSE);
02296       }
02297    }
02298    else {
02299       if ((fTxtQueryName->GetText()) &&
02300          ((fTxtQueryName->GetText()) ||
02301           (fTxtChain->GetText())))
02302          fViewer->GetQueryFrame()->Modified(kTRUE);
02303       else
02304          fViewer->GetQueryFrame()->Modified(kFALSE);
02305    }
02306 }
02307 
02308 //______________________________________________________________________________
02309 void TEditQueryFrame::UpdateFields(TQueryDescription *desc)
02310 {
02311    // Update entry fields with query description values.
02312 
02313    fChain = 0;
02314    fQuery = desc;
02315    fTxtChain->SetText("");
02316    if (desc->fChain) {
02317       fChain = desc->fChain;
02318       fTxtChain->SetText(desc->fTDSetString);
02319    }
02320    fTxtQueryName->SetText(desc->fQueryName);
02321    fTxtSelector->SetText(desc->fSelectorString);
02322    fTxtOptions->SetText(desc->fOptions);
02323    fNumEntries->SetIntNumber(desc->fNoEntries);
02324    fNumFirstEntry->SetIntNumber(desc->fFirstEntry);
02325    fTxtEventList->SetText(desc->fEventList);
02326 }
02327 
02328 ////////////////////////////////////////////////////////////////////////////////
02329 // Query Frame
02330 
02331 //______________________________________________________________________________
02332 TSessionQueryFrame::TSessionQueryFrame(TGWindow* p, Int_t w, Int_t h) :
02333    TGCompositeFrame(p, w, h)
02334 {
02335    // Constructor
02336 
02337    fEntries = 0;
02338    fFiles = 0;
02339    fFirst = 0;
02340    fModified = 0;
02341    fPrevProcessed = 0;
02342    fPrevTotal = 0;
02343    fStatus = kStopped;
02344 }
02345 
02346 //______________________________________________________________________________
02347 TSessionQueryFrame::~TSessionQueryFrame()
02348 {
02349    // Destructor.
02350 
02351    Cleanup();
02352 }
02353 
02354 //______________________________________________________________________________
02355 void TSessionQueryFrame::Build(TSessionViewer *gui)
02356 {
02357    // Build query informations frame.
02358 
02359    SetLayoutManager(new TGVerticalLayout(this));
02360    SetCleanup(kDeepCleanup);
02361    fFirst = fEntries = fPrevTotal = 0;
02362    fPrevProcessed = 0;
02363    fViewer = gui;
02364    fModified = kFALSE;
02365 
02366    // main query tab
02367    fTab = new TGTab(this, 200, 200);
02368    AddFrame(fTab, new TGLayoutHints(kLHintsTop | kLHintsExpandX |
02369          kLHintsExpandY, 2, 2, 2, 2));
02370 
02371    // add "Status" tab element
02372    TGCompositeFrame *tf = fTab->AddTab("Status");
02373    fFB = new TGCompositeFrame(tf, 100, 100, kVerticalFrame);
02374    tf->AddFrame(fFB, new TGLayoutHints(kLHintsTop | kLHintsLeft |
02375          kLHintsExpandX | kLHintsExpandY));
02376 
02377    // new frame containing control buttons and feedback histos canvas
02378    TGCompositeFrame* frmcanvas = new TGHorizontalFrame(fFB, 350, 100);
02379    // control buttons frame
02380    TGCompositeFrame* frmBut2 = new TGVerticalFrame(frmcanvas, 150, 100);
02381    fBtnSubmit = new TGTextButton(frmBut2, "        Submit        ");
02382    fBtnSubmit->SetToolTipText("Submit (process) selected query");
02383    frmBut2->AddFrame(fBtnSubmit,new TGLayoutHints(kLHintsCenterY | kLHintsLeft |
02384          kLHintsExpandX, 5, 5, 5, 5));
02385    fBtnStop = new TGTextButton(frmBut2, "Stop");
02386    fBtnStop->SetToolTipText("Stop processing query");
02387    frmBut2->AddFrame(fBtnStop,new TGLayoutHints(kLHintsCenterY | kLHintsLeft |
02388          kLHintsExpandX, 5, 5, 5, 5));
02389    fBtnAbort = new TGTextButton(frmBut2, "Abort");
02390    fBtnAbort->SetToolTipText("Abort processing query");
02391    frmBut2->AddFrame(fBtnAbort,new TGLayoutHints(kLHintsCenterY | kLHintsLeft |
02392          kLHintsExpandX, 5, 5, 5, 5));
02393    frmcanvas->AddFrame(frmBut2, new TGLayoutHints(kLHintsLeft | kLHintsCenterY |
02394          kLHintsExpandY));
02395    // feedback histos embedded canvas
02396    fECanvas = new TRootEmbeddedCanvas("fECanvas", frmcanvas, 400, 150);
02397    fStatsCanvas = fECanvas->GetCanvas();
02398    fStatsCanvas->SetFillColor(10);
02399    fStatsCanvas->SetBorderMode(0);
02400    frmcanvas->AddFrame(fECanvas, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
02401             4, 4, 4, 4));
02402    fFB->AddFrame(frmcanvas, new TGLayoutHints(kLHintsLeft | kLHintsTop |
02403          kLHintsExpandX | kLHintsExpandY));
02404 
02405    // progress infos label
02406    fLabInfos = new TGLabel(fFB, "                                  ");
02407    fFB->AddFrame(fLabInfos, new TGLayoutHints(kLHintsLeft, 5, 5, 5, 5));
02408    // progress status label
02409    fLabStatus = new TGLabel(fFB, "                                  ");
02410    fFB->AddFrame(fLabStatus, new TGLayoutHints(kLHintsLeft, 5, 5, 5, 5));
02411 
02412    //progress bar
02413    frmProg = new TGHProgressBar(fFB, TGProgressBar::kFancy, 350 - 20);
02414    frmProg->ShowPosition();
02415    frmProg->SetBarColor("green");
02416    fFB->AddFrame(frmProg, new TGLayoutHints(kLHintsExpandX, 5, 5, 5, 5));
02417    // total progress infos
02418    fFB->AddFrame(fTotal = new TGLabel(fFB,
02419          " Estimated time left : 0 sec (--- events of --- processed) "),
02420          new TGLayoutHints(kLHintsLeft, 5, 5, 5, 5));
02421    // progress rate infos
02422    fFB->AddFrame(fRate = new TGLabel(fFB,
02423          " Processing Rate : -- events/sec    "),
02424          new TGLayoutHints(kLHintsLeft, 5, 5, 5, 5));
02425 
02426    // add "Results" tab element
02427    tf = fTab->AddTab("Results");
02428    fFC = new TGCompositeFrame(tf, 100, 100, kVerticalFrame);
02429    tf->AddFrame(fFC, new TGLayoutHints(kLHintsTop | kLHintsLeft |
02430          kLHintsExpandX | kLHintsExpandY));
02431    // query result (header) information text view
02432    fInfoTextView = new TGTextView(fFC, 330, 185, "", kSunkenFrame |
02433          kDoubleBorder);
02434    fFC->AddFrame(fInfoTextView, new TGLayoutHints(kLHintsTop | kLHintsLeft |
02435          kLHintsExpandY | kLHintsExpandX, 5, 5, 10, 10));
02436 
02437    // add "Retrieve", "Finalize" and "Show Log" buttons
02438    TGCompositeFrame* frmBut3 = new TGHorizontalFrame(fFC, 350, 100);
02439    fBtnRetrieve = new TGTextButton(frmBut3, "Retrieve");
02440    fBtnRetrieve->SetToolTipText("Retrieve query results");
02441    frmBut3->AddFrame(fBtnRetrieve,new TGLayoutHints(kLHintsTop | kLHintsLeft |
02442          kLHintsExpandX, 5, 5, 10, 10));
02443    fBtnFinalize = new TGTextButton(frmBut3, "Finalize");
02444    fBtnFinalize->SetToolTipText("Finalize query");
02445    frmBut3->AddFrame(fBtnFinalize,new TGLayoutHints(kLHintsTop | kLHintsLeft |
02446          kLHintsExpandX, 5, 5, 10, 10));
02447    fBtnShowLog = new TGTextButton(frmBut3, "Show Log");
02448    fBtnShowLog->SetToolTipText("Show query log (open log window)");
02449    frmBut3->AddFrame(fBtnShowLog,new TGLayoutHints(kLHintsTop | kLHintsLeft |
02450          kLHintsExpandX, 5, 5, 10, 10));
02451    fFC->AddFrame(frmBut3, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX));
02452 
02453    // add "Results" tab element
02454    tf = fTab->AddTab("Edit Query");
02455    fFD = new TEditQueryFrame(tf, 100, 100);
02456    fFD->Build(fViewer);
02457    tf->AddFrame(fFD, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 10, 0));
02458    TString btntxt;
02459    if (fViewer->GetActDesc()->fLocal ||
02460       (fViewer->GetActDesc()->fProof &&
02461        fViewer->GetActDesc()->fProof->IsValid())) {
02462       btntxt = "         Submit         ";
02463    }
02464    else {
02465       btntxt = "     Apply changes      ";
02466    }
02467    tf->AddFrame(fBtnSave = new TGTextButton(tf, btntxt),
02468                 new TGLayoutHints(kLHintsTop | kLHintsLeft, 10, 5, 25, 5));
02469 
02470    // connect button actions to functions
02471    fBtnSave->Connect("Clicked()", "TEditQueryFrame", fFD,
02472          "OnBtnSave()");
02473    fBtnSubmit->Connect("Clicked()", "TSessionQueryFrame", this,
02474          "OnBtnSubmit()");
02475    fBtnFinalize->Connect("Clicked()", "TSessionQueryFrame", this,
02476          "OnBtnFinalize()");
02477    fBtnStop->Connect("Clicked()", "TSessionQueryFrame", this,
02478          "OnBtnStop()");
02479    fBtnAbort->Connect("Clicked()", "TSessionQueryFrame", this,
02480          "OnBtnAbort()");
02481    fBtnShowLog->Connect("Clicked()", "TSessionQueryFrame", this,
02482          "OnBtnShowLog()");
02483    fBtnRetrieve->Connect("Clicked()", "TSessionQueryFrame", this,
02484          "OnBtnRetrieve()");
02485 //   fBtnSave->SetState(kButtonDisabled);
02486    Resize(350, 310);
02487 }
02488 
02489 //______________________________________________________________________________
02490 void TSessionQueryFrame::Modified(Bool_t mod)
02491 {
02492    // Notify changes in query editor settings.
02493 
02494    fModified = mod;
02495    if (fModified) {
02496       fBtnSave->SetState(kButtonUp);
02497    }
02498    else {
02499       fBtnSave->SetState(kButtonDisabled);
02500    }
02501    if (fViewer->GetActDesc()->fLocal ||
02502       (fViewer->GetActDesc()->fProof &&
02503        fViewer->GetActDesc()->fProof->IsValid()))
02504       fBtnSave->SetState(kButtonUp);
02505 }
02506 
02507 //______________________________________________________________________________
02508 void TSessionQueryFrame::Feedback(TList *objs)
02509 {
02510    // Feedback function connected to Feedback signal.
02511    // Used to update feedback histograms.
02512 
02513    // if no actual session, just return
02514    if (!fViewer->GetActDesc()->fAttached)
02515       return;
02516    if (!fViewer->GetActDesc()->fProof)
02517       return;
02518    if ((fViewer->GetActDesc()->fActQuery) &&
02519        (fViewer->GetActDesc()->fActQuery->fStatus !=
02520         TQueryDescription::kSessionQuerySubmitted) &&
02521        (fViewer->GetActDesc()->fActQuery->fStatus !=
02522         TQueryDescription::kSessionQueryRunning) )
02523       return;
02524    TProof *sender = dynamic_cast<TProof*>((TQObject*)gTQSender);
02525    // if Proof sender match actual session one, update feedback histos
02526    if (sender && (sender == fViewer->GetActDesc()->fProof))
02527       UpdateHistos(objs);
02528 }
02529 
02530 //______________________________________________________________________________
02531 void TSessionQueryFrame::UpdateHistos(TList *objs)
02532 {
02533    // Update feedback histograms.
02534    TVirtualPad *save = gPad;
02535    TObject *o;
02536    Int_t pos = 1;
02537    Int_t i = 0;
02538    while (kFeedbackHistos[i]) {
02539       // check if user has selected this histogram in the option menu
02540       if (fViewer->GetCascadeMenu()->IsEntryChecked(41+i)) {
02541          if ( (o = objs->FindObject(kFeedbackHistos[i]))) {
02542             fStatsCanvas->cd(pos);
02543             gPad->SetEditable(kTRUE);
02544             if (TH1 *h = dynamic_cast<TH1*>(o)) {
02545                h->SetStats(0);
02546                h->SetBarWidth(0.75);
02547                h->SetBarOffset(0.125);
02548                h->SetFillColor(9);
02549                h->Draw("bar");
02550                pos++;
02551             }
02552             else if (TH2 *h2 = dynamic_cast<TH2*>(o)) {
02553                h2->Draw();
02554                pos++;
02555             }
02556             gPad->Modified();
02557          }
02558       }
02559       i++;
02560    }
02561    // update canvas
02562    fStatsCanvas->cd();
02563    fStatsCanvas->Modified();
02564    fStatsCanvas->Update();
02565    if (save != 0) {
02566       save->cd();
02567    } else {
02568       gPad = 0;
02569    }
02570 }
02571 
02572 //______________________________________________________________________________
02573 void TSessionQueryFrame::Progress(Long64_t total, Long64_t processed)
02574 {
02575    // Update progress bar and status labels.
02576 
02577    Long_t tt;
02578    UInt_t hh=0, mm=0, ss=0;
02579    TString stm;
02580    // if no actual session, just return
02581    if (!fViewer->GetActDesc()->fProof)
02582       return;
02583    // if Proof sender does't match actual session one, return
02584    TProof *sender = dynamic_cast<TProof*>((TQObject*)gTQSender);
02585    if (!sender || (sender != fViewer->GetActDesc()->fProof))
02586       return;
02587 
02588    if ((fViewer->GetActDesc()->fActQuery) &&
02589        (fViewer->GetActDesc()->fActQuery->fStatus !=
02590         TQueryDescription::kSessionQuerySubmitted) &&
02591        (fViewer->GetActDesc()->fActQuery->fStatus !=
02592         TQueryDescription::kSessionQueryRunning) ) {
02593       fTotal->SetText(" Estimated time left : 0 sec (0 events of 0 processed)        ");
02594       fRate->SetText(" Processing Rate : 0.0f events/sec   ");
02595       frmProg->Reset();
02596       fFB->Layout();
02597       return;
02598    }
02599 
02600    if (total < 0)
02601       total = fPrevTotal;
02602    else
02603       fPrevTotal = total;
02604 
02605    // if no change since last call, just return
02606    if (fPrevProcessed == processed)
02607       return;
02608    TString buf;
02609 
02610    // Update informations at first call
02611    if (fEntries != total) {
02612       buf.Form("PROOF cluster : \"%s\" - %d worker nodes",
02613                fViewer->GetActDesc()->fProof->GetMaster(),
02614                fViewer->GetActDesc()->fProof->GetParallel());
02615       fLabInfos->SetText(buf);
02616 
02617       fEntries = total;
02618       buf.Form(" %d files, %lld events, starting event %lld",
02619                fFiles, fEntries, fFirst);
02620       fLabStatus->SetText(buf);
02621    }
02622 
02623    // compute progress bar position and update
02624    Float_t pos = (Float_t)((Double_t)(processed * 100)/(Double_t)total);
02625    frmProg->SetPosition(pos);
02626    // if 100%, stop animation and set icon to "connected"
02627    if (pos >= 100.0) {
02628       fViewer->SetChangePic(kFALSE);
02629       fViewer->ChangeRightLogo("monitor01.xpm");
02630    }
02631 
02632    // get current time
02633    if ((fViewer->GetActDesc()->fActQuery->fStatus ==
02634         TQueryDescription::kSessionQueryRunning) ||
02635        (fViewer->GetActDesc()->fActQuery->fStatus ==
02636         TQueryDescription::kSessionQuerySubmitted))
02637       fViewer->GetActDesc()->fActQuery->fEndTime = gSystem->Now();
02638    TTime tdiff = fViewer->GetActDesc()->fActQuery->fEndTime -
02639                  fViewer->GetActDesc()->fActQuery->fStartTime;
02640    Float_t eta = 0;
02641    if (processed)
02642       eta = ((Float_t)((Long64_t)tdiff)*total/Float_t(processed) -
02643             Long64_t(tdiff))/1000.;
02644 
02645    tt = (Long_t)eta;
02646    if (tt > 0) {
02647       hh = (UInt_t)(tt / 3600);
02648       mm = (UInt_t)((tt % 3600) / 60);
02649       ss = (UInt_t)((tt % 3600) % 60);
02650    }
02651    if (hh)
02652       stm.Form("%d h %d min %d sec", hh, mm, ss);
02653    else if (mm)
02654       stm.Form("%d min %d sec", mm, ss);
02655    else
02656       stm.Form("%d sec", ss);
02657    if (processed == total) {
02658       // finished
02659       tt = (Long_t) Long64_t(tdiff)/1000;
02660       if (tt > 0) {
02661          hh = (UInt_t)(tt / 3600);
02662          mm = (UInt_t)((tt % 3600) / 60);
02663          ss = (UInt_t)((tt % 3600) % 60);
02664       }
02665       if (hh)
02666          stm.Form("%d h %d min %d sec", hh, mm, ss);
02667       else if (mm)
02668          stm.Form("%d min %d sec", mm, ss);
02669       else
02670          stm.Form("%d sec", ss);
02671       buf.Form(" Processed : %lld events in %s", total, stm.Data());
02672       fTotal->SetText(buf.Data());
02673    } else {
02674       // update status infos
02675       buf.Form(" Estimated time left : %s (%lld events of %lld processed)        ",
02676                stm.Data(), processed, total);
02677       fTotal->SetText(buf.Data());
02678    }
02679    if (processed > 0 && (Long64_t)tdiff > 0) {
02680       buf.Form(" Processing Rate : %.1f events/sec   ",
02681                (Float_t)processed/(Long64_t)tdiff*1000.);
02682       fRate->SetText(buf);
02683    }
02684    fPrevProcessed = processed;
02685 
02686    fFB->Layout();
02687 }
02688 
02689 //______________________________________________________________________________
02690 void TSessionQueryFrame::Progress(Long64_t total, Long64_t processed,
02691                                   Long64_t /*bytesread*/ , Float_t /*initTime*/,
02692                                   Float_t /*procTime*/, Float_t /*evtrti*/,
02693                                   Float_t /*mbrti*/)
02694 {
02695    // New version of Progress (just forward to the old version
02696    // for the time being).
02697 
02698    Progress(total, processed);
02699 }
02700 
02701 //______________________________________________________________________________
02702 void TSessionQueryFrame::ProgressLocal(Long64_t total, Long64_t processed)
02703 {
02704    // Update progress bar and status labels.
02705 
02706    Long_t tt;
02707    UInt_t hh=0, mm=0, ss=0;
02708    TString stm;
02709    TString cproc;
02710    Int_t status;
02711 
02712    switch (fViewer->GetActDesc()->fActQuery->fStatus) {
02713 
02714       case TQueryDescription::kSessionQueryAborted:
02715          cproc = " - ABORTED";
02716          status = kAborted;
02717          break;
02718       case TQueryDescription::kSessionQueryStopped:
02719          cproc = " - STOPPED";
02720          status = kStopped;
02721          break;
02722       case TQueryDescription::kSessionQueryRunning:
02723          cproc = " ";
02724          status = kRunning;
02725          break;
02726       case TQueryDescription::kSessionQueryCompleted:
02727       case TQueryDescription::kSessionQueryFinalized:
02728          cproc = " ";
02729          status = kDone;
02730          break;
02731       default:
02732          status = -1;
02733          break;
02734    }
02735    if (processed < 0) processed = 0;
02736 
02737    frmProg->SetBarColor("green");
02738    if (status == kAborted)
02739       frmProg->SetBarColor("red");
02740    else if (status == kStopped)
02741       frmProg->SetBarColor("yellow");
02742    else if (status == -1 ) {
02743       fTotal->SetText(" Estimated time left : 0 sec (0 events of 0 processed)        ");
02744       fRate->SetText(" Processing Rate : 0.0f events/sec   ");
02745       frmProg->Reset();
02746       fFB->Layout();
02747       return;
02748    }
02749 
02750    if (total < 0)
02751       total = fPrevTotal;
02752    else
02753       fPrevTotal = total;
02754 
02755    // if no change since last call, just return
02756    TString buf;
02757 
02758    // Update informations at first call
02759    if (fEntries != total) {
02760       fLabInfos->SetText("Local Session");
02761 
02762       fEntries = total;
02763       buf.Form(" %d files, %lld events, starting event %lld",
02764                fFiles, fEntries, fFirst);
02765       fLabStatus->SetText(buf.Data());
02766    }
02767 
02768    // compute progress bar position and update
02769    Float_t pos = 0.0;
02770    if (processed > 0 && total > 0)
02771       pos = (Float_t)((Double_t)(processed * 100)/(Double_t)total);
02772    frmProg->SetPosition(pos);
02773    // if 100%, stop animation and set icon to "connected"
02774    if (pos >= 100.0) {
02775       fViewer->SetChangePic(kFALSE);
02776       fViewer->ChangeRightLogo("monitor01.xpm");
02777    }
02778 
02779    // get current time
02780    if (status == kRunning)
02781       fViewer->GetActDesc()->fActQuery->fEndTime = gSystem->Now();
02782    TTime tdiff = fViewer->GetActDesc()->fActQuery->fEndTime -
02783                  fViewer->GetActDesc()->fActQuery->fStartTime;
02784    Float_t eta = 0;
02785    if (processed)
02786       eta = ((Float_t)((Long64_t)tdiff)*total/(Float_t)(processed) -
02787             (Long64_t)(tdiff))/1000.;
02788 
02789    tt = (Long_t)eta;
02790    if (tt > 0) {
02791       hh = (UInt_t)(tt / 3600);
02792       mm = (UInt_t)((tt % 3600) / 60);
02793       ss = (UInt_t)((tt % 3600) % 60);
02794    }
02795    if (hh)
02796       stm = TString::Format("%d h %d min %d sec", hh, mm, ss);
02797    else if (mm)
02798       stm = TString::Format("%d min %d sec", mm, ss);
02799    else
02800       stm = TString::Format("%d sec", ss);
02801    if ((processed != total) && (status == kRunning)) {
02802       // update status infos
02803       buf.Form(" Estimated time left : %s (%lld events of %lld processed)        ",
02804                stm.Data(), processed, total);
02805       fTotal->SetText(buf);
02806    } else {
02807       tt = (Long_t) Long64_t(tdiff)/1000;
02808       if (tt > 0) {
02809          hh = (UInt_t)(tt / 3600);
02810          mm = (UInt_t)((tt % 3600) / 60);
02811          ss = (UInt_t)((tt % 3600) % 60);
02812       }
02813       if (hh)
02814          stm = TString::Format("%d h %d min %d sec", hh, mm, ss);
02815       else if (mm)
02816          stm = TString::Format("%d min %d sec", mm, ss);
02817       else
02818          stm = TString::Format("%d sec", ss);
02819       buf.Form(" Processed : %ld events in %s",
02820                (Long_t)processed, stm.Data());
02821       buf += cproc;
02822       fTotal->SetText(buf.Data());
02823    }
02824    if (processed > 0 && (Long64_t)tdiff > 0) {
02825       buf.Form(" Processing Rate : %.1f events/sec   ",
02826                (Float_t)processed/(Long64_t)tdiff*1000.);
02827       fRate->SetText(buf.Data());
02828    }
02829    fPrevProcessed = processed;
02830 
02831    fFB->Layout();
02832 }
02833 
02834 //______________________________________________________________________________
02835 void TSessionQueryFrame::IndicateStop(Bool_t aborted)
02836 {
02837    // Indicate that Cancel or Stop was clicked.
02838 
02839    if (aborted == kTRUE) {
02840       // Aborted
02841       frmProg->SetBarColor("red");
02842    }
02843    else {
02844       // Stopped
02845       frmProg->SetBarColor("yellow");
02846    }
02847    // disconnect progress related signals
02848    if (fViewer->GetActDesc()->fProof &&
02849        fViewer->GetActDesc()->fProof->IsValid()) {
02850       fViewer->GetActDesc()->fProof->Disconnect("Progress(Long64_t,Long64_t)",
02851                this, "Progress(Long64_t,Long64_t)");
02852       fViewer->GetActDesc()->fProof->Disconnect("Progress(Long64_t,Long64_t,Long64_t,Float_t,Float_t,Float_t,Float_t)",
02853                this, "Progress(Long64_t,Long64_t,Long64_t,Float_t,Float_t,Float_t,Float_t)");
02854       fViewer->GetActDesc()->fProof->Disconnect("StopProcess(Bool_t)", this,
02855                "IndicateStop(Bool_t)");
02856    }
02857 }
02858 
02859 //______________________________________________________________________________
02860 void TSessionQueryFrame::ResetProgressDialog(const char * /*selector*/, Int_t files,
02861                                         Long64_t first, Long64_t entries)
02862 {
02863    // Reset progress frame information fields.
02864 
02865    TString buf;
02866    fFiles         = files > 0 ? files : 0;
02867    fFirst         = first;
02868    fEntries       = entries;
02869    fPrevProcessed = 0;
02870    fPrevTotal     = 0;
02871 
02872    if (!fViewer->GetActDesc()->fLocal) {
02873       frmProg->SetBarColor("green");
02874       frmProg->Reset();
02875    }
02876 
02877    buf.Form("%0d files, %0lld events, starting event %0lld",
02878             fFiles > 0 ? fFiles : 0, fEntries > 0 ? fEntries : 0,
02879             fFirst >= 0 ? fFirst : 0);
02880    fLabStatus->SetText(buf.Data());
02881    // Reconnect the slots
02882    if (fViewer->GetActDesc()->fProof &&
02883        fViewer->GetActDesc()->fProof->IsValid()) {
02884       fViewer->GetActDesc()->fProof->Connect("Progress(Long64_t,Long64_t)",
02885                "TSessionQueryFrame", this, "Progress(Long64_t,Long64_t)");
02886       fViewer->GetActDesc()->fProof->Connect("Progress(Long64_t,Long64_t,Long64_t,Float_t,Float_t,Float_t,Float_t)",
02887                "TSessionQueryFrame", this,
02888                "Progress(Long64_t,Long64_t,Long64_t,Float_t,Float_t,Float_t,Float_t)");
02889       fViewer->GetActDesc()->fProof->Connect("StopProcess(Bool_t)",
02890                "TSessionQueryFrame", this, "IndicateStop(Bool_t)");
02891       buf.Form("PROOF cluster : \"%s\" - %d worker nodes",
02892                 fViewer->GetActDesc()->fProof->GetMaster(),
02893                 fViewer->GetActDesc()->fProof->GetParallel());
02894       fLabInfos->SetText(buf.Data());
02895    }
02896    else if (fViewer->GetActDesc()->fLocal) {
02897       fStatsCanvas->Clear();
02898       fLabInfos->SetText("Local Session");
02899       fLabStatus->SetText(" ");
02900    }
02901    else {
02902       fLabInfos->SetText(" ");
02903       fLabStatus->SetText(" ");
02904    }
02905    fFB->Layout();
02906 }
02907 
02908 //______________________________________________________________________________
02909 void TSessionQueryFrame::OnBtnFinalize()
02910 {
02911    // Finalize query.
02912 
02913    // check if Proof is valid
02914    if (fViewer->GetActDesc()->fProof &&
02915        fViewer->GetActDesc()->fProof->IsValid()) {
02916       gPad->SetEditable(kFALSE);
02917       TGListTreeItem *item = fViewer->GetSessionHierarchy()->GetSelected();
02918       if (!item) return;
02919       TObject *obj = (TObject *)item->GetUserData();
02920       if (obj->IsA() == TQueryDescription::Class()) {
02921          // as it can take time, set watch cursor
02922          gVirtualX->SetCursor(GetId(),gVirtualX->CreateCursor(kWatch));
02923          TQueryDescription *query = (TQueryDescription *)obj;
02924          fViewer->GetActDesc()->fProof->Finalize(query->fReference);
02925          UpdateButtons(query);
02926          // restore cursor
02927          gVirtualX->SetCursor(GetId(), 0);
02928       }
02929    }
02930    if (fViewer->GetActDesc()->fLocal) {
02931       gPad->SetEditable(kFALSE);
02932       TChain *chain = (TChain *)fViewer->GetActDesc()->fActQuery->fChain;
02933       if (chain)
02934          ((TTreePlayer *)(chain->GetPlayer()))->GetSelectorFromFile()->Terminate();
02935    }
02936 }
02937 
02938 //______________________________________________________________________________
02939 void TSessionQueryFrame::OnBtnStop()
02940 {
02941    // Stop processing query.
02942 
02943    // check for proof validity
02944    if (fViewer->GetActDesc()->fProof &&
02945        fViewer->GetActDesc()->fProof->IsValid()) {
02946       fViewer->GetActDesc()->fProof->StopProcess(kFALSE);
02947    }
02948    if (fViewer->GetActDesc()->fLocal) {
02949       gROOT->SetInterrupt();
02950       fViewer->GetActDesc()->fActQuery->fStatus =
02951          TQueryDescription::kSessionQueryStopped;
02952    }
02953    // stop icon animation and set connected icon
02954    fViewer->ChangeRightLogo("monitor01.xpm");
02955    fViewer->SetChangePic(kFALSE);
02956 }
02957 
02958 //______________________________________________________________________________
02959 void TSessionQueryFrame::OnBtnShowLog()
02960 {
02961    // Show query log.
02962 
02963    TGListTreeItem *item = fViewer->GetSessionHierarchy()->GetSelected();
02964    if (!item) return;
02965    TObject *obj = (TObject *)item->GetUserData();
02966    if (obj->IsA() != TQueryDescription::Class())
02967       return;
02968    TQueryDescription *query = (TQueryDescription *)obj;
02969    fViewer->ShowLog(query->fReference.Data());
02970 }
02971 
02972 //______________________________________________________________________________
02973 void TSessionQueryFrame::OnBtnRetrieve()
02974 {
02975    // Retrieve query.
02976 
02977    // check for proof validity
02978    if (fViewer->GetActDesc()->fAttached &&
02979        fViewer->GetActDesc()->fProof &&
02980        fViewer->GetActDesc()->fProof->IsValid()) {
02981       TGListTreeItem *item = fViewer->GetSessionHierarchy()->GetSelected();
02982       if (!item) return;
02983       TObject *obj = (TObject *)item->GetUserData();
02984       if (obj->IsA() == TQueryDescription::Class()) {
02985          // as it can take time, set watch cursor
02986          gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kWatch));
02987          TQueryDescription *query = (TQueryDescription *)obj;
02988          Int_t rc = fViewer->GetActDesc()->fProof->Retrieve(query->fReference);
02989          if (rc == 0)
02990             fViewer->OnCascadeMenu();
02991          // restore cursor
02992          gVirtualX->SetCursor(GetId(), 0);
02993       }
02994    }
02995    if (fViewer->GetActDesc()->fLocal) {
02996       TGListTreeItem *item=0, *item2=0;
02997       item = fViewer->GetSessionHierarchy()->FindItemByObj(fViewer->GetSessionItem(),
02998                                                            fViewer->GetActDesc());
02999       if (item) {
03000          item2 = fViewer->GetSessionHierarchy()->FindItemByObj(item,
03001                                     fViewer->GetActDesc()->fActQuery);
03002       }
03003       if (item2) {
03004          // add input and output list entries
03005          TChain *chain = (TChain *)fViewer->GetActDesc()->fActQuery->fChain;
03006          if (chain) {
03007             TSelector *selector = ((TTreePlayer *)(chain->GetPlayer()))->GetSelectorFromFile();
03008             if (selector) {
03009                TList *objlist = selector->GetOutputList();
03010                if (objlist)
03011                   if (!fViewer->GetSessionHierarchy()->FindChildByName(item2, "OutputList"))
03012                      fViewer->GetSessionHierarchy()->AddItem(item2, "OutputList");
03013             }
03014          }
03015       }
03016       // update list tree, query frame informations, and buttons state
03017       fViewer->GetSessionHierarchy()->ClearViewPort();
03018       fClient->NeedRedraw(fViewer->GetSessionHierarchy());
03019       UpdateInfos();
03020       UpdateButtons(fViewer->GetActDesc()->fActQuery);
03021    }
03022 }
03023 
03024 //______________________________________________________________________________
03025 void TSessionQueryFrame::OnBtnAbort()
03026 {
03027    // Abort processing query.
03028 
03029    // check for proof validity
03030    if (fViewer->GetActDesc()->fProof &&
03031        fViewer->GetActDesc()->fProof->IsValid()) {
03032       fViewer->GetActDesc()->fProof->StopProcess(kTRUE);
03033    }
03034    if (fViewer->GetActDesc()->fLocal) {
03035       gROOT->SetInterrupt();
03036       fViewer->GetActDesc()->fActQuery->fStatus =
03037          TQueryDescription::kSessionQueryAborted;
03038    }
03039    // stop icon animation and set connected icon
03040    fViewer->ChangeRightLogo("monitor01.xpm");
03041    fViewer->SetChangePic(kFALSE);
03042 }
03043 
03044 //______________________________________________________________________________
03045 void TSessionQueryFrame::OnBtnSubmit()
03046 {
03047    // Submit query.
03048 
03049    Int_t retval;
03050    Long64_t id = 0;
03051    TGListTreeItem *item = fViewer->GetSessionHierarchy()->GetSelected();
03052    if (!item) return;
03053    // retrieve query description attached to list tree item
03054    TObject *obj = (TObject *)item->GetUserData();
03055    if (obj->IsA() != TQueryDescription::Class())
03056       return;
03057    TQueryDescription *newquery = (TQueryDescription *)obj;
03058    // reset progress informations
03059    ResetProgressDialog(newquery->fSelectorString,
03060          newquery->fNbFiles, newquery->fFirstEntry, newquery->fNoEntries);
03061    // set query start time
03062    newquery->fStartTime = gSystem->Now();
03063    fViewer->GetActDesc()->fNbHistos = 0;
03064    // check for proof validity
03065    if (fViewer->GetActDesc()->fProof &&
03066        fViewer->GetActDesc()->fProof->IsValid()) {
03067       fViewer->GetActDesc()->fProof->SetBit(TProof::kUsingSessionGui);
03068       // set query description status to submitted
03069       newquery->fStatus = TQueryDescription::kSessionQuerySubmitted;
03070       // if feedback option selected
03071       if (fViewer->GetOptionsMenu()->IsEntryChecked(kOptionsFeedback)) {
03072          Int_t i = 0;
03073          // browse list of feedback histos and check user's selected ones
03074          while (kFeedbackHistos[i]) {
03075             if (fViewer->GetCascadeMenu()->IsEntryChecked(41+i)) {
03076                fViewer->GetActDesc()->fProof->AddFeedback(kFeedbackHistos[i]);
03077                fViewer->GetActDesc()->fNbHistos++;
03078             }
03079             i++;
03080          }
03081          // connect feedback signal
03082          fViewer->GetActDesc()->fProof->Connect("Feedback(TList *objs)",
03083                            "TSessionQueryFrame", fViewer->GetQueryFrame(),
03084                            "Feedback(TList *objs)");
03085          gROOT->Time();
03086       }
03087       else {
03088          // if feedback option not selected, clear Proof's feedback option
03089          fViewer->GetActDesc()->fProof->ClearFeedback();
03090       }
03091       // set current proof session
03092       fViewer->GetActDesc()->fProof->cd();
03093       // check if parameter file has been specified
03094       if (newquery->fChain) {
03095          if (fViewer->GetActDesc()->fProof->IsLite()) {
03096             newquery->fOptions = "";
03097          }
03098          // set query reference id
03099          newquery->fReference= TString::Format("session-%s:q%d",
03100                             fViewer->GetActDesc()->fProof->GetSessionTag(),
03101                             fViewer->GetActDesc()->fProof->GetSeqNum()+1);
03102          if (newquery->fChain->IsA() == TChain::Class()) {
03103             // TChain case
03104             newquery->fStatus = TQueryDescription::kSessionQuerySubmitted;
03105             ((TChain *)newquery->fChain)->SetProof(fViewer->GetActDesc()->fProof);
03106             id = ((TChain *)newquery->fChain)->Process(newquery->fSelectorString,
03107                     newquery->fOptions,
03108                     newquery->fNoEntries > 0 ? newquery->fNoEntries : 1234567890,
03109                     newquery->fFirstEntry);
03110          }
03111          else if (newquery->fChain->IsA() == TDSet::Class()) {
03112             // TDSet case
03113             newquery->fStatus = TQueryDescription::kSessionQuerySubmitted;
03114             id = ((TDSet *)newquery->fChain)->Process(newquery->fSelectorString,
03115                   newquery->fOptions,
03116                   newquery->fNoEntries,
03117                   newquery->fFirstEntry);
03118          }
03119       }
03120       else {
03121          Error("Submit", "No TChain defined; skipping");
03122          newquery->fStatus = TQueryDescription::kSessionQueryCreated;
03123          return;
03124       }
03125       // set query reference id to unique identifier
03126       newquery->fReference= TString::Format("session-%s:q%lld",
03127                             fViewer->GetActDesc()->fProof->GetSessionTag(), id);
03128       // start icon animation
03129       fViewer->SetChangePic(kTRUE);
03130    }
03131    else if (fViewer->GetActDesc()->fLocal) { // local session case
03132       // if feedback option selected
03133       if (fViewer->GetOptionsMenu()->IsEntryChecked(kOptionsFeedback)) {
03134          Int_t i = 0;
03135          // browse list of feedback histos and check user's selected ones
03136          while (kFeedbackHistos[i]) {
03137             if (fViewer->GetCascadeMenu()->IsEntryChecked(41+i)) {
03138                fViewer->GetActDesc()->fNbHistos++;
03139             }
03140             i++;
03141          }
03142       }
03143       if (newquery->fChain) {
03144          if (newquery->fChain->IsA() == TChain::Class()) {
03145             // TChain case
03146             newquery->fStatus = TQueryDescription::kSessionQueryRunning;
03147             fViewer->EnableTimer();
03148             UpdateButtons(newquery);
03149             gPad->SetEditable(kFALSE);
03150             ((TChain *)newquery->fChain)->SetTimerInterval(100);
03151             id = ((TChain *)newquery->fChain)->Process(newquery->fSelectorString,
03152                   newquery->fOptions,
03153                   newquery->fNoEntries > 0 ? newquery->fNoEntries : 1234567890,
03154                   newquery->fFirstEntry);
03155             ((TChain *)newquery->fChain)->SetTimerInterval(0);
03156             OnBtnRetrieve();
03157             TChain *chain = (TChain *)newquery->fChain;
03158             ProgressLocal(chain->GetEntries(),
03159                           chain->GetReadEntry()+1);
03160             if ((newquery->fStatus != TQueryDescription::kSessionQueryAborted) &&
03161                 (newquery->fStatus != TQueryDescription::kSessionQueryStopped))
03162                newquery->fStatus = TQueryDescription::kSessionQueryCompleted;
03163             UpdateButtons(newquery);
03164          }
03165          else {
03166             new TGMsgBox(fClient->GetRoot(), this, "Error Submitting Query",
03167                          "Only TChains are allowed in Local Session (no TDSet) !",
03168                           kMBIconExclamation,kMBOk,&retval);
03169          }
03170       }
03171       else {
03172          Error("Submit", "No TChain defined; skipping");
03173          newquery->fStatus = TQueryDescription::kSessionQueryCreated;
03174          return;
03175       }
03176       // set query reference id to unique identifier
03177       newquery->fReference = TString::Format("local-session-%s:q%lld", newquery->fQueryName.Data(), id);
03178    }
03179    // update buttons state
03180    UpdateButtons(newquery);
03181 }
03182 
03183 //______________________________________________________________________________
03184 void TSessionQueryFrame::UpdateButtons(TQueryDescription *desc)
03185 {
03186    // Update buttons state for the current query status.
03187 
03188    TGListTreeItem *item = fViewer->GetSessionHierarchy()->GetSelected();
03189    if (!item) return;
03190    // retrieve query description attached to list tree item
03191    TObject *obj = (TObject *)item->GetUserData();
03192    if (obj->IsA() != TQueryDescription::Class())
03193       return;
03194    TQueryDescription *query = (TQueryDescription *)obj;
03195    if (desc != query) return;
03196 
03197    Bool_t submit_en = kFALSE;
03198    if ((fViewer->GetActDesc()->fProof &&
03199        fViewer->GetActDesc()->fProof->IsValid()) ||
03200        fViewer->GetActDesc()->fLocal)
03201       submit_en = kTRUE;
03202 
03203    switch (desc->fStatus) {
03204       case TQueryDescription::kSessionQueryFromProof:
03205          fBtnSubmit->SetEnabled(submit_en);
03206          fBtnFinalize->SetEnabled(kTRUE);
03207          fBtnStop->SetEnabled(kFALSE);
03208          fBtnAbort->SetEnabled(kFALSE);
03209          fBtnShowLog->SetEnabled(kTRUE);
03210          fBtnRetrieve->SetEnabled(kTRUE);
03211          break;
03212 
03213       case TQueryDescription::kSessionQueryCompleted:
03214          fBtnSubmit->SetEnabled(submit_en);
03215          fBtnFinalize->SetEnabled(kTRUE);
03216          if (((desc->fResult == 0) || (desc->fResult &&
03217               (desc->fResult->IsFinalized() ||
03218               (desc->fResult->GetInputObject("TDSet") == 0)))) &&
03219               !(fViewer->GetActDesc()->fLocal))
03220             fBtnFinalize->SetEnabled(kFALSE);
03221          fBtnStop->SetEnabled(kFALSE);
03222          fBtnAbort->SetEnabled(kFALSE);
03223          fBtnShowLog->SetEnabled(kTRUE);
03224          fBtnRetrieve->SetEnabled(kTRUE);
03225          break;
03226 
03227       case TQueryDescription::kSessionQueryCreated:
03228          fBtnSubmit->SetEnabled(submit_en);
03229          fBtnFinalize->SetEnabled(kFALSE);
03230          fBtnStop->SetEnabled(kFALSE);
03231          fBtnAbort->SetEnabled(kFALSE);
03232          fBtnShowLog->SetEnabled(kTRUE);
03233          fBtnRetrieve->SetEnabled(kFALSE);
03234          break;
03235 
03236       case TQueryDescription::kSessionQuerySubmitted:
03237          fBtnSubmit->SetEnabled(kFALSE);
03238          fBtnFinalize->SetEnabled(kFALSE);
03239          fBtnStop->SetEnabled(kTRUE);
03240          fBtnAbort->SetEnabled(kTRUE);
03241          fBtnShowLog->SetEnabled(kTRUE);
03242          fBtnRetrieve->SetEnabled(kFALSE);
03243          break;
03244 
03245       case TQueryDescription::kSessionQueryRunning:
03246          fBtnSubmit->SetEnabled(kFALSE);
03247          fBtnFinalize->SetEnabled(kFALSE);
03248          fBtnStop->SetEnabled(kTRUE);
03249          fBtnAbort->SetEnabled(kTRUE);
03250          fBtnShowLog->SetEnabled(kTRUE);
03251          fBtnRetrieve->SetEnabled(kFALSE);
03252          break;
03253 
03254       case TQueryDescription::kSessionQueryStopped:
03255          fBtnSubmit->SetEnabled(submit_en);
03256          fBtnFinalize->SetEnabled(kTRUE);
03257          fBtnStop->SetEnabled(kFALSE);
03258          fBtnAbort->SetEnabled(kFALSE);
03259          fBtnShowLog->SetEnabled(kTRUE);
03260          fBtnRetrieve->SetEnabled(kTRUE);
03261          break;
03262 
03263       case TQueryDescription::kSessionQueryAborted:
03264          fBtnSubmit->SetEnabled(submit_en);
03265          fBtnFinalize->SetEnabled(kFALSE);
03266          fBtnStop->SetEnabled(kFALSE);
03267          fBtnAbort->SetEnabled(kFALSE);
03268          fBtnShowLog->SetEnabled(kTRUE);
03269          fBtnRetrieve->SetEnabled(kFALSE);
03270          break;
03271 
03272       case TQueryDescription::kSessionQueryFinalized:
03273          fBtnSubmit->SetEnabled(submit_en);
03274          fBtnFinalize->SetEnabled(kFALSE);
03275          fBtnStop->SetEnabled(kFALSE);
03276          fBtnAbort->SetEnabled(kFALSE);
03277          fBtnShowLog->SetEnabled(kTRUE);
03278          fBtnRetrieve->SetEnabled(kFALSE);
03279          break;
03280 
03281       default:
03282          break;
03283    }
03284    if (fViewer->GetActDesc()->fLocal &&
03285        !(fViewer->GetActDesc()->fActQuery->fChain)) {
03286       fBtnFinalize->SetEnabled(kFALSE);
03287       fBtnRetrieve->SetEnabled(kFALSE);
03288    }
03289 }
03290 
03291 //______________________________________________________________________________
03292 void TSessionQueryFrame::UpdateInfos()
03293 {
03294    // Update query information (header) text view.
03295 
03296    TString buffer;
03297    const char *qst[] = {"aborted  ", "submitted", "running  ",
03298                         "stopped  ", "completed"};
03299 
03300    if (fViewer->GetActDesc()->fActQuery)
03301       fFD->UpdateFields(fViewer->GetActDesc()->fActQuery);
03302 
03303    if (fViewer->GetActDesc()->fLocal ||
03304       (fViewer->GetActDesc()->fConnected &&
03305        fViewer->GetActDesc()->fAttached &&
03306        fViewer->GetActDesc()->fProof &&
03307        fViewer->GetActDesc()->fProof->IsValid())) {
03308       fBtnSave->SetText("         Submit         ");
03309    }
03310    else {
03311       fBtnSave->SetText("     Apply changes      ");
03312    }
03313    fClient->NeedRedraw(fBtnSave);
03314    fInfoTextView->Clear();
03315    if (!fViewer->GetActDesc()->fActQuery ||
03316        !fViewer->GetActDesc()->fActQuery->fResult) {
03317       ResetProgressDialog("", 0, 0, 0);
03318       if (fViewer->GetActDesc()->fLocal) {
03319          if (fViewer->GetActDesc()->fActQuery) {
03320             TChain *chain = (TChain *)fViewer->GetActDesc()->fActQuery->fChain;
03321             if (chain) {
03322                ProgressLocal(chain->GetEntries(),
03323                              chain->GetReadEntry()+1);
03324             }
03325             else {
03326                ProgressLocal(0, 0);
03327             }
03328             UpdateButtons(fViewer->GetActDesc()->fActQuery);
03329          }
03330       }
03331       else {
03332          fTotal->SetText(" Estimated time left : 0 sec (0 events of 0 processed)        ");
03333          fRate->SetText(" Processing Rate : 0.0f events/sec   ");
03334          frmProg->Reset();
03335          fFB->Layout();
03336       }
03337       return;
03338    }
03339    TQueryResult *result = fViewer->GetActDesc()->fActQuery->fResult;
03340 
03341    // Status label
03342    Int_t st = (result->GetStatus() > 0 && result->GetStatus() <=
03343                TQueryResult::kCompleted) ? result->GetStatus() : 0;
03344 
03345    Int_t qry = result->GetSeqNum();
03346 
03347    buffer = TString::Format("------------------------------------------------------\n");
03348    // Print header
03349    if (!result->IsDraw()) {
03350       const char *fin = result->IsFinalized() ? "finalized" : qst[st];
03351       const char *arc = result->IsArchived() ? "(A)" : "";
03352       buffer = TString::Format(" Query No  : %d\n", qry);
03353       buffer += TString::Format(" Ref       : \"%s:%s\"\n", result->GetTitle(),
03354                                 result->GetName());
03355       buffer += TString::Format(" Selector  : %s\n",
03356                                 result->GetSelecImp()->GetTitle());
03357       buffer += TString::Format("Status    : %9s%s\n", fin, arc);
03358       buffer += TString::Format("------------------------------------------------------\n");
03359    } else {
03360       buffer += TString::Format(" Query No  : %d\n", qry);
03361       buffer += TString::Format(" Ref       : \"%s:%s\"\n", result->GetTitle(),
03362                                 result->GetName());
03363       buffer += TString::Format(" Selector  : %s\n",
03364                                 result->GetSelecImp()->GetTitle());
03365       buffer += TString::Format("------------------------------------------------------\n");
03366    }
03367 
03368    // Time information
03369    Int_t elapsed = (Int_t)(result->GetEndTime().Convert() -
03370                            result->GetStartTime().Convert());
03371    buffer += TString::Format(" Started   : %s\n",
03372                              result->GetStartTime().AsString());
03373    buffer += TString::Format(" Real time : %d sec (CPU time: %.1f sec)\n",
03374                              elapsed, result->GetUsedCPU());
03375 
03376    // Number of events processed, rate, size
03377    Double_t rate = 0.0;
03378    if (result->GetEntries() > -1 && elapsed > 0)
03379       rate = result->GetEntries() / (Double_t)elapsed ;
03380    Float_t size = ((Float_t)result->GetBytes())/(1024*1024);
03381    buffer += TString::Format(" Processed : %lld events (size: %.3f MBs)\n",
03382                              result->GetEntries(), size);
03383    buffer += TString::Format(" Rate      : %.1f evts/sec\n", rate);
03384 
03385    // Package information
03386    if (strlen(result->GetParList()) > 1) {
03387       buffer += TString::Format(" Packages  :  %s\n", result->GetParList());
03388    }
03389 
03390    // Result information
03391    TString res = result->GetResultFile();
03392    if (!result->IsArchived()) {
03393       Int_t dq = res.Index("queries");
03394       if (dq > -1) {
03395          res.Remove(0,res.Index("queries"));
03396          res.Insert(0,"<PROOF_SandBox>/");
03397       }
03398       if (res.BeginsWith("-")) {
03399          res = (result->GetStatus() == TQueryResult::kAborted) ?
03400                "not available" : "sent to client";
03401       }
03402    }
03403    if (res.Length() > 1) {
03404       buffer += TString::Format("------------------------------------------------------\n");
03405       buffer += TString::Format(" Results   : %s\n", res.Data());
03406    }
03407 
03408    if (result->GetOutputList() && result->GetOutputList()->GetSize() > 0) {
03409       buffer += TString::Format(" Outlist   : %d objects\n",
03410                                 result->GetOutputList()->GetSize());
03411       buffer += TString::Format("------------------------------------------------------\n");
03412    }
03413    fInfoTextView->LoadBuffer(buffer.Data());
03414 
03415    //Float_t pos = Float_t((Double_t)(result->GetEntries() * 100)/(Double_t)total);
03416    if (result->GetStatus() == TQueryResult::kAborted)
03417       frmProg->SetBarColor("red");
03418    else if (result->GetStatus() == TQueryResult::kStopped)
03419       frmProg->SetBarColor("yellow");
03420    else
03421       frmProg->SetBarColor("green");
03422 
03423    frmProg->SetPosition(100.0);
03424 
03425    buffer = TString::Format(" Processed : %lld events in %.1f sec", result->GetEntries(),
03426                            (Float_t)elapsed);
03427    fTotal->SetText(buffer.Data());
03428    buffer = TString::Format(" Processing Rate : %.1f events/sec   ", rate);
03429    fRate->SetText(buffer.Data());
03430    fFB->Layout();
03431 }
03432 
03433 //////////////////////////////////////////////////////////////////////////////////////////
03434 // Output frame
03435 
03436 //______________________________________________________________________________
03437 TSessionOutputFrame::TSessionOutputFrame(TGWindow* p, Int_t w, Int_t h) :
03438    TGCompositeFrame(p, w, h), fLVContainer(0)
03439 {
03440    // Constructor.
03441 }
03442 
03443 //______________________________________________________________________________
03444 TSessionOutputFrame::~TSessionOutputFrame()
03445 {
03446    // Destructor.
03447 
03448    delete fLVContainer; // this container is inside the TGListView and is not
03449                         // deleted automatically
03450    Cleanup();
03451 }
03452 
03453 //______________________________________________________________________________
03454 void TSessionOutputFrame::Build(TSessionViewer *gui)
03455 {
03456    // Build query output information frame.
03457 
03458    fViewer = gui;
03459    SetLayoutManager(new TGVerticalLayout(this));
03460    SetCleanup(kDeepCleanup);
03461 
03462    // Container of object TGListView
03463    TGListView *frmListView = new TGListView(this, 340, 190);
03464    fLVContainer = new TGLVContainer(frmListView, kSunkenFrame, GetWhitePixel());
03465    fLVContainer->Associate(frmListView);
03466    fLVContainer->SetCleanup(kDeepCleanup);
03467    AddFrame(frmListView, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
03468          4, 4, 4, 4));
03469 
03470    frmListView->Connect("Clicked(TGLVEntry*, Int_t, Int_t, Int_t)",
03471          "TSessionOutputFrame", this,
03472          "OnElementClicked(TGLVEntry* ,Int_t, Int_t, Int_t)");
03473    frmListView->Connect("DoubleClicked(TGLVEntry*, Int_t, Int_t, Int_t)",
03474          "TSessionOutputFrame", this,
03475          "OnElementDblClicked(TGLVEntry* ,Int_t, Int_t, Int_t)");
03476 }
03477 
03478 //______________________________________________________________________________
03479 void TSessionOutputFrame::OnElementClicked(TGLVEntry* entry, Int_t btn, Int_t x,
03480                                            Int_t y)
03481 {
03482    // Handle mouse clicks on list view items.
03483 
03484    TObject *obj = (TObject *)entry->GetUserData();
03485    if ((obj) && (btn ==3)) {
03486       // if right button, popup context menu
03487       fViewer->GetContextMenu()->Popup(x, y, obj, (TBrowser *)0);
03488    }
03489 }
03490 
03491 //______________________________________________________________________________
03492 void TSessionOutputFrame::OnElementDblClicked(TGLVEntry* entry, Int_t , Int_t, Int_t)
03493 {
03494    // Handle double-clicks on list view items.
03495 
03496    char action[512];
03497    TString act;
03498    TObject *obj = (TObject *)entry->GetUserData();
03499    TString ext = obj->GetName();
03500    gPad->SetEditable(kFALSE);
03501    // check default action from root.mimes
03502    if (fClient->GetMimeTypeList()->GetAction(obj->IsA()->GetName(), action)) {
03503       act = TString::Format("((%s*)0x%lx)%s", obj->IsA()->GetName(), (Long_t)obj, action);
03504       if (act[0] == '!') {
03505          act.Remove(0, 1);
03506          gSystem->Exec(act.Data());
03507       } else {
03508          // do not allow browse
03509          if (!act.Contains("Browse"))
03510             gROOT->ProcessLine(act.Data());
03511       }
03512    }
03513 }
03514 
03515 //______________________________________________________________________________
03516 void TSessionOutputFrame::AddObject(TObject *obj)
03517 {
03518    // Add object to output list view.
03519 
03520    TGLVEntry *item;
03521    if (obj) {
03522       item = new TGLVEntry(fLVContainer, obj->GetName(), obj->IsA()->GetName());
03523       item->SetUserData(obj);
03524       fLVContainer->AddItem(item);
03525    }
03526 }
03527 
03528 //////////////////////////////////////////////////////////////////////////////////////////
03529 // Input Frame
03530 
03531 //______________________________________________________________________________
03532 TSessionInputFrame::TSessionInputFrame(TGWindow* p, Int_t w, Int_t h) :
03533    TGCompositeFrame(p, w, h), fLVContainer(0)
03534 {
03535    // Constructor.
03536 }
03537 
03538 //______________________________________________________________________________
03539 TSessionInputFrame::~TSessionInputFrame()
03540 {
03541    // Destructor.
03542 
03543    delete fLVContainer; // this container is inside the TGListView and is not
03544                         // deleted automatically
03545    Cleanup();
03546 }
03547 
03548 //______________________________________________________________________________
03549 void TSessionInputFrame::Build(TSessionViewer *gui)
03550 {
03551    // Build query input informations frame.
03552 
03553    fViewer = gui;
03554    SetLayoutManager(new TGVerticalLayout(this));
03555    SetCleanup(kDeepCleanup);
03556 
03557    // Container of object TGListView
03558    TGListView *frmListView = new TGListView(this, 340, 190);
03559    fLVContainer = new TGLVContainer(frmListView, kSunkenFrame, GetWhitePixel());
03560    fLVContainer->Associate(frmListView);
03561    fLVContainer->SetCleanup(kDeepCleanup);
03562    AddFrame(frmListView, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
03563          4, 4, 4, 4));
03564 }
03565 
03566 //______________________________________________________________________________
03567 void TSessionInputFrame::AddObject(TObject *obj)
03568 {
03569    // Add object to input list view.
03570 
03571    TGLVEntry *item;
03572    if (obj) {
03573       item = new TGLVEntry(fLVContainer, obj->GetName(), obj->IsA()->GetName());
03574       item->SetUserData(obj);
03575       fLVContainer->AddItem(item);
03576    }
03577 }
03578 
03579 //////////////////////////////////////////////////////////////////////////////////////////
03580 // Session Viewer Main Frame
03581 
03582 //______________________________________________________________________________
03583 TSessionViewer::TSessionViewer(const char *name, UInt_t w, UInt_t h) :
03584    TGMainFrame(gClient->GetRoot(), w, h), fSessionHierarchy(0), fSessionItem(0)
03585 {
03586    // Main Session viewer constructor.
03587 
03588    // only one session viewer allowed
03589    if (gSessionViewer)
03590       return;
03591    Build();
03592    SetWindowName(name);
03593    Resize(w, h);
03594    gSessionViewer = this;
03595 }
03596 
03597 //______________________________________________________________________________
03598 TSessionViewer::TSessionViewer(const char *name, Int_t x, Int_t y, UInt_t w,
03599                               UInt_t h) : TGMainFrame(gClient->GetRoot(), w, h),
03600                               fSessionHierarchy(0), fSessionItem(0)
03601 {
03602    // Main Session viewer constructor.
03603 
03604    // only one session viewer allowed
03605    if (gSessionViewer)
03606       return;
03607    Build();
03608    SetWindowName(name);
03609    Move(x, y);
03610    Resize(w, h);
03611    gSessionViewer = this;
03612 }
03613 
03614 //______________________________________________________________________________
03615 void TSessionViewer::ReadConfiguration(const char *filename)
03616 {
03617    // Read configuration file and populate list of sessions
03618    // list of queries and list of packages.
03619    // Read and set also global options as feedback histos.
03620 
03621    if (fViewerEnv)
03622       delete fViewerEnv;
03623    fViewerEnv = new TEnv();
03624 
03625    const char *fn = (filename && strlen(filename)) ? filename : fConfigFile.Data();
03626 
03627    fViewerEnv->ReadFile(fn, kEnvUser);
03628 
03629    Bool_t bval = (Bool_t)fViewerEnv->GetValue("Option.Feedback", 1);
03630    if (bval)
03631       fOptionsMenu->CheckEntry(kOptionsFeedback);
03632    else
03633       fOptionsMenu->UnCheckEntry(kOptionsFeedback);
03634 
03635    bval = (Bool_t)fViewerEnv->GetValue("Option.MasterHistos", 1);
03636    if (bval) {
03637       fOptionsMenu->CheckEntry(kOptionsStatsHist);
03638       gEnv->SetValue("Proof.StatsHist", 1);
03639    }
03640    else {
03641       fOptionsMenu->UnCheckEntry(kOptionsStatsHist);
03642       gEnv->SetValue("Proof.StatsHist", 0);
03643    }
03644    bval = (Bool_t)fViewerEnv->GetValue("Option.MasterEvents", 0);
03645    if (bval)
03646       fOptionsMenu->CheckEntry(kOptionsStatsTrace);
03647    else
03648       fOptionsMenu->UnCheckEntry(kOptionsStatsTrace);
03649    bval = (Bool_t)fViewerEnv->GetValue("Option.WorkerEvents", 0);
03650    if (bval)
03651       fOptionsMenu->CheckEntry(kOptionsSlaveStatsTrace);
03652    else
03653       fOptionsMenu->UnCheckEntry(kOptionsSlaveStatsTrace);
03654 
03655    Int_t i = 0;
03656    while (kFeedbackHistos[i]) {
03657       bval = (Bool_t)fViewerEnv->GetValue(Form("Option.%s",kFeedbackHistos[i]),
03658                                           i == 1 ? 1 : 0);
03659       if (bval)
03660          fCascadeMenu->CheckEntry(41+i);
03661       else
03662          fCascadeMenu->UnCheckEntry(41+i);
03663       i++;
03664    }
03665    TSessionDescription *proofDesc;
03666    fSessions->Delete();
03667    if (fSessionItem)
03668       fSessionHierarchy->DeleteChildren(fSessionItem);
03669    else
03670       fSessionItem = fSessionHierarchy->AddItem(0, "Sessions", fBaseIcon,
03671             fBaseIcon);
03672    // add local session description
03673    TGListTreeItem *item = fSessionHierarchy->AddItem(fSessionItem, "Local",
03674                                                      fLocal, fLocal);
03675    fSessionHierarchy->SetToolTipItem(item, "Local Session");
03676    TSessionDescription *localdesc = new TSessionDescription();
03677    localdesc->fTag = "";
03678    localdesc->fName = "Local";
03679    localdesc->fAddress = "Local";
03680    localdesc->fPort = 0;
03681    localdesc->fConfigFile = "";
03682    localdesc->fLogLevel = 0;
03683    localdesc->fUserName = "";
03684    localdesc->fQueries = new TList();
03685    localdesc->fPackages = new TList();
03686    localdesc->fActQuery = 0;
03687    localdesc->fProof = 0;
03688    localdesc->fProofMgr = 0;
03689    localdesc->fAttached = kFALSE;
03690    localdesc->fConnected = kFALSE;
03691    localdesc->fLocal = kTRUE;
03692    localdesc->fSync = kTRUE;
03693    localdesc->fAutoEnable = kFALSE;
03694    localdesc->fNbHistos = 0;
03695    item->SetUserData(localdesc);
03696    fSessions->Add((TObject *)localdesc);
03697    fActDesc = localdesc;
03698 
03699    SysInfo_t info;
03700    gSystem->GetSysInfo(&info);
03701    // if the machine has more than one CPU, add one PROOF lite session
03702    // (not supported on Windows yet)
03703    if (!info.fOS.Contains("Microsoft") && info.fCpus > 1) {
03704       // add proof lite session description
03705       item = fSessionHierarchy->AddItem(fSessionItem, "Lite",
03706                                         fProofDiscon, fProofDiscon);
03707       fSessionHierarchy->SetToolTipItem(item, "PROOF Lite");
03708       TSessionDescription *litedesc = new TSessionDescription();
03709       litedesc->fTag = "";
03710       litedesc->fName = "PROOF Lite";
03711       litedesc->fAddress = "lite";
03712       litedesc->fPort = 0;
03713       litedesc->fConfigFile = "";
03714       litedesc->fLogLevel = 0;
03715       litedesc->fUserName = "";
03716       litedesc->fQueries = new TList();
03717       litedesc->fPackages = new TList();
03718       litedesc->fActQuery = 0;
03719       litedesc->fProof = 0;
03720       litedesc->fProofMgr = 0;
03721       litedesc->fAttached = kFALSE;
03722       litedesc->fConnected = kFALSE;
03723       litedesc->fLocal = kFALSE;
03724       litedesc->fSync = kTRUE;
03725       litedesc->fAutoEnable = kFALSE;
03726       litedesc->fNbHistos = 0;
03727       item->SetUserData(litedesc);
03728       fSessions->Add((TObject *)litedesc);
03729       fActDesc = litedesc;
03730    }
03731    TIter next(fViewerEnv->GetTable());
03732    TEnvRec *er;
03733    while ((er = (TEnvRec*) next())) {
03734       const char *s;
03735       if ((s = strstr(er->GetName(), "SessionDescription."))) {
03736          const char *val = fViewerEnv->GetValue(s, (const char*)0);
03737          if (val) {
03738             Int_t cnt = 0;
03739             char *v = StrDup(val);
03740             s += 7;
03741             while (1) {
03742                TString name = strtok(!cnt ? v : 0, ";");
03743                if (name.IsNull()) break;
03744                TString sessiontag = strtok(0, ";");
03745                TString address = strtok(0, ";");
03746                if (address.IsNull()) break;
03747                TString port = strtok(0, ";");
03748                if (port.IsNull()) break;
03749                TString loglevel = strtok(0, ";");
03750                if (loglevel.IsNull()) break;
03751                TString configfile = strtok(0, ";");
03752                TString user = strtok(0, ";");
03753                if (user.IsNull()) break;
03754                TString sync = strtok(0, ";");
03755                TString autoen = strtok(0, ";");
03756 
03757                // build session description
03758                proofDesc = new TSessionDescription();
03759                proofDesc->fTag = sessiontag.Length() > 2 ? sessiontag.Data() : "";
03760                proofDesc->fName = name;
03761                proofDesc->fAddress = address;
03762                proofDesc->fPort = atoi(port);
03763                proofDesc->fConfigFile = configfile.Length() > 2 ? configfile.Data() : "";
03764                proofDesc->fLogLevel = atoi(loglevel);
03765                proofDesc->fConnected = kFALSE;
03766                proofDesc->fAttached = kFALSE;
03767                proofDesc->fLocal = kFALSE;
03768                proofDesc->fQueries = new TList();
03769                proofDesc->fPackages = new TList();
03770                proofDesc->fActQuery = 0;
03771                proofDesc->fProof = 0;
03772                proofDesc->fProofMgr = 0;
03773                proofDesc->fSync = (Bool_t)(atoi(sync));
03774                proofDesc->fAutoEnable = (Bool_t)(atoi(autoen));
03775                proofDesc->fUserName = user;
03776                fSessions->Add((TObject *)proofDesc);
03777                item = fSessionHierarchy->AddItem(
03778                      fSessionItem, proofDesc->fName.Data(),
03779                      fProofDiscon, fProofDiscon);
03780                fSessionHierarchy->SetToolTipItem(item, "Proof Session");
03781                item->SetUserData(proofDesc);
03782                fActDesc = proofDesc;
03783                cnt++;
03784             }
03785             delete [] v;
03786          }
03787       }
03788       if ((s = strstr(er->GetName(), "QueryDescription."))) {
03789          const char *val = fViewerEnv->GetValue(s, (const char*)0);
03790          if (val) {
03791             Int_t cnt = 0;
03792             char *v = StrDup(val);
03793             s += 7;
03794             while (1) {
03795 
03796                TString status = strtok(!cnt ? v : 0, ";");
03797                if (status.IsNull()) break;
03798 
03799                TString reference = strtok(0, ";");
03800                if (reference.IsNull()) break;
03801                TString queryname = strtok(0, ";");
03802                if (queryname.IsNull()) break;
03803                TString selector = strtok(0, ";");
03804                if (selector.IsNull()) break;
03805                TString dset = strtok(0, ";");
03806                TString options = strtok(0, ";");
03807                TString eventlist = strtok(0, ";");
03808                TString nbfiles = strtok(0, ";");
03809                TString nbentries = strtok(0, ";");
03810                TString firstentry = strtok(0, ";");
03811 
03812                TQueryDescription *newquery = new TQueryDescription();
03813                newquery->fStatus =
03814                   (TQueryDescription::ESessionQueryStatus)(atoi(status));
03815                newquery->fSelectorString  = selector.Length() > 2 ? selector.Data() : "";
03816                newquery->fReference       = reference.Length() > 2 ? reference.Data() : "";
03817                newquery->fTDSetString     = dset.Length() > 2 ? dset.Data() : "";
03818                newquery->fQueryName       = queryname.Length() > 2 ? queryname.Data() : "";
03819                newquery->fOptions         = options.Length() > 2 ? options.Data() : "";
03820                newquery->fEventList       = eventlist.Length() > 2 ? eventlist.Data() : "";
03821                newquery->fNbFiles         = atoi(nbfiles);
03822                newquery->fNoEntries       = atoi(nbentries);
03823                newquery->fFirstEntry      = atoi(firstentry);
03824                newquery->fResult          = 0;
03825                newquery->fChain           = 0;
03826                fActDesc->fQueries->Add((TObject *)newquery);
03827                cnt++;
03828                TGListTreeItem *item1 = fSessionHierarchy->FindChildByData(
03829                      fSessionItem, fActDesc);
03830                TGListTreeItem *item2 = fSessionHierarchy->AddItem(
03831                      item1, newquery->fQueryName, fQueryCon, fQueryCon);
03832                item2->SetUserData(newquery);
03833             }
03834             delete [] v;
03835          }
03836       }
03837    }
03838    fSessionHierarchy->ClearHighlighted();
03839    fSessionHierarchy->OpenItem(fSessionItem);
03840    if (fActDesc == localdesc) {
03841       fSessionHierarchy->HighlightItem(fSessionItem);
03842       fSessionHierarchy->SetSelected(fSessionItem);
03843    }
03844    else {
03845       fSessionHierarchy->OpenItem(item);
03846       fSessionHierarchy->HighlightItem(item);
03847       fSessionHierarchy->SetSelected(item);
03848    }
03849    fSessionHierarchy->ClearViewPort();
03850    fClient->NeedRedraw(fSessionHierarchy);
03851 }
03852 
03853 //______________________________________________________________________________
03854 void TSessionViewer::UpdateListOfProofs()
03855 {
03856    // Update list of existing Proof sessions.
03857 
03858    // get list of proof sessions
03859    Bool_t found  = kFALSE;
03860    Bool_t exists = kFALSE;
03861    TGListTreeItem *item = 0;
03862    TSeqCollection *proofs = gROOT->GetListOfProofs();
03863    TSessionDescription *desc = 0;
03864    TSessionDescription *newdesc;
03865    if (proofs) {
03866       TObject *o = proofs->First();
03867       if (o && dynamic_cast<TProofMgr *>(o)) {
03868          TProofMgr *mgr = dynamic_cast<TProofMgr *>(o);
03869          if (mgr && mgr->QuerySessions("L")) {
03870             TIter nxd(mgr->QuerySessions("L"));
03871             TProofDesc *d = 0;
03872             TProof *p = 0;
03873             while ((d = (TProofDesc *)nxd())) {
03874                TIter nextfs(fSessions);
03875                // check if session exists in the list
03876                exists = kFALSE;
03877                while ((desc = (TSessionDescription *)nextfs())) {
03878                   if ((desc->fTag == d->GetName()) ||
03879                       (desc->fName == d->GetTitle())) {
03880                      exists = kTRUE;
03881                      break;
03882                   }
03883                }
03884                TIter nexts(fSessions);
03885                found = kFALSE;
03886                p = d->GetProof();
03887                while ((desc = (TSessionDescription *)nexts())) {
03888                   if (desc->fConnected && desc->fAttached)
03889                      continue;
03890                   if (p && ((exists && ((desc->fTag == d->GetName()) ||
03891                       (desc->fName == d->GetTitle()))) ||
03892                       (!exists && (desc->fAddress == p->GetMaster())))) {
03893                      desc->fConnected  = kTRUE;
03894                      desc->fAttached   = kTRUE;
03895                      desc->fProof      = p;
03896                      desc->fProofMgr   = mgr;
03897                      desc->fTag        = d->GetName();
03898                      item = fSessionHierarchy->FindChildByData(fSessionItem,
03899                                                                desc);
03900                      if (item) {
03901                         item->SetPictures(fProofCon, fProofCon);
03902                         if (item == fSessionHierarchy->GetSelected()) {
03903                            fActDesc->fProof->Connect("Progress(Long64_t,Long64_t)",
03904                                     "TSessionQueryFrame", fQueryFrame,
03905                                     "Progress(Long64_t,Long64_t)");
03906                            fActDesc->fProof->Connect("Progress(Long64_t,Long64_t,Long64_t,Float_t,Float_t,Float_t,Float_t)",
03907                                     "TSessionQueryFrame", fQueryFrame,
03908                                     "Progress(Long64_t,Long64_t,Long64_t,Float_t,Float_t,Float_t,Float_t)");
03909                            fActDesc->fProof->Connect("StopProcess(Bool_t)",
03910                                     "TSessionQueryFrame", fQueryFrame,
03911                                     "IndicateStop(Bool_t)");
03912                            fActDesc->fProof->Connect(
03913                               "ResetProgressDialog(const char*, Int_t,Long64_t,Long64_t)",
03914                               "TSessionQueryFrame", fQueryFrame,
03915                               "ResetProgressDialog(const char*,Int_t,Long64_t,Long64_t)");
03916                            // enable timer used for status bar icon's animation
03917                            EnableTimer();
03918                            // change status bar right icon to connected pixmap
03919                            ChangeRightLogo("monitor01.xpm");
03920                            // do not animate yet
03921                            SetChangePic(kFALSE);
03922                            // connect to signal "query result ready"
03923                            fActDesc->fProof->Connect("QueryResultReady(char *)",
03924                                     "TSessionViewer", this, "QueryResultReady(char *)");
03925                            // display connection information on status bar
03926                            TString msg;
03927                            msg.Form("PROOF Cluster %s ready", fActDesc->fName.Data());
03928                            fStatusBar->SetText(msg.Data(), 1);
03929                            UpdateListOfPackages();
03930                            fSessionFrame->UpdatePackages();
03931                            fSessionFrame->UpdateListOfDataSets();
03932                            fPopupSrv->DisableEntry(kSessionConnect);
03933                            fSessionMenu->DisableEntry(kSessionConnect);
03934                            fPopupSrv->EnableEntry(kSessionDisconnect);
03935                            fSessionMenu->EnableEntry(kSessionDisconnect);
03936                            fToolBar->GetButton(kSessionDisconnect)->SetState(kButtonUp);
03937                            fToolBar->GetButton(kSessionConnect)->SetState(kButtonDisabled);
03938                            fSessionFrame->SetLogLevel(fActDesc->fLogLevel);
03939                            // update session information frame
03940                            fSessionFrame->ProofInfos();
03941                            fSessionFrame->SetLocal(kFALSE);
03942                            if (fActFrame != fSessionFrame) {
03943                               fV2->HideFrame(fActFrame);
03944                               fV2->ShowFrame(fSessionFrame);
03945                               fActFrame = fSessionFrame;
03946                            }
03947                         }
03948                      }
03949                      if (desc->fLogLevel < 0)
03950                         desc->fLogLevel = 0;
03951                      found = kTRUE;
03952                      break;
03953                   }
03954                }
03955                if (found) continue;
03956                newdesc = new TSessionDescription();
03957                // and fill informations from Proof session
03958                newdesc->fTag       = d->GetName();
03959                newdesc->fName      = d->GetTitle();
03960                newdesc->fAddress   = d->GetTitle();
03961                newdesc->fConnected = kFALSE;
03962                newdesc->fAttached  = kFALSE;
03963                newdesc->fProofMgr  = mgr;
03964                p = d->GetProof();
03965                if (p) {
03966                   newdesc->fConnected  = kTRUE;
03967                   newdesc->fAttached   = kTRUE;
03968                   if (p->IsLite())
03969                      newdesc->fAddress = "lite";
03970                   else
03971                      newdesc->fAddress = p->GetMaster();
03972                   newdesc->fConfigFile = p->GetConfFile();
03973                   newdesc->fUserName   = p->GetUser();
03974                   newdesc->fPort       = p->GetPort();
03975                   newdesc->fLogLevel   = p->GetLogLevel();
03976                   newdesc->fProof      = p;
03977                   newdesc->fProof->Connect("Progress(Long64_t,Long64_t)",
03978                            "TSessionQueryFrame", fQueryFrame,
03979                            "Progress(Long64_t,Long64_t)");
03980                   newdesc->fProof->Connect("Progress(Long64_t,Long64_t,Long64_t,Float_t,Float_t,Float_t,Float_t)",
03981                            "TSessionQueryFrame", fQueryFrame,
03982                            "Progress(Long64_t,Long64_t,Long64_t,Float_t,Float_t,Float_t,Float_t)");
03983                   newdesc->fProof->Connect("StopProcess(Bool_t)",
03984                            "TSessionQueryFrame", fQueryFrame,
03985                            "IndicateStop(Bool_t)");
03986                   newdesc->fProof->Connect(
03987                            "ResetProgressDialog(const char*, Int_t,Long64_t,Long64_t)",
03988                            "TSessionQueryFrame", fQueryFrame,
03989                            "ResetProgressDialog(const char*,Int_t,Long64_t,Long64_t)");
03990                   // enable timer used for status bar icon's animation
03991                   EnableTimer();
03992                   // change status bar right icon to connected pixmap
03993                   ChangeRightLogo("monitor01.xpm");
03994                   // do not animate yet
03995                   SetChangePic(kFALSE);
03996                   // connect to signal "query result ready"
03997                   newdesc->fProof->Connect("QueryResultReady(char *)",
03998                            "TSessionViewer", this, "QueryResultReady(char *)");
03999                }
04000                newdesc->fQueries    = new TList();
04001                newdesc->fPackages   = new TList();
04002                if (newdesc->fLogLevel < 0)
04003                   newdesc->fLogLevel = 0;
04004                newdesc->fActQuery   = 0;
04005                newdesc->fLocal = kFALSE;
04006                newdesc->fSync = kFALSE;
04007                newdesc->fAutoEnable = kFALSE;
04008                newdesc->fNbHistos = 0;
04009                // add new session description in list tree
04010                if (p)
04011                   item = fSessionHierarchy->AddItem(fSessionItem, newdesc->fName.Data(),
04012                            fProofCon, fProofCon);
04013                else
04014                   item = fSessionHierarchy->AddItem(fSessionItem, newdesc->fName.Data(),
04015                            fProofDiscon, fProofDiscon);
04016                fSessionHierarchy->SetToolTipItem(item, "Proof Session");
04017                item ->SetUserData(newdesc);
04018                // and in our session description list
04019                fSessions->Add(newdesc);
04020             }
04021          }
04022          return;
04023       }
04024       TIter nextp(proofs);
04025       TProof *proof;
04026       // loop over existing Proof sessions
04027       while ((proof = (TProof *)nextp())) {
04028          TIter nexts(fSessions);
04029          found = kFALSE;
04030          // check if session is already in the list
04031          while ((desc = (TSessionDescription *)nexts())) {
04032             if (desc->fProof == proof) {
04033                desc->fConnected = kTRUE;
04034                desc->fAttached = kTRUE;
04035                found = kTRUE;
04036                break;
04037             }
04038          }
04039          if (found) continue;
04040          // create new session description
04041          newdesc = new TSessionDescription();
04042          // and fill informations from Proof session
04043          newdesc->fName       = proof->GetMaster();
04044          newdesc->fConfigFile = proof->GetConfFile();
04045          newdesc->fUserName   = proof->GetUser();
04046          newdesc->fPort       = proof->GetPort();
04047          newdesc->fLogLevel   = proof->GetLogLevel();
04048          if (newdesc->fLogLevel < 0)
04049             newdesc->fLogLevel = 0;
04050          if (proof->IsLite())
04051             newdesc->fAddress = "lite";
04052          else
04053             newdesc->fAddress = proof->GetMaster();
04054          newdesc->fQueries    = new TList();
04055          newdesc->fPackages   = new TList();
04056          newdesc->fProof      = proof;
04057          newdesc->fActQuery   = 0;
04058          newdesc->fConnected = kTRUE;
04059          newdesc->fAttached = kTRUE;
04060          newdesc->fLocal = kFALSE;
04061          newdesc->fSync = kFALSE;
04062          newdesc->fAutoEnable = kFALSE;
04063          newdesc->fNbHistos = 0;
04064          // add new session description in list tree
04065          item = fSessionHierarchy->AddItem(fSessionItem, newdesc->fName.Data(),
04066                   fProofCon, fProofCon);
04067          fSessionHierarchy->SetToolTipItem(item, "Proof Session");
04068          item ->SetUserData(newdesc);
04069          // and in our session description list
04070          fSessions->Add(newdesc);
04071       }
04072    }
04073 }
04074 
04075 //______________________________________________________________________________
04076 void TSessionViewer::UpdateListOfSessions()
04077 {
04078    // Update list of existing Proof sessions.
04079 
04080    // get list of proof sessions
04081    TGListTreeItem *item;
04082    TList *sessions = fActDesc->fProofMgr->QuerySessions("");
04083    if (sessions) {
04084       TIter nextp(sessions);
04085       TProofDesc *pdesc;
04086       TProof *proof;
04087       TSessionDescription *newdesc;
04088       // loop over existing Proof sessions
04089       while ((pdesc = (TProofDesc *)nextp())) {
04090          TIter nexts(fSessions);
04091          TSessionDescription *desc = 0;
04092          Bool_t found = kFALSE;
04093          // check if session is already in the list
04094          while ((desc = (TSessionDescription *)nexts())) {
04095             if ((desc->fTag == pdesc->GetName()) ||
04096                 (desc->fName == pdesc->GetTitle())) {
04097                desc->fConnected = kTRUE;
04098                found = kTRUE;
04099                break;
04100             }
04101          }
04102          if (found) continue;
04103          // create new session description
04104          newdesc = new TSessionDescription();
04105          // and fill informations from Proof session
04106          newdesc->fTag        = pdesc->GetName();
04107          newdesc->fName       = pdesc->GetTitle();
04108          proof = pdesc->GetProof();
04109          if (proof) {
04110             newdesc->fConfigFile = proof->GetConfFile();
04111             newdesc->fUserName   = proof->GetUser();
04112             newdesc->fPort       = proof->GetPort();
04113             newdesc->fLogLevel   = proof->GetLogLevel();
04114             if (newdesc->fLogLevel < 0)
04115                newdesc->fLogLevel = 0;
04116             if (proof->IsLite())
04117                newdesc->fAddress = "lite";
04118             else
04119                newdesc->fAddress = proof->GetMaster();
04120             newdesc->fProof      = proof;
04121          }
04122          else {
04123             newdesc->fProof      = 0;
04124             newdesc->fConfigFile = "";
04125             newdesc->fUserName   = fActDesc->fUserName;
04126             newdesc->fPort       = fActDesc->fPort;
04127             newdesc->fLogLevel   = 0;
04128             newdesc->fAddress    = fActDesc->fAddress;
04129          }
04130          newdesc->fQueries    = new TList();
04131          newdesc->fPackages   = new TList();
04132          newdesc->fProofMgr   = fActDesc->fProofMgr;
04133          newdesc->fActQuery   = 0;
04134          newdesc->fConnected  = kTRUE;
04135          newdesc->fAttached   = kFALSE;
04136          newdesc->fLocal      = kFALSE;
04137          newdesc->fSync       = kFALSE;
04138          newdesc->fAutoEnable = kFALSE;
04139          newdesc->fNbHistos   = 0;
04140          // add new session description in list tree
04141          item = fSessionHierarchy->AddItem(fSessionItem, newdesc->fName.Data(),
04142                   fProofDiscon, fProofDiscon);
04143          fSessionHierarchy->SetToolTipItem(item, "Proof Session");
04144          item ->SetUserData(newdesc);
04145          // and in our session description list
04146          fSessions->Add(newdesc);
04147          // set actual description to the last one
04148       }
04149    }
04150 }
04151 
04152 //______________________________________________________________________________
04153 void TSessionViewer::WriteConfiguration(const char *filename)
04154 {
04155    // Save actual configuration in config file "filename".
04156 
04157    TSessionDescription *session;
04158    TQueryDescription *query;
04159    Int_t scnt = 0, qcnt = 1;
04160    const char *fname = filename ? filename : fConfigFile.Data();
04161 
04162    delete fViewerEnv;
04163    gSystem->Unlink(fname);
04164    fViewerEnv = new TEnv();
04165 
04166    fViewerEnv->SetValue("Option.Feedback",
04167          (Int_t)fOptionsMenu->IsEntryChecked(kOptionsFeedback));
04168    fViewerEnv->SetValue("Option.MasterHistos",
04169          (Int_t)fOptionsMenu->IsEntryChecked(kOptionsStatsHist));
04170    fViewerEnv->SetValue("Option.MasterEvents",
04171          (Int_t)fOptionsMenu->IsEntryChecked(kOptionsStatsTrace));
04172    fViewerEnv->SetValue("Option.WorkerEvents",
04173          (Int_t)fOptionsMenu->IsEntryChecked(kOptionsSlaveStatsTrace));
04174 
04175    Int_t i = 0;
04176    // browse list of feedback histos and check user's selected ones
04177    while (kFeedbackHistos[i]) {
04178       fViewerEnv->SetValue(Form("Option.%s",kFeedbackHistos[i]),
04179          (Int_t)fCascadeMenu->IsEntryChecked(41+i));
04180       i++;
04181    }
04182 
04183    TIter snext(fSessions);
04184    while ((session = (TSessionDescription *) snext())) {
04185       if ((scnt > 0) && ((session->fAddress.Length() < 3) ||
04186            session->fUserName.Length() < 2)) {
04187          // skip gROOT's list of sessions
04188          continue;
04189       }
04190       if ((scnt > 0) && (session->fName == session->fAddress)) {
04191          // skip gROOT's list of proofs
04192          continue;
04193       }
04194       TString sessionstring;
04195       sessionstring += session->fName;
04196       sessionstring += ";";
04197       sessionstring += session->fTag.Length() > 1 ? session->fTag.Data() : " ";
04198       sessionstring += ";";
04199       sessionstring += session->fAddress;
04200       sessionstring += ";";
04201       sessionstring += TString::Format("%d", session->fPort);
04202       sessionstring += ";";
04203       sessionstring += TString::Format("%d", session->fLogLevel);
04204       sessionstring += ";";
04205       sessionstring += session->fConfigFile.Length() > 1 ? session->fConfigFile.Data() : " ";
04206       sessionstring += ";";
04207       sessionstring += session->fUserName;
04208       sessionstring += ";";
04209       sessionstring += TString::Format("%d", session->fSync);
04210       sessionstring += ";";
04211       sessionstring += TString::Format("%d", session->fAutoEnable);
04212       if (scnt > 0) // skip local session
04213          fViewerEnv->SetValue(Form("SessionDescription.%d",scnt), sessionstring);
04214       scnt++;
04215 
04216       TIter qnext(session->fQueries);
04217       while ((query = (TQueryDescription *) qnext())) {
04218          TString querystring;
04219          querystring += TString::Format("%d", query->fStatus);
04220          querystring += ";";
04221          querystring += query->fReference.Length() > 1 ? query->fReference.Data() : " ";
04222          querystring += ";";
04223          querystring += query->fQueryName;
04224          querystring += ";";
04225          querystring += query->fSelectorString.Length() > 1 ? query->fSelectorString.Data() : " ";
04226          querystring += ";";
04227          querystring += query->fTDSetString.Length() > 1 ? query->fTDSetString.Data() : " ";
04228          querystring += ";";
04229          querystring += query->fOptions.Length() > 1 ? query->fOptions.Data() : " ";
04230          querystring += ";";
04231          querystring += query->fEventList.Length() > 1 ? query->fEventList.Data() : " ";
04232          querystring += ";";
04233          querystring += TString::Format("%d",query->fNbFiles);
04234          querystring += ";";
04235          querystring += TString::Format("%lld",query->fNoEntries);
04236          querystring += ";";
04237          querystring += TString::Format("%lld",query->fFirstEntry);
04238          fViewerEnv->SetValue(Form("QueryDescription.%d",qcnt), querystring);
04239          qcnt++;
04240       }
04241    }
04242 
04243    fViewerEnv->WriteFile(fname);
04244 }
04245 
04246 //______________________________________________________________________________
04247 void TSessionViewer::Build()
04248 {
04249    // Build main session viewer frame and subframes.
04250 
04251    TString buf;
04252    fActDesc = 0;
04253    fActFrame = 0;
04254    fLogWindow = 0;
04255    fBusy = kFALSE;
04256    fAutoSave = kTRUE;
04257    fChangePic = kFALSE;
04258    fStart = fElapsed = 0;
04259 
04260    SetCleanup(kDeepCleanup);
04261    // set minimun size
04262    SetWMSizeHints(400 + 200, 370+50, 2000, 1000, 1, 1);
04263 
04264    // collect icons
04265    fLocal = fClient->GetPicture("local_session.xpm");
04266    fProofCon = fClient->GetPicture("proof_connected.xpm");
04267    fProofDiscon = fClient->GetPicture("proof_disconnected.xpm");
04268    fQueryCon = fClient->GetPicture("query_connected.xpm");
04269    fQueryDiscon = fClient->GetPicture("query_disconnected.xpm");
04270    fBaseIcon = fClient->GetPicture("proof_base.xpm");
04271 
04272    //--- File menu
04273    fFileMenu = new TGPopupMenu(fClient->GetDefaultRoot());
04274    fFileMenu->AddEntry("&Load Config...", kFileLoadConfig);
04275    fFileMenu->AddEntry("&Save Config...", kFileSaveConfig);
04276    fFileMenu->AddSeparator();
04277    fFileMenu->AddEntry("&Close Viewer",    kFileCloseViewer);
04278    fFileMenu->AddSeparator();
04279    fFileMenu->AddEntry("&Quit ROOT",       kFileQuit);
04280 
04281    //--- Session menu
04282    fSessionMenu = new TGPopupMenu(gClient->GetDefaultRoot());
04283    fSessionMenu->AddLabel("Session Management");
04284    fSessionMenu->AddSeparator();
04285    fSessionMenu->AddEntry("&New Session", kSessionNew);
04286    fSessionMenu->AddEntry("&Add to the list", kSessionAdd);
04287    fSessionMenu->AddEntry("De&lete", kSessionDelete);
04288    fSessionMenu->AddSeparator();
04289    fSessionMenu->AddEntry("&Connect...", kSessionConnect);
04290    fSessionMenu->AddEntry("&Disconnect", kSessionDisconnect);
04291    fSessionMenu->AddEntry("Shutdo&wn",  kSessionShutdown);
04292    fSessionMenu->AddEntry("&Show status",kSessionShowStatus);
04293    fSessionMenu->AddEntry("&Get Queries",kSessionGetQueries);
04294    fSessionMenu->AddSeparator();
04295    fSessionMenu->AddEntry("&Cleanup", kSessionCleanup);
04296    fSessionMenu->AddEntry("&Reset",kSessionReset);
04297    fSessionMenu->DisableEntry(kSessionAdd);
04298 
04299    //--- Query menu
04300    fQueryMenu = new TGPopupMenu(gClient->GetDefaultRoot());
04301    fQueryMenu->AddLabel("Query Management");
04302    fQueryMenu->AddSeparator();
04303    fQueryMenu->AddEntry("&New...", kQueryNew);
04304    fQueryMenu->AddEntry("&Edit", kQueryEdit);
04305    fQueryMenu->AddEntry("&Submit", kQuerySubmit);
04306    fQueryMenu->AddSeparator();
04307    fQueryMenu->AddEntry("Start &Viewer", kQueryStartViewer);
04308    fQueryMenu->AddSeparator();
04309    fQueryMenu->AddEntry("&Delete", kQueryDelete);
04310 
04311    fViewerEnv = 0;
04312 #ifdef WIN32
04313    fConfigFile = TString::Format("%s\\%s", gSystem->HomeDirectory(), kConfigFile);
04314 #else
04315    fConfigFile = TString::Format("%s/%s", gSystem->HomeDirectory(), kConfigFile);
04316 #endif
04317 
04318    fCascadeMenu = new TGPopupMenu(fClient->GetDefaultRoot());
04319    Int_t i = 0;
04320    while (kFeedbackHistos[i]) {
04321       fCascadeMenu->AddEntry(kFeedbackHistos[i], 41+i);
04322       i++;
04323    }
04324    fCascadeMenu->AddEntry("User defined...", 50);
04325    // disable it for now (until implemented)
04326    fCascadeMenu->DisableEntry(50);
04327 
04328    //--- Options menu
04329    fOptionsMenu = new TGPopupMenu(fClient->GetDefaultRoot());
04330    fOptionsMenu->AddLabel("Global Options");
04331    fOptionsMenu->AddSeparator();
04332    fOptionsMenu->AddEntry("&Autosave Config", kOptionsAutoSave);
04333    fOptionsMenu->AddSeparator();
04334    fOptionsMenu->AddEntry("Master &Histos", kOptionsStatsHist);
04335    fOptionsMenu->AddEntry("&Master Events", kOptionsStatsTrace);
04336    fOptionsMenu->AddEntry("&Worker Events", kOptionsSlaveStatsTrace);
04337    fOptionsMenu->AddSeparator();
04338    fOptionsMenu->AddEntry("Feedback &Active", kOptionsFeedback);
04339    fOptionsMenu->AddSeparator();
04340    fOptionsMenu->AddPopup("&Feedback Histos", fCascadeMenu);
04341    fOptionsMenu->CheckEntry(kOptionsAutoSave);
04342 
04343    //--- Help menu
04344    fHelpMenu = new TGPopupMenu(gClient->GetDefaultRoot());
04345    fHelpMenu->AddEntry("&About ROOT...",  kHelpAbout);
04346 
04347    fFileMenu->Associate(this);
04348    fSessionMenu->Associate(this);
04349    fQueryMenu->Associate(this);
04350    fOptionsMenu->Associate(this);
04351    fCascadeMenu->Associate(this);
04352    fHelpMenu->Associate(this);
04353 
04354    //--- create menubar and add popup menus
04355    fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
04356 
04357    fMenuBar->AddPopup("&File", fFileMenu, new TGLayoutHints(kLHintsTop |
04358          kLHintsLeft, 0, 4, 0, 0));
04359    fMenuBar->AddPopup("&Session", fSessionMenu, new TGLayoutHints(kLHintsTop |
04360          kLHintsLeft, 0, 4, 0, 0));
04361    fMenuBar->AddPopup("&Query",  fQueryMenu, new TGLayoutHints(kLHintsTop |
04362          kLHintsLeft, 0, 4, 0, 0));
04363    fMenuBar->AddPopup("&Options",  fOptionsMenu, new TGLayoutHints(kLHintsTop |
04364          kLHintsLeft, 0, 4, 0, 0));
04365    fMenuBar->AddPopup("&Help", fHelpMenu, new TGLayoutHints(kLHintsTop |
04366          kLHintsRight));
04367 
04368    TGHorizontal3DLine *toolBarSep = new TGHorizontal3DLine(this);
04369    AddFrame(toolBarSep, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
04370 
04371    AddFrame(fMenuBar, new TGLayoutHints(kLHintsTop | kLHintsLeft |
04372          kLHintsExpandX, 0, 0, 1, 1));
04373 
04374    toolBarSep = new TGHorizontal3DLine(this);
04375    AddFrame(toolBarSep, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
04376 
04377    //---- toolbar
04378 
04379    int spacing = 8;
04380    fToolBar = new TGToolBar(this, 60, 20, kHorizontalFrame);
04381    for (int ii = 0; xpm_toolbar[ii]; ii++) {
04382       tb_data[ii].fPixmap = xpm_toolbar[ii];
04383       if (strlen(xpm_toolbar[ii]) == 0) {
04384          spacing = 8;
04385          continue;
04386       }
04387       fToolBar->AddButton(this, &tb_data[ii], spacing);
04388       spacing = 0;
04389    }
04390    AddFrame(fToolBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 0, 0));
04391    toolBarSep = new TGHorizontal3DLine(this);
04392    AddFrame(toolBarSep, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
04393    fToolBar->GetButton(kQuerySubmit)->SetState(kButtonDisabled);
04394 
04395    fPopupSrv = new TGPopupMenu(fClient->GetDefaultRoot());
04396    fPopupSrv->AddEntry("Connect",kSessionConnect);
04397    fPopupSrv->AddEntry("Disconnect",kSessionDisconnect);
04398    fPopupSrv->AddEntry("Shutdown",kSessionShutdown);
04399    fPopupSrv->AddEntry("Browse",kSessionBrowse);
04400    fPopupSrv->AddEntry("Show status",kSessionShowStatus);
04401    fPopupSrv->AddEntry("Delete", kSessionDelete);
04402    fPopupSrv->AddEntry("Get Queries",kSessionGetQueries);
04403    fPopupSrv->AddSeparator();
04404    fPopupSrv->AddEntry("Cleanup", kSessionCleanup);
04405    fPopupSrv->AddEntry("Reset",kSessionReset);
04406    fPopupSrv->Connect("Activated(Int_t)","TSessionViewer", this,
04407          "MyHandleMenu(Int_t)");
04408 
04409    fPopupQry = new TGPopupMenu(fClient->GetDefaultRoot());
04410    fPopupQry->AddEntry("Edit",kQueryEdit);
04411    fPopupQry->AddEntry("Submit",kQuerySubmit);
04412    fPopupQry->AddSeparator();
04413    fPopupQry->AddEntry("Start &Viewer", kQueryStartViewer);
04414    fPopupQry->AddSeparator();
04415    fPopupQry->AddEntry("Delete",kQueryDelete);
04416    fPopupQry->Connect("Activated(Int_t)","TSessionViewer", this,
04417          "MyHandleMenu(Int_t)");
04418 
04419 
04420    fSessionMenu->DisableEntry(kSessionGetQueries);
04421    fSessionMenu->DisableEntry(kSessionShowStatus);
04422    fPopupSrv->DisableEntry(kSessionGetQueries);
04423    fPopupSrv->DisableEntry(kSessionShowStatus);
04424    fPopupSrv->DisableEntry(kSessionDisconnect);
04425    fPopupSrv->DisableEntry(kSessionShutdown);
04426    fPopupSrv->DisableEntry(kSessionCleanup);
04427    fPopupSrv->DisableEntry(kSessionReset);
04428    fSessionMenu->DisableEntry(kSessionDisconnect);
04429    fSessionMenu->DisableEntry(kSessionShutdown);
04430    fSessionMenu->DisableEntry(kSessionCleanup);
04431    fSessionMenu->DisableEntry(kSessionReset);
04432    fToolBar->GetButton(kSessionDisconnect)->SetState(kButtonDisabled);
04433 
04434    //--- Horizontal mother frame -----------------------------------------------
04435    fHf = new TGHorizontalFrame(this, 10, 10);
04436    fHf->SetCleanup(kDeepCleanup);
04437 
04438    //--- fV1 -------------------------------------------------------------------
04439    fV1 = new TGVerticalFrame(fHf, 100, 100, kFixedWidth);
04440    fV1->SetCleanup(kDeepCleanup);
04441 
04442    fTreeView = new TGCanvas(fV1, 100, 200, kSunkenFrame | kDoubleBorder);
04443    fV1->AddFrame(fTreeView, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
04444          2, 0, 0, 0));
04445    fSessionHierarchy = new TGListTree(fTreeView, kHorizontalFrame);
04446    fSessionHierarchy->DisableOpen();
04447    fSessionHierarchy->Connect("Clicked(TGListTreeItem*,Int_t,Int_t,Int_t)",
04448          "TSessionViewer", this,
04449          "OnListTreeClicked(TGListTreeItem*, Int_t, Int_t, Int_t)");
04450    fSessionHierarchy->Connect("DoubleClicked(TGListTreeItem*,Int_t)",
04451          "TSessionViewer", this,
04452          "OnListTreeDoubleClicked(TGListTreeItem*, Int_t)");
04453    fV1->Resize(fTreeView->GetDefaultWidth()+100, fV1->GetDefaultHeight());
04454 
04455    //--- fV2 -------------------------------------------------------------------
04456    fV2 = new TGVerticalFrame(fHf, 350, 310);
04457    fV2->SetCleanup(kDeepCleanup);
04458 
04459    //--- Server Frame ----------------------------------------------------------
04460    fServerFrame = new TSessionServerFrame(fV2, 350, 310);
04461    fSessions = new TList;
04462    ReadConfiguration();
04463    fServerFrame->Build(this);
04464    fV2->AddFrame(fServerFrame, new TGLayoutHints(kLHintsTop | kLHintsExpandX |
04465          kLHintsExpandY, 2, 0, 1, 2));
04466 
04467    //--- Session Frame ---------------------------------------------------------
04468    fSessionFrame = new TSessionFrame(fV2, 350, 310);
04469    fSessionFrame->Build(this);
04470    fV2->AddFrame(fSessionFrame, new TGLayoutHints(kLHintsTop | kLHintsExpandX |
04471          kLHintsExpandY, 2, 0, 1, 2));
04472 
04473    //--- Query Frame -----------------------------------------------------------
04474    fQueryFrame = new TSessionQueryFrame(fV2, 350, 310);
04475    fQueryFrame->Build(this);
04476    fV2->AddFrame(fQueryFrame, new TGLayoutHints(kLHintsTop | kLHintsExpandX |
04477          kLHintsExpandY, 2, 0, 1, 2));
04478 
04479    //--- Output Frame ----------------------------------------------------------
04480    fOutputFrame = new TSessionOutputFrame(fV2, 350, 310);
04481    fOutputFrame->Build(this);
04482    fV2->AddFrame(fOutputFrame, new TGLayoutHints(kLHintsTop | kLHintsExpandX |
04483          kLHintsExpandY, 2, 0, 1, 2));
04484 
04485    //--- Input Frame -----------------------------------------------------------
04486    fInputFrame = new TSessionInputFrame(fV2, 350, 310);
04487    fInputFrame->Build(this);
04488    fV2->AddFrame(fInputFrame, new TGLayoutHints(kLHintsTop | kLHintsExpandX |
04489          kLHintsExpandY, 2, 0, 1, 2));
04490 
04491    fHf->AddFrame(fV1, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
04492 
04493    // add vertical splitter between list tree and frames
04494    TGVSplitter *splitter = new TGVSplitter(fHf, 4);
04495    splitter->SetFrame(fV1, kTRUE);
04496    fHf->AddFrame(splitter,new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
04497    fHf->AddFrame(new TGVertical3DLine(fHf), new TGLayoutHints(kLHintsLeft |
04498          kLHintsExpandY));
04499 
04500    fHf->AddFrame(fV2, new TGLayoutHints(kLHintsRight | kLHintsExpandX |
04501          kLHintsExpandY));
04502 
04503    AddFrame(fHf, new TGLayoutHints(kLHintsRight | kLHintsExpandX |
04504          kLHintsExpandY));
04505 
04506    // if description available, update server infos frame
04507    if (fActDesc) {
04508       if (!fActDesc->fLocal) {
04509          fServerFrame->Update(fActDesc);
04510       }
04511       else {
04512          fServerFrame->SetAddEnabled();
04513          fServerFrame->SetConnectEnabled(kFALSE);
04514       }
04515    }
04516 
04517    //--- Status Bar ------------------------------------------------------------
04518    int parts[] = { 36, 49, 15 };
04519    fStatusBar = new TGStatusBar(this, 10, 10);
04520    fStatusBar->SetCleanup(kDeepCleanup);
04521    fStatusBar->SetParts(parts, 3);
04522    for (int p = 0; p < 3; ++p)
04523       fStatusBar->GetBarPart(p)->SetCleanup(kDeepCleanup);
04524    AddFrame(fStatusBar, new TGLayoutHints(kLHintsTop | kLHintsLeft |
04525          kLHintsExpandX, 0, 0, 1, 1));
04526 
04527    // connection icon (animation) and time info
04528    fStatusBar->SetText("      00:00:00", 2);
04529    TGCompositeFrame *leftpart = fStatusBar->GetBarPart(2);
04530    fRightIconPicture = (TGPicture *)fClient->GetPicture("proof_disconnected.xpm");
04531    fRightIcon = new TGIcon(leftpart, fRightIconPicture,
04532          fRightIconPicture->GetWidth(),fRightIconPicture->GetHeight());
04533    leftpart->AddFrame(fRightIcon, new TGLayoutHints(kLHintsLeft, 2, 0, 0, 0));
04534 
04535    // connection progress bar
04536    TGCompositeFrame *rightpart = fStatusBar->GetBarPart(0);
04537    fConnectProg = new TGHProgressBar(rightpart, TGProgressBar::kStandard, 100);
04538    fConnectProg->ShowPosition();
04539    fConnectProg->SetBarColor("green");
04540    rightpart->AddFrame(fConnectProg, new TGLayoutHints(kLHintsExpandX, 1, 1, 1, 1));
04541 
04542    // add user info
04543    fUserGroup = gSystem->GetUserInfo();
04544    buf.Form("User : %s - %s", fUserGroup->fRealName.Data(),
04545              fUserGroup->fGroup.Data());
04546    fStatusBar->SetText(buf.Data(), 1);
04547 
04548    fTimer = 0;
04549 
04550    // create context menu
04551    fContextMenu = new TContextMenu("SessionViewerContextMenu") ;
04552 
04553    SetWindowName("ROOT Session Viewer");
04554    MapSubwindows();
04555    MapWindow();
04556 
04557    // hide frames
04558    fServerFrame->SetAddEnabled(kFALSE);
04559    fStatusBar->GetBarPart(0)->HideFrame(fConnectProg);
04560    fV2->HideFrame(fSessionFrame);
04561    fV2->HideFrame(fQueryFrame);
04562    fV2->HideFrame(fOutputFrame);
04563    fV2->HideFrame(fInputFrame);
04564    fQueryFrame->GetQueryEditFrame()->OnNewQueryMore();
04565    fActFrame = fServerFrame;
04566    UpdateListOfProofs();
04567    Resize(610, 420);
04568 }
04569 
04570 //______________________________________________________________________________
04571 TSessionViewer::~TSessionViewer()
04572 {
04573    // Destructor.
04574 
04575    delete fUserGroup;
04576    if (gSessionViewer == this)
04577       gSessionViewer = 0;
04578 }
04579 
04580 //______________________________________________________________________________
04581 void TSessionViewer::OnListTreeClicked(TGListTreeItem *entry, Int_t btn,
04582                                        Int_t x, Int_t y)
04583 {
04584    // Handle mouse clicks in list tree.
04585 
04586    TList *objlist;
04587    TObject *obj;
04588    TString msg;
04589 
04590    fSessionMenu->DisableEntry(kSessionAdd);
04591    fToolBar->GetButton(kQuerySubmit)->SetState(kButtonDisabled);
04592    if (entry->GetParent() == 0) {  // PROOF
04593       // switch frames only if actual one doesn't match
04594       if (fActFrame != fServerFrame) {
04595          fV2->HideFrame(fActFrame);
04596          fV2->ShowFrame(fServerFrame);
04597          fActFrame = fServerFrame;
04598       }
04599       fSessionMenu->DisableEntry(kSessionDelete);
04600       fSessionMenu->EnableEntry(kSessionAdd);
04601       fServerFrame->SetAddEnabled();
04602       fServerFrame->SetConnectEnabled(kFALSE);
04603       fPopupSrv->DisableEntry(kSessionConnect);
04604       fSessionMenu->DisableEntry(kSessionConnect);
04605       fToolBar->GetButton(kSessionConnect)->SetState(kButtonDisabled);
04606    }
04607    else if (entry->GetParent()->GetParent() == 0) { // Server
04608       if (entry->GetUserData()) {
04609          obj = (TObject *)entry->GetUserData();
04610          if (obj->IsA() != TSessionDescription::Class())
04611             return;
04612          // update server frame informations
04613          fServerFrame->Update((TSessionDescription *)obj);
04614          fActDesc = (TSessionDescription*)obj;
04615          // if Proof valid, update connection infos
04616          if (fActDesc->fConnected && fActDesc->fAttached &&
04617              fActDesc->fProof && fActDesc->fProof->IsValid()) {
04618             fActDesc->fProof->cd();
04619             msg.Form("PROOF Cluster %s ready", fActDesc->fName.Data());
04620          }
04621          else {
04622             msg.Form("PROOF Cluster %s not connected", fActDesc->fName.Data());
04623          }
04624          fStatusBar->SetText(msg.Data(), 1);
04625       }
04626       if ((fActDesc->fConnected) && (fActDesc->fAttached)) {
04627          fPopupSrv->DisableEntry(kSessionConnect);
04628          fSessionMenu->DisableEntry(kSessionConnect);
04629          fToolBar->GetButton(kSessionConnect)->SetState(kButtonDisabled);
04630          UpdateListOfPackages();
04631          fSessionFrame->UpdateListOfDataSets();
04632       }
04633       else {
04634          fPopupSrv->EnableEntry(kSessionConnect);
04635          fSessionMenu->EnableEntry(kSessionConnect);
04636          fToolBar->GetButton(kSessionConnect)->SetState(kButtonUp);
04637       }
04638       // local session
04639       if (fActDesc->fLocal) {
04640          if (fActFrame != fSessionFrame) {
04641             fV2->HideFrame(fActFrame);
04642             fV2->ShowFrame(fSessionFrame);
04643             fActFrame = fSessionFrame;
04644             UpdateListOfPackages();
04645             fSessionFrame->UpdateListOfDataSets();
04646          }
04647          fSessionFrame->SetLocal();
04648          fServerFrame->SetAddEnabled();
04649          fServerFrame->SetConnectEnabled(kFALSE);
04650       }
04651       // proof session not connected
04652       if ((!fActDesc->fLocal) && (!fActDesc->fAttached) &&
04653           (fActFrame != fServerFrame)) {
04654          fV2->HideFrame(fActFrame);
04655          fV2->ShowFrame(fServerFrame);
04656          fActFrame = fServerFrame;
04657       }
04658       // proof session connected
04659       if ((!fActDesc->fLocal) && (fActDesc->fConnected) &&
04660           (fActDesc->fAttached)) {
04661          if (fActFrame != fSessionFrame) {
04662             fV2->HideFrame(fActFrame);
04663             fV2->ShowFrame(fSessionFrame);
04664             fActFrame = fSessionFrame;
04665          }
04666          fSessionFrame->SetLocal(kFALSE);
04667       }
04668       fSessionFrame->SetLogLevel(fActDesc->fLogLevel);
04669       fServerFrame->SetLogLevel(fActDesc->fLogLevel);
04670       if (fActDesc->fAutoEnable)
04671          fSessionFrame->CheckAutoEnPack(kTRUE);
04672       else
04673          fSessionFrame->CheckAutoEnPack(kFALSE);
04674       // update session information frame
04675       fSessionFrame->ProofInfos();
04676       fSessionFrame->UpdatePackages();
04677       fServerFrame->SetAddEnabled(kFALSE);
04678       fServerFrame->SetConnectEnabled();
04679    }
04680    else if (entry->GetParent()->GetParent()->GetParent() == 0) { // query
04681       obj = (TObject *)entry->GetParent()->GetUserData();
04682       if (obj->IsA() == TSessionDescription::Class()) {
04683          fActDesc = (TSessionDescription *)obj;
04684       }
04685       obj = (TObject *)entry->GetUserData();
04686       if (obj->IsA() == TQueryDescription::Class()) {
04687          fActDesc->fActQuery = (TQueryDescription *)obj;
04688       }
04689       // update query informations and buttons state
04690       fQueryFrame->UpdateInfos();
04691       fQueryFrame->UpdateButtons(fActDesc->fActQuery);
04692       if (fActFrame != fQueryFrame) {
04693          fV2->HideFrame(fActFrame);
04694          fV2->ShowFrame(fQueryFrame);
04695          fActFrame = fQueryFrame;
04696       }
04697       if ((fActDesc->fConnected) && (fActDesc->fAttached) &&
04698           (fActDesc->fActQuery->fStatus != TQueryDescription::kSessionQueryRunning) &&
04699           (fActDesc->fActQuery->fStatus != TQueryDescription::kSessionQuerySubmitted) )
04700          fToolBar->GetButton(kQuerySubmit)->SetState(kButtonUp);
04701       // trick to update feedback histos
04702       OnCascadeMenu();
04703    }
04704    else {   // a list (input, output)
04705       obj = (TObject *)entry->GetParent()->GetParent()->GetUserData();
04706       if (obj->IsA() == TSessionDescription::Class()) {
04707          fActDesc = (TSessionDescription *)obj;
04708       }
04709       obj = (TObject *)entry->GetParent()->GetUserData();
04710       if (obj->IsA() == TQueryDescription::Class()) {
04711          fActDesc->fActQuery = (TQueryDescription *)obj;
04712       }
04713       if (fActDesc->fActQuery) {
04714          // update input/output list views
04715          fInputFrame->RemoveAll();
04716          fOutputFrame->RemoveAll();
04717          if (fActDesc->fActQuery->fResult) {
04718             objlist = fActDesc->fActQuery->fResult->GetOutputList();
04719             if (objlist) {
04720                TIter nexto(objlist);
04721                while ((obj = (TObject *) nexto())) {
04722                   fOutputFrame->AddObject(obj);
04723                }
04724             }
04725             objlist = fActDesc->fActQuery->fResult->GetInputList();
04726             if (objlist) {
04727                TIter nexti(objlist);
04728                while ((obj = (TObject *) nexti())) {
04729                   fInputFrame->AddObject(obj);
04730                }
04731             }
04732          }
04733          else {
04734             TChain *chain = (TChain *)fActDesc->fActQuery->fChain;
04735             if (chain) {
04736                objlist = ((TTreePlayer *)(chain->GetPlayer()))->GetSelectorFromFile()->GetOutputList();
04737                if (objlist) {
04738                   TIter nexto(objlist);
04739                   while ((obj = (TObject *) nexto())) {
04740                      fOutputFrame->AddObject(obj);
04741                   }
04742                }
04743             }
04744          }
04745          fInputFrame->Resize();
04746          fOutputFrame->Resize();
04747          fClient->NeedRedraw(fOutputFrame->GetLVContainer());
04748          fClient->NeedRedraw(fInputFrame->GetLVContainer());
04749       }
04750       // switch frames
04751       if (strstr(entry->GetText(),"Output")) {
04752          if (fActFrame != fOutputFrame) {
04753             fV2->HideFrame(fActFrame);
04754             fV2->ShowFrame(fOutputFrame);
04755             fActFrame = fOutputFrame;
04756          }
04757       }
04758       else if (strstr(entry->GetText(),"Input")) {
04759          if (fActFrame != fInputFrame) {
04760             fV2->HideFrame(fActFrame);
04761             fV2->ShowFrame(fInputFrame);
04762             fActFrame = fInputFrame;
04763          }
04764       }
04765    }
04766    if (btn == 3) { // right button
04767       // place popup menus
04768       TGListTreeItem *item = fSessionHierarchy->GetSelected();
04769       if (!item) return;
04770       obj = (TObject *)item->GetUserData();
04771       if (obj && obj->IsA() == TQueryDescription::Class()) {
04772          fPopupQry->PlaceMenu(x, y, 1, 1);
04773       }
04774       else if (obj && obj->IsA() == TSessionDescription::Class()) {
04775          if (!fActDesc->fLocal)
04776             fPopupSrv->PlaceMenu(x, y, 1, 1);
04777       }
04778    }
04779    // enable / disable menu entries
04780    if (fActDesc->fConnected && fActDesc->fAttached) {
04781       fSessionMenu->EnableEntry(kSessionGetQueries);
04782       fSessionMenu->EnableEntry(kSessionShowStatus);
04783       fPopupSrv->EnableEntry(kSessionGetQueries);
04784       fPopupSrv->EnableEntry(kSessionShowStatus);
04785       fPopupSrv->EnableEntry(kSessionDisconnect);
04786       fPopupSrv->EnableEntry(kSessionShutdown);
04787       fPopupSrv->EnableEntry(kSessionCleanup);
04788       fPopupSrv->EnableEntry(kSessionReset);
04789       fSessionMenu->EnableEntry(kSessionDisconnect);
04790       fSessionMenu->EnableEntry(kSessionShutdown);
04791       fSessionMenu->EnableEntry(kSessionCleanup);
04792       fSessionMenu->EnableEntry(kSessionReset);
04793       fToolBar->GetButton(kSessionDisconnect)->SetState(kButtonUp);
04794       fQueryMenu->EnableEntry(kQuerySubmit);
04795       fPopupQry->EnableEntry(kQuerySubmit);
04796    }
04797    else {
04798       fSessionMenu->DisableEntry(kSessionGetQueries);
04799       fSessionMenu->DisableEntry(kSessionShowStatus);
04800       fPopupSrv->DisableEntry(kSessionGetQueries);
04801       fPopupSrv->DisableEntry(kSessionShowStatus);
04802       if (entry->GetParent() != 0)
04803          fSessionMenu->EnableEntry(kSessionDelete);
04804       fPopupSrv->EnableEntry(kSessionDelete);
04805       fPopupSrv->DisableEntry(kSessionDisconnect);
04806       fPopupSrv->DisableEntry(kSessionShutdown);
04807       fPopupSrv->DisableEntry(kSessionCleanup);
04808       fPopupSrv->DisableEntry(kSessionReset);
04809       fSessionMenu->DisableEntry(kSessionDisconnect);
04810       fSessionMenu->DisableEntry(kSessionShutdown);
04811       fSessionMenu->DisableEntry(kSessionCleanup);
04812       fSessionMenu->DisableEntry(kSessionReset);
04813       fToolBar->GetButton(kSessionDisconnect)->SetState(kButtonDisabled);
04814       fQueryMenu->DisableEntry(kQuerySubmit);
04815       fPopupQry->DisableEntry(kQuerySubmit);
04816    }
04817    if (fActDesc->fLocal) {
04818       fSessionMenu->DisableEntry(kSessionDelete);
04819       fSessionMenu->DisableEntry(kSessionConnect);
04820       fSessionMenu->DisableEntry(kSessionDisconnect);
04821       fSessionMenu->DisableEntry(kSessionShutdown);
04822       fSessionMenu->DisableEntry(kSessionCleanup);
04823       fSessionMenu->DisableEntry(kSessionReset);
04824       fToolBar->GetButton(kSessionDisconnect)->SetState(kButtonDisabled);
04825       fToolBar->GetButton(kSessionConnect)->SetState(kButtonDisabled);
04826       fQueryMenu->EnableEntry(kQuerySubmit);
04827       fPopupQry->EnableEntry(kQuerySubmit);
04828    }
04829 }
04830 
04831 //______________________________________________________________________________
04832 void TSessionViewer::OnListTreeDoubleClicked(TGListTreeItem *entry, Int_t /*btn*/)
04833 {
04834    // Handle mouse double clicks in list tree (connect to server).
04835 
04836    if (entry == fSessionItem)
04837       return;
04838    if (entry->GetParent()->GetParent() == 0) { // Server
04839       if (entry->GetUserData()) {
04840          TObject *obj = (TObject *)entry->GetUserData();
04841          if (obj->IsA() != TSessionDescription::Class())
04842             return;
04843          fActDesc = (TSessionDescription*)obj;
04844          // if Proof valid, update connection infos
04845       }
04846       if ((!fActDesc->fLocal) && ((!fActDesc->fConnected) ||
04847           (!fActDesc->fAttached))) {
04848          fServerFrame->OnBtnConnectClicked();
04849       }
04850    }
04851 }
04852 
04853 //______________________________________________________________________________
04854 void TSessionViewer::Terminate()
04855 {
04856    // Terminate Session : save configuration, clean temporary files and close
04857    // Proof connections.
04858 
04859    // clean-up temporary files
04860    TString pathtmp;
04861    pathtmp = TString::Format("%s/%s", gSystem->TempDirectory(), kSession_RedirectFile);
04862    if (!gSystem->AccessPathName(pathtmp)) {
04863       gSystem->Unlink(pathtmp);
04864    }
04865    pathtmp = TString::Format("%s/%s", gSystem->TempDirectory(), kSession_RedirectCmd);
04866    if (!gSystem->AccessPathName(pathtmp)) {
04867       gSystem->Unlink(pathtmp);
04868    }
04869    // close opened Proof sessions (if any)
04870    TIter next(fSessions);
04871    TSessionDescription *desc = 0;
04872    while ((desc = (TSessionDescription *)next())) {
04873       if (desc->fAttached && desc->fProof &&
04874           desc->fProof->IsValid())
04875          desc->fProof->Detach();
04876    }
04877    // Save configuration
04878    if (fAutoSave)
04879       WriteConfiguration();
04880 }
04881 
04882 //______________________________________________________________________________
04883 void TSessionViewer::CloseWindow()
04884 {
04885    // Close main Session Viewer window.
04886 
04887    // clean-up temporary files
04888    TString pathtmp;
04889    pathtmp = TString::Format("%s/%s", gSystem->TempDirectory(), kSession_RedirectFile);
04890    if (!gSystem->AccessPathName(pathtmp)) {
04891       gSystem->Unlink(pathtmp);
04892    }
04893    pathtmp = TString::Format("%s/%s", gSystem->TempDirectory(), kSession_RedirectCmd);
04894    if (!gSystem->AccessPathName(pathtmp)) {
04895       gSystem->Unlink(pathtmp);
04896    }
04897    // Save configuration
04898    if (fAutoSave)
04899       WriteConfiguration();
04900    Cleanup();
04901    fSessions->Delete();
04902    if (fSessionItem)
04903       fSessionHierarchy->DeleteChildren(fSessionItem);
04904    delete fSessionHierarchy; // this has been put int TGCanvas which isn't a
04905                              // TGComposite frame and doesn't do cleanups.
04906    fClient->FreePicture(fLocal);
04907    fClient->FreePicture(fProofCon);
04908    fClient->FreePicture(fProofDiscon);
04909    fClient->FreePicture(fQueryCon);
04910    fClient->FreePicture(fQueryDiscon);
04911    fClient->FreePicture(fBaseIcon);
04912    delete fTimer;
04913    DeleteWindow();
04914 }
04915 
04916 //______________________________________________________________________________
04917 void TSessionViewer::ChangeRightLogo(const char *name)
04918 {
04919     // Change the right logo (used for animation).
04920 
04921    fClient->FreePicture(fRightIconPicture);
04922    fRightIconPicture = (TGPicture *)fClient->GetPicture(name);
04923    fRightIcon->SetPicture(fRightIconPicture);
04924 }
04925 
04926 //______________________________________________________________________________
04927 void TSessionViewer::EnableTimer()
04928 {
04929    // Enable animation timer.
04930 
04931    if (!fTimer) fTimer = new TTimer(this, 500);
04932    fTimer->Reset();
04933    fTimer->TurnOn();
04934    time( &fStart );
04935 }
04936 
04937 //______________________________________________________________________________
04938 void TSessionViewer::DisableTimer()
04939 {
04940    // Disable animation timer.
04941 
04942    if (fTimer)
04943       fTimer->TurnOff();
04944    ChangeRightLogo("proof_disconnected.xpm");
04945 }
04946 
04947 //______________________________________________________________________________
04948 Bool_t TSessionViewer::HandleTimer(TTimer *)
04949 {
04950    // Handle animation timer.
04951 
04952    TString buf;
04953    struct tm *connected;
04954    Int_t count = gRandom->Integer(4);
04955    if (count > 3) {
04956       count = 0;
04957    }
04958    if (fChangePic)
04959       ChangeRightLogo(xpm_names[count]);
04960    time( &fElapsed );
04961    time_t elapsed_time = (time_t)difftime( fElapsed, fStart );
04962    connected = gmtime( &elapsed_time );
04963    buf.Form("      %02d:%02d:%02d", connected->tm_hour,
04964             connected->tm_min, connected->tm_sec);
04965    fStatusBar->SetText(buf.Data(), 2);
04966 
04967    if (fActDesc->fLocal) {
04968       if ((fActDesc->fActQuery) &&
04969          (fActDesc->fActQuery->fStatus ==
04970          TQueryDescription::kSessionQueryRunning)) {
04971          TChain *chain = (TChain *)fActDesc->fActQuery->fChain;
04972          if (chain)
04973             fQueryFrame->ProgressLocal(chain->GetEntries(),
04974                                        chain->GetReadEntry()+1);
04975       }
04976    }
04977 
04978    fTimer->Reset();
04979    return kTRUE;
04980 }
04981 
04982 //______________________________________________________________________________
04983 void TSessionViewer::LogMessage(const char *msg, Bool_t all)
04984 {
04985    // Load/append a log msg in the log frame.
04986 
04987    if (fLogWindow) {
04988       if (all) {
04989          // load buffer
04990          fLogWindow->LoadBuffer(msg);
04991       } else {
04992          // append
04993          fLogWindow->AddBuffer(msg);
04994       }
04995    }
04996 }
04997 
04998 //______________________________________________________________________________
04999 void TSessionViewer::QueryResultReady(char *query)
05000 {
05001    // Handle signal "query result ready" coming from Proof session.
05002 
05003    TString strtmp;
05004    strtmp.Form("Query Result Ready for %s", query);
05005    // show information on status bar
05006    ShowInfo(strtmp.Data());
05007    TGListTreeItem *item=0, *item2=0;
05008    TQueryDescription *lquery = 0;
05009    // loop over actual queries to find which one is ready
05010 
05011    TIter nexts(fSessions);
05012    TSessionDescription *desc = 0;
05013    // check if session is already in the list
05014    while ((desc = (TSessionDescription *)nexts())) {
05015       if (desc && !desc->fAttached)
05016          continue;
05017       TIter nextp(desc->fQueries);
05018       while ((lquery = (TQueryDescription *)nextp())) {
05019          if (lquery->fReference.Contains(query)) {
05020             // results are ready for this query
05021             lquery->fResult = desc->fProof->GetQueryResult(query);
05022             lquery->fStatus = TQueryDescription::kSessionQueryFromProof;
05023             if (!lquery->fResult)
05024                break;
05025             // get query status
05026             lquery->fStatus = lquery->fResult->IsFinalized() ?
05027                TQueryDescription::kSessionQueryFinalized :
05028                (TQueryDescription::ESessionQueryStatus)lquery->fResult->GetStatus();
05029             // get data set
05030             TObject *o = lquery->fResult->GetInputObject("TDSet");
05031             if (o)
05032                lquery->fChain = (TDSet *) o;
05033             item = fSessionHierarchy->FindItemByObj(fSessionItem, desc);
05034             if (item) {
05035                item2 = fSessionHierarchy->FindItemByObj(item, lquery);
05036             }
05037             if (item2) {
05038                // add input and output list entries
05039                if (lquery->fResult->GetInputList())
05040                   if (!fSessionHierarchy->FindChildByName(item2, "InputList"))
05041                      fSessionHierarchy->AddItem(item2, "InputList");
05042                if (lquery->fResult->GetOutputList())
05043                   if (!fSessionHierarchy->FindChildByName(item2, "OutputList"))
05044                      fSessionHierarchy->AddItem(item2, "OutputList");
05045             }
05046             // update list tree, query frame informations, and buttons state
05047             fSessionHierarchy->ClearViewPort();
05048             fClient->NeedRedraw(fSessionHierarchy);
05049             fQueryFrame->UpdateInfos();
05050             fQueryFrame->UpdateButtons(lquery);
05051             break;
05052          }
05053       }
05054    }
05055 }
05056 
05057 //______________________________________________________________________________
05058 void TSessionViewer::CleanupSession()
05059 {
05060    // Clean-up Proof session.
05061 
05062    TGListTreeItem *item = fSessionHierarchy->GetSelected();
05063    if (!item) return;
05064    TObject *obj = (TObject *)item->GetUserData();
05065    if (obj->IsA() != TSessionDescription::Class()) return;
05066    if (!fActDesc->fProof || !fActDesc->fProof->IsValid()) return;
05067    TString m;
05068    m.Form("Are you sure to cleanup the session \"%s::%s\"",
05069          fActDesc->fName.Data(), fActDesc->fTag.Data());
05070    Int_t result;
05071    new TGMsgBox(fClient->GetRoot(), this, "", m.Data(), 0,
05072          kMBYes | kMBNo | kMBCancel, &result);
05073    if (result == kMBYes) {
05074       // send cleanup request for the session specified by the tag reference
05075       TString sessiontag;
05076       sessiontag.Form("session-%s",fActDesc->fTag.Data());
05077       fActDesc->fProof->CleanupSession(sessiontag.Data());
05078       // clear the list of queries
05079       fActDesc->fQueries->Clear();
05080       fSessionHierarchy->DeleteChildren(item);
05081       fSessionFrame->OnBtnGetQueriesClicked();
05082       if (fAutoSave)
05083          WriteConfiguration();
05084    }
05085    // update list tree
05086    fSessionHierarchy->ClearViewPort();
05087    fClient->NeedRedraw(fSessionHierarchy);
05088 }
05089 
05090 //______________________________________________________________________________
05091 void TSessionViewer::ResetSession()
05092 {
05093    // Reset Proof session.
05094 
05095    TGListTreeItem *item = fSessionHierarchy->GetSelected();
05096    if (!item) return;
05097    TObject *obj = (TObject *)item->GetUserData();
05098    if (obj->IsA() != TSessionDescription::Class()) return;
05099    if (!fActDesc->fProof || !fActDesc->fProof->IsValid()) return;
05100    TString m;
05101    m.Form("Do you really want to reset the session \"%s::%s\"",
05102          fActDesc->fName.Data(), fActDesc->fAddress.Data());
05103    Int_t result;
05104    new TGMsgBox(fClient->GetRoot(), this, "", m.Data(), 0,
05105          kMBYes | kMBNo | kMBCancel, &result);
05106    if (result == kMBYes) {
05107       // reset the session
05108       TProof::Mgr(fActDesc->fAddress)->Reset(fActDesc->fUserName);
05109       // reset connected flag
05110       fActDesc->fAttached = kFALSE;
05111       fActDesc->fProof = 0;
05112       // disable animation timer
05113       DisableTimer();
05114       // change list tree item picture to disconnected pixmap
05115       TGListTreeItem *item2 = fSessionHierarchy->FindChildByData(
05116                               fSessionItem, fActDesc);
05117       item2->SetPictures(fProofDiscon, fProofDiscon);
05118 
05119       OnListTreeClicked(fSessionHierarchy->GetSelected(), 1, 0, 0);
05120       fSessionHierarchy->ClearViewPort();
05121       fClient->NeedRedraw(fSessionHierarchy);
05122       fStatusBar->SetText("", 1);
05123    }
05124    // update list tree
05125    fSessionHierarchy->ClearViewPort();
05126    fClient->NeedRedraw(fSessionHierarchy);
05127 }
05128 
05129 //______________________________________________________________________________
05130 void TSessionViewer::DeleteQuery()
05131 {
05132    // Delete query from list tree and ask user if he wants do delete it also
05133    // from server.
05134 
05135    TGListTreeItem *item = fSessionHierarchy->GetSelected();
05136    if (!item) return;
05137    TObject *obj = (TObject *)item->GetUserData();
05138    if (obj->IsA() != TQueryDescription::Class()) return;
05139    TQueryDescription *query = (TQueryDescription *)obj;
05140    TString m;
05141    Int_t result = 0;
05142 
05143    if (fActDesc->fAttached && fActDesc->fProof && fActDesc->fProof->IsValid()) {
05144       if ((fActDesc->fActQuery->fStatus == TQueryDescription::kSessionQuerySubmitted) ||
05145           (fActDesc->fActQuery->fStatus == TQueryDescription::kSessionQueryRunning) ) {
05146          new TGMsgBox(fClient->GetRoot(), this, "Delete Query",
05147                       "Deleting running queries is not allowed", kMBIconExclamation,
05148                       kMBOk, &result);
05149          return;
05150       }
05151       m.Form("Do you want to delete query \"%s\" from server too ?",
05152             query->fQueryName.Data());
05153       new TGMsgBox(fClient->GetRoot(), this, "", m.Data(), kMBIconQuestion,
05154             kMBYes | kMBNo | kMBCancel, &result);
05155    }
05156    else {
05157       m.Form("Dou you really want to delete query \"%s\" ?",
05158             query->fQueryName.Data());
05159       new TGMsgBox(fClient->GetRoot(), this, "", m.Data(), kMBIconQuestion,
05160             kMBOk | kMBCancel, &result);
05161    }
05162    if (result == kMBYes) {
05163       fActDesc->fProof->Remove(query->fReference.Data());
05164       fActDesc->fQueries->Remove((TObject *)query);
05165       fSessionHierarchy->DeleteItem(item);
05166       delete query;
05167    }
05168    else if (result == kMBNo || result == kMBOk) {
05169       fActDesc->fQueries->Remove((TObject *)query);
05170       fSessionHierarchy->DeleteItem(item);
05171       delete query;
05172    }
05173    fSessionHierarchy->ClearViewPort();
05174    fClient->NeedRedraw(fSessionHierarchy);
05175    if (fAutoSave)
05176       WriteConfiguration();
05177 }
05178 
05179 //______________________________________________________________________________
05180 void TSessionViewer::EditQuery()
05181 {
05182    // Edit currently selected query.
05183 
05184    TGListTreeItem *item = fSessionHierarchy->GetSelected();
05185    if (!item) return;
05186    TObject *obj = (TObject *)item->GetUserData();
05187    if (obj->IsA() != TQueryDescription::Class()) return;
05188    TQueryDescription *query = (TQueryDescription *)obj;
05189    TNewQueryDlg *dlg = new TNewQueryDlg(this, 350, 310, query, kTRUE);
05190    dlg->Popup();
05191 }
05192 
05193 //______________________________________________________________________________
05194 void TSessionViewer::StartViewer()
05195 {
05196    // Start TreeViewer from selected TChain.
05197 
05198    TGListTreeItem *item = fSessionHierarchy->GetSelected();
05199    if (!item) return;
05200    TObject *obj = (TObject *)item->GetUserData();
05201    if (obj->IsA() != TQueryDescription::Class()) return;
05202    TQueryDescription *query = (TQueryDescription *)obj;
05203    if (!query->fChain && query->fResult &&
05204       (obj = query->fResult->GetInputObject("TDSet"))) {
05205       query->fChain = (TDSet *) obj;
05206    }
05207    if (!query->fChain) return;
05208    if (query->fChain->IsA() == TChain::Class())
05209       ((TChain *)query->fChain)->StartViewer();
05210    else if (query->fChain->IsA() == TDSet::Class())
05211       ((TDSet *)query->fChain)->StartViewer();
05212 }
05213 
05214 //______________________________________________________________________________
05215 void TSessionViewer::ShowPackages()
05216 {
05217    // Query the list of uploaded packages from proof and display it
05218    // into a new text window.
05219 
05220    Window_t wdummy;
05221    Int_t  ax, ay;
05222 
05223    if (fActDesc->fLocal) return;
05224    if (!fActDesc->fProof || !fActDesc->fProof->IsValid())
05225       return;
05226    TString pathtmp = TString::Format("%s/%s", gSystem->TempDirectory(),
05227             kSession_RedirectFile);
05228    // redirect stdout/stderr to temp file
05229    if (gSystem->RedirectOutput(pathtmp.Data(), "w") != 0) {
05230       Error("ShowStatus", "stdout/stderr redirection failed; skipping");
05231       return;
05232    }
05233    fActDesc->fProof->ShowPackages(kTRUE);
05234    // restore stdout/stderr
05235    if (gSystem->RedirectOutput(0) != 0) {
05236       Error("ShowStatus", "stdout/stderr retore failed; skipping");
05237       return;
05238    }
05239    if (!fLogWindow) {
05240       fLogWindow = new TSessionLogView(this, 700, 100);
05241    } else {
05242       // Clear window
05243       fLogWindow->Clear();
05244    }
05245    fLogWindow->LoadFile(pathtmp.Data());
05246    gVirtualX->TranslateCoordinates(GetId(), fClient->GetDefaultRoot()->GetId(),
05247                                     0, 0, ax, ay, wdummy);
05248    fLogWindow->Move(ax, ay + GetHeight() + 35);
05249    fLogWindow->Popup();
05250 }
05251 
05252 //______________________________________________________________________________
05253 void TSessionViewer::UpdateListOfPackages()
05254 {
05255    // Update the list of packages.
05256 
05257    TObjString *packname;
05258    TPackageDescription *package;
05259    if (fActDesc->fConnected && fActDesc->fAttached &&
05260        fActDesc->fProof && fActDesc->fProof->IsValid() &&
05261        fActDesc->fProof->IsParallel()) {
05262       //fActDesc->fPackages->Clear();
05263       TList *packlist = fActDesc->fProof->GetListOfEnabledPackages();
05264       if(packlist) {
05265          TIter nextenabled(packlist);
05266          while ((packname = (TObjString *)nextenabled())) {
05267             package = new TPackageDescription;
05268             package->fName = packname->GetName();
05269             package->fName += ".par";
05270             package->fPathName = package->fName;
05271             package->fId   = fActDesc->fPackages->GetEntries();
05272             package->fUploaded = kTRUE;
05273             package->fEnabled = kTRUE;
05274             if (!fActDesc->fPackages->FindObject(package->fName)) {
05275                fActDesc->fPackages->Add((TObject *)package);
05276             }
05277          }
05278       }
05279       packlist = fActDesc->fProof->GetListOfPackages();
05280       if(packlist) {
05281          TIter nextpack(packlist);
05282          while ((packname = (TObjString *)nextpack())) {
05283             package = new TPackageDescription;
05284             package->fName = packname->GetName();
05285             package->fName += ".par";
05286             package->fPathName = package->fName;
05287             package->fId   = fActDesc->fPackages->GetEntries();
05288             package->fUploaded = kTRUE;
05289             package->fEnabled = kFALSE;
05290             if (!fActDesc->fPackages->FindObject(package->fName)) {
05291                fActDesc->fPackages->Add((TObject *)package);
05292             }
05293          }
05294       }
05295    }
05296 //   fSessionFrame->UpdatePackages();
05297 }
05298 
05299 //______________________________________________________________________________
05300 void TSessionViewer::ShowEnabledPackages()
05301 {
05302    // Query list of enabled packages from proof and display it
05303    // into a new text window.
05304 
05305    Window_t wdummy;
05306    Int_t  ax, ay;
05307 
05308    if (fActDesc->fLocal) return;
05309    if (!fActDesc->fProof || !fActDesc->fProof->IsValid())
05310       return;
05311    TString pathtmp = TString::Format("%s/%s", gSystem->TempDirectory(),
05312          kSession_RedirectFile);
05313    // redirect stdout/stderr to temp file
05314    if (gSystem->RedirectOutput(pathtmp.Data(), "w") != 0) {
05315       Error("ShowStatus", "stdout/stderr redirection failed; skipping");
05316       return;
05317    }
05318    fActDesc->fProof->ShowEnabledPackages(kTRUE);
05319    // restore stdout/stderr
05320    if (gSystem->RedirectOutput(0) != 0) {
05321       Error("ShowStatus", "stdout/stderr retore failed; skipping");
05322       return;
05323    }
05324    if (!fLogWindow) {
05325       fLogWindow = new TSessionLogView(this, 700, 100);
05326    } else {
05327       // Clear window
05328       fLogWindow->Clear();
05329    }
05330    fLogWindow->LoadFile(pathtmp.Data());
05331    gVirtualX->TranslateCoordinates(GetId(), fClient->GetDefaultRoot()->GetId(),
05332                                     0, 0, ax, ay, wdummy);
05333    fLogWindow->Move(ax, ay + GetHeight() + 35);
05334    fLogWindow->Popup();
05335 }
05336 
05337 //______________________________________________________________________________
05338 void TSessionViewer::ShowLog(const char *queryref)
05339 {
05340    // Display the content of the temporary log file for queryref
05341    // into a new text window.
05342 
05343    Window_t wdummy;
05344    Int_t  ax, ay;
05345 
05346    if (fActDesc->fProof) {
05347       gVirtualX->SetCursor(GetId(),gVirtualX->CreateCursor(kWatch));
05348       if (!fLogWindow) {
05349          fLogWindow = new TSessionLogView(this, 700, 100);
05350       } else {
05351          // Clear window
05352          fLogWindow->Clear();
05353       }
05354       fActDesc->fProof->Connect("LogMessage(const char*,Bool_t)",
05355             "TSessionViewer", this, "LogMessage(const char*,Bool_t)");
05356       Bool_t logonly = fActDesc->fProof->SendingLogToWindow();
05357       fActDesc->fProof->SendLogToWindow(kTRUE);
05358       if (queryref)
05359          fActDesc->fProof->ShowLog(queryref);
05360       else
05361          fActDesc->fProof->ShowLog(0);
05362       fActDesc->fProof->SendLogToWindow(logonly);
05363       // set log window position at the bottom of Session Viewer
05364       gVirtualX->TranslateCoordinates(GetId(),
05365             fClient->GetDefaultRoot()->GetId(), 0, 0, ax, ay, wdummy);
05366       fLogWindow->Move(ax, ay + GetHeight() + 35);
05367       fLogWindow->Popup();
05368       gVirtualX->SetCursor(GetId(), 0);
05369    }
05370 }
05371 
05372 //______________________________________________________________________________
05373 void TSessionViewer::ShowInfo(const char *txt)
05374 {
05375    // Display text in status bar.
05376 
05377    fStatusBar->SetText(txt,0);
05378    fClient->NeedRedraw(fStatusBar);
05379    gSystem->ProcessEvents();
05380 }
05381 
05382 //______________________________________________________________________________
05383 void TSessionViewer::ShowStatus()
05384 {
05385    // Retrieve and display Proof status.
05386 
05387    Window_t wdummy;
05388    Int_t  ax, ay;
05389 
05390    if (!fActDesc->fProof || !fActDesc->fProof->IsValid())
05391       return;
05392    TString pathtmp = TString::Format("%s/%s", gSystem->TempDirectory(),
05393             kSession_RedirectFile);
05394    // redirect stdout/stderr to temp file
05395    if (gSystem->RedirectOutput(pathtmp.Data(), "w") != 0) {
05396       Error("ShowStatus", "stdout/stderr redirection failed; skipping");
05397       return;
05398    }
05399    fActDesc->fProof->GetStatus();
05400    // restore stdout/stderr
05401    if (gSystem->RedirectOutput(0) != 0) {
05402       Error("ShowStatus", "stdout/stderr retore failed; skipping");
05403       return;
05404    }
05405    if (!fLogWindow) {
05406       fLogWindow = new TSessionLogView(this, 700, 100);
05407    } else {
05408       // Clear window
05409       fLogWindow->Clear();
05410    }
05411    fLogWindow->LoadFile(pathtmp.Data());
05412    gVirtualX->TranslateCoordinates(GetId(), fClient->GetDefaultRoot()->GetId(),
05413                                     0, 0, ax, ay, wdummy);
05414    fLogWindow->Move(ax, ay + GetHeight() + 35);
05415    fLogWindow->Popup();
05416 }
05417 
05418 //______________________________________________________________________________
05419 void TSessionViewer::StartupMessage(char *msg, Bool_t, Int_t done, Int_t total)
05420 {
05421    // Handle startup message (connection progress) coming from Proof session.
05422 
05423    Float_t pos = Float_t(Double_t(done * 100)/Double_t(total));
05424    fConnectProg->SetPosition(pos);
05425    fStatusBar->SetText(msg, 1);
05426 }
05427 
05428 //______________________________________________________________________________
05429 void TSessionViewer::MyHandleMenu(Int_t id)
05430 {
05431    // Handle session viewer custom popup menus.
05432 
05433    switch (id) {
05434 
05435       case kSessionDelete:
05436          fServerFrame->OnBtnDeleteClicked();
05437          break;
05438 
05439       case kSessionConnect:
05440          fServerFrame->OnBtnConnectClicked();
05441          break;
05442 
05443       case kSessionDisconnect:
05444          fSessionFrame->OnBtnDisconnectClicked();
05445          break;
05446 
05447       case kSessionShutdown:
05448          fSessionFrame->ShutdownSession();
05449          break;
05450 
05451       case kSessionCleanup:
05452          CleanupSession();
05453          break;
05454 
05455       case kSessionReset:
05456          ResetSession();
05457          break;
05458 
05459       case kSessionBrowse:
05460          if (fActDesc->fProof && fActDesc->fProof->IsValid()) {
05461             TBrowser *b = new TBrowser();
05462             fActDesc->fProof->Browse(b);
05463          }
05464          break;
05465 
05466       case kSessionShowStatus:
05467          ShowStatus();
05468          break;
05469 
05470       case kSessionGetQueries:
05471          fSessionFrame->OnBtnGetQueriesClicked();
05472          break;
05473 
05474       case kQueryEdit:
05475          EditQuery();
05476          break;
05477 
05478       case kQueryDelete:
05479          DeleteQuery();
05480          break;
05481 
05482       case kQueryStartViewer:
05483          StartViewer();
05484          break;
05485 
05486       case kQuerySubmit:
05487          fQueryFrame->OnBtnSubmit();
05488          break;
05489    }
05490 }
05491 
05492 //______________________________________________________________________________
05493 void TSessionViewer::OnCascadeMenu()
05494 {
05495    // Handle feedback histograms configuration menu.
05496 
05497    // divide stats canvas by number of selected feedback histos
05498    fQueryFrame->GetStatsCanvas()->cd();
05499    fQueryFrame->GetStatsCanvas()->Clear();
05500    fQueryFrame->GetStatsCanvas()->Modified();
05501    fQueryFrame->GetStatsCanvas()->Update();
05502    if (!fActDesc || !fActDesc->fActQuery) return;
05503    fActDesc->fNbHistos = 0;
05504    Int_t i = 0;
05505 
05506    if (fActDesc->fAttached && fActDesc->fProof &&
05507        fActDesc->fProof->IsValid()) {
05508       if (fOptionsMenu->IsEntryChecked(kOptionsFeedback)) {
05509          // browse list of feedback histos and check user's selected ones
05510          while (kFeedbackHistos[i]) {
05511             if (fCascadeMenu->IsEntryChecked(41+i)) {
05512                fActDesc->fProof->AddFeedback(kFeedbackHistos[i]);
05513             }
05514             i++;
05515          }
05516       }
05517       else {
05518          // if feedback option not selected, clear Proof's feedback option
05519          fActDesc->fProof->ClearFeedback();
05520       }
05521    }
05522 
05523    i = 0;
05524    // loop over feedback histo list
05525    while (kFeedbackHistos[i]) {
05526       // check if user has selected this histogram in the option menu
05527       if (fCascadeMenu->IsEntryChecked(41+i))
05528          fActDesc->fNbHistos++;
05529       i++;
05530    }
05531    fQueryFrame->GetStatsCanvas()->SetEditable(kTRUE);
05532    fQueryFrame->GetStatsCanvas()->Clear();
05533    if (fActDesc->fNbHistos == 4)
05534       fQueryFrame->GetStatsCanvas()->Divide(2, 2);
05535    else if (fActDesc->fNbHistos > 4)
05536       fQueryFrame->GetStatsCanvas()->Divide(3, 2);
05537    else
05538       fQueryFrame->GetStatsCanvas()->Divide(fActDesc->fNbHistos, 1);
05539 
05540    // if actual query has results, update feedback histos
05541    if (fActDesc->fActQuery && fActDesc->fActQuery->fResult &&
05542        fActDesc->fActQuery->fResult->GetOutputList()) {
05543       fQueryFrame->UpdateHistos(fActDesc->fActQuery->fResult->GetOutputList());
05544       fQueryFrame->ResetProgressDialog("", 0, 0, 0);
05545    }
05546    else if (fActDesc->fActQuery) {
05547       fQueryFrame->ResetProgressDialog(fActDesc->fActQuery->fSelectorString,
05548                                        fActDesc->fActQuery->fNbFiles,
05549                                        fActDesc->fActQuery->fFirstEntry,
05550                                        fActDesc->fActQuery->fNoEntries);
05551    }
05552    fQueryFrame->UpdateInfos();
05553 }
05554 //______________________________________________________________________________
05555 Bool_t TSessionViewer::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
05556 {
05557    // Handle messages send to the TSessionViewer object. E.g. all menu entries
05558    // messages.
05559 
05560    TNewQueryDlg *dlg;
05561 
05562    switch (GET_MSG(msg)) {
05563       case kC_COMMAND:
05564          switch (GET_SUBMSG(msg)) {
05565             case kCM_BUTTON:
05566             case kCM_MENU:
05567                switch (parm1) {
05568 
05569                   case kFileCloseViewer:
05570                      CloseWindow();
05571                      break;
05572 
05573                   case kFileLoadConfig:
05574                      {
05575                         TGFileInfo fi;
05576                         fi.fFilename = strdup((char *)gSystem->BaseName(fConfigFile));
05577                         fi.fIniDir = strdup((char *)gSystem->HomeDirectory());
05578                         fi.fFileTypes = conftypes;
05579                         new TGFileDialog(fClient->GetRoot(), this, kFDOpen, &fi);
05580                         if (fi.fFilename) {
05581                            fConfigFile = fi.fFilename;
05582                            ReadConfiguration(fConfigFile);
05583                            OnListTreeClicked(fSessionHierarchy->GetSelected(), 1, 0, 0);
05584                         }
05585                      }
05586                      break;
05587 
05588                   case kFileSaveConfig:
05589                      {
05590                         TGFileInfo fi;
05591                         fi.fFilename = strdup((char *)gSystem->BaseName(fConfigFile));
05592                         fi.fIniDir = strdup((char *)gSystem->HomeDirectory());
05593                         fi.fFileTypes = conftypes;
05594                         new TGFileDialog(fClient->GetRoot(), this, kFDSave, &fi);
05595                         if (fi.fFilename) {
05596                            fConfigFile = fi.fFilename;
05597                            WriteConfiguration(fConfigFile);
05598                         }
05599                      }
05600                      break;
05601 
05602                   case kFileQuit:
05603                      Terminate();
05604                      if (!gApplication->ReturnFromRun())
05605                         delete this;
05606                      gApplication->Terminate(0);
05607                      break;
05608 
05609                   case kSessionNew:
05610                      fServerFrame->OnBtnNewServerClicked();
05611                      break;
05612 
05613                   case kSessionAdd:
05614                      fServerFrame->OnBtnAddClicked();
05615                      break;
05616 
05617                   case kSessionDelete:
05618                      fServerFrame->OnBtnDeleteClicked();
05619                      break;
05620 
05621                   case kSessionCleanup:
05622                      CleanupSession();
05623                      break;
05624 
05625                   case kSessionReset:
05626                      ResetSession();
05627                      break;
05628 
05629                   case kSessionConnect:
05630                      fServerFrame->OnBtnConnectClicked();
05631                      break;
05632 
05633                   case kSessionDisconnect:
05634                      fSessionFrame->OnBtnDisconnectClicked();
05635                      break;
05636 
05637                   case kSessionShutdown:
05638                      fSessionFrame->ShutdownSession();
05639                      break;
05640 
05641                   case kSessionShowStatus:
05642                      ShowStatus();
05643                      break;
05644 
05645                   case kSessionGetQueries:
05646                      fSessionFrame->OnBtnGetQueriesClicked();
05647                      break;
05648 
05649                   case kQueryNew:
05650                      dlg = new TNewQueryDlg(this, 350, 310);
05651                      dlg->Popup();
05652                      break;
05653 
05654                   case kQueryEdit:
05655                      EditQuery();
05656                      break;
05657 
05658                   case kQueryDelete:
05659                      DeleteQuery();
05660                      break;
05661 
05662                   case kQueryStartViewer:
05663                      StartViewer();
05664                      break;
05665 
05666                   case kQuerySubmit:
05667                      fQueryFrame->OnBtnSubmit();
05668                      break;
05669 
05670                   case kOptionsAutoSave:
05671                      if(fOptionsMenu->IsEntryChecked(kOptionsAutoSave)) {
05672                         fOptionsMenu->UnCheckEntry(kOptionsAutoSave);
05673                         fAutoSave = kFALSE;
05674                      }
05675                      else {
05676                         fOptionsMenu->CheckEntry(kOptionsAutoSave);
05677                         fAutoSave = kTRUE;
05678                      }
05679                      break;
05680 
05681                   case kOptionsStatsHist:
05682                      if(fOptionsMenu->IsEntryChecked(kOptionsStatsHist)) {
05683                         fOptionsMenu->UnCheckEntry(kOptionsStatsHist);
05684                         gEnv->SetValue("Proof.StatsHist", 0);
05685                      }
05686                      else {
05687                         fOptionsMenu->CheckEntry(kOptionsStatsHist);
05688                         gEnv->SetValue("Proof.StatsHist", 1);
05689                      }
05690                      break;
05691 
05692                   case kOptionsStatsTrace:
05693                      if(fOptionsMenu->IsEntryChecked(kOptionsStatsTrace)) {
05694                         fOptionsMenu->UnCheckEntry(kOptionsStatsTrace);
05695                         gEnv->SetValue("Proof.StatsTrace", 0);
05696                      }
05697                      else {
05698                         fOptionsMenu->CheckEntry(kOptionsStatsTrace);
05699                         gEnv->SetValue("Proof.StatsTrace", 1);
05700                      }
05701                      break;
05702 
05703                   case kOptionsSlaveStatsTrace:
05704                      if(fOptionsMenu->IsEntryChecked(kOptionsSlaveStatsTrace)) {
05705                         fOptionsMenu->UnCheckEntry(kOptionsSlaveStatsTrace);
05706                         gEnv->SetValue("Proof.SlaveStatsTrace", 0);
05707                      }
05708                      else {
05709                         fOptionsMenu->CheckEntry(kOptionsSlaveStatsTrace);
05710                         gEnv->SetValue("Proof.SlaveStatsTrace", 1);
05711                      }
05712                      break;
05713 
05714                   case kOptionsFeedback:
05715                      if(fOptionsMenu->IsEntryChecked(kOptionsFeedback)) {
05716                         fOptionsMenu->UnCheckEntry(kOptionsFeedback);
05717                      }
05718                      else {
05719                         fOptionsMenu->CheckEntry(kOptionsFeedback);
05720                      }
05721                      break;
05722 
05723                   case 41:
05724                   case 42:
05725                   case 43:
05726                   case 44:
05727                   case 45:
05728                   case 46:
05729                      if (fCascadeMenu->IsEntryChecked(parm1)) {
05730                         fCascadeMenu->UnCheckEntry(parm1);
05731                      }
05732                      else {
05733                         fCascadeMenu->CheckEntry(parm1);
05734                      }
05735                      OnCascadeMenu();
05736                      break;
05737 
05738                   case 50:
05739                      if (fCascadeMenu->IsEntryChecked(parm1)) {
05740                         fCascadeMenu->UnCheckEntry(parm1);
05741                      }
05742                      else {
05743                         fCascadeMenu->CheckEntry(parm1);
05744                      }
05745                      OnCascadeMenu();
05746                      break;
05747 
05748                   case kHelpAbout:
05749                      {
05750 #ifdef R__UNIX
05751                         TString rootx;
05752 # ifdef ROOTBINDIR
05753                         rootx = ROOTBINDIR;
05754 # else
05755                         rootx = gSystem->Getenv("ROOTSYS");
05756                         if (!rootx.IsNull()) rootx += "/bin";
05757 # endif
05758                         rootx += "/root -a &";
05759                         gSystem->Exec(rootx);
05760 #else
05761 #ifdef WIN32
05762                         new TWin32SplashThread(kTRUE);
05763 #else
05764                         char str[32];
05765                         sprintf(str, "About ROOT %s...", gROOT->GetVersion());
05766                         TRootHelpDialog *hd = new TRootHelpDialog(this, str, 600, 400);
05767                         hd->SetText(gHelpAbout);
05768                         hd->Popup();
05769 #endif
05770 #endif
05771                      }
05772                      break;
05773 
05774                   default:
05775                      break;
05776                }
05777             default:
05778                break;
05779          }
05780       default:
05781          break;
05782    }
05783 
05784    return kTRUE;
05785 }

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