gtreeTableTest.C

Go to the documentation of this file.
00001 // This TableTest class is a simple example of how to use a TGTreeTable. 
00002 // TableTest inherits from TGMainFrame to create a top
00003 // level frame to embed the TGTreeTable in. First, the staff.root file
00004 // is opened to obtain a tree. A TGTreeTable is then created using the
00005 // tree. In the end, the table is added to the TGMainFrame that is the
00006 // TableTest and the necessary calls to correctly draw the window are
00007 // made. For more information about the use of TGTreeTable, see it's
00008 // documentation.
00009 
00010 // author, Roel Aaij 13/07/2007
00011 
00012 #include <iostream>
00013 #include <TApplication.h>
00014 #include <TGClient.h>
00015 #include <TGButton.h>
00016 #include <TGFrame.h>
00017 #include <TGWindow.h>
00018 #include <TString.h>
00019 #include <TGTreeTable.h>
00020 #include <TFile.h>
00021 #include <TNtuple.h>
00022 #include <TTree.h>
00023 
00024 // A little class to automatically handle the generation of unique
00025 // widget ids.
00026 class IDList {
00027 private:
00028    Int_t nID;               // Generates unique widget IDs.
00029 public:
00030    IDList() : nID(0) {}
00031    ~IDList() {}
00032    Int_t GetUnID(void) { return ++nID ; }
00033 };
00034 
00035 class TableTest : public TGMainFrame {
00036 
00037 private:
00038    IDList        fIDs;      // Generator for unique widget IDs.
00039    UInt_t        fNTableRows;
00040    UInt_t        fNTableColumns;
00041    TGTreeTable  *fTreeTable;
00042    TFile        *fFile;
00043    
00044 public:
00045    TableTest(const TGWindow *p, UInt_t ntrows, UInt_t ntcols, 
00046              UInt_t w = 100, UInt_t h = 100);
00047    virtual ~TableTest() ;
00048 
00049    void DoExit() ;
00050 
00051    TGTreeTable *GetTable() { return fTreeTable; }
00052 
00053    ClassDef(TableTest, 0)
00054 };
00055                           
00056 TableTest::TableTest(const TGWindow *p, UInt_t ntrows, UInt_t ntcols, 
00057                      UInt_t w, UInt_t h) 
00058    : TGMainFrame(p, w, h), fNTableRows(ntrows), fNTableColumns(ntcols), 
00059      fTreeTable(0)
00060 {
00061    SetCleanup(kDeepCleanup) ;   
00062    Connect("CloseWindow()", "TableTest", this, "DoExit()") ;
00063    DontCallClose() ;
00064    
00065    // Open the root file
00066    fFile = new TFile("$ROOTSYS/tutorials/tree/cernstaff.root");
00067 
00068    if (!fFile || fFile->IsZombie()) {
00069       printf("Please run <ROOT location>/tutorials/tree/cernbuild.C first.");
00070       return;
00071    }
00072 
00073    // Get the tree from the file.
00074    TTree *tree = (TTree *)fFile->Get("T");
00075 
00076    // Setup the expressions for the columns and the selection of the
00077    // interface.
00078    TString varexp = "px:py:pz:random:sin(px):log(px/py):log(pz)";
00079    TString select = "px>0 && py>0 && pz>0";
00080    TString options = "";
00081 
00082    // Create the table and add it to the TableTest that is a TGMainFrame
00083    fTreeTable = new TGTreeTable(this, fIDs.GetUnID(), tree);
00084    AddFrame(fTreeTable, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00085 
00086    // Calls to layout and draw the TableTest that is a TGMainFrame.
00087    SetWindowName("TGTreeTable Test") ;
00088    MapSubwindows() ;
00089    Layout();
00090    Resize(GetDefaultWidth()+20, 600) ;
00091    MapWindow() ;
00092    
00093 } ;
00094 
00095 TableTest::~TableTest()
00096 {
00097    // Destructor
00098    fFile->Close();
00099    Cleanup() ;
00100 }
00101  
00102  void TableTest::DoExit()
00103 {
00104    // Exit this application via the Exit button or Window Manager.
00105    // Use one of the both lines according to your needs.
00106    // Please note to re-run this macro in the same ROOT session,
00107    // you have to compile it to get signals/slots 'on place'.
00108    
00109    DeleteWindow();            // to stay in the ROOT session
00110    //   gApplication->Terminate();   // to exit and close the ROOT session   
00111 }
00112 
00113 TGTreeTable *gtreeTableTest(UInt_t ntrows = 50, UInt_t ntcols = 10) {
00114    TableTest *test = new TableTest(0, ntrows, ntcols, 500, 200);
00115    return test->GetTable();
00116 }

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