TTreeViewer.cxx

Go to the documentation of this file.
00001 // @(#)root/treeviewer:$Id: TTreeViewer.cxx 36308 2010-10-12 07:13:29Z brun $
00002 //Author : Andrei Gheata   16/08/00
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, 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 // TreeViewer is a graphic user interface designed to handle ROOT trees and to
00015 // take advantage of TTree class features.
00016 //
00017 // It uses ROOT native GUI widgets adapted for 'drag and drop' functionality.
00018 // in the same session.
00019 // The following capabilities are making the viewer a helpful tool for analysis:
00020 //  - several trees may be opened in the same session;
00021 //  - branches and leaves can be easily browsed or scanned;
00022 //  - fast drawing of branch expressions by double-clicking;
00023 //  - new variables/selections easy to compose with the built-in editor;
00024 //  - histograms can be composed by dragging leaves or user-defined expressions
00025 //  to X, Y and Z axis items;
00026 //  - the tree entries to be processed can be selected with a double slider;
00027 //  - selections can be defined and activated by dragging them to the 'Cut' item;
00028 //  - all expressions can be aliased and aliases can be used in composing others;
00029 //  - input/output event lists easy to handle;
00030 //  - menu with histogram drawing options;
00031 //  - user commands may be executed within the viewer and the current command
00032 //  can be echoed;
00033 //  - current 'Draw' event loop is reflected by a progress bar and may be
00034 //  interrupted by the user;
00035 //  - all widgets have self-explaining tool tips and/or context menus;
00036 //  - expressions/leaves can be dragged to a 'scan box' and scanned by
00037 //  double-clicking this item. The result can be redirected to an ASCII file;
00038 //
00039 // The layout has the following items:
00040 //
00041 //  - a menu bar with entries : File, Edit, Run, Options and Help;
00042 //  - a toolbar in the upper part where you can issue user commands, change
00043 //  the drawing option and the histogram name, three check buttons Hist, Rec
00044 //  and Scan.HIST toggles histogram drawing mode, REC enables recording of the
00045 //  last command issued and SCAN enables redirecting of TTree::Scan command in
00046 //  an ASCII file (see -Scanning expressions-);
00047 //  - a button bar in the lower part with : buttons DRAW/STOP that issue histogram
00048 //  drawing and stop the current command respectively, two text widgets where
00049 //  input and output event lists can be specified, a message box and a RESET
00050 //  button on the right that clear edited expression content (see Editing...)
00051 //  - a tree-type list on the main left panel where you can select among trees or
00052 //  branches. The tree/branch will be detailed in the right panel.
00053 //  Mapped trees are provided with context menus, activated by right-clicking;
00054 //  - a view-type list on the right panel. The first column contain X, Y and
00055 //  Z expression items, an optional cut and ten optional editable expressions.
00056 //  Expressions and leaf-type items can be dragged or deleted. A right click on
00057 //  the list-box or item activates context menus.
00058 //
00059 // Opening a new tree and saving a session :
00060 //
00061 //   To open a new tree in the viewer use <File/Open tree file> menu
00062 // The content of the file (keys) will be listed. Use <SetTreeName> function
00063 // from the context menu of the right panel, entering a tree name among those
00064 // listed.
00065 //   To save the current session, use <File/Save> menu or the <SaveSource>
00066 // function from the context menu of the right panel (to specify the name of the
00067 // file - name.C)
00068 //   To open a previously saved session for the tree MyTree, first open MyTree
00069 // in the browser, then use <File/Open session> menu.
00070 //
00071 // Dragging items:
00072 //
00073 // Items that can be dragged from the list in the right : expressions and
00074 // leaves. Dragging an item and dropping to another will copy the content of first
00075 // to the last (leaf->expression, expression->expression). Items far to the right
00076 // side of the list can be easily dragged to the left (where expressions are
00077 // placed) by dragging them to the left at least 10 pixels.
00078 //
00079 // Editing expressions
00080 //
00081 //   Any editable expression from the right panel has two components : a
00082 // true name (that will be used when TTree::Draw() commands are issued) and an
00083 // alias. The visible name is the alias. Aliases of user defined expressions have
00084 // a leading ~ and may be used in new expressions. Expressions containing boolean
00085 // operators have a specific icon and may be dragged to the active cut (scissors
00086 // item) position.
00087 //    The expression editor can be activated by double-clicking empty expression,
00088 // using <EditExpression> from the selected expression context menu or using
00089 // <Edit/Expression> menu.
00090 //    The editor will pop-up in the left part, but it can be moved.
00091 // The editor usage is the following :
00092 //   - you can write C expressions made of leaf names by hand or you can insert
00093 //   any item from the right panel by clicking on it (recommandable);
00094 //   - you can click on other expressions/leaves to paste them in the editor;
00095 //   - you should write the item alias by hand since it not only make the expression
00096 //  meaningfull, but it also highly improve the layout for big expressions
00097 //   - you may redefine an old alias - the other expressions depending on it will
00098 //   be modified accordingly. An alias must not be the leading string of other aliases.
00099 //  When Draw commands are issued, the name of the corresponding histogram axes
00100 //  will become the aliases of the expressions.
00101 //
00102 // User commands can be issued directly from the textbox labeled "Command"
00103 // from the upper-left toolbar by typing and pressing Enter at the end.
00104 //   An other way is from the right panel context menu : ExecuteCommand.
00105 // All commands can be interrupted at any time by pressing the STOP button
00106 // from the bottom-left
00107 // You can toggle recording of the current command in the history file by
00108 // checking the Rec button from the top-right
00109 //
00110 // Context menus
00111 //
00112 //   You can activate context menus by right-clicking on items or inside the
00113 // right panel.
00114 // Context menus for mapped items from the left tree-type list :
00115 //   The items from the left that are provided with context menus are tree and
00116 // branch items. You can directly activate the *MENU* marked methods of TTree
00117 // from this menu.
00118 // Context menu for the right panel :
00119 //   A general context menu is acivated if the user right-clicks the right panel.
00120 //   Commands are :
00121 //   - EmptyAll        : clears the content of all expressions;
00122 //   - ExecuteCommand  : execute a ROOT command;
00123 //   - MakeSelector    : equivalent of TTree::MakeSelector();
00124 //   - NewExpression   : add an expression item in the right panel;
00125 //   - Process         : equivalent of TTree::Process();
00126 //   - SaveSource      : save the current session as a C++ macro;
00127 //   - SetScanFileName : define a name for the file where TTree::Scan command
00128 //   is redirected when the <Scan> button is checked;
00129 //   - SetTreeName     : open a new tree whith this name in the viewer;
00130 //   A specific context menu is activated if expressions/leaves are right-clicked.
00131 //   Commands are :
00132 //   - Draw            : draw a histogram for this item;
00133 //   - EditExpression  : pops-up the expression editor;
00134 //   - Empty           : empty the name and alias of this item;
00135 //   - RemoveItem      : removes clicked item from the list;
00136 //   - Scan            : scan this expression;
00137 //   - SetExpression   : edit name and alias for this item by hand;
00138 //
00139 // Starting the viewer
00140 //
00141 //   1) From the TBrowser :
00142 //  Select a tree in the TBrowser, then call the StartViewer() method from its
00143 // context menu (right-click on the tree).
00144 //   2) From the command line :
00145 //  Start a ROOT session in the directory where you have your tree.
00146 // You will need first to load the library for TTreeViewer and optionally other
00147 // libraries for user defined classes (you can do this later in the session) :
00148 //    root [0] gSystem->Load(\"TTreeViewer\");
00149 // Supposing you have the tree MyTree in the file MyFile, you can do :
00150 //    root [1] TFile file(\"Myfile\");
00151 //    root [2] new TTreeViewer(\"Mytree\");
00152 // or :
00153 //    root [2] TreeViewer *tv = new TTreeViewer();
00154 //    root [3] tv->SetTreeName(\"Mytree\");
00155 //
00156 //Begin_Html
00157 /*
00158 <img src="treeview.gif">
00159 */
00160 //End_Html
00161 //
00162 
00163 #include "RConfigure.h"
00164 
00165 #include "Riostream.h"
00166 #include "TTreeViewer.h"
00167 #include "HelpText.h"
00168 #include "HelpTextTV.h"
00169 #include "TTVLVContainer.h"
00170 #include "TTVSession.h"
00171 
00172 #include "TROOT.h"
00173 #include "TError.h"
00174 #include "TGMsgBox.h"
00175 #include "TTreePlayer.h"
00176 #include "TContextMenu.h"
00177 #include "TInterpreter.h"
00178 #include "TLeaf.h"
00179 #include "TRootHelpDialog.h"
00180 #include "TSystem.h"
00181 #include "TApplication.h"
00182 #include "TVirtualX.h"
00183 #include "TGClient.h"
00184 #include "TKey.h"
00185 #include "TFile.h"
00186 #include "TGMenu.h"
00187 #include "TGFrame.h"
00188 #include "TCanvas.h"
00189 #include "TH1.h"
00190 #include "TTree.h"
00191 #include "TFriendElement.h"
00192 #include "TObjArray.h"
00193 #include "TObjString.h"
00194 #include "TGButton.h"
00195 #include "TGButtonGroup.h"
00196 #include "TGTextEntry.h"
00197 #include "TGComboBox.h"
00198 #include "TGLabel.h"
00199 #include "TGListView.h"
00200 #include "TGListTree.h"
00201 #include "TGMimeTypes.h"
00202 #include "TGSplitter.h"
00203 #include "TGDoubleSlider.h"
00204 #include "TGToolBar.h"
00205 #include "TGStatusBar.h"
00206 #include "Getline.h"
00207 #include "TTimer.h"
00208 #include "TG3DLine.h"
00209 #include "TGFileDialog.h"
00210 #include "TGProgressBar.h"
00211 #include "TClonesArray.h"
00212 #include "TSpider.h"
00213 
00214 #ifdef WIN32
00215 #include "TWin32SplashThread.h"
00216 #endif
00217 
00218 // drawing options
00219 static const char* gOptgen[16] =
00220 {
00221    "","AXIS","HIST","SAME","CYL","POL","SPH","PSR","LEGO","LEGO1","LEGO2",
00222    "SURF","SURF1","SURF2","SURF3","SURF4"
00223 };
00224 static const char* gOpt1D[12] =
00225 {
00226    "","AH","B","C","E","E1","E2","E3","E4","L","P","*H"
00227 };
00228 static const char* gOpt2D[14] =
00229 {
00230    "","ARR","BOX","COL","COL2","CONT","CONT0","CONT1","CONT2","CONT3",
00231    "FB","BB","SCAT","PROF"
00232 };
00233 
00234 static const char* gOpenTypes[] = {"Root files",   "*.root",
00235                                    0,              0       };
00236 
00237 static const char* gMacroTypes[] = {"C++ macros",   "*.C",
00238                                    0,              0       };
00239 
00240 // Menu command id's
00241 enum ERootTreeViewerCommands {
00242    kFileCanvas,
00243    kFileBrowse,
00244    kFileLoadLibrary = 3,
00245    kFileOpenSession,
00246    kFileSaveMacro,
00247    kFilePrint,
00248    kFileClose,
00249    kFileQuit,
00250 
00251    kEditExpression,
00252    kEditCut,
00253    kEditMacro,
00254    kEditEvent,
00255 
00256    kRunCommand,
00257    kRunMacro,
00258 
00259    kOptionsReset,
00260    kOptionsGeneral = 20,
00261    kOptions1D = 50,
00262    kOptions2D = 70,
00263 
00264    kHelpAbout = 100,
00265    kHelpAboutTV,
00266    kHelpStart,
00267    kHelpLayout,
00268    kHelpOpenSave,
00269    kHelpDragging,
00270    kHelpEditing,
00271    kHelpSession,
00272    kHelpCommands,
00273    kHelpContext,
00274    kHelpDrawing,
00275    kHelpMacros,
00276 
00277    kBarCommand,
00278    kBarOption,
00279    kBarCut,
00280    kAxis
00281 };
00282 
00283 // button Id's
00284 enum EButtonIdentifiers {
00285    kDRAW,
00286    kRESET,
00287    kSTOP,
00288    kCLOSE,
00289    kSLIDER,
00290    kBGFirst,
00291    kBGPrevious,
00292    kBGRecord,
00293    kBGNext,
00294    kBGLast
00295 };
00296 
00297 ClassImp(TTreeViewer)
00298 
00299 //______________________________________________________________________________
00300 TTreeViewer::TTreeViewer(const char* treeName) : 
00301    TGMainFrame(0,10,10,kVerticalFrame),
00302    fDimension(0), fVarDraw(0), fScanMode(0), 
00303    fTreeIndex(0), fDefaultCursor(0), fWatchCursor(0), 
00304    fCounting(0), fStopMapping(0), fEnableCut(0),fNexpressions(0)
00305 {
00306    // TTreeViewer default constructor
00307 
00308    fTree = 0;
00309    if (!gClient) return;
00310    char command[128];
00311    snprintf(command,128, "TTreeViewer *gTV = (TTreeViewer*)0x%lx", (ULong_t)this);
00312    gROOT->ProcessLine(command);
00313    gROOT->ProcessLine("TTree *tv__tree = 0;");
00314    fTreeList = new TList;
00315    gROOT->ProcessLine("TList *tv__tree_list = new TList;");
00316    fFilename = "";
00317    gROOT->ProcessLine("TFile *tv__tree_file = 0;");
00318    gInterpreter->SaveContext();
00319    BuildInterface();
00320    SetTreeName(treeName);
00321 }
00322 
00323 //______________________________________________________________________________
00324 TTreeViewer::TTreeViewer(const TTree *tree) : 
00325    TGMainFrame(0, 10, 10, kVerticalFrame),
00326    fDimension(0), fVarDraw(0), fScanMode(0), 
00327    fTreeIndex(0), fDefaultCursor(0), fWatchCursor(0), 
00328    fCounting(0), fStopMapping(0), fEnableCut(0),fNexpressions(0)
00329 
00330 {
00331    // TTreeViewer constructor with a pointer to a Tree
00332 
00333    fTree = 0;
00334    char command[128];
00335    snprintf(command,128, "TTreeViewer *gTV = (TTreeViewer*)0x%lx", (ULong_t)this);
00336    gROOT->ProcessLine(command);
00337    if (!tree) return;
00338    gROOT->ProcessLine("TTree *tv__tree = 0;");
00339    fTreeList = new TList;
00340    gROOT->ProcessLine("TList *tv__tree_list = new TList;");
00341    fFilename = "";
00342    gROOT->ProcessLine("TFile *tv__tree_file = 0;");
00343    gInterpreter->SaveContext();
00344    BuildInterface();
00345    TDirectory *dirsav = gDirectory;
00346    TDirectory *cdir = tree->GetDirectory();
00347    if (cdir) cdir->cd();
00348 
00349    SetTreeName(tree->GetName());
00350    // If the tree is a chain, the tree directory will be changed by SwitchTree
00351    // (called by SetTreeName)
00352    cdir = tree->GetDirectory();
00353    if (cdir) {
00354       if (cdir->GetFile()) fFilename = cdir->GetFile()->GetName();
00355    }
00356    if (dirsav) dirsav->cd();
00357 }
00358 //______________________________________________________________________________
00359 void TTreeViewer::AppendTree(TTree *tree)
00360 {
00361    // Allow geting the tree from the context menu.
00362 
00363    if (!tree) return;
00364    TTree *ftree;
00365    if (fTreeList) {
00366       if (fTreeList->FindObject(tree)) {
00367          printf("Tree found\n");
00368          TIter next(fTreeList);
00369          Int_t index = 0;
00370          while ((ftree = (TTree*)next())) {
00371             if (ftree==tree) {printf("found at index %i\n", index);break;}
00372             index++;
00373          }
00374          SwitchTree(index);
00375          if (fTree != fMappedTree) {
00376             // switch also the global "tree" variable
00377             fLVContainer->RemoveNonStatic();
00378             // map it on the right panel
00379             MapTree(fTree);
00380             fListView->Layout();
00381             TGListTreeItem *base = 0;
00382             TGListTreeItem *parent = fLt->FindChildByName(base, "TreeList");
00383             TGListTreeItem *item = fLt->FindChildByName(parent, fTree->GetName());
00384             fLt->ClearHighlighted();
00385             fLt->HighlightItem(item);
00386             fClient->NeedRedraw(fLt);
00387          }
00388          return;
00389       }
00390    }
00391    if (fTree != tree) {
00392       fTree = tree;
00393       // load the tree via the interpreter
00394       char command[100];
00395       command[0] = 0;
00396       // define a global "tree" variable for the same tree
00397       snprintf(command,100, "tv__tree = (TTree *)0x%lx;", (ULong_t)tree);
00398       ExecuteCommand(command);
00399    }
00400    //--- add the tree to the list if it is not already in
00401    if (fTreeList) fTreeList->Add(fTree);
00402    ExecuteCommand("tv__tree_list->Add(tv__tree);");
00403    //--- map this tree
00404    TGListTreeItem *base = 0;
00405    TGListTreeItem *parent = fLt->FindChildByName(base, "TreeList");
00406    if (!parent) parent = fLt->AddItem(base, "TreeList", new ULong_t(kLTNoType));
00407    ULong_t *itemType = new ULong_t((fTreeIndex << 8) | kLTTreeType);
00408    fTreeIndex++;
00409    TGListTreeItem *lTreeItem = fLt->AddItem(parent, tree->GetName(), itemType,
00410                gClient->GetPicture("tree_t.xpm"), gClient->GetPicture("tree_t.xpm"));
00411    MapTree(fTree, lTreeItem, kFALSE);
00412    fLt->OpenItem(parent);
00413    fLt->HighlightItem(lTreeItem);
00414    fClient->NeedRedraw(fLt);
00415 
00416    //--- map slider and list view
00417    SwitchTree(fTreeIndex-1);
00418    fLVContainer->RemoveNonStatic();
00419    MapTree(fTree);
00420    fListView->Layout();
00421    SetFile();
00422 }
00423 //______________________________________________________________________________
00424 void TTreeViewer::SetNexpressions(Int_t expr)
00425 {
00426    // Change the number of expression widgets.
00427 
00428    Int_t diff = expr - fNexpressions;
00429    if (diff <= 0) return;
00430    if (!fLVContainer) return;
00431    for (Int_t i=0; i<TMath::Abs(diff); i++) NewExpression();
00432 }
00433 //______________________________________________________________________________
00434 void TTreeViewer::SetScanFileName(const char *name)
00435 {
00436    // Set the name of the file where to redirect <Scan> output.
00437 
00438    if (fTree) ((TTreePlayer *)fTree->GetPlayer())->SetScanFileName(name);
00439 }
00440 //______________________________________________________________________________
00441 void TTreeViewer::SetScanRedirect(Bool_t mode)
00442 {
00443    // Set the state of Scan check button.
00444 
00445    if (mode)
00446       fBarScan->SetState(kButtonDown);
00447    else
00448       fBarScan->SetState(kButtonUp);
00449 }
00450 //______________________________________________________________________________
00451 void TTreeViewer::SetTreeName(const char* treeName)
00452 {
00453    // Allow geting the tree from the context menu.
00454 
00455    if (!treeName) return;
00456    TTree *tree = (TTree *) gROOT->FindObject(treeName);
00457    if (fTreeList) {
00458       if (fTreeList->FindObject(treeName)) {
00459          printf("Tree found\n");
00460          TIter next(fTreeList);
00461          Int_t index = 0;
00462          while ((tree = (TTree*)next())) {
00463             if (!strcmp(treeName, tree->GetName())) {printf("found at index %i\n", index);break;}
00464             index++;
00465          }
00466          SwitchTree(index);
00467          if (fTree != fMappedTree) {
00468             // switch also the global "tree" variable
00469             fLVContainer->RemoveNonStatic();
00470             // map it on the right panel
00471             MapTree(fTree);
00472             fListView->Layout();
00473             TGListTreeItem *base = 0;
00474             TGListTreeItem *parent = fLt->FindChildByName(base, "TreeList");
00475             TGListTreeItem *item = fLt->FindChildByName(parent, fTree->GetName());
00476             fLt->ClearHighlighted();
00477             fLt->HighlightItem(item);
00478             fClient->NeedRedraw(fLt);
00479          }
00480          return;
00481       }
00482    }
00483    if (!tree) return;
00484 //   ((TTreePlayer *)tree->GetPlayer())->SetViewer(this);
00485    if (fTree != tree) {
00486       fTree = tree;
00487       // load the tree via the interpreter
00488       // define a global "tree" variable for the same tree
00489       TString command = TString::Format("tv__tree = (TTree *) gROOT->FindObject(\"%s\");", treeName);
00490       ExecuteCommand(command.Data());
00491    }
00492    //--- add the tree to the list if it is not already in
00493    if (fTreeList) fTreeList->Add(fTree);
00494    ExecuteCommand("tv__tree_list->Add(tv__tree);");
00495    //--- map this tree
00496    TGListTreeItem *base = 0;
00497    TGListTreeItem *parent = fLt->FindChildByName(base, "TreeList");
00498    if (!parent) parent = fLt->AddItem(base, "TreeList", new ULong_t(kLTNoType));
00499    ULong_t *itemType = new ULong_t((fTreeIndex << 8) | kLTTreeType);
00500    fTreeIndex++;
00501    TGListTreeItem *lTreeItem = fLt->AddItem(parent, treeName, itemType,
00502                gClient->GetPicture("tree_t.xpm"), gClient->GetPicture("tree_t.xpm"));
00503    MapTree(fTree, lTreeItem, kFALSE);
00504    fLt->OpenItem(parent);
00505    fLt->HighlightItem(lTreeItem);
00506    fClient->NeedRedraw(fLt);
00507 
00508    //--- map slider and list view
00509    SwitchTree(fTreeIndex-1);
00510    fLVContainer->RemoveNonStatic();
00511    MapTree(fTree);
00512    fListView->Layout();
00513    SetFile();
00514 }
00515 //______________________________________________________________________________
00516 void TTreeViewer::SetFile()
00517 {
00518    // Set file name containing the tree.
00519 
00520    if (!fTree) return;
00521    TSeqCollection *list = gROOT->GetListOfFiles();
00522    TTree *tree;
00523    TIter next(list);
00524    TObject *obj;
00525    TFile   *file;
00526    while ((obj=next())) {
00527       file = (TFile*)obj;
00528       if (file) {
00529          tree = (TTree*)file->Get(fTree->GetName());
00530          if (tree) {
00531             fFilename = file->GetName();
00532             cout << "File name : "<< fFilename << endl;
00533             return;
00534          } else {
00535             fFilename = "";
00536          }
00537       }
00538    }
00539    fFilename = "";
00540 }
00541 //______________________________________________________________________________
00542 void TTreeViewer::BuildInterface()
00543 {
00544    // Create all viewer widgets.
00545 
00546    //--- timer & misc
00547    fCounting = kFALSE;
00548    fScanMode = kFALSE;
00549    fEnableCut = kTRUE;
00550    fTimer = new TTimer(this, 20, kTRUE);
00551    fLastOption = "";
00552    fSession = new TTVSession(this);
00553    //--- cursors
00554    fDefaultCursor = gVirtualX->CreateCursor(kPointer);
00555    fWatchCursor = gVirtualX->CreateCursor(kWatch);
00556    //--- colours
00557    ULong_t color;
00558    gClient->GetColorByName("blue",color);
00559    //--- pictures for X, Y and Z expression items
00560    fPicX = gClient->GetPicture("x_pic.xpm");
00561    fPicY = gClient->GetPicture("y_pic.xpm");
00562    fPicZ = gClient->GetPicture("z_pic.xpm");
00563 
00564    //--- general context menu
00565    fContextMenu = new TContextMenu("TreeViewer context menu","");
00566    fMappedTree = 0;
00567    fMappedBranch = 0;
00568    fDialogBox = 0;
00569    fDimension = 0;
00570    fVarDraw = kFALSE;
00571    fStopMapping = kFALSE;
00572 //   fFilename = "";
00573    fSourceFile = "treeviewer.C";
00574    //--- lists : trees and widgets to be removed
00575 //   fTreeList = 0;
00576    fTreeIndex = 0;
00577    fWidgets = new TList();
00578    //--- create menus --------------------------------------------------------
00579    //--- File menu
00580    fFileMenu = new TGPopupMenu(fClient->GetRoot());
00581    fFileMenu->AddEntry("&New canvas",      kFileCanvas);
00582    fFileMenu->AddEntry("Open &tree file...", kFileBrowse);
00583    fFileMenu->AddEntry("&Load Library...", kFileLoadLibrary);
00584    fFileMenu->AddEntry("&Open session",   kFileOpenSession);
00585    fFileMenu->AddEntry("&Save source",    kFileSaveMacro);
00586    fFileMenu->AddSeparator();
00587    fFileMenu->AddEntry("&Print",           kFilePrint);
00588    fFileMenu->AddEntry("&Close",           kFileClose);
00589    fFileMenu->AddSeparator();
00590    fFileMenu->AddEntry("&Quit ROOT",       kFileQuit);
00591 
00592    fFileMenu->DisableEntry(kFilePrint);
00593 
00594    //--- Edit menu
00595    fEditMenu = new TGPopupMenu(gClient->GetRoot());
00596    fEditMenu->AddEntry("&Expression...",   kEditExpression);
00597    fEditMenu->AddEntry("&Cut...",          kEditCut);
00598    fEditMenu->AddEntry("&Macro...",        kEditMacro);
00599    fEditMenu->AddEntry("E&Vent...",        kEditEvent);
00600 
00601    fEditMenu->DisableEntry(kEditMacro);
00602    fEditMenu->DisableEntry(kEditEvent);
00603    //---Run menu
00604    fRunMenu = new TGPopupMenu(gClient->GetRoot());
00605    fRunMenu->AddEntry("&Macro...",         kRunMacro);
00606    fRunMenu->DisableEntry(kRunMacro);
00607    //--- Options menu
00608    //--- General options
00609    fOptionsGen = new TGPopupMenu(gClient->GetRoot());
00610    fOptionsGen->AddEntry("Default",        kOptionsGeneral);
00611    fOptionsGen->AddSeparator();
00612    fOptionsGen->AddEntry("Axis only",      kOptionsGeneral+1);  // "AXIS"
00613    fOptionsGen->AddEntry("Contour only",   kOptionsGeneral+2);  // "HIST"
00614    fOptionsGen->AddEntry("Superimpose",    kOptionsGeneral+3);  //"SAME"
00615    fOptionsGen->AddEntry("Cylindrical",    kOptionsGeneral+4);  //"CYL"
00616    fOptionsGen->AddEntry("Polar",          kOptionsGeneral+5);  //"POL"
00617    fOptionsGen->AddEntry("Spherical",      kOptionsGeneral+6);  //"SPH"
00618    fOptionsGen->AddEntry("PsRap/Phi",      kOptionsGeneral+7);  //"PSR"
00619    fOptionsGen->AddEntry("Lego HLR",       kOptionsGeneral+8);  //"LEGO"
00620    fOptionsGen->AddEntry("Lego HSR",       kOptionsGeneral+9);  //"LEGO1"
00621    fOptionsGen->AddEntry("Lego Color",     kOptionsGeneral+10); //"LEGO2"
00622    fOptionsGen->AddEntry("Surface HLR",    kOptionsGeneral+11); //"SURF"
00623    fOptionsGen->AddEntry("Surface HSR",    kOptionsGeneral+12); //"SURF1"
00624    fOptionsGen->AddEntry("Surface Col",    kOptionsGeneral+13); //"SURF2"
00625    fOptionsGen->AddEntry("Surf+Cont",      kOptionsGeneral+14); //"SURF3"
00626    fOptionsGen->AddEntry("Gouraud",        kOptionsGeneral+15); //"SURF4"
00627    fOptionsGen->Associate(this);
00628    //--- 1D options
00629    fOptions1D = new TGPopupMenu(gClient->GetRoot());
00630    fOptions1D->AddEntry("Default",         kOptions1D);
00631    fOptions1D->AddSeparator();
00632    fOptions1D->AddEntry("No labels/ticks", kOptions1D+1);       // "AH"
00633    fOptions1D->AddEntry("Bar chart",       kOptions1D+2);       // "B"
00634    fOptions1D->AddEntry("Smooth curve",    kOptions1D+3);       // "C"
00635    fOptions1D->AddEntry("Errors",          kOptions1D+4);       // "E"
00636    fOptions1D->AddEntry("Errors 1",        kOptions1D+5);       // "E1"
00637    fOptions1D->AddEntry("Errors 2",        kOptions1D+6);       // "E2"
00638    fOptions1D->AddEntry("Errors 3",        kOptions1D+7);       // "E3"
00639    fOptions1D->AddEntry("Errors 4",        kOptions1D+8);       // "E4"
00640    fOptions1D->AddEntry("Line",            kOptions1D+9);       // "L"
00641    fOptions1D->AddEntry("Markers",         kOptions1D+10);      // "P"
00642    fOptions1D->AddEntry("Stars",           kOptions1D+11);      // "*H"
00643    fOptions1D->Associate(this);
00644    //--- 2D options
00645    fOptions2D = new TGPopupMenu(gClient->GetRoot());
00646    fOptions2D->AddEntry("Default",         kOptions2D);
00647    fOptions2D->AddSeparator();
00648    fOptions2D->AddEntry("Arrows",          kOptions2D+1);       // "ARR"
00649    fOptions2D->AddEntry("Box/Surf",        kOptions2D+2);       // "BOX"
00650    fOptions2D->AddEntry("Box/Color",       kOptions2D+3);       // "COL"
00651    fOptions2D->AddEntry("Box/ColMap",      kOptions2D+4);       // "COLZ"
00652    fOptions2D->AddEntry("Contour",         kOptions2D+5);       // "CONT"
00653    fOptions2D->AddEntry("Contour 0",       kOptions2D+6);       // "CONT0"
00654    fOptions2D->AddEntry("Contour 1",       kOptions2D+7);       // "CONT1"
00655    fOptions2D->AddEntry("Contour 2",       kOptions2D+8);       // "CONT2"
00656    fOptions2D->AddEntry("Contour 3",       kOptions2D+9);       // "CONT3"
00657    fOptions2D->AddEntry("No front-box",    kOptions2D+10);      // "FB"
00658    fOptions2D->AddEntry("No back-box",     kOptions2D+11);      // "BB"
00659    fOptions2D->AddEntry("Scatter",         kOptions2D+12);      // "SCAT"
00660    fOptions2D->AddEntry("Profile",         kOptions2D+13);      // "SCAT"
00661    fOptions2D->Associate(this);
00662 
00663    fOptionsMenu = new TGPopupMenu(gClient->GetRoot());
00664    fOptionsMenu->AddPopup("&General Options...", fOptionsGen);
00665    fOptionsMenu->AddPopup("&1D Options",         fOptions1D);
00666    fOptionsMenu->AddPopup("&2D Options",         fOptions2D);
00667    fOptionsMenu->AddSeparator();
00668    fOptionsMenu->AddEntry("&Reset options",      kOptionsReset);
00669    //--- Help menu
00670    fHelpMenu = new TGPopupMenu(gClient->GetRoot());
00671    fHelpMenu->AddEntry("&About ROOT...",         kHelpAbout);
00672    fHelpMenu->AddEntry("&About TreeViewer...",   kHelpAboutTV);
00673    fHelpMenu->AddSeparator();
00674    fHelpMenu->AddEntry("&Starting...",           kHelpStart);
00675    fHelpMenu->AddEntry("&Layout...",             kHelpLayout);
00676    fHelpMenu->AddEntry("&Open/Save",             kHelpOpenSave);
00677    fHelpMenu->AddEntry("&Dragging...",           kHelpDragging);
00678    fHelpMenu->AddEntry("&Editing expressions...",kHelpEditing);
00679    fHelpMenu->AddEntry("&Session...",            kHelpSession);
00680    fHelpMenu->AddEntry("&User commands...",      kHelpCommands);
00681    fHelpMenu->AddEntry("&Context menus...",      kHelpContext);
00682    fHelpMenu->AddEntry("D&rawing...",            kHelpDrawing);
00683    fHelpMenu->AddEntry("&Macros...",             kHelpMacros);
00684 
00685    fFileMenu->Associate(this);
00686    fEditMenu->Associate(this);
00687    fRunMenu->Associate(this);
00688    fOptionsMenu->Associate(this);
00689    fHelpMenu->Associate(this);
00690 
00691    //--- menubar layout hints
00692    fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 0,0,1,1);
00693    fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
00694    fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
00695    //--- create menubar and add popup menus
00696    fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
00697 
00698    fMenuBar->AddPopup("&File", fFileMenu, fMenuBarItemLayout);
00699    fMenuBar->AddPopup("&Edit", fEditMenu, fMenuBarItemLayout);
00700    fMenuBar->AddPopup("&Run",  fRunMenu,  fMenuBarItemLayout);
00701    fMenuBar->AddPopup("&Options", fOptionsMenu, fMenuBarItemLayout);
00702    fMenuBar->AddPopup("&Help", fHelpMenu, fMenuBarHelpLayout);
00703 
00704    AddFrame(fMenuBar, fMenuBarLayout);
00705    //--- toolbar ----------------------------------------------------------------
00706    fToolBar = new TGToolBar(this, 10, 10, kHorizontalFrame);
00707    fBarLayout = new TGLayoutHints(kLHintsTop | kLHintsExpandX);
00708 
00709    TGLayoutHints *lo;
00710    lo = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 4,4,0,0);
00711    fWidgets->Add(lo);
00712    //--- label for Command text entry
00713    fBarLbl1 = new TGLabel(fToolBar,"Command");
00714    fToolBar->AddFrame(fBarLbl1,lo);
00715    //--- command text entry
00716    fBarCommand = new TGTextEntry(fToolBar, new TGTextBuffer(250),kBarCommand);
00717    fBarCommand->SetWidth(120);
00718    fBarCommand->Associate(this);
00719    fBarCommand->SetToolTipText("User commands executed via interpreter. Type <ENTER> to execute");
00720    fToolBar->AddFrame(fBarCommand, lo);
00721    //--- first vertical separator
00722    TGVertical3DLine *vSeparator = new TGVertical3DLine(fToolBar);
00723    lo = new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 4,4,0,0);
00724    fWidgets->Add(lo);
00725    fWidgets->Add(vSeparator);
00726    fToolBar->AddFrame(vSeparator, lo);
00727 
00728    lo = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 4,4,0,0);
00729    fWidgets->Add(lo);
00730    //--- label for Option text entry
00731    fBarLbl2 = new TGLabel(fToolBar,"Option");
00732    fToolBar->AddFrame(fBarLbl2, lo);
00733    //--- drawing option text entry
00734    fBarOption = new TGTextEntry(fToolBar, new TGTextBuffer(200),kBarOption);
00735    fBarOption->SetWidth(100);
00736    fBarOption->Associate(this);
00737    fBarOption->SetToolTipText("Histogram graphics option. Type option here and click <Draw> (or  <ENTER> to update current histogram).");
00738    fToolBar->AddFrame(fBarOption, lo);
00739    //--- second vertical separator
00740    vSeparator = new TGVertical3DLine(fToolBar);
00741    lo = new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 4,4,0,0);
00742    fWidgets->Add(lo);
00743    fWidgets->Add(vSeparator);
00744    fToolBar->AddFrame(vSeparator, lo);
00745 
00746    lo = new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 4,4,0,0);
00747    fWidgets->Add(lo);
00748    //--- label for Histogram text entry
00749    fBarLbl3 = new TGLabel(fToolBar,"Histogram");
00750    fToolBar->AddFrame(fBarLbl3, lo);
00751    //--- histogram name text entry
00752    fBarHist = new TGTextEntry(fToolBar, new TGTextBuffer(100));
00753    fBarHist->SetWidth(50);
00754    fBarHist->SetText("htemp");
00755    fBarHist->SetToolTipText("Name of the histogram created by <Draw> command.");
00756    fToolBar->AddFrame(fBarHist, lo);
00757    //--- Hist check button
00758    fBarH = new TGCheckButton(fToolBar, "Hist");
00759    fBarH->SetToolTipText("Checked : redraw only current histogram");
00760    fBarH->SetState(kButtonUp);
00761    fToolBar->AddFrame(fBarH, lo);
00762    //--- Scan check button
00763    fBarScan = new TGCheckButton(fToolBar, "Scan");
00764    fBarScan->SetState(kButtonUp);
00765    fBarScan->SetToolTipText("Check to redirect TTree::Scan command in a file");
00766    fToolBar->AddFrame(fBarScan, lo);
00767    //--- Rec check button
00768    fBarRec = new TGCheckButton(fToolBar, "Rec");
00769    fBarRec->SetState(kButtonDown);
00770    fBarRec->SetToolTipText("Check to record commands in history file and be verbose");
00771    fToolBar->AddFrame(fBarRec, lo);
00772    //--- 1'st horizontal tool bar separator ----------------------------------------
00773    TGHorizontal3DLine *toolBarSep = new TGHorizontal3DLine(this);
00774    fWidgets->Add(toolBarSep);
00775    AddFrame(toolBarSep, fBarLayout);
00776    AddFrame(fToolBar, fBarLayout);
00777    //--- 2'nd horizontal tool bar separator ----------------------------------------
00778    toolBarSep = new TGHorizontal3DLine(this);
00779    fWidgets->Add(toolBarSep);
00780    AddFrame(toolBarSep, fBarLayout);
00781 
00782    //--- Horizontal mother frame ---------------------------------------------------
00783    fHf = new TGHorizontalFrame(this, 10, 10);
00784    //--- Vertical frames
00785    fSlider = new TGDoubleVSlider(fHf, 10, kDoubleScaleBoth, kSLIDER);
00786 //   fSlider->SetBackgroundColor(color);
00787    fSlider->Associate(this);
00788 
00789    //--- fV1 -----------------------------------------------------------------------
00790    fV1 = new TGVerticalFrame(fHf, 10, 10, kFixedWidth);
00791    fTreeHdr = new TGCompositeFrame(fV1, 10, 10, kSunkenFrame | kVerticalFrame);
00792 
00793    fLbl1 = new TGLabel(fTreeHdr, "Current Folder");
00794    lo = new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsCenterY, 3, 0, 0, 0);
00795    fWidgets->Add(lo);
00796    fTreeHdr->AddFrame(fLbl1, lo);
00797 
00798    lo = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 0, 1, 0);
00799    fWidgets->Add(lo);
00800    fV1->AddFrame(fTreeHdr, lo);
00801 
00802    //--- tree view canvas on the left
00803    fTreeView = new TGCanvas(fV1, fV1->GetWidth(), 10, kSunkenFrame | kDoubleBorder);
00804    //--- container frame
00805    fLt = new TGListTree(fTreeView->GetViewPort(), 10, 10, kHorizontalFrame,
00806                         GetWhitePixel());
00807    fLt->Associate(this);
00808    fTreeView->SetContainer(fLt);
00809 
00810    lo = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 2,0,0,0);
00811    fWidgets->Add(lo);
00812    fV1->AddFrame(fTreeView, lo);
00813 
00814    //--- button horizontal frame
00815    fHpb = new TGHorizontalFrame(fV1, fTreeHdr->GetWidth(), 10, kSunkenFrame);
00816 
00817    //--- DRAW button
00818    fPicDraw = gClient->GetPicture("draw_t.xpm");
00819    fDRAW  = new TGPictureButton(fHpb,fPicDraw,kDRAW);
00820    fDRAW->SetToolTipText("Draw current selection");
00821    fDRAW->Associate(this);
00822 
00823    lo = new TGLayoutHints(kLHintsTop | kLHintsLeft, 2,2,4,2);
00824    fWidgets->Add(lo);
00825    fHpb->AddFrame(fDRAW, lo);
00826 
00827    //--- SPIDER button
00828    fSPIDER = new TGTextButton(fHpb,"SPIDER");
00829    fSPIDER->SetToolTipText("Scan current selection using a spider plot");
00830    fSPIDER->Associate(this);
00831 
00832    lo = new TGLayoutHints(kLHintsTop | kLHintsLeft, 2,2,4,2);
00833    fWidgets->Add(lo);
00834    fHpb->AddFrame(fSPIDER,lo);
00835    //---connect SPIDER button to ExecuteScan() method
00836    fSPIDER->Connect("Clicked()","TTreeViewer",this,"ExecuteSpider()");
00837 
00838    //--- STOP button (breaks current operation)
00839 //   fPicStop = gClient->GetPicture("mb_stop_s.xpm");
00840    fPicStop = gClient->GetPicture("stop_t.xpm");
00841    fSTOP  = new TGPictureButton(fHpb,fPicStop,kSTOP);
00842    fSTOP->SetToolTipText("Abort current operation");
00843    fSTOP->Associate(this);
00844 
00845    lo = new TGLayoutHints(kLHintsTop | kLHintsLeft, 2,2,4,2);
00846    fWidgets->Add(lo);
00847    fHpb->AddFrame(fSTOP, lo);
00848 
00849    //--- REFR button (breaks current operation)
00850    fPicRefr = gClient->GetPicture("refresh2.xpm");
00851    fREFR  = new TGPictureButton(fHpb,fPicRefr,kDRAW);
00852    fREFR->SetToolTipText("Update the tree viewer");
00853    lo = new TGLayoutHints(kLHintsTop | kLHintsLeft, 2,2,4,2);
00854    fWidgets->Add(lo);
00855    fHpb->AddFrame(fREFR, lo);
00856    //---connect REFR button to DoRefresh() method
00857    fREFR->Connect("Clicked()", "TTreeViewer", this, "DoRefresh()");
00858 
00859    lo = new TGLayoutHints(kLHintsTop | kLHintsLeft, 2,2,2,2);
00860    fWidgets->Add(lo);
00861    fV1->AddFrame(fHpb, lo);
00862 
00863    //--- fV2
00864    fV2 = new TGVerticalFrame(fHf, 10, 10);
00865    fListHdr = new TGCompositeFrame(fV2, 10, 10, kSunkenFrame | kFitHeight);
00866    fLbl2 = new TGLabel(fListHdr, "Current Tree:                 ");
00867    lo = new TGLayoutHints(kLHintsTop | kLHintsLeft, 3, 0, 0, 0);
00868    fWidgets->Add(lo);
00869    fListHdr->AddFrame(fLbl2, lo);
00870 
00871    //--- progress bar
00872    fProgressBar = new TGHProgressBar(fListHdr);
00873    fProgressBar->SetBarColor("red");
00874    fProgressBar->SetFillType(TGProgressBar::kBlockFill);
00875    lo = new TGLayoutHints(kLHintsBottom | kLHintsExpandX, 2,2,4,2);
00876    fWidgets->Add(lo);
00877    fListHdr->AddFrame(fProgressBar, lo);
00878    lo = new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY, 2,0,1,2);
00879    fWidgets->Add(lo);
00880    fV2->AddFrame(fListHdr, lo);
00881 
00882    fV1->Resize(fTreeHdr->GetDefaultWidth()+100, fV1->GetDefaultHeight());
00883    lo = new TGLayoutHints(kLHintsLeft | kLHintsExpandY);
00884    fWidgets->Add(lo);
00885    fHf->AddFrame(fSlider, lo);
00886    lo = new TGLayoutHints(kLHintsLeft | kLHintsExpandY);
00887    fWidgets->Add(lo);
00888    fHf->AddFrame(fV1, lo);
00889 
00890    //--- vertical splitter
00891    TGVSplitter *splitter = new TGVSplitter(fHf);
00892    splitter->SetFrame(fV1,kTRUE);
00893    lo = new TGLayoutHints(kLHintsLeft | kLHintsExpandY);
00894    fWidgets->Add(splitter);
00895    fWidgets->Add(lo);
00896    fHf->AddFrame(splitter,lo);
00897 
00898 
00899 
00900    //-- listview for the content of the tree/branch -----------------------------
00901    fListView = new TGListView(fListHdr,400,300);
00902    //--- container frame
00903    fLVContainer = new TTVLVContainer(fListView->GetViewPort(),400,300);
00904    fLVContainer->Associate(this);
00905    fLVContainer->SetListView(fListView);
00906    fLVContainer->SetViewer(this);
00907    fLVContainer->SetBackgroundColor(GetWhitePixel());
00908    fListView->GetViewPort()->SetBackgroundColor(GetWhitePixel());
00909    fListView->SetContainer(fLVContainer);
00910    fListView->SetViewMode(kLVList);
00911    lo = new TGLayoutHints(kLHintsRight | kLHintsTop | kLHintsExpandX | kLHintsExpandY);
00912    fWidgets->Add(lo);
00913 
00914    fListHdr->AddFrame(fListView,lo);
00915 
00916    lo = new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY);
00917    fWidgets->Add(lo);
00918    fHf->AddFrame(fV2,lo);
00919 
00920    AddFrame(fHf, lo);
00921    //--- 3rd horizontal tool bar separator ----------------------------------------
00922    toolBarSep = new TGHorizontal3DLine(this);
00923    fWidgets->Add(toolBarSep);
00924    AddFrame(toolBarSep, fBarLayout);
00925 
00926    //--- label for IList text entry
00927    fBFrame = new TGHorizontalFrame(this,10,10);
00928    fBLbl4 = new TGLabel(fBFrame,"IList");
00929    lo = new TGLayoutHints(kLHintsLeft | kLHintsBottom, 2,2,2,2);
00930    fWidgets->Add(lo);
00931    fBFrame->AddFrame(fBLbl4, lo);
00932    //--- IList text entry
00933    fBarListIn =  new TGTextEntry(fBFrame, new TGTextBuffer(100));
00934    fBarListIn->SetWidth(60);
00935    fBarListIn->SetToolTipText("Name of a previously created event list");
00936    fBFrame->AddFrame(fBarListIn, lo);
00937    //--- label for OList text entry
00938    fBLbl5 = new TGLabel(fBFrame,"OList");
00939    fBFrame->AddFrame(fBLbl5, lo);
00940    //--- OList text entry
00941    fBarListOut =  new TGTextEntry(fBFrame, new TGTextBuffer(100));
00942    fBarListOut->SetWidth(60);
00943    fBarListOut->SetToolTipText("Output event list. Use <Draw> to generate it.");
00944    fBFrame->AddFrame(fBarListOut, lo);
00945    //--- Status bar
00946    fStatusBar = new TGStatusBar(fBFrame, 10, 10);
00947    fStatusBar->SetWidth(200);
00948    fStatusBar->Draw3DCorner(kFALSE);
00949    lo = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY | kLHintsLeft | kLHintsExpandX, 2,2,2,2);
00950    fWidgets->Add(lo);
00951    fBFrame->AddFrame(fStatusBar, lo);
00952    //--- RESET button
00953    fReset = new TGTextButton(fBFrame,"RESET",kRESET);
00954    fReset->SetToolTipText("Reset variable's fields and drawing options");
00955    fReset->Associate(this);
00956    lo = new TGLayoutHints(kLHintsTop | kLHintsRight, 2,2,2,2);
00957    fWidgets->Add(lo);
00958    fBFrame->AddFrame(fReset,lo);
00959    //---  group of buttons for session handling
00960    fBGFirst = new TGPictureButton(fBFrame,
00961                                   gClient->GetPicture("first_t.xpm"), kBGFirst);
00962    fBGFirst->SetToolTipText("First record");
00963    fBGFirst->Associate(this);
00964    fBGPrevious = new TGPictureButton(fBFrame,
00965                                   gClient->GetPicture("previous_t.xpm"), kBGPrevious);
00966    fBGPrevious->SetToolTipText("Previous record");
00967    fBGPrevious->Associate(this);
00968    fBGRecord = new TGPictureButton(fBFrame,
00969                                   gClient->GetPicture("record_t.xpm"), kBGRecord);
00970    fBGRecord->SetToolTipText("Record");
00971    fBGRecord->Associate(this);
00972    fBGNext = new TGPictureButton(fBFrame,
00973                                  gClient->GetPicture("next_t.xpm"), kBGNext);
00974    fBGNext->SetToolTipText("Next record");
00975    fBGNext->Associate(this);
00976    fBGLast = new TGPictureButton(fBFrame,
00977                                  gClient->GetPicture("last_t.xpm"), kBGLast);
00978    fBGLast->SetToolTipText("Last record");
00979    fBGLast->Associate(this);
00980 
00981    fCombo = new TGComboBox(fBFrame, 0);
00982    fCombo->SetHeight(fReset->GetDefaultHeight());
00983    fCombo->SetWidth(100);
00984    fCombo->Associate(this);
00985 
00986    lo = new TGLayoutHints(kLHintsCenterY | kLHintsRight, 0,0,2,0);
00987    fWidgets->Add(lo);
00988    fBFrame->AddFrame(fCombo,      lo);
00989    fBFrame->AddFrame(fBGLast,     lo);
00990    fBFrame->AddFrame(fBGNext,     lo);
00991    fBFrame->AddFrame(fBGRecord,   lo);
00992    fBFrame->AddFrame(fBGPrevious, lo);
00993    fBFrame->AddFrame(fBGFirst,    lo);
00994    lo = new TGLayoutHints(kLHintsExpandX,2,2,2,0);
00995    fWidgets->Add(lo);
00996    AddFrame(fBFrame,lo);
00997 
00998    // map the window
00999    SetWindowName("TreeViewer");
01000    MapSubwindows();
01001    Resize(GetDefaultSize());
01002    MapWindow();
01003 
01004    // put default items in the listview on the right
01005    const TGPicture *pic, *spic;
01006 
01007    fLVContainer->RemoveAll();
01008    TTVLVEntry* entry;
01009    Char_t symbol;
01010    entry = new TTVLVEntry(fLVContainer,fPicX,fPicX,new TGString(),0,kLVSmallIcons);
01011    symbol = 'X';
01012    entry->SetUserData(new ULong_t((symbol << 8) | kLTExpressionType | kLTTreeType));
01013    entry->SetToolTipText("X expression. Drag and drop expressions here");
01014    //--- X item
01015    fLVContainer->AddThisItem(entry);
01016    entry->Empty();
01017    entry->MapWindow();
01018 
01019    entry = new TTVLVEntry(fLVContainer,fPicY,fPicY,new TGString(),0,kLVSmallIcons);
01020    symbol = 'Y';
01021    entry->SetUserData(new ULong_t((symbol << 8) | kLTExpressionType | kLTTreeType));
01022    entry->SetToolTipText("Y expression. Drag and drop expressions here");
01023    //--- Y item
01024    fLVContainer->AddThisItem(entry);
01025    entry->Empty();
01026    entry->MapWindow();
01027 
01028    entry = new TTVLVEntry(fLVContainer,fPicZ,fPicZ,new TGString(),0,kLVSmallIcons);
01029    symbol = 'Z';
01030    entry->SetUserData(new ULong_t((symbol << 8) | kLTExpressionType | kLTTreeType));
01031    entry->SetToolTipText("Z expression. Drag and drop expressions here");
01032    //--- Z item
01033    fLVContainer->AddThisItem(entry);
01034    entry->Empty();
01035    entry->MapWindow();
01036 
01037    pic = gClient->GetPicture("cut_t.xpm");
01038    spic = gClient->GetPicture("cut_t.xpm");
01039    entry = new TTVLVEntry(fLVContainer,pic,spic,new TGString(),0,kLVSmallIcons);
01040    entry->SetUserData(new ULong_t(kLTExpressionType | kLTCutType));
01041    entry->SetToolTipText("Active cut. Double-click to enable/disable");
01042    //--- Cut item (scissors icon)
01043    fLVContainer->AddThisItem(entry);
01044    entry->Empty();
01045    entry->MapWindow();
01046 
01047    pic = gClient->GetPicture("pack_t.xpm");
01048    spic = gClient->GetPicture("pack-empty_t.xpm");
01049    entry = new TTVLVEntry(fLVContainer,pic,spic,new TGString("Scan box"),0,kLVSmallIcons);
01050    entry->SetUserData(new ULong_t(kLTExpressionType | kLTPackType));
01051    entry->SetToolTipText("Drag and drop expressions/leaves here. Double-click to scan. Check <Scan> to redirect on file.");
01052    //--- Scan Box
01053    fLVContainer->AddThisItem(entry);
01054    entry->MapWindow();
01055    entry->SetTrueName("");
01056 
01057    //--- 10 expression items
01058    fNexpressions = 10;
01059    for (Int_t i=0; i<fNexpressions; i++) {
01060       pic = gClient->GetPicture("expression_t.xpm");
01061       spic = gClient->GetPicture("expression_t.xpm");
01062       entry = new TTVLVEntry(fLVContainer,pic,spic,new TGString(),0,kLVSmallIcons);
01063       entry->SetUserData(new ULong_t(kLTExpressionType | kLTDragType));
01064       entry->SetToolTipText("User defined expression/cut. Double-click to edit");
01065       fLVContainer->AddThisItem(entry);
01066       entry->Empty();
01067       entry->MapWindow();
01068    }
01069 
01070    fListView->Layout();
01071    fListView->Resize();
01072 //   EmptyAll();
01073    // map the tree if it was supplied in the constructor
01074 
01075    if (!fTree) {
01076       fSlider->SetRange(0,1000000);
01077       fSlider->SetPosition(0,1000000);
01078    } else {
01079       fSlider->SetRange(0,fTree->GetEntries()-1);
01080       fSlider->SetPosition(0,fTree->GetEntries()-1);
01081    }
01082    PrintEntries();
01083    fProgressBar->SetPosition(0);
01084    fProgressBar->ShowPosition();
01085    ActivateButtons(kFALSE, kFALSE, kFALSE, kFALSE);
01086 
01087    // map the window
01088    ///SetWindowName("TreeViewer");
01089    MapSubwindows();
01090    Resize(GetDefaultSize());
01091    MapWindow();
01092 }
01093 
01094 //______________________________________________________________________________
01095 TTreeViewer::~TTreeViewer()
01096 {
01097    // TTreeViewer destructor.
01098 
01099    if (!gClient) return;
01100    gClient->FreePicture(fPicX);
01101    gClient->FreePicture(fPicY);
01102    gClient->FreePicture(fPicZ);
01103    gClient->FreePicture(fPicDraw);
01104    gClient->FreePicture(fPicStop);
01105    gClient->FreePicture(fPicRefr);
01106 
01107    fDialogBox = TGSelectBox::GetInstance();
01108    if (fDialogBox) delete fDialogBox;
01109 
01110    delete fContextMenu;
01111 
01112    delete fBarLbl1;
01113    delete fBarLbl2;
01114    delete fBarLbl3;
01115    delete fBLbl4;
01116    delete fBLbl5;
01117    delete fBarCommand;
01118    delete fBarOption;
01119    delete fBarHist;
01120    delete fBarListIn;
01121    delete fBarListOut;
01122 
01123    delete fBarH;
01124    delete fBarScan;
01125    delete fBarRec;
01126 
01127    delete fToolBar;
01128 
01129    delete fSlider;
01130    delete fV1;
01131    delete fV2;
01132    delete fLbl1;
01133    delete fLbl2;
01134    delete fHf;
01135    delete fTreeHdr;
01136    delete fListHdr;
01137    delete fLt;
01138    delete fTreeView;
01139    delete fLVContainer;
01140    delete fListView;
01141 
01142    delete fProgressBar;
01143    delete fHpb;
01144 
01145    delete fDRAW;
01146    delete fSPIDER;
01147    delete fSTOP;
01148    delete fReset;
01149    delete fBGFirst;
01150    delete fBGPrevious;
01151    delete fBGRecord;
01152    delete fBGNext;
01153    delete fBGLast;
01154    delete fCombo;
01155    delete fBFrame;
01156 
01157    delete fMenuBar;
01158    delete fFileMenu;
01159    delete fEditMenu;
01160 
01161    delete fOptionsGen;
01162    delete fOptions1D;
01163    delete fOptions2D;
01164    delete fOptionsMenu;
01165    delete fHelpMenu;
01166    delete fMenuBarLayout;
01167    delete fMenuBarItemLayout;
01168    delete fMenuBarHelpLayout;
01169    delete fBarLayout;
01170 
01171    fWidgets->Delete();
01172    delete fWidgets;
01173    if (fTreeList) {
01174       delete fTreeList;
01175    }
01176    delete fTimer;
01177    delete fSession;
01178 }
01179 //______________________________________________________________________________
01180 void TTreeViewer::ActivateButtons(Bool_t first, Bool_t previous,
01181                                   Bool_t next, Bool_t last)
01182 {
01183    // Enable/disable session buttons.
01184 
01185    if (first)    fBGFirst->SetState(kButtonUp);
01186    else          fBGFirst->SetState(kButtonDisabled);
01187    if (previous) fBGPrevious->SetState(kButtonUp);
01188    else          fBGPrevious->SetState(kButtonDisabled);
01189    if (next)     fBGNext->SetState(kButtonUp);
01190    else          fBGNext->SetState(kButtonDisabled);
01191    if (last)     fBGLast->SetState(kButtonUp);
01192    else          fBGLast->SetState(kButtonDisabled);
01193 }
01194 
01195 //______________________________________________________________________________
01196 const char* TTreeViewer::Cut()
01197 {
01198    // Apply Cut
01199 
01200    return fLVContainer->Cut();
01201 }
01202 
01203 //______________________________________________________________________________
01204 const char* TTreeViewer::ScanList()
01205 {
01206    // returns scanlist
01207 
01208    return fLVContainer->ScanList();
01209 }
01210 
01211 //______________________________________________________________________________
01212 void TTreeViewer::SetSession(TTVSession *session)
01213 {
01214    // Set current session
01215 
01216    if (session) {
01217       delete fSession;
01218       fSession = session;
01219    }
01220 }
01221 
01222 //______________________________________________________________________________
01223 const char* TTreeViewer::EmptyBrackets(const char* name)
01224 {
01225    // Empty the bracket content of a string.
01226 
01227    TString stripped(name);
01228    if (!stripped.Contains("[")) return name;
01229    TString retstr(name);
01230    TObjString *objstr;
01231    Int_t index = 0;
01232    while (stripped.Index("[", index) != kNPOS) {
01233       Int_t start = stripped.Index("[", index);
01234       Int_t end   = stripped.Index("]", index);
01235       if (end == kNPOS) {
01236          objstr = new TObjString(retstr.Data());
01237          fWidgets->Add(objstr);
01238          return (objstr->GetString()).Data();
01239       }
01240       index = start+2;
01241       retstr = stripped.Remove(start+1, end-start-1);
01242       stripped = retstr;
01243    }
01244    objstr = new TObjString(retstr.Data());
01245    fWidgets->Add(objstr);
01246    return (objstr->GetString()).Data();
01247 }
01248 
01249 //______________________________________________________________________________
01250 void TTreeViewer::EmptyAll()
01251 {
01252    // Clear the content of all items in the list view.
01253 
01254    fLVContainer->EmptyAll();
01255 }
01256 
01257 //______________________________________________________________________________
01258 void TTreeViewer::Empty()
01259 {
01260    // Empty the content of the selected expression.
01261 
01262    void *p = 0;
01263    TTVLVEntry *item = 0;
01264    if ((item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p)) == 0) {
01265       Warning("Empty", "No item selected.");
01266       return;
01267    }
01268    ULong_t *itemType = (ULong_t *) item->GetUserData();
01269    if (!(*itemType & kLTExpressionType)) {
01270       Warning("Empty", "Not expression type.");
01271       return;
01272    }
01273    if (*itemType & kLTPackType) {
01274       item->SetSmallPic(fClient->GetPicture("pack-empty_t.xpm"));
01275       item->SetTrueName("");
01276       return;
01277    }
01278    item->Empty();
01279 }
01280 
01281 //______________________________________________________________________________
01282 TTVLVEntry * TTreeViewer::ExpressionItem(Int_t index)
01283 {
01284    // Get the item from a specific position.
01285 
01286    return fLVContainer->ExpressionItem(index);
01287 }
01288 
01289 //______________________________________________________________________________
01290 TList* TTreeViewer::ExpressionList()
01291 {
01292    // Get the list of expression items.
01293 
01294    return fLVContainer->ExpressionList();
01295 }
01296 
01297 //______________________________________________________________________________
01298 Int_t TTreeViewer::Dimension()
01299 {
01300    // Compute dimension of the histogram.
01301 
01302    fDimension = 0;
01303    if (strlen(Ex())) fDimension++;
01304    if (strlen(Ey())) fDimension++;
01305    if (strlen(Ez())) fDimension++;
01306    return fDimension;
01307 }
01308 
01309 //______________________________________________________________________________
01310 void TTreeViewer::ExecuteDraw()
01311 {
01312    // Called when the DRAW button is executed.
01313 
01314    TString varexp;
01315    TString command;
01316    Int_t dimension = 0;
01317    TString alias[3];
01318    TTVLVEntry *item;
01319    Int_t i;
01320    // fill in expressions
01321    if (fVarDraw) {
01322       void *p = 0;
01323       dimension = 1;
01324       if (!(item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p))) return;
01325       alias[0] = item->GetAlias();
01326       if (alias[0].BeginsWith("~")) alias[0].Remove(0, 1);
01327       varexp = item->ConvertAliases();
01328    } else {
01329       if (strlen(Ez())) {
01330          dimension++;
01331          varexp = Ez();
01332          item = ExpressionItem(2);
01333          alias[2] = item->GetAlias();
01334          if (alias[2].BeginsWith("~")) alias[2].Remove(0, 1);
01335       }
01336       if (strlen(Ez()) && (strlen(Ex()) || strlen(Ey()))) varexp += ":";
01337       if (strlen(Ey())) {
01338          dimension++;
01339          varexp += Ey();
01340          item = ExpressionItem(1);
01341          alias[1] = item->GetAlias();
01342          if (alias[1].BeginsWith("~")) alias[1].Remove(0, 1);
01343       }
01344       if (strlen(Ey()) && strlen(Ex())) varexp += ":";
01345       if (strlen(Ex())) {
01346          dimension++;
01347          varexp += Ex();
01348          item = ExpressionItem(0);
01349          alias[0] = item->GetAlias();
01350          if (alias[0].BeginsWith("~")) alias[0].Remove(0, 1);
01351       }
01352    }
01353    if (!dimension && !fScanMode) {
01354       Warning("ExecuteDraw", "Nothing to draw on X,Y,Z.");
01355       return;
01356    }
01357    // find ListIn
01358    fTree->SetEventList(0);
01359    TEventList *elist = 0;
01360    if (strlen(fBarListIn->GetText())) {
01361       elist = (TEventList *) gROOT->FindObject(fBarListIn->GetText());
01362       if (elist) fTree->SetEventList(elist);
01363    }
01364    // find ListOut
01365    if (strlen(fBarListOut->GetText())) varexp = TString::Format(">>%s", fBarListOut->GetText());
01366    // find histogram name
01367    if (strcmp("htemp", fBarHist->GetText())) {
01368       varexp += ">>";
01369       varexp += fBarHist->GetText();
01370    }
01371    // find canvas/pad where to draw
01372    TPad *pad = (TPad*)gROOT->GetSelectedPad();
01373    if (pad) pad->cd();
01374    // find graphics option
01375    const char* gopt = fBarOption->GetText();
01376    // just in case a previous interrupt was posted
01377    gROOT->SetInterrupt(kFALSE);
01378    // check if cut is enabled
01379    const char *cut = "";
01380    if (fEnableCut) cut = Cut();
01381 
01382    // get entries to be processed
01383    Long64_t nentries = (Long64_t)(fSlider->GetMaxPosition() -
01384                             fSlider->GetMinPosition() + 1);
01385    Long64_t firstentry =(Long64_t) fSlider->GetMinPosition();
01386 //printf("firstentry=%lld, nentries=%lld\n",firstentry,nentries);
01387    // check if Scan is checked and if there is something in the box
01388    if (fScanMode) {
01389 //      fBarScan->SetState(kButtonUp);
01390       fScanMode = kFALSE;
01391       if (strlen(ScanList())) varexp = ScanList();
01392       command = TString::Format("tv__tree->Scan(\"%s\",\"%s\",\"%s\", %lld, %lld);",
01393               varexp.Data(), cut, gopt, nentries, firstentry);
01394       if (fBarScan->GetState() == kButtonDown) {
01395          ((TTreePlayer *)fTree->GetPlayer())->SetScanRedirect(kTRUE);
01396       } else {
01397          ((TTreePlayer *)fTree->GetPlayer())->SetScanRedirect(kFALSE);
01398       }
01399       ExecuteCommand(command.Data(), kTRUE);
01400       return;
01401    }
01402    // check if only histogram has to be updated
01403    if (fBarH->GetState() == kButtonDown) {
01404       // reset 'Hist' mode
01405       fBarH->SetState(kButtonUp);
01406       TH1 *hist = fTree->GetHistogram();
01407       if (hist && gPad) {
01408          //hist = (TH1*)gPad->GetListOfPrimitives()->FindObject(fBarHist->GetText());
01409          if (hist) {
01410             // check if graphic option was modified
01411             TString last(fLastOption);
01412             TString current(gopt);
01413             current.ToUpper();
01414             last.ToUpper();
01415             if (current == last) {
01416                gPad->Update();
01417                return;
01418             }
01419             if (dimension == 3 && strlen(gopt)) {
01420                cout << "Graphics option " << gopt << " not valid for 3D histograms" << endl;
01421                return;
01422             }
01423             cout << " Graphics option for current histogram changed to " << gopt << endl;
01424             hist->Draw(gopt);
01425             fLastOption = fBarOption->GetText();
01426             gPad->Update();
01427             return;
01428          }
01429       }
01430    }
01431    // send draw command
01432    fLastOption = fBarOption->GetText();
01433    if (!strlen(gopt) && dimension!=3)
01434    //{
01435    //   gopt = "hist";
01436    //   fLastOption = "hist";
01437    //}
01438    if (dimension == 3 && strlen(gopt)) {
01439       cout << "Graphics option " << gopt << " not valid for 3D histograms" << endl;
01440       gopt = "";
01441       fLastOption = "";
01442    }
01443    command = TString::Format("tv__tree->Draw(\"%s\",\"%s\",\"%s\", %lld, %lld);",
01444            varexp.Data(), cut, gopt, nentries, firstentry);
01445    if (fCounting) return;
01446    fCounting = kTRUE;
01447    fTree->SetTimerInterval(200);
01448    fTimer->TurnOn();
01449    ExecuteCommand(command.Data());
01450    HandleTimer(fTimer);
01451    fTimer->TurnOff();
01452    fTree->SetTimerInterval(0);
01453    fCounting = kFALSE;
01454    fProgressBar->SetPosition(0);
01455    fProgressBar->ShowPosition();
01456    TH1 *hist = fTree->GetHistogram();
01457    if (hist) {
01458    // put expressions aliases on axes
01459       Int_t current = 0;
01460       for (i=0; i<3; i++) {
01461          if (alias[i].Length()) {
01462             if (i != current) {
01463                alias[current] = alias[i];
01464                alias[i] = "";
01465             }
01466             current++;
01467          }
01468       }
01469       //hist = (TH1*)gPad->GetListOfPrimitives()->FindObject(fBarHist->GetText());
01470       TAxis *axis[3];
01471       axis[0] = hist->GetXaxis();
01472       axis[1] = hist->GetYaxis();
01473       axis[2] = hist->GetZaxis();
01474       for (Int_t ind=0; ind<3; ind++) axis[ind]->SetTitle(alias[ind].Data());
01475    }
01476    if (gPad) gPad->Update();
01477 }
01478 
01479 
01480 //______________________________________________________________________________
01481 void TTreeViewer::ExecuteSpider()
01482 {
01483    // Draw a spider plot for the selected entries.
01484 
01485    TString varexp;
01486    Int_t dimension = 0;
01487    TString alias[3];
01488    TTVLVEntry *item;
01489    Bool_t previousexp = kFALSE;
01490    // fill in expressions
01491    if (strlen(Ez())) {
01492       previousexp = kTRUE;
01493       dimension++;
01494       varexp = Ez();
01495       item = ExpressionItem(2);
01496       alias[2] = item->GetAlias();
01497       if (alias[2].BeginsWith("~")) alias[2].Remove(0, 1);
01498    }
01499    if (strlen(Ez()) && (strlen(Ex()) || strlen(Ey()))) varexp += ":";
01500    if (strlen(Ey())) {
01501       previousexp = kTRUE;
01502       dimension++;
01503       varexp += Ey();
01504       item = ExpressionItem(1);
01505       alias[1] = item->GetAlias();
01506       if (alias[1].BeginsWith("~")) alias[1].Remove(0, 1);
01507    }
01508    if (strlen(Ey()) && strlen(Ex())) varexp += ":";
01509    if (strlen(Ex())) {
01510       previousexp = kTRUE;
01511       dimension++;
01512       varexp += Ex();
01513       item = ExpressionItem(0);
01514       alias[0] = item->GetAlias();
01515       if (alias[0].BeginsWith("~")) alias[0].Remove(0, 1);
01516    }
01517    for(Int_t i=0;i<10;++i){
01518       if(strlen(En(i+5))){
01519          ++dimension;
01520          if(previousexp){
01521             varexp += ":";
01522             varexp += En(i+5);
01523          } else varexp = En(i+5);
01524          previousexp = kTRUE;
01525       }
01526    }
01527    if (dimension<3) {
01528       Warning("ExecuteSpider", "Need at least 3 variables");
01529       return;
01530    }
01531    // find ListIn
01532    fTree->SetEventList(0);
01533    TEventList *elist = 0;
01534    if (strlen(fBarListIn->GetText())) {
01535       elist = (TEventList *) gROOT->FindObject(fBarListIn->GetText());
01536       if (elist) fTree->SetEventList(elist);
01537    }
01538    // find ListOut
01539    if (strlen(fBarListOut->GetText())) varexp = TString::Format(">>%s", fBarListOut->GetText());
01540    // find canvas/pad where to draw
01541    TPad *pad = (TPad*)gROOT->GetSelectedPad();
01542    if (pad) pad->cd();
01543    // find graphics option
01544    const char* gopt = fBarOption->GetText();
01545    // just in case a previous interrupt was posted
01546    gROOT->SetInterrupt(kFALSE);
01547    // check if cut is enabled
01548    const char *cut = "";
01549    if (fEnableCut) cut = Cut();
01550 
01551    // get entries to be processed
01552    Long64_t nentries = (Long64_t)(fSlider->GetMaxPosition() -
01553                             fSlider->GetMinPosition() + 1);
01554    Long64_t firstentry =(Long64_t) fSlider->GetMinPosition();
01555 
01556    // create the spider plot
01557 
01558    TSpider* spider = new TSpider(fTree,varexp.Data(),cut,Form("%s spider average",gopt),nentries,firstentry);
01559    spider->Draw();
01560 
01561    if (gPad) gPad->Update();
01562 }
01563 
01564 //______________________________________________________________________________
01565 const char* TTreeViewer::Ex()
01566 {
01567    // Get the expression to be drawn on X axis.
01568 
01569    return fLVContainer->Ex();
01570 }
01571 
01572 //______________________________________________________________________________
01573 const char* TTreeViewer::Ey()
01574 {
01575    // Get the expression to be drawn on Y axis.
01576 
01577    return fLVContainer->Ey();
01578 }
01579 
01580 //______________________________________________________________________________
01581 const char* TTreeViewer::Ez()
01582 {
01583    // Get the expression to be drawn on Z axis.
01584 
01585    return fLVContainer->Ez();
01586 }
01587 
01588 //______________________________________________________________________________
01589 const char* TTreeViewer::En(Int_t n)
01590 {
01591    // Get the n'th expression
01592    TTVLVEntry *e = fLVContainer->ExpressionItem(n);
01593    if(e) return e->ConvertAliases();
01594    return "";
01595 }
01596 
01597 //______________________________________________________________________________
01598 void TTreeViewer::EditExpression()
01599 {
01600    // Start the expression editor.
01601 
01602    void *p = 0;
01603    // get the selected item
01604    TTVLVEntry *item = 0;
01605    if ((item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p)) == 0) {
01606       Warning("EditExpression", "No item selected.");
01607       return;
01608    }
01609    // check if it is an expression
01610    ULong_t *itemType = (ULong_t *) item->GetUserData();
01611    if (!(*itemType & kLTExpressionType)) {
01612       Warning("EditExpression", "Not expression type.");
01613       return;
01614    }
01615    // check if the editor is already active
01616    fDialogBox = TGSelectBox::GetInstance();
01617    if (!fDialogBox) {
01618       fDialogBox = new TGSelectBox(fClient->GetRoot(), this, fV1->GetWidth() - 10);
01619    }
01620    // copy current item data into editor boxes
01621    fDialogBox->SetEntry(item);
01622    fDialogBox->SetWindowName("Expression editor");
01623    // check if you are editing the cut expression
01624    if (*itemType & kLTCutType || item->IsCut()) {
01625       fDialogBox->SetLabel("Selection");
01626    } else {
01627       fDialogBox->SetLabel("Expression");
01628    }
01629 }
01630 
01631 //______________________________________________________________________________
01632 Int_t TTreeViewer::MakeSelector(const char* selector)
01633 {
01634    // Get use of TTree::MakeSelector() via the context menu.
01635 
01636    if (!fTree) return 0;
01637    return fTree->MakeSelector(selector);
01638 }
01639 
01640 //______________________________________________________________________________
01641 Long64_t TTreeViewer::Process(const char* filename, Option_t *option, Long64_t nentries, Long64_t firstentry)
01642 {
01643    // Get use of TTree::Process() via the context menu.
01644 
01645    if (!fTree) return 0;
01646    return fTree->Process(filename, option, nentries, firstentry);
01647 }
01648 
01649 //______________________________________________________________________________
01650 const char *TTreeViewer::GetGrOpt()
01651 {
01652    // Get graph option
01653 
01654    return fBarOption->GetText();
01655 }
01656 
01657 //______________________________________________________________________________
01658 void TTreeViewer::SetGrOpt(const char *option)
01659 {
01660    // Set graph option
01661 
01662    fBarOption->SetText(option);
01663 }
01664 
01665 //______________________________________________________________________________
01666 Bool_t TTreeViewer::IsScanRedirected()
01667 {
01668    // Return kTRUE if scan is redirected
01669 
01670    return (fBarScan->GetState()==kButtonDown);
01671 }
01672 
01673 //______________________________________________________________________________
01674 void TTreeViewer::RemoveItem()
01675 {
01676    // Remove the selected item from the list.
01677 
01678    void *p = 0;
01679    TTVLVEntry *item = 0;
01680    // get the selected item
01681    if ((item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p)) == 0) {
01682       Warning("RemoveItem", "No item selected.");
01683       return;
01684    }
01685    // check if it is removable
01686    ULong_t *itemType = (ULong_t *) item->GetUserData();
01687    if (!(*itemType & kLTDragType)) {
01688       Warning("RemoveItem", "Not removable type.");
01689       return;
01690    }
01691    fLVContainer->RemoveItem(item);
01692    fListView->Layout();
01693 }
01694 
01695 //______________________________________________________________________________
01696 void TTreeViewer::RemoveLastRecord()
01697 {
01698    // Remove the current record.
01699 
01700    fSession->RemoveLastRecord();
01701 }
01702 
01703 //______________________________________________________________________________
01704 Bool_t TTreeViewer::HandleTimer(TTimer *timer)
01705 {
01706    // This function is called by the fTimer object.
01707 
01708    if (fCounting) {
01709       Float_t first = fSlider->GetMinPosition();
01710       Float_t last  = fSlider->GetMaxPosition();
01711       Float_t current = (Float_t)fTree->GetReadEntry();
01712       Float_t percent = (current-first+1)/(last-first+1);
01713       fProgressBar->SetPosition(100.*percent);
01714       fProgressBar->ShowPosition();
01715    }
01716    timer->Reset();
01717    return kFALSE;
01718 }
01719 
01720 //______________________________________________________________________________
01721 Bool_t TTreeViewer::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
01722 {
01723    // Handle menu and other commands generated.
01724 
01725    TRootHelpDialog *hd;
01726 
01727    switch (GET_MSG(msg)) {
01728       case kC_VSLIDER :
01729          // handle slider messages
01730          PrintEntries();
01731       break;
01732       case kC_TEXTENTRY:
01733          switch (GET_SUBMSG(msg)) {
01734          // handle enter posted by the Command text entry
01735             case kTE_ENTER:
01736                if ((Int_t)parm1 == kBarCommand) {
01737                   ExecuteCommand(fBarCommand->GetText());
01738                   fBarCommand->Clear();
01739                }
01740                if ((Int_t)parm1 == kBarOption) {
01741                   fVarDraw = kFALSE;
01742                   fBarH->SetState(kButtonDown);
01743                   ExecuteDraw();
01744                   fBarH->SetState(kButtonUp);
01745                }
01746                break;
01747             default:
01748                break;
01749          }
01750          break;
01751       case kC_LISTTREE:
01752          switch (GET_SUBMSG(msg)) {
01753          // handle mouse messages in the list-tree (left panel)
01754             case kCT_ITEMCLICK :
01755                if ((parm1==kButton1) || (parm1==kButton3)) {
01756                   TGListTreeItem *ltItem = 0;
01757                   // get item that sent this
01758                   if ((ltItem = fLt->GetSelected()) != 0) {
01759                   // get item type
01760                      ULong_t *itemType = (ULong_t *)ltItem->GetUserData();
01761                      if (*itemType & kLTTreeType) {
01762                      // already mapped tree item clicked
01763                         Int_t index = (Int_t)(*itemType >> 8);
01764                         SwitchTree(index);
01765                         if (fTree != fMappedTree) {
01766                            // switch also the global "tree" variable
01767                            fLVContainer->RemoveNonStatic();
01768                            // map it on the right panel
01769                            MapTree(fTree);
01770                            fListView->Layout();
01771                         }
01772                         // activate context menu for this tree
01773                         if (parm1 == kButton3) {
01774                            Int_t x = (Int_t)(parm2 &0xffff);
01775                            Int_t y = (Int_t)((parm2 >> 16) & 0xffff);
01776                            fContextMenu->Popup(x, y, fTree);
01777                         }
01778                      }
01779 
01780                      if (*itemType & kLTBranchType) {
01781                      // branch item clicked
01782                         SetParentTree(ltItem);
01783                         if (!fTree) break; // really needed ?
01784                         TBranch *branch = fTree->GetBranch(ltItem->GetText());
01785                         if (!branch) break;
01786                         // check if it is mapped on the right panel
01787                         if (branch != fMappedBranch) {
01788                            fLVContainer->RemoveNonStatic();
01789                            MapBranch(branch);
01790                            fStopMapping = kFALSE;
01791                            fListView->Layout();
01792                         }
01793                         // activate context menu for this branch (no *MENU* methods ):)
01794                         if (parm1 == kButton3) {
01795                            Int_t x = (Int_t)(parm2 &0xffff);
01796                            Int_t y = (Int_t)((parm2 >> 16) & 0xffff);
01797                            fContextMenu->Popup(x, y, branch);
01798                         }
01799                      }
01800 
01801                      if (*itemType & kLTLeafType) {
01802                      // leaf item clicked
01803                         SetParentTree(ltItem);
01804                         if (!fTree) break;
01805                         // find parent branch
01806                         TBranch *branch = fTree->GetBranch(ltItem->GetParent()->GetText());
01807                         if (!branch) {
01808                            if (fTree != fMappedTree) {
01809                               fLVContainer->RemoveNonStatic();
01810                               MapTree(fTree);
01811                               fListView->Layout();
01812                            }
01813                         } else {
01814                            // check if it is already mapped
01815                            if (branch!=fMappedBranch) {
01816                               fLVContainer->RemoveNonStatic();
01817                               MapBranch(branch);
01818                               fStopMapping = kFALSE;
01819                               fListView->Layout();
01820                            }
01821                         }
01822                         // select corresponding leaf on the right panel
01823                         fLVContainer->SelectItem(ltItem->GetText());
01824                         if (parm1 == kButton3) {
01825                         // activate context menu for this leaf
01826                            ProcessMessage(MK_MSG(kC_CONTAINER, kCT_ITEMCLICK), kButton3, parm2);
01827                         }
01828                      }
01829                   }
01830                }
01831                break;
01832             case kCT_ITEMDBLCLICK :
01833                fClient->NeedRedraw(fLt);
01834                if (parm1 == kButton1) {
01835                // execute double-click action for corresponding item in the right panel
01836                   ProcessMessage(MK_MSG(kC_CONTAINER, kCT_ITEMDBLCLICK), kButton1, parm2);
01837                }
01838                break;
01839             default:
01840                break;
01841          }
01842          break;
01843       case kC_COMMAND:
01844          switch (GET_SUBMSG(msg)){
01845             case kCM_COMBOBOX:
01846                fSession->Show(fSession->GetRecord((Int_t)parm2));
01847             break;
01848             case kCM_BUTTON:
01849                switch (parm1) {
01850                // handle button messages
01851                   case kRESET:
01852                      EmptyAll();
01853                      break;
01854                   case kDRAW:
01855                      fVarDraw = kFALSE;
01856                      ExecuteDraw();
01857                      break;
01858                   case kSTOP:
01859                      if (fCounting)
01860                         gROOT->SetInterrupt(kTRUE);
01861                      break;
01862                   case kCLOSE:
01863                      SendCloseMessage();
01864                      break;
01865                   case kBGFirst:
01866                      fSession->Show(fSession->First());
01867                      break;
01868                   case kBGPrevious:
01869                      fSession->Show(fSession->Previous());
01870                      break;
01871                   case kBGRecord:
01872                      fSession->AddRecord();
01873                      break;
01874                   case kBGNext:
01875                      fSession->Show(fSession->Next());
01876                      break;
01877                   case kBGLast:
01878                      fSession->Show(fSession->Last());
01879                      break;
01880                   default:
01881                      break;
01882                }
01883                break;
01884             case kCM_MENU:
01885             // handle menu messages
01886                // check if sent by Options menu
01887                if ((parm1>=kOptionsReset) && (parm1<kHelpAbout)) {
01888                   Dimension();
01889                   if ((fDimension==0) && (parm1>=kOptions1D)) {
01890                      Warning("ProcessMessage", "Edit expressions first.");
01891                      break;
01892                   }
01893                   if ((fDimension==1) && (parm1>=kOptions2D)) {
01894                      Warning("ProcessMessage", "You have only one expression active.");
01895                      break;
01896                   }
01897                   if ((fDimension==2) && (parm1>=kOptions1D) &&(parm1<kOptions2D)) {
01898                      Warning("ProcessMessage", "1D drawing options not apply to 2D histograms.");
01899                      break;
01900                   }
01901                   // make composed option
01902                   MapOptions(parm1);
01903                   break;
01904                }
01905                switch (parm1) {
01906                   case kFileCanvas:
01907                      gROOT->MakeDefCanvas();
01908                      break;
01909                   case kFileBrowse:
01910                      if (1) {
01911                         static TString dir(".");
01912                         TGFileInfo info;
01913                         info.fFileTypes = gOpenTypes;
01914                         info.fIniDir    = StrDup(dir);
01915                         new TGFileDialog(fClient->GetRoot(), this, kFDOpen, &info);
01916                         if (!info.fFilename) return kTRUE;
01917                         dir = info.fIniDir;
01918                         TString command = TString::Format("tv__tree_file = new TFile(\"%s\");",
01919                            gSystem->UnixPathName(info.fFilename));
01920                         ExecuteCommand(command.Data());
01921                         ExecuteCommand("tv__tree_file->ls();");
01922                         cout << "Use SetTreeName() from context menu and supply a tree name" << endl;
01923                         cout << "The context menu is activated by right-clicking the panel from right" << endl;
01924                      }
01925                      break;
01926                   case kFileLoadLibrary:
01927                      fBarCommand->SetText("gSystem->Load(\"\");");
01928                      if (1) {
01929                         Event_t event;
01930                         event.fType = kButtonPress;
01931                         event.fCode = kButton1;
01932 
01933                         fBarCommand->HandleButton(&event);
01934                      }
01935                      fBarCommand->SetCursorPosition(15);
01936                      break;
01937                   case kFileOpenSession:
01938                      if (1) {
01939                         static TString dir(".");
01940                         TGFileInfo info;
01941                         info.fFileTypes = gMacroTypes;
01942                         info.fIniDir    = StrDup(dir);
01943                         new TGFileDialog(fClient->GetRoot(), this, kFDOpen, &info);
01944                         if (!info.fFilename) return kTRUE;
01945                         dir = info.fIniDir;
01946                         gInterpreter->Reset();
01947                         if (!gInterpreter->IsLoaded(info.fFilename)) gInterpreter->LoadMacro(info.fFilename);
01948                         char command[1024];
01949                         command[0] = 0;
01950                         snprintf(command,1024,"open_session((void*)0x%lx);", (Long_t)this);
01951                         ExecuteCommand(command);
01952                      }
01953                      break;
01954                   case kFileSaveMacro:
01955                      SaveSource();
01956                      break;
01957                   case kFilePrint:
01958                      break;
01959                   case kFileClose:
01960                      SendCloseMessage();
01961                      break;
01962                   case kFileQuit:
01963                      gApplication->Terminate(0);
01964                      break;
01965                   case kEditExpression:
01966                      EditExpression();
01967                      break;
01968                   case kEditCut:
01969                      EditExpression();
01970                      break;
01971                   case kEditMacro:
01972                      break;
01973                   case kEditEvent:
01974                      break;
01975                   case kRunMacro:
01976                      break;
01977                   case kHelpAbout:
01978                      {
01979 #ifdef R__UNIX
01980                         TString rootx;
01981 # ifdef ROOTBINDIR
01982                         rootx = ROOTBINDIR;
01983 # else
01984                         rootx = gSystem->Getenv("ROOTSYS");
01985                         if (!rootx.IsNull()) rootx += "/bin";
01986 # endif
01987                         rootx += "/root -a &";
01988                         gSystem->Exec(rootx);
01989 #else
01990 #ifdef WIN32
01991                         new TWin32SplashThread(kTRUE);
01992 #else
01993                         char str[32];
01994                         snprintf(str,32, "About ROOT %s...", gROOT->GetVersion());
01995                         hd = new TRootHelpDialog(this, str, 600, 400);
01996                         hd->SetText(gHelpAbout);
01997                         hd->Popup();
01998 #endif
01999 #endif
02000                      }
02001                      break;
02002                   case kHelpAboutTV:
02003                      hd = new TRootHelpDialog(this, "About TreeViewer...", 600, 400);
02004                      hd->SetText(gTVHelpAbout);
02005                      hd->Resize(hd->GetDefaultSize());
02006                      hd->Popup();
02007                      break;
02008                   case kHelpStart:
02009                      hd = new TRootHelpDialog(this, "Quick start...", 600, 400);
02010                      hd->SetText(gTVHelpStart);
02011                      hd->Popup();
02012                      break;
02013                   case kHelpLayout:
02014                      hd = new TRootHelpDialog(this, "Layout...", 600, 400);
02015                      hd->SetText(gTVHelpLayout);
02016                      hd->Popup();
02017                      break;
02018                   case kHelpOpenSave:
02019                      hd = new TRootHelpDialog(this, "Open/Save...", 600, 400);
02020                      hd->SetText(gTVHelpOpenSave);
02021                      hd->Popup();
02022                      break;
02023                   case kHelpDragging:
02024                      hd = new TRootHelpDialog(this, "Dragging items...", 600, 400);
02025                      hd->SetText(gTVHelpDraggingItems);
02026                      hd->Popup();
02027                      break;
02028                   case kHelpEditing:
02029                      hd = new TRootHelpDialog(this, "Editing expressions...", 600, 400);
02030                      hd->SetText(gTVHelpEditExpressions);
02031                      hd->Popup();
02032                      break;
02033                   case kHelpSession:
02034                      hd = new TRootHelpDialog(this, "Session...", 600, 400);
02035                      hd->SetText(gTVHelpSession);
02036                      hd->Popup();
02037                      break;
02038                   case kHelpCommands:
02039                      hd = new TRootHelpDialog(this, "Executing user commands...", 600, 400);
02040                      hd->SetText(gTVHelpUserCommands);
02041                      hd->Popup();
02042                      break;
02043                   case kHelpContext:
02044                      hd = new TRootHelpDialog(this, "Context menus...", 600, 400);
02045                      hd->SetText(gTVHelpContext);
02046                      hd->Popup();
02047                      break;
02048                   case kHelpDrawing:
02049                      hd = new TRootHelpDialog(this, "Drawing histograms...", 600, 400);
02050                      hd->SetText(gTVHelpDrawing);
02051                      hd->Popup();
02052                      break;
02053                   case kHelpMacros:
02054                      hd = new TRootHelpDialog(this, "Using macros...", 600, 400);
02055                      hd->SetText(gTVHelpMacros);
02056                      hd->Popup();
02057                      break;
02058                   default:
02059                      break;
02060                }
02061                break;
02062             default:
02063                break;
02064          }
02065          break;
02066       case kC_CONTAINER:
02067          switch (GET_SUBMSG(msg)) {
02068          // handle messages sent from the listview (right panel)
02069             case kCT_SELCHANGED:
02070                break;
02071             case kCT_ITEMCLICK:
02072             // handle mouse messages
02073                switch (parm1) {
02074                   case kButton1:
02075                      if (fLVContainer->NumSelected()) {
02076                      // get item that sent this
02077                         void *p = 0;
02078                         TTVLVEntry *item;
02079                         if ((item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p)) != 0) {
02080                            const char* vname = item->GetTrueName();
02081                            TString trueName(vname);
02082                            if (trueName.Contains("[]")) {
02083                               TIter next(fTree->GetListOfLeaves());
02084                               TLeaf *leaf;
02085                               while((leaf=(TLeaf*)next())) {
02086                                  if (!strcmp(vname, EmptyBrackets(leaf->GetName())))
02087                                     vname = leaf->GetName();
02088                               }
02089                            }
02090                            char* msg2 = new char[2000];
02091                            // get item type
02092                            ULong_t *itemType = (ULong_t *) item->GetUserData();
02093                            if (*itemType & kLTTreeType) {
02094                            // X, Y or Z clicked
02095                               char symbol = (char)((*itemType) >> 8);
02096                               snprintf(msg2,2000, "%c expression : %s", symbol, vname);
02097                            } else {
02098                               if (*itemType & kLTCutType) {
02099                               // scissors clicked
02100                                  snprintf(msg2,2000, "Cut : %s", vname);
02101                               } else {
02102                                  if (*itemType & kLTPackType) {
02103                                     snprintf(msg2,2000, "Box : %s", vname);
02104                                  } else {
02105                                     if (*itemType & kLTExpressionType) {
02106                                        // expression clicked
02107                                        snprintf(msg2,2000, "Expression : %s", vname);
02108                                     } else {
02109                                        if (*itemType & kLTBranchType) {
02110                                           snprintf(msg2,2000, "Branch : %s", vname);
02111                                        } else {
02112                                           snprintf(msg2,2000, "Leaf : %s", vname);
02113                                        }
02114                                     }
02115                                  }
02116                               }
02117                            }
02118                            // write who is responsable for this
02119                            TString message = msg2;
02120                            message = message(0,150);
02121                            Message(msg2);
02122                            delete[] msg2;
02123                            // check if this should be pasted into the expression editor
02124                            if ((*itemType & kLTBranchType) || (*itemType & kLTCutType)) break;
02125                            fDialogBox = TGSelectBox::GetInstance();
02126                            if (!fDialogBox || !strlen(vname)) break;
02127                            if (item == fDialogBox->EditedEntry()) break;
02128                            // paste it
02129 //                           char first = (char) vname[0];
02130                            TString insert(item->GetAlias());
02131 //                           if (first != '(') insert += "(";
02132 //                           insert += item->GetAlias();
02133 //                           if (first != '(') insert += ")";
02134 
02135                            fDialogBox->GrabPointer();
02136                            fDialogBox->InsertText(insert.Data());
02137                            // put the cursor at the right position
02138                         }
02139                      }
02140                      break;
02141                   case kButton2:
02142                      break;
02143                   case kButton3:
02144                   // activate general context menu
02145                      if (fLVContainer->NumSelected()) {
02146                         void *p = 0;
02147                         Int_t x = (Int_t)(parm2 &0xffff);
02148                         Int_t y = (Int_t)((parm2 >> 16) & 0xffff);
02149                         TTVLVEntry *item = 0;
02150                         if ((item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p)) != 0) {
02151                            fContextMenu->Popup(x, y, item->GetContext());
02152                         }
02153                      } else {        // empty click
02154                         Int_t x = (Int_t)(parm2 &0xffff);
02155                         Int_t y = (Int_t)((parm2 >> 16) & 0xffff);
02156                         fContextMenu->Popup(x, y, this);
02157                      }
02158                      break;
02159                   default:
02160                      break;
02161                }
02162                break;
02163             case kCT_ITEMDBLCLICK:
02164                switch (parm1) {
02165                   case kButton1:
02166                      if (fLVContainer->NumSelected()) {
02167                      // get item that sent this
02168                         void *p = 0;
02169                         TTVLVEntry *item;
02170                         if ((item = (TTVLVEntry *) fLVContainer->GetNextSelected(&p)) != 0) {
02171                         // get item type
02172                            ULong_t *itemType = (ULong_t *) item->GetUserData();
02173                            if (!(*itemType & kLTCutType) && !(*itemType & kLTBranchType)
02174                                && !(*itemType & kLTPackType)) {
02175                               if (strlen(item->GetTrueName())) {
02176                                  fVarDraw = kTRUE;
02177                                  // draw on double-click
02178                                  ExecuteDraw();
02179                                  break;
02180                               } else {
02181                               // open expression in editor
02182                                  EditExpression();
02183                               }
02184                            }
02185                            if (*itemType & kLTCutType) {
02186                               fEnableCut = !fEnableCut;
02187                               if (fEnableCut) {
02188                                  item->SetSmallPic(gClient->GetPicture("cut_t.xpm"));
02189                               } else {
02190                                  item->SetSmallPic(gClient->GetPicture("cut-disable_t.xpm"));
02191                               }
02192                            }
02193                            if (*itemType & kLTPackType) {
02194                               fScanMode = kTRUE;
02195                               ExecuteDraw();
02196                            }
02197                         }
02198                      }
02199                      break;
02200                   case kButton2:
02201                      break;
02202                   case kButton3:
02203                      break;
02204                   default:
02205                      break;
02206                }
02207                break;
02208             case 4:
02209 //               cout << "Dragging Item" << endl;
02210             default:
02211                break;
02212          }
02213          break;
02214       default:
02215          break;
02216    }
02217    return kTRUE;
02218 }
02219 
02220 //______________________________________________________________________________
02221 void TTreeViewer::CloseWindow()
02222 {
02223    // Close the viewer.
02224 
02225    DeleteWindow();
02226 }
02227 
02228 //______________________________________________________________________________
02229 void TTreeViewer::ExecuteCommand(const char* command, Bool_t fast)
02230 {
02231    // Execute all user commands.
02232 
02233    // Execute the command, write it to history file and echo it to output
02234    if (fBarRec->GetState() == kButtonDown) {
02235    // show the command on the command line
02236       //printf("%s\n", command);
02237       char comm[2000];
02238       comm[0] = 0;
02239       if (strlen(command) > 1999) {
02240          Warning("ExecuteCommand", "Command too long: aborting.");
02241          return;
02242       }
02243       snprintf(comm,2000, "%s", command);
02244       // print the command to history file
02245       Gl_histadd(comm);
02246    }
02247    // execute it
02248    if (fast) {
02249       gROOT->ProcessLineFast(command);
02250    } else {
02251       gROOT->ProcessLine(command);
02252    }
02253    // make sure that 'draw on double-click' flag is reset
02254    fVarDraw = kFALSE;
02255 }
02256 //______________________________________________________________________________
02257 void TTreeViewer::MapOptions(Long_t parm1)
02258 {
02259    // Scan the selected options from option menu.
02260 
02261    Int_t ind;
02262    if (parm1 == kOptionsReset) {
02263       for (ind=kOptionsGeneral; ind<kOptionsGeneral+16; ind++)
02264          fOptionsGen->UnCheckEntry(ind);
02265       for (ind=kOptions1D; ind<kOptions1D+12; ind++)
02266          fOptions1D->UnCheckEntry(ind);
02267       for (ind=kOptions2D; ind<kOptions2D+14; ind++)
02268          fOptions2D->UnCheckEntry(ind);
02269    }
02270    if ((parm1 < kOptions1D) && (parm1 != kOptionsReset)) {
02271       if (fOptionsGen->IsEntryChecked((Int_t)parm1)) {
02272          fOptionsGen->UnCheckEntry((Int_t)parm1);
02273       } else {
02274          fOptionsGen->CheckEntry((Int_t)parm1);
02275          if ((Int_t)parm1 != kOptionsGeneral) fOptionsGen->UnCheckEntry((Int_t)kOptionsGeneral);
02276       }
02277       if (fOptionsGen->IsEntryChecked((Int_t)kOptionsGeneral)) {
02278       // uncheck all in this menu
02279          for (ind=kOptionsGeneral+1; ind<kOptionsGeneral+16; ind++) {
02280             fOptionsGen->UnCheckEntry(ind);
02281          }
02282       }
02283    }
02284 
02285    if ((parm1 < kOptions2D) && (parm1 >= kOptions1D)) {
02286       if (fOptions1D->IsEntryChecked((Int_t)parm1)) {
02287          fOptions1D->UnCheckEntry((Int_t)parm1);
02288       } else {
02289          fOptions1D->CheckEntry((Int_t)parm1);
02290          if ((Int_t)parm1 != kOptions1D) fOptions1D->UnCheckEntry((Int_t)kOptions1D);
02291       }
02292       if (fOptions1D->IsEntryChecked((Int_t)kOptions1D)) {
02293       // uncheck all in this menu
02294          for (ind=kOptions1D+1; ind<kOptions1D+12; ind++) {
02295             fOptions1D->UnCheckEntry(ind);
02296          }
02297       }
02298    }
02299 
02300    if (parm1 >= kOptions2D) {
02301       if (fOptions2D->IsEntryChecked((Int_t)parm1)) {
02302          fOptions2D->UnCheckEntry((Int_t)parm1);
02303       } else {
02304          fOptions2D->CheckEntry((Int_t)parm1);
02305          if ((Int_t)parm1 != kOptions2D) fOptions2D->UnCheckEntry((Int_t)kOptions2D);
02306       }
02307       if (fOptions2D->IsEntryChecked((Int_t)kOptions2D)) {
02308       // uncheck all in this menu
02309          for (ind=kOptions2D+1; ind<kOptions2D+14; ind++) {
02310             fOptions2D->UnCheckEntry(ind);
02311          }
02312       }
02313    }
02314    // concatenate options
02315    fBarOption->SetText("");
02316    for (ind=kOptionsGeneral; ind<kOptionsGeneral+16; ind++) {
02317       if (fOptionsGen->IsEntryChecked(ind))
02318          fBarOption->AppendText(gOptgen[ind-kOptionsGeneral]);
02319    }
02320    if (Dimension() == 1) {
02321       for (ind=kOptions1D; ind<kOptions1D+12; ind++) {
02322          if (fOptions1D->IsEntryChecked(ind))
02323             fBarOption->AppendText(gOpt1D[ind-kOptions1D]);
02324       }
02325    }
02326    if (Dimension() == 2) {
02327       for (ind=kOptions2D; ind<kOptions2D+14; ind++) {
02328          if (fOptions2D->IsEntryChecked(ind))
02329             fBarOption->AppendText(gOpt2D[ind-kOptions2D]);
02330       }
02331    }
02332 }
02333 
02334 //______________________________________________________________________________
02335 void TTreeViewer::MapTree(TTree *tree, TGListTreeItem *parent, Bool_t listIt)
02336 {
02337    // Map current tree and expand its content (including friends) in the lists.
02338    
02339    if (!tree) return;
02340    TObjArray *branches = tree->GetListOfBranches();
02341    if (!branches) return; // A Chain with no underlying trees.
02342    TBranch   *branch;
02343    // loop on branches
02344    Int_t id;
02345    for (id=0; id<branches->GetEntries(); id++) {
02346       branch = (TBranch *)branches->At(id);
02347       if (branch->TestBit(kDoNotProcess))  continue;
02348       TString name = branch->GetName();
02349       if (name.Contains("fBits") || name.Contains("fUniqueID")) continue;
02350       // now map sub-branches
02351       MapBranch(branch, "", parent, listIt);
02352       fStopMapping = kFALSE;
02353    }
02354    //Map branches of friend Trees (if any)
02355    //Look at tree->GetTree() to insure we see both the friendss of a chain
02356    //and the friends of the chain members
02357    TIter nextf( tree->GetTree()->GetListOfFriends() ); 
02358    TFriendElement *fr;
02359    while ((fr = (TFriendElement*)nextf())) {
02360       TTree * t = fr->GetTree();
02361       branches = t->GetListOfBranches();
02362       for (id=0; id<branches->GetEntries(); id++) {
02363          branch = (TBranch *)branches->At(id);
02364          if (branch->TestBit(kDoNotProcess))  continue;
02365          TString name = branch->GetName();
02366          if (name.Contains("fBits") || name.Contains("fUniqueID")) continue;
02367          // now map sub-branches
02368          MapBranch(branch, fr->GetName(), parent, listIt);
02369          fStopMapping = kFALSE;
02370       }
02371    }
02372    
02373    // tell who was last mapped
02374    if (listIt) {
02375       fMappedTree    = tree;
02376       fMappedBranch  = 0;
02377    }
02378 }
02379 
02380 //______________________________________________________________________________
02381 void TTreeViewer::MapBranch(TBranch *branch, const char *prefix, TGListTreeItem *parent, Bool_t listIt)
02382 {
02383    // Map current branch and expand its content in the list view.
02384 
02385    if (!branch) return;
02386    TString   name;
02387    if (prefix && strlen(prefix) >0) name = Form("%s.%s",prefix,branch->GetName());
02388    else                             name = branch->GetName();
02389    Int_t     ind;
02390    TGListTreeItem *branchItem = 0;
02391    ULong_t *itemType;
02392    // map this branch
02393    if (name.Contains("fBits") || name.Contains("fUniqueID")) return;
02394    if (parent) {
02395    // make list tree items for each branch according to the type
02396       const TGPicture *pic, *spic;
02397       if ((branch->GetListOfBranches()->GetEntries()) ||
02398           (branch->GetNleaves())) {
02399          if (branch->GetListOfBranches()->GetEntries()) {
02400             itemType = new ULong_t(kLTBranchType);
02401             if (branch->InheritsFrom("TBranchObject")) {
02402                pic = gClient->GetPicture("branch-ob_t.xpm");
02403                spic = gClient->GetPicture("branch-ob_t.xpm");
02404             } else {
02405                if (branch->InheritsFrom("TBranchClones")) {
02406                   pic = gClient->GetPicture("branch-cl_t.xpm");
02407                   spic = gClient->GetPicture("branch-cl_t.xpm");
02408                } else {
02409                   pic = gClient->GetPicture("branch_t.xpm");
02410                   spic = gClient->GetPicture("branch_t.xpm");
02411                }
02412             }
02413             branchItem = fLt->AddItem(parent, EmptyBrackets(name), itemType, pic, spic);
02414          } else {
02415             if (branch->GetNleaves() > 1) {
02416                itemType = new ULong_t(kLTBranchType);
02417                pic = gClient->GetPicture("branch_t.xpm");
02418                spic = gClient->GetPicture("branch_t.xpm");
02419                branchItem = fLt->AddItem(parent, EmptyBrackets(name), itemType,pic, spic);
02420                TObjArray *leaves = branch->GetListOfLeaves();
02421                TLeaf *leaf = 0;
02422                TString leafName;
02423                for (Int_t lf=0; lf<leaves->GetEntries(); lf++) {
02424                   leaf = (TLeaf *)leaves->At(lf);
02425                   leafName = name;
02426                   leafName.Append(".").Append(EmptyBrackets(leaf->GetName()));
02427                   itemType = new ULong_t(kLTLeafType);
02428                   pic = gClient->GetPicture("leaf_t.xpm");
02429                   spic = gClient->GetPicture("leaf_t.xpm");
02430                   fLt->AddItem(branchItem, leafName.Data(), itemType, pic, spic);
02431                }
02432             } else {
02433                itemType = new ULong_t(kLTLeafType);
02434                pic = gClient->GetPicture("leaf_t.xpm");
02435                spic = gClient->GetPicture("leaf_t.xpm");
02436                branchItem = fLt->AddItem(parent, EmptyBrackets(name), itemType, pic, spic);
02437             }
02438          }
02439       }
02440    }
02441    // list branch in list view if necessary
02442    if (listIt) {
02443       TGString *textEntry = 0;
02444       const TGPicture *pic, *spic;
02445       TTVLVEntry *entry;
02446       // make list view items in the right frame
02447       if (!fStopMapping) {
02448          fMappedBranch = branch;
02449          fMappedTree = 0;
02450          fStopMapping = kTRUE;
02451       }
02452       if ((branch->GetListOfBranches()->GetEntries()) ||
02453           (branch->GetNleaves())) {
02454          textEntry = new TGString(EmptyBrackets(name.Data()));
02455          if (branch->GetListOfBranches()->GetEntries()) {
02456             if (branch->InheritsFrom("TBranchObject")) {
02457                pic = gClient->GetPicture("branch-ob_t.xpm");
02458                spic = gClient->GetPicture("branch-ob_t.xpm");
02459             } else {
02460                if (branch->InheritsFrom("TBranchClones")) {
02461                   pic = gClient->GetPicture("branch-cl_t.xpm");
02462                   spic = gClient->GetPicture("branch-cl_t.xpm");
02463                } else {
02464                   pic = gClient->GetPicture("branch_t.xpm");
02465                   spic = gClient->GetPicture("branch_t.xpm");
02466                }
02467             }
02468             entry = new TTVLVEntry(fLVContainer,pic,spic,textEntry,0,kLVSmallIcons);
02469             entry->SetUserData(new UInt_t(kLTBranchType));
02470             entry->SetToolTipText("Branch with sub-branches. Can not be dragged");
02471             fLVContainer->AddThisItem(entry);
02472             entry->MapWindow();
02473             entry->SetAlias(textEntry->GetString());
02474          } else {
02475             if (branch->GetNleaves() > 1) {
02476                if (textEntry) delete textEntry;
02477                textEntry = new TGString(EmptyBrackets(name.Data()));
02478                pic = gClient->GetPicture("branch_t.xpm");
02479                spic = gClient->GetPicture("branch_t.xpm");
02480                entry = new TTVLVEntry(fLVContainer, pic, spic, textEntry,0,kLVSmallIcons);
02481                entry->SetUserData(new UInt_t(kLTBranchType));
02482                entry->SetToolTipText("Branch with more than one leaf. Can not be dragged");
02483                fLVContainer->AddThisItem(entry);
02484                entry->MapWindow();
02485                entry->SetAlias(textEntry->GetString());
02486 
02487                TObjArray *leaves = branch->GetListOfLeaves();
02488                TLeaf *leaf = 0;
02489                TString leafName;
02490                for (Int_t lf=0; lf<leaves->GetEntries(); lf++) {
02491                   leaf = (TLeaf *)leaves->At(lf);
02492                   leafName = name;
02493                   leafName.Append(".").Append(EmptyBrackets(leaf->GetName()));
02494                   textEntry = new TGString(leafName.Data());
02495                   pic = gClient->GetPicture("leaf_t.xpm");
02496                   spic = gClient->GetPicture("leaf_t.xpm");
02497                   entry = new TTVLVEntry(fLVContainer, pic, spic, textEntry,0,kLVSmallIcons);
02498                   entry->SetUserData(new UInt_t(kLTDragType | kLTLeafType));
02499                   entry->SetToolTipText("Double-click to draw. Drag to X, Y, Z or scan box.");
02500                   fLVContainer->AddThisItem(entry);
02501                   entry->MapWindow();
02502                   entry->SetAlias(textEntry->GetString());
02503                }
02504             } else {
02505                pic = (gClient->GetMimeTypeList())->GetIcon("TLeaf",kFALSE);
02506                if (!pic) pic = gClient->GetPicture("leaf_t.xpm");
02507                spic = gClient->GetMimeTypeList()->GetIcon("TLeaf",kTRUE);
02508                if (!spic) spic = gClient->GetPicture("leaf_t.xpm");
02509                entry = new TTVLVEntry(fLVContainer,pic,spic,textEntry,0,kLVSmallIcons);
02510                entry->SetUserData(new UInt_t(kLTDragType | kLTLeafType));
02511                entry->SetToolTipText("Double-click to draw. Drag to X, Y, Z or scan box.");
02512                fLVContainer->AddThisItem(entry);
02513                entry->MapWindow();
02514                entry->SetAlias(textEntry->GetString());
02515             }
02516          }
02517       }
02518    }
02519 
02520    TObjArray *branches = branch->GetListOfBranches();
02521    TBranch   *branchDaughter = 0;
02522 
02523    // loop all sub-branches
02524    for (ind=0; ind<branches->GetEntries(); ind++) {
02525       branchDaughter = (TBranch *)branches->UncheckedAt(ind);
02526       // map also all sub-branches
02527       MapBranch(branchDaughter, "", branchItem, listIt);
02528    }
02529 }
02530 
02531 //______________________________________________________________________________
02532 void TTreeViewer::NewExpression()
02533 {
02534    // Create new expression
02535 
02536    fLVContainer->RemoveNonStatic();
02537    const TGPicture  *pic = gClient->GetPicture("expression_t.xpm");
02538    const TGPicture *spic = gClient->GetPicture("expression_t.xpm");
02539 
02540    TTVLVEntry *entry = new TTVLVEntry(fLVContainer,pic,spic,
02541                                             new TGString(),0,kLVSmallIcons);
02542    entry->SetUserData(new ULong_t(kLTExpressionType | kLTDragType));
02543    fLVContainer->AddThisItem(entry);
02544    entry->MapWindow();
02545    entry->Empty();
02546    if (fMappedTree) MapTree(fTree);
02547    if (fMappedBranch) MapBranch(fMappedBranch);
02548    fListView->Layout();
02549    fNexpressions++;
02550 }
02551 
02552 //______________________________________________________________________________
02553 void TTreeViewer::SetParentTree(TGListTreeItem *item)
02554 {
02555    // Find parent tree of a clicked item.
02556 
02557    if (!item) return;
02558    ULong_t *itemType = (ULong_t *)item->GetUserData();
02559    TGListTreeItem *parent = 0;
02560    Int_t index;
02561    if (!(*itemType & kLTTreeType)) {
02562       parent = item->GetParent();
02563       SetParentTree(parent);
02564    } else {
02565       index = (Int_t)(*itemType >> 8);
02566       SwitchTree(index);
02567    }
02568 }
02569 
02570 //______________________________________________________________________________
02571 void TTreeViewer::Message(const char* msg)
02572 {
02573    // Send a message on the status bar.
02574 
02575    fStatusBar->SetText(msg);
02576 }
02577 
02578 //______________________________________________________________________________
02579 void TTreeViewer::DoError(int level, const char *location, const char *fmt, va_list va) const
02580 {
02581    // Put error/warning into TMsgBox and also forward to console.
02582 
02583    TObject::DoError(level, location, fmt, va);
02584 
02585    // in case level will abort we will not come here...
02586 
02587    static const int buf_size = 2048;
02588    char buf[buf_size], *bp;
02589 
02590    int n = vsnprintf(buf, buf_size, fmt, va);
02591    // old vsnprintf's return -1 if string is truncated new ones return
02592    // total number of characters that would have been written
02593    if (n == -1 || n >= buf_size) {
02594       TObject::Warning("DoError", "Error message string truncated...");
02595    }
02596    if (level >= kSysError && level < kFatal)
02597       bp = Form("%s (%s)", buf, gSystem->GetError());
02598    else
02599       bp = buf;
02600 
02601    const char *title = "";
02602    if (level == kInfo)
02603       title = "Info";
02604    if (level == kWarning)
02605       title = "Warning";
02606    if (level == kError)
02607       title = "Error";
02608    if (level == kSysError)
02609       title = "System Error";
02610 
02611    new TGMsgBox(fClient->GetRoot(), this, title, bp, kMBIconExclamation);
02612 }
02613 
02614 //______________________________________________________________________________
02615 void TTreeViewer::PrintEntries()
02616 {
02617    // Print the number of selected entries on status-bar.
02618 
02619    if (!fTree) return;
02620    char * msg = new char[100];
02621    snprintf(msg,100, "First entry : %lld Last entry : %lld",
02622            (Long64_t)fSlider->GetMinPosition(), (Long64_t)fSlider->GetMaxPosition());
02623    Message(msg);
02624    delete[] msg;
02625 }
02626 
02627 //______________________________________________________________________________
02628 void TTreeViewer::SaveSource(const char* filename, Option_t *)
02629 {
02630    // Save current session as a C++ macro file.
02631 
02632    if (!fTree) return;
02633    char quote = '"';
02634    ofstream out;
02635    Int_t lenfile = strlen(filename);
02636    char * fname;
02637    if (!lenfile) {
02638       fname = (char*)fSourceFile;
02639       lenfile = strlen(fname);
02640    } else {
02641       fname = (char*)filename;
02642       fSourceFile = filename;
02643    }
02644    // if filename is given, open this file, otherwise create a file
02645    // with a name : treeviewer.C
02646    if (lenfile) {
02647       out.open(fname, ios::out);
02648    } else {
02649       fname = new char[13];
02650       strlcpy(fname, "treeviewer.C",13);
02651       out.open(fname, ios::out);
02652    }
02653    if (!out.good ()) {
02654       printf("SaveSource cannot open file : %s\n", fname);
02655       fSourceFile = "treeviewer.C";
02656       if (!lenfile) delete [] fname;
02657       return;
02658    }
02659    //   Write macro header and date/time stamp
02660    TDatime t;
02661    TString sname(fname);
02662    sname = sname.ReplaceAll(".C", "");
02663    out <<"void "<<sname.Data()<<"() {"<<endl;
02664    out <<"//=========Macro generated by ROOT version"<<gROOT->GetVersion()<<endl;
02665    out <<"//=========for tree "<<quote<<fTree->GetName()<<quote<<" ("<<t.AsString()<<")"<<endl;
02666    out <<"//===This macro can be opened from a TreeViewer session after loading"<<endl;
02667    out <<"//===the corresponding tree, or by running root with the macro name argument"<<endl<<endl;
02668    out <<"   open_session();"<<endl;
02669    out <<"}"<<endl<<endl;
02670    out <<"open_session(void *p = 0) {"<<endl;
02671    out <<"   gSystem->Load("<<quote<<"libTreeViewer"<<quote<<");"<<endl;
02672    out <<"   TTreeViewer *treeview = (TTreeViewer *) p;"<<endl;
02673    out <<"   if (!treeview) treeview = new TTreeViewer();"<<endl;
02674    out <<"   TTree *tv_tree = (TTree*)gROOT->FindObject("<<quote<<fTree->GetName()<<quote<<");"<<endl;
02675    out <<"   TFile *tv_file = (TFile*)gROOT->GetListOfFiles()->FindObject("<<quote<<fFilename<<quote<<");"<<endl;
02676    out <<"   if (!tv_tree) {"<<endl;
02677    out <<"      if (!tv_file) tv_file = new TFile("<<quote<<fFilename<<quote<<");"<<endl;
02678    out <<"      if (tv_file)  tv_tree = (TTree*)tv_file->Get("<<quote<<fTree->GetName()<<quote<<");"<<endl;
02679    out <<"      if(!tv_tree) {"<<endl;
02680    out <<"         printf(\"Tree %s not found\", fTree->GetName());"<<endl;
02681    out <<"         return;"<<endl;
02682    out <<"      }"<<endl;
02683    out <<"   }"<<endl<<endl;
02684    out <<"   treeview->SetTreeName("<<quote<<fTree->GetName()<<quote<<");"<<endl;
02685    out <<"   treeview->SetNexpressions("<<fNexpressions<<");"<<endl;
02686    // get expressions
02687    TTVLVEntry *item;
02688    out <<"//         Set expressions on axis and cut"<<endl;
02689    out <<"   TTVLVEntry *item;"<<endl;
02690    for (Int_t i=0; i<4; i++) {
02691       switch (i) {
02692          case 0:
02693             out <<"//   X expression"<<endl;
02694             break;
02695          case 1:
02696             out <<"//   Y expression"<<endl;
02697             break;
02698          case 2:
02699             out <<"//   Z expression"<<endl;
02700             break;
02701          case 3:
02702             out <<"//   Cut expression"<<endl;
02703             break;
02704          default:
02705             break;
02706       }
02707       item = ExpressionItem(i);
02708       out <<"   item = treeview->ExpressionItem("<<i<<");"<<endl;
02709       out <<"   item->SetExpression("<<quote<<item->GetTrueName()<<quote
02710           <<", "<<quote<<item->GetAlias()<<quote<<");"<<endl;
02711    }
02712    out <<"//         Scan list"<<endl;
02713    item = ExpressionItem(4);
02714    out <<"   item = treeview->ExpressionItem(4);"<<endl;
02715    out <<"   item->SetExpression("<<quote<<item->GetTrueName()<<quote
02716           <<", "<<quote<<"Scan box"<<quote<<");"<<endl;
02717    out <<"//         User defined expressions"<<endl;
02718    TString itemType;
02719    for (Int_t crt=5; crt<fNexpressions+5; crt++) {
02720       item = ExpressionItem(crt);
02721       if (item->IsCut())
02722          itemType = "kTRUE";
02723       else
02724          itemType = "kFALSE";
02725       out <<"   item = treeview->ExpressionItem("<<crt<<");"<<endl;
02726       out <<"   item->SetExpression("<<quote<<item->GetTrueName()<<quote
02727           <<", "<<quote<<item->GetAlias()<<quote<<", "<<itemType.Data()<<");"<<endl;
02728    }
02729    fSession->SaveSource(out);
02730    out <<"}"<<endl;
02731    out.close();
02732    printf("C++ Macro file: %s has been generated\n", fname);
02733    if (!lenfile) delete [] fname;
02734 }
02735 
02736 //______________________________________________________________________________
02737 Bool_t TTreeViewer::SwitchTree(Int_t index)
02738 {
02739    // Makes current the tree at a given index in the list.
02740 
02741    TTree *tree = (TTree *) fTreeList->At(index);
02742    if (!tree) {
02743       Warning("SwitchTree", "No tree found.");
02744       return kFALSE;
02745    }
02746    if ((tree == fTree) && (tree == fMappedTree)) return kFALSE;     // nothing to switch
02747    std::string command;
02748    if (tree != fTree) {
02749       command = "tv__tree = (TTree *) tv__tree_list->At";
02750       command += Form("(%i)",index);
02751       ExecuteCommand(command.c_str());
02752    }
02753 
02754    fTree = tree;
02755    fSlider->SetRange(0,fTree->GetEntries()-1);
02756    fSlider->SetPosition(0,fTree->GetEntries()-1);
02757    command = "Current Tree : ";
02758    command += fTree->GetName();
02759    fLbl2->SetText(new TGString(command.c_str()));
02760    fTreeHdr->Layout();
02761    MapSubwindows();
02762    Resize(GetDefaultSize());
02763    MapWindow();
02764    ///Resize();  //ia
02765    PrintEntries();
02766    return kTRUE;
02767 }
02768 
02769 //______________________________________________________________________________
02770 void TTreeViewer::SetRecordName(const char *name)
02771 {
02772    // Set record name
02773 
02774    fSession->SetRecordName(name);
02775 }
02776 
02777 //______________________________________________________________________________
02778 void TTreeViewer::SetCurrentRecord(Long64_t entry)
02779 {
02780    // Set current record
02781 
02782    fCombo->Select(entry);
02783 }
02784 
02785 //______________________________________________________________________________
02786 void TTreeViewer::SetHistogramTitle(const char *title)
02787 {
02788    // Set title of Histogram
02789 
02790    if (!gPad) return;
02791    TH1 *hist = (TH1*)gPad->GetListOfPrimitives()->FindObject(fBarHist->GetText());
02792    if (hist) {
02793       hist->SetTitle(title);
02794       gPad->Update();
02795    }
02796 }
02797 //______________________________________________________________________________
02798 void TTreeViewer::SetUserCode(const char *code, Bool_t autoexec)
02799 {
02800    // user defined command for current record
02801 
02802    TTVRecord *rec = fSession->GetCurrent();
02803    if (rec) rec->SetUserCode(code, autoexec);
02804 }
02805 //______________________________________________________________________________
02806 void TTreeViewer::UpdateCombo()
02807 {
02808    // Updates combo box to current session entries.
02809 
02810    fCombo->RemoveEntries(0, 1000);
02811    for (Long64_t entry=0; entry<fSession->GetEntries(); entry++) {
02812       fCombo->AddEntry(fSession->GetRecord(entry)->GetName(), entry);
02813    }
02814 }
02815 
02816 //______________________________________________________________________________
02817 void TTreeViewer::UpdateRecord(const char *name)
02818 {
02819    // Updates current record to new X, Y, Z items.
02820 
02821    fSession->UpdateRecord(name);
02822 }
02823 
02824 //______________________________________________________________________________
02825 void TTreeViewer::DoRefresh()
02826 {
02827    // This slot is called when button REFR is clicked
02828 
02829    fTree->Refresh();
02830    Float_t min = fSlider->GetMinPosition();
02831    Float_t max = (Float_t)fTree->GetEntries()-1;
02832    fSlider->SetRange(min,max);
02833    fSlider->SetPosition(min,max);
02834    ExecuteDraw();
02835 }

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