Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRestBrowser added event selection bar #272

Merged
merged 2 commits into from
Aug 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions source/framework/core/inc/TRestBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; //!
Expand All @@ -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; //!
Expand All @@ -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
Expand All @@ -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);

Expand Down
169 changes: 133 additions & 36 deletions source/framework/core/src/TRestBrowser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
//////////////////////////////////////////////////////////////////////////

#include "TRestBrowser.h"
#include "TTreeFormula.h"

using namespace std;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -109,32 +118,32 @@ 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));

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)");
Expand All @@ -145,60 +154,88 @@ 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, "<<Previous"); ///< Load Event button
fButOptPrev = new TGTextButton(switchButtonBar, "--"); ///< Load Event button
fButOptPrev->Connect("Clicked()", "TRestBrowser", this, "PreviousPlotOptionAction()");
switchButtonBar->AddFrame(fButOptPrev, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));

fButOptRefresh = new TGTextButton(switchButtonBar, "Plot"); ///< Load Event button
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();
frmMain->Layout();
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) {
Expand Down Expand Up @@ -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);
Expand Down