00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <iostream>
00014 #include <TApplication.h>
00015 #include <TGClient.h>
00016 #include <TGButton.h>
00017 #include <TGFrame.h>
00018 #include <TGWindow.h>
00019 #include <TString.h>
00020 #include <TGTable.h>
00021 #include <TTreeTableInterface.h>
00022 #include <TFile.h>
00023 #include <TNtuple.h>
00024 #include <TSelectorDraw.h>
00025
00026
00027
00028
00029 class IDList {
00030 private:
00031 Int_t nID ;
00032 public:
00033 IDList() : nID(0) {}
00034 ~IDList() {}
00035 Int_t GetUnID(void) { return ++nID ; }
00036 } ;
00037
00038 class TableTest : public TGMainFrame {
00039
00040 private:
00041 IDList fIDs ;
00042 UInt_t fNTableRows;
00043 UInt_t fNTableColumns;
00044 TGTable *fTable;
00045 TFile *fFile;
00046
00047 TTreeTableInterface *fInterface;
00048
00049 public:
00050 TableTest(const TGWindow *p, UInt_t ntrows, UInt_t ntcols,
00051 UInt_t w = 100, UInt_t h = 100) ;
00052 virtual ~TableTest() ;
00053
00054 void DoExit() ;
00055
00056 TGTable *GetTable() { return fTable; }
00057 TTreeTableInterface *GetInterface() { return fInterface; }
00058
00059 ClassDef(TableTest, 0)
00060 };
00061
00062 TableTest::TableTest(const TGWindow *p, UInt_t ntrows, UInt_t ntcols,
00063 UInt_t w, UInt_t h)
00064 : TGMainFrame(p, w, h), fNTableRows(ntrows), fNTableColumns(ntcols),
00065 fTable(0)
00066 {
00067 SetCleanup(kDeepCleanup) ;
00068 Connect("CloseWindow()", "TableTest", this, "DoExit()") ;
00069 DontCallClose() ;
00070
00071
00072 fFile = new TFile("$ROOTSYS/tutorials/hsimple.root");
00073
00074 if (!fFile || fFile->IsZombie()) {
00075 printf("Please run <ROOT location>/tutorials/hsimple.C first.");
00076 return;
00077 }
00078
00079
00080 TNtuple *ntuple = (TNtuple *)fFile->Get("ntuple");
00081
00082
00083
00084 TString varexp = "px:py:pz:random:sin(px):log(px/py):log(pz)";
00085 TString select = "";
00086 TString options = "";
00087
00088
00089 fInterface = new TTreeTableInterface(ntuple, varexp.Data(), select.Data(),
00090 options.Data());
00091
00092
00093 fTable = new TGTable(this, fIDs.GetUnID(), fInterface, fNTableRows,
00094 fNTableColumns);
00095 AddFrame(fTable, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00096
00097
00098 SetWindowName("Tree Table Test") ;
00099 MapSubwindows() ;
00100 Layout();
00101 Resize(GetDefaultWidth()+20, 600) ;
00102 MapWindow() ;
00103
00104 } ;
00105
00106 TableTest::~TableTest()
00107 {
00108
00109 delete fInterface;
00110 fFile->Close();
00111 Cleanup() ;
00112 }
00113
00114 void TableTest::DoExit()
00115 {
00116
00117
00118
00119
00120
00121 DeleteWindow();
00122
00123 }
00124
00125 TGTable *ntupleTableTest(UInt_t ntrows = 50, UInt_t ntcols = 10) {
00126 TableTest *test = new TableTest(0, ntrows, ntcols, 500, 200);
00127 return test->GetTable();
00128 }