From 64a742214735790ea4cd87277a14f26aace746e7 Mon Sep 17 00:00:00 2001 From: nkx Date: Tue, 26 Jul 2022 21:12:49 +0800 Subject: [PATCH] TRestBrowser added event selection bar --- source/framework/core/inc/TRestBrowser.h | 17 ++- source/framework/core/src/TRestBrowser.cxx | 169 ++++++++++++++++----- source/framework/tools/src/TRestTools.cxx | 4 +- 3 files changed, 150 insertions(+), 40 deletions(-) diff --git a/source/framework/core/inc/TRestBrowser.h b/source/framework/core/inc/TRestBrowser.h index 10af1cba6..4e3cf43be 100644 --- a/source/framework/core/inc/TRestBrowser.h +++ b/source/framework/core/inc/TRestBrowser.h @@ -24,7 +24,10 @@ class TRestBrowser { protected: #ifndef __CINT__ - TGMainFrame* frmMain = nullptr; //! + TGMainFrame* frmMain = nullptr; //! + TGMainFrame* frmBot = 0; //! + + // Frames and buttons on left//! TGVerticalFrame* fVFrame = nullptr; //! < The main vertical frame for browser controlling TGLabel* fEventRowLabel = nullptr; //! TGLabel* fEventIdLabel = nullptr; //! @@ -45,6 +48,13 @@ class TRestBrowser { TGPictureButton* fMenuOpen = nullptr; //! Open file button TGTextButton* fExit = nullptr; //! Exit button + // Frames and buttons on bottom + TGVerticalFrame* fHFrame = 0; //! + TGLabel* fSelectionTextBoxLabel = 0; //! + TGTextEntry* fSelectionTextBox = 0; //! TextBox for plot options + TGTextButton* fButEvePrev = 0; //! Previous plot option + TGTextButton* fButEveNext = 0; //! Refresh plot + TCanvas* fCanDefault = nullptr; //! Int_t fEventRow = 0; //! Int_t fEventId = 0; //! @@ -63,7 +73,8 @@ class TRestBrowser { void SetViewer(TRestEventViewer* eV); void SetViewer(const TString& viewerName); - void SetButtons(); + void SetLeftPanelButtons(); + void SetBottomPanelButtons(); Bool_t LoadEventId(Int_t eventID, Int_t subEventID = -1); Bool_t LoadEventEntry(Int_t n); #endif @@ -87,6 +98,8 @@ class TRestBrowser { void RowValueChangedAction(Long_t val); void IdValueChangedAction(Long_t val); + void NextEventAction(); + void PreviousEventAction(); void EventTypeChangedAction(Int_t id); diff --git a/source/framework/core/src/TRestBrowser.cxx b/source/framework/core/src/TRestBrowser.cxx index d57c25584..f5894c242 100644 --- a/source/framework/core/src/TRestBrowser.cxx +++ b/source/framework/core/src/TRestBrowser.cxx @@ -24,6 +24,7 @@ ////////////////////////////////////////////////////////////////////////// #include "TRestBrowser.h" +#include "TTreeFormula.h" using namespace std; @@ -65,18 +66,26 @@ void TRestBrowser::Initialize(const TString& opt) { fBrowser->StartEmbedding(0, -1); frmMain = new TGMainFrame(gClient->GetRoot(), 300); frmMain->SetCleanup(kDeepCleanup); - frmMain->SetWindowName("Controller"); - SetButtons(); + frmMain->SetWindowName("Controller1"); + SetLeftPanelButtons(); fBrowser->StopEmbedding(); fBrowser->StartEmbedding(1, -1); fCanDefault = new TCanvas(); fBrowser->StopEmbedding(); - // frmMain->DontCallClose(); - frmMain->MapSubwindows(); - // frmMain->Resize(); - frmMain->Layout(); - frmMain->MapWindow(); + + fBrowser->StartEmbedding(2, -1); + frmBot = new TGMainFrame(gClient->GetRoot(), 300); + frmBot->SetCleanup(kDeepCleanup); + frmBot->SetWindowName("Controller2"); + SetBottomPanelButtons(); + fBrowser->StopEmbedding(); + + //// frmMain->DontCallClose(); + //frmMain->MapSubwindows(); + //// frmMain->Resize(); + //frmMain->Layout(); + //frmMain->MapWindow(); } void TRestBrowser::SetViewer(TRestEventViewer* eV) { @@ -109,22 +118,22 @@ void TRestBrowser::SetViewer(const TString& viewerName) { } } -void TRestBrowser::SetButtons() { +void TRestBrowser::SetLeftPanelButtons() { TString icondir = (TString)getenv("ROOTSYS") + "/icons/"; - auto vFrame = new TGVerticalFrame(frmMain); - vFrame->Resize(300, 200); + fVFrame = new TGVerticalFrame(frmMain); + fVFrame->Resize(300, 200); // row in the tree - fEventRowLabel = new TGLabel(vFrame, "Entry:"); - vFrame->AddFrame(fEventRowLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + fEventRowLabel = new TGLabel(fVFrame, "Entry:"); + fVFrame->AddFrame(fEventRowLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); - fEventRowNumberBox = new TGNumberEntry(vFrame, fEventRow); + fEventRowNumberBox = new TGNumberEntry(fVFrame, fEventRow); fEventRowNumberBox->Connect("ValueSet(Long_t)", "TRestBrowser", this, "RowValueChangedAction(Long_t)"); - vFrame->AddFrame(fEventRowNumberBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + fVFrame->AddFrame(fEventRowNumberBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); // event id and sub event id - auto labelBar = new TGHorizontalFrame(vFrame); + auto labelBar = new TGHorizontalFrame(fVFrame); { fEventIdLabel = new TGLabel(labelBar, "Event ID:"); labelBar->AddFrame(fEventIdLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); @@ -132,9 +141,9 @@ void TRestBrowser::SetButtons() { fEventSubIdLabel = new TGLabel(labelBar, "Sub ID:"); labelBar->AddFrame(fEventSubIdLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); } - vFrame->AddFrame(labelBar, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + fVFrame->AddFrame(labelBar, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); - auto numberBoxBar = new TGHorizontalFrame(vFrame); + auto numberBoxBar = new TGHorizontalFrame(fVFrame); { fEventIdNumberBox = new TGNumberEntry(numberBoxBar, fEventId); fEventIdNumberBox->Connect("ValueSet(Long_t)", "TRestBrowser", this, "IdValueChangedAction(Long_t)"); @@ -145,28 +154,28 @@ void TRestBrowser::SetButtons() { "IdValueChangedAction(Long_t)"); numberBoxBar->AddFrame(fEventSubIdNumberBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); } - vFrame->AddFrame(numberBoxBar, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + fVFrame->AddFrame(numberBoxBar, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); // event type to choose - fEventTypeLabel = new TGLabel(vFrame, "Event Type:"); - vFrame->AddFrame(fEventTypeLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + fEventTypeLabel = new TGLabel(fVFrame, "Event Type:"); + fVFrame->AddFrame(fEventTypeLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); - fEventTypeComboBox = new TGComboBox(vFrame); + fEventTypeComboBox = new TGComboBox(fVFrame); fEventTypeComboBox->Connect("Selected(Int_t)", "TRestBrowser", this, "EventTypeChangedAction(Int_t)"); - vFrame->AddFrame(fEventTypeComboBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + fVFrame->AddFrame(fEventTypeComboBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); // plot option buttons - fPlotOptionLabel = new TGLabel(vFrame, "Plot Options:"); - vFrame->AddFrame(fPlotOptionLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + fPlotOptionLabel = new TGLabel(fVFrame, "Plot Options:"); + fVFrame->AddFrame(fPlotOptionLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); - fPlotOptionTextBox = new TGTextEntry(vFrame, ""); + fPlotOptionTextBox = new TGTextEntry(fVFrame, ""); fPlotOptionTextBox->SetText(""); fPlotOptionTextBox->Connect("ReturnPressed()", "TRestBrowser", this, "PlotAction()"); - vFrame->AddFrame(fPlotOptionTextBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + fVFrame->AddFrame(fPlotOptionTextBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); - auto switchButtonBar = new TGHorizontalFrame(vFrame); + auto switchButtonBar = new TGHorizontalFrame(fVFrame); { - fButOptPrev = new TGTextButton(switchButtonBar, "<Connect("Clicked()", "TRestBrowser", this, "PreviousPlotOptionAction()"); switchButtonBar->AddFrame(fButOptPrev, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); @@ -174,24 +183,24 @@ void TRestBrowser::SetButtons() { fButOptRefresh->Connect("Clicked()", "TRestBrowser", this, "PlotAction()"); switchButtonBar->AddFrame(fButOptRefresh, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); - fButOptNext = new TGTextButton(switchButtonBar, "Next>>"); ///< Load Event button + fButOptNext = new TGTextButton(switchButtonBar, "++"); ///< Load Event button fButOptNext->Connect("Clicked()", "TRestBrowser", this, "NextPlotOptionAction()"); switchButtonBar->AddFrame(fButOptNext, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); } - vFrame->AddFrame(switchButtonBar, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + fVFrame->AddFrame(switchButtonBar, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); // tool buttons - fMenuOpen = new TGPictureButton(vFrame, gClient->GetPicture(icondir + "bld_open.png")); + fMenuOpen = new TGPictureButton(fVFrame, gClient->GetPicture(icondir + "bld_open.png")); fMenuOpen->Connect("Clicked()", "TRestBrowser", this, "LoadFileAction()"); - vFrame->AddFrame(fMenuOpen, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + fVFrame->AddFrame(fMenuOpen, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); - fExit = new TGTextButton(vFrame, "EXIT"); ///< Exit button + fExit = new TGTextButton(fVFrame, "EXIT"); ///< Exit button fExit->Connect("Clicked()", "TRestBrowser", this, "ExitAction()"); - vFrame->AddFrame(fExit, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + fVFrame->AddFrame(fExit, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); - frmMain->Resize(TGDimension(300, frmMain->GetHeight() + vFrame->GetHeight())); + frmMain->Resize(TGDimension(300, frmMain->GetHeight() + fVFrame->GetHeight())); - frmMain->AddFrame(vFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + frmMain->AddFrame(fVFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); // frmMain->DontCallClose(); frmMain->MapSubwindows(); // frmMain->Resize(); @@ -199,6 +208,34 @@ void TRestBrowser::SetButtons() { frmMain->MapWindow(); } +void TRestBrowser::SetBottomPanelButtons() { + fHFrame = new TGVerticalFrame(frmBot); + fHFrame->Resize(300, 100); + + fSelectionTextBoxLabel = new TGLabel(fHFrame, "Selection:"); + fHFrame->AddFrame(fSelectionTextBoxLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + + fSelectionTextBox = new TGTextEntry(fHFrame, ""); + fHFrame->AddFrame(fSelectionTextBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + + auto bottonsbar = new TGHorizontalFrame(fHFrame); + { + fButEveNext = new TGTextButton(bottonsbar, "Previous Event"); ///< Exit button + fButEveNext->Connect("Clicked()", "TRestBrowser", this, "PreviousEventAction()"); + bottonsbar->AddFrame(fButEveNext, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + + fButEvePrev = new TGTextButton(bottonsbar, "Next Event"); ///< Exit button + fButEvePrev->Connect("Clicked()", "TRestBrowser", this, "NextEventAction()"); + bottonsbar->AddFrame(fButEvePrev, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + } + fHFrame->AddFrame(bottonsbar, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + + frmBot->AddFrame(fHFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); + frmBot->MapSubwindows(); + frmBot->Layout(); + frmBot->MapWindow(); +} + void TRestBrowser::InitFromConfigFile() { cout << __PRETTY_FUNCTION__ << endl; } void TRestBrowser::SetInputEvent(TRestEvent* event) { @@ -414,6 +451,66 @@ void TRestBrowser::IdValueChangedAction(Long_t val) { } } +void TRestBrowser::NextEventAction() { + string sel = (string)fSelectionTextBox->GetText(); + if (sel == "") { + fEventRow++; + LoadEventEntry(fEventRow); + } else { + TRestAnalysisTree* tree = fRestRun->GetAnalysisTree(); + TTreeFormula formula("Selection", sel.c_str(), tree); + if (formula.GetNdim() > 0) { // valid expression + fEventRow++; + while (1) { + tree->GetEntry(fEventRow); + if (formula.EvalInstance(fEventRow) == 1) { + LoadEventEntry(fEventRow); + break; + } else { + cout << fEventRow << endl; + fEventRow++; + } + if (fEventRow >= fRestRun->GetAnalysisTree()->GetEntries()) { + LoadEventEntry(fEventRow); + break; + } + } + } else { + cout << "invalid selection!" << endl; + } + } +} + +void TRestBrowser::PreviousEventAction() { + string sel = (string)fSelectionTextBox->GetText(); + if (sel == "") { + fEventRow--; + LoadEventEntry(fEventRow); + } else { + TRestAnalysisTree* tree = fRestRun->GetAnalysisTree(); + TTreeFormula formula("Selection", sel.c_str(), tree); + if (formula.GetNdim() > 0) { // valid expression + fEventRow--; + while (1) { + tree->GetEntry(fEventRow); + if (formula.EvalInstance(fEventRow) == 1) { + LoadEventEntry(fEventRow); + break; + } else { + cout << fEventRow << endl; + fEventRow--; + } + if (fEventRow < 0) { + LoadEventEntry(fEventRow); + break; + } + } + } else { + cout << "invalid selection!" << endl; + } + } +} + void TRestBrowser::LoadFileAction() { TGFileInfo fi; new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDOpen, &fi); diff --git a/source/framework/tools/src/TRestTools.cxx b/source/framework/tools/src/TRestTools.cxx index 72de1bae3..727105329 100644 --- a/source/framework/tools/src/TRestTools.cxx +++ b/source/framework/tools/src/TRestTools.cxx @@ -93,7 +93,7 @@ void TRestTools::LoadRESTLibrary(bool silent) { vector ldPaths; #ifdef WIN32 - ldpaths.push_back(REST_PATH + "/bin/"); + ldPaths.push_back(REST_PATH + "/bin/"); #else ldPaths.push_back(REST_PATH + "/lib/"); #endif // WIN32 @@ -130,7 +130,7 @@ void TRestTools::LoadRESTLibrary(bool silent) { if (excluded) { continue; } - fileList.emplace_back(it.path()); + fileList.emplace_back(it.path().string()); } }