00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <iostream>
00015 #include <TApplication.h>
00016 #include <TGClient.h>
00017 #include <TGButton.h>
00018 #include <TGFrame.h>
00019 #include <TGWindow.h>
00020 #include <TString.h>
00021 #include <TGTable.h>
00022 #include <TTreeTableInterface.h>
00023 #include <TFile.h>
00024 #include <TNtuple.h>
00025 #include <TSelectorDraw.h>
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/tree/cernstaff.root");
00073
00074 if (!fFile || fFile->IsZombie()) {
00075 printf("Please run <ROOT location>/tutorials/tree/cernbuild.C first.");
00076 return;
00077 }
00078
00079
00080 TTree *tree = (TTree *)fFile->Get("T");
00081
00082
00083 TString varexp = "*";
00084 TString select = "";
00085 TString options = "";
00086 fInterface = new TTreeTableInterface(tree, varexp.Data(), select.Data(),
00087 options.Data());
00088
00089
00090
00091 fTable = new TGTable(this, fIDs.GetUnID(), fInterface, fNTableRows,
00092 fNTableColumns);
00093 AddFrame(fTable, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00094
00095
00096 SetWindowName("Tree Table Test") ;
00097 MapSubwindows() ;
00098 Layout();
00099 Resize(GetDefaultWidth()+20, 600) ;
00100 MapWindow() ;
00101
00102 } ;
00103
00104 TableTest::~TableTest()
00105 {
00106
00107 delete fInterface;
00108 fFile->Close();
00109 Cleanup() ;
00110 }
00111
00112 void TableTest::DoExit()
00113 {
00114
00115
00116
00117
00118
00119 DeleteWindow();
00120
00121 }
00122
00123 TGTable *staffTableTest(UInt_t ntrows = 50, UInt_t ntcols = 10) {
00124 TableTest *test = new TableTest(0, ntrows, ntcols, 500, 200);
00125 return test->GetTable();
00126 }