Commit 895ca346 authored by nkx Nicholas's avatar nkx Nicholas
Browse files

TRestBrowser: updated to both display/switch row, event id, sub event id

parent 53e4e3cc
......@@ -29,14 +29,24 @@ class TRestBrowser {
// Frames and buttons
TGVerticalFrame* fVFrame = 0; //! < Vertical frame.
TGNumberEntry* fNEvent = 0; //! Event number.
TGLabel* fLabel = 0; //! label(content"plot options:")
TGPictureButton* fButPrev = 0; //! Previous event.
TGPictureButton* fLoadEvent = 0; //! Load Event button
TGPictureButton* fButNext = 0; //! Next number.
TGLabel* fEventRowLabel = 0; //! label(content"plot options:")
TGLabel* fEventIdLabel = 0; //! label(content"plot options:")
TGLabel* fEventSubIdLabel = 0; //! label(content"plot options:")
TGNumberEntry* fEventRowNumberBox = 0; //! Event number.
TGNumberEntry* fEventIdNumberBox = 0; //! Event number.
TGNumberEntry* fEventSubIdNumberBox = 0; //! Event number.
TGPictureButton* fButEventPrev = 0; //! Previous event.
TGPictureButton* fButEventLoad = 0; //! Load Event button
TGPictureButton* fButEventNext = 0; //! Next number.
TGPictureButton* fMenuOpen = 0; //! Open file
TGTextButton* fExit = 0; //! Load Event button
TGLabel* fPlotOptionLabel = 0; //! label(content"plot options:")
TGTextEntry* fPlotOptionTextBox = 0;
TGTextButton* fButOptPrev = 0; //! Previous event.
TGTextButton* fButOptLoad = 0; //! Load Event button
TGTextButton* fButOptNext = 0; //! Next number.
TCanvas* fCanDefault = 0; //!
TBrowser* b = 0; //!
......@@ -47,10 +57,11 @@ class TRestBrowser {
#ifndef __CINT__
Bool_t pureAnalysis;
TString fInputFileName;
Int_t fCurrentEntry = 0;
Int_t fCurrentId = 0;
TRestEventViewer* fEventViewer = 0; //!
Bool_t LoadEventId(Int_t id, Int_t subid = -1);
Bool_t LoadEventEntry(Int_t n);
#endif
public:
......@@ -63,6 +74,7 @@ class TRestBrowser {
void Initialize(TString opt = "FI");
void InitFromConfigFile();
Bool_t OpenFile(TString filename);
void SetViewer(TRestEventViewer* eV);
void SetViewer(TString viewerName);
......@@ -74,18 +86,17 @@ class TRestBrowser {
TRestEventViewer* GetViewer() { return fEventViewer; }
TGVerticalFrame* generateNewFrame();
void addFrame(TGFrame* f);
void LoadEventAction();
void LoadNextEventAction();
void LoadPrevEventAction();
// actions
void LoadFileAction();
void ExitAction();
Bool_t OpenFile(TString fName);
Bool_t LoadEventId(Int_t id);
Bool_t LoadEventEntry(Int_t n);
void RowValueChangedAction(Long_t val);
void IdValueChangedAction(Long_t val);
void NextPlotOptionAction();
void PreviousPlotOptionAction();
void PlotAction();
};
#endif
......@@ -34,33 +34,21 @@ class TRestEventViewer {
protected:
TGeoManager* fGeometry = 0; //!
TRestEvent* fEvent = 0; //!
TRestBrowser* fController = 0; //!
TPad* fPad = 0;
TCanvas* fCanvas = 0;
TGTextButton* fButNext = 0; //! Next signal.
TGTextButton* fButPrev = 0; //! Previous signal.
TGLabel* fLabel = 0; //! label(content"plot options:")
TGTextEntry* fOptwindow = 0; //! option input window.
TGTextButton* fButOpt = 0; //! draw with option.
public:
virtual void Initialize();
virtual void AddEvent(TRestEvent* ev);
void NextOption();
void PreviousOption();
void OptionPlot();
virtual void Plot(const char* option);
virtual void DeleteCurrentEvent();
// Setters
virtual void SetGeometry(TGeoManager* geo) { fGeometry = geo; }
void SetEvent(TRestEvent* ev) { fEvent = ev; }
void SetController(TRestBrowser* b) { fController = b; }
// Getters
TGeoManager* GetGeometry() { return fGeometry; }
TRestEvent* GetEvent() { return fEvent; }
......
......@@ -53,8 +53,6 @@ TRestBrowser::~TRestBrowser() {
void TRestBrowser::Initialize(TString opt) {
pureAnalysis = kFALSE;
fCurrentEntry = 0;
fCurrentId = 0;
r = new TRestRun();
......@@ -85,7 +83,6 @@ void TRestBrowser::SetViewer(TRestEventViewer* eV) {
}
if (eV != NULL) {
fEventViewer = eV;
eV->SetController(this);
b->StartEmbedding(1, -1);
eV->Initialize();
b->StopEmbedding();
......@@ -107,32 +104,42 @@ void TRestBrowser::SetViewer(TString viewerName) {
void TRestBrowser::setButtons() {
TString icondir = (TString)getenv("ROOTSYS") + "/icons/";
fVFrame = generateNewFrame();
auto fVFrame = new TGVerticalFrame(frmMain);
fVFrame->Resize(300, 200);
fLabel = new TGLabel(fVFrame, "EventId:");
fVFrame->AddFrame(fLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
// row in the tree
fEventRowLabel = new TGLabel(fVFrame, "Row:");
fVFrame->AddFrame(fEventRowLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
fNEvent = new TGNumberEntry(fVFrame, fCurrentId);
fNEvent->SetIntNumber(fCurrentId);
fVFrame->AddFrame(fNEvent, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
fEventRowNumberBox = new TGNumberEntry(fVFrame, 0);
fEventRowNumberBox->Connect("ValueSet(Long_t)", "TRestBrowser", this, "RowValueChangedAction(Long_t)");
fVFrame->AddFrame(fEventRowNumberBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
auto controlbar = new TGHorizontalFrame(fVFrame);
// event id and sub event id
auto labelbar = new TGHorizontalFrame(fVFrame);
{
fButPrev = new TGPictureButton(controlbar, gClient->GetPicture(icondir + "GoBack.gif"));
fButPrev->Connect("Clicked()", "TRestBrowser", this, "LoadPrevEventAction()");
controlbar->AddFrame(fButPrev, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
fLoadEvent = new TGPictureButton(
controlbar, gClient->GetPicture(icondir + "refresh.png")); ///< Load Event button
fLoadEvent->Connect("Clicked()", "TRestBrowser", this, "LoadEventAction()");
controlbar->AddFrame(fLoadEvent, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
fButNext = new TGPictureButton(controlbar, gClient->GetPicture(icondir + "GoForward.gif"));
fButNext->Connect("Clicked()", "TRestBrowser", this, "LoadNextEventAction()");
controlbar->AddFrame(fButNext, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
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));
}
fVFrame->AddFrame(labelbar, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
auto numberboxbar = new TGHorizontalFrame(fVFrame);
{
fEventIdNumberBox = new TGNumberEntry(numberboxbar, 0);
fEventIdNumberBox->Connect("ValueSet(Long_t)", "TRestBrowser", this, "IdValueChangedAction(Long_t)");
numberboxbar->AddFrame(fEventIdNumberBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
fEventSubIdNumberBox = new TGNumberEntry(numberboxbar, 0);
fEventSubIdNumberBox->Connect("ValueSet(Long_t)", "TRestBrowser", this,
"IdValueChangedAction(Long_t)");
numberboxbar->AddFrame(fEventSubIdNumberBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
}
fVFrame->AddFrame(controlbar, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
fVFrame->AddFrame(numberboxbar, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
// tool buttoms
fMenuOpen = new TGPictureButton(fVFrame, gClient->GetPicture(icondir + "bld_open.png"));
fMenuOpen->Connect("Clicked()", "TRestBrowser", this, "LoadFileAction()");
fVFrame->AddFrame(fMenuOpen, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
......@@ -141,16 +148,33 @@ void TRestBrowser::setButtons() {
fExit->Connect("Clicked()", "TRestBrowser", this, "ExitAction()");
fVFrame->AddFrame(fExit, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
addFrame(fVFrame);
// plot option buttoms
fPlotOptionLabel = new TGLabel(fVFrame, "Plot Options:");
fVFrame->AddFrame(fPlotOptionLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
// frmMain->AddFrame(fVFrame,new TGLayoutHints(kLHintsExpandX |
// kLHintsExpandY));
}
fPlotOptionTextBox = new TGTextEntry(fVFrame, "");
fPlotOptionTextBox->SetText("");
fVFrame->AddFrame(fPlotOptionTextBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
auto frame1 = new TGHorizontalFrame(fVFrame);
{
fButOptPrev = new TGTextButton(frame1, "<<Previous"); ///< Load Event button
fButOptPrev->Connect("Clicked()", "TRestBrowser", this, "PreviousPlotOptionAction()");
frame1->AddFrame(fButOptPrev, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
fButOptLoad = new TGTextButton(frame1, "Plot"); ///< Load Event button
fButOptLoad->Connect("Clicked()", "TRestBrowser", this, "PlotAction()");
frame1->AddFrame(fButOptLoad, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
fButOptNext = new TGTextButton(frame1, "Next>>"); ///< Load Event button
fButOptNext->Connect("Clicked()", "TRestBrowser", this, "NextPlotOptionAction()");
frame1->AddFrame(fButOptNext, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
}
fVFrame->AddFrame(frame1, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
void TRestBrowser::addFrame(TGFrame* f) {
frmMain->Resize(TGDimension(300, frmMain->GetHeight() + f->GetHeight()));
frmMain->Resize(TGDimension(300, frmMain->GetHeight() + fVFrame->GetHeight()));
frmMain->AddFrame(f, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
frmMain->AddFrame(fVFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
// frmMain->DontCallClose();
frmMain->MapSubwindows();
// frmMain->Resize();
......@@ -158,76 +182,7 @@ void TRestBrowser::addFrame(TGFrame* f) {
frmMain->MapWindow();
}
TGVerticalFrame* TRestBrowser::generateNewFrame() {
auto frame = new TGVerticalFrame(frmMain);
frame->Resize(300, 200);
return frame;
}
void TRestBrowser::LoadEventAction() {
Int_t eventN = (Int_t)fNEvent->GetNumber();
debug << "TRestBrowser::LoadEventAction. Id:" << eventN << endl;
LoadEventId(eventN);
}
void TRestBrowser::LoadNextEventAction() {
Int_t nextEvent = fCurrentEntry + 1;
debug << "TRestBrowser::LoadNextEventAction. Next entry:" << nextEvent << endl;
LoadEventEntry(nextEvent);
}
void TRestBrowser::LoadPrevEventAction() {
Int_t prevEvent = fCurrentEntry - 1;
debug << "TRestBrowser::LoadNextEventAction. Previous entry:" << prevEvent << endl;
LoadEventEntry(prevEvent);
}
void TRestBrowser::LoadFileAction() {
TGFileInfo fi;
new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDOpen, &fi);
TString dir = fi.fFilename;
cout << "Opening " << dir.Data() << endl;
if (TRestTools::fileExists(dir.Data())) {
OpenFile(dir);
fNEvent->SetIntNumber(fCurrentId);
}
}
Bool_t TRestBrowser::OpenFile(TString fName) {
if (!TRestTools::fileExists((string)fName)) {
cout << "WARNING. Input file " << fName << " does not exist" << endl;
return kFALSE;
}
fInputFileName = fName;
r->OpenInputFile(fName);
TFile* f = r->GetInputFile();
TTree* t = r->GetEventTree();
fCurrentEntry = r->GetCurrentEntry();
TGeoManager* geometry = gGeoManager;
if (t != NULL) {
// init viewer
pureAnalysis = kFALSE;
if (fEventViewer == NULL) SetViewer("TRestEventViewer");
if (geometry != NULL && fEventViewer != NULL) fEventViewer->SetGeometry(geometry);
LoadEventAction();
} else {
pureAnalysis = kTRUE;
}
return kTRUE;
}
void TRestBrowser::InitFromConfigFile() { cout << __PRETTY_FUNCTION__ << endl; }
void TRestBrowser::SetInputEvent(TRestEvent* eve) {
if (r != NULL) {
......@@ -244,15 +199,19 @@ Bool_t TRestBrowser::LoadEventEntry(Int_t n) {
warning << "TRestBrowser::LoadEventEntry. This is a pure analysis file..." << endl;
return kFALSE;
}
if (r->GetAnalysisTree() != NULL && n < r->GetAnalysisTree()->GetEntries() && n >= 0) {
r->GetEntry(n);
fCurrentEntry = r->GetCurrentEntry();
fCurrentId = r->GetAnalysisTree()->GetEventID();
debug << "TRestBrowser:LoadEventEntry. Setting current id : " << fCurrentId << endl;
debug << "TRestBrowser:LoadEventEntry. Setting current entry : " << fCurrentEntry << endl;
fNEvent->SetIntNumber(fCurrentId);
TRestEvent* ev = r->GetInputEvent();
if (!ev) {
ferr << "internal error!" << endl;
} else {
fEventRowNumberBox->SetIntNumber(r->GetCurrentEntry());
fEventIdNumberBox->SetIntNumber(ev->GetID());
fEventSubIdNumberBox->SetIntNumber(ev->GetSubID());
r->GetAnalysisTree()->PrintObservables();
cout << endl;
}
} else {
warning << "TRestBrowser::LoadEventEntry. Event out of limits" << endl;
return kFALSE;
......@@ -260,15 +219,14 @@ Bool_t TRestBrowser::LoadEventEntry(Int_t n) {
if (fEventViewer != NULL) {
fEventViewer->AddEvent(r->GetInputEvent());
fEventViewer->Plot(fPlotOptionTextBox->GetText());
}
r->GetAnalysisTree()->PrintObservables();
fCanDefault->cd();
return kTRUE;
}
Bool_t TRestBrowser::LoadEventId(Int_t id) {
Bool_t TRestBrowser::LoadEventId(Int_t id, Int_t subid) {
if (r->GetInputFile() == NULL || r->GetInputFile()->IsZombie()) {
warning << "TRestBrowser::LoadEventEntry. No File..." << endl;
return kFALSE;
......@@ -278,19 +236,20 @@ Bool_t TRestBrowser::LoadEventId(Int_t id) {
warning << "TRestBrowser::LoadEventEntry. This is a pure analysis file..." << endl;
return kFALSE;
}
if (r->GetAnalysisTree() != NULL && r->GetAnalysisTree()->GetEntries() > 0) {
TRestEvent* ev = r->GetEventWithID(id);
TRestEvent* ev = r->GetEventWithID(id, subid);
if (!ev) {
warning << "Event ID : " << id << " not found!" << endl;
warning << "Getting entry 0" << endl;
r->GetEntry(0);
fEventIdNumberBox->SetBackgroundColor(kRed);
fEventSubIdNumberBox->SetForegroundColor(kRed);
} else {
fEventRowNumberBox->SetIntNumber(r->GetCurrentEntry());
fEventIdNumberBox->SetIntNumber(ev->GetID());
fEventSubIdNumberBox->SetIntNumber(ev->GetSubID());
r->GetAnalysisTree()->PrintObservables();
cout << endl;
}
fCurrentEntry = r->GetCurrentEntry();
fCurrentId = r->GetAnalysisTree()->GetEventID();
debug << "TRestBrowser:LoadEventId. Setting current id : " << fCurrentId << endl;
debug << "TRestBrowser:LoadEventId. Setting current entry : " << fCurrentEntry << endl;
} else {
warning << "TRestBrowser::LoadEventEntry. Event out of limits" << endl;
return kFALSE;
......@@ -298,14 +257,99 @@ Bool_t TRestBrowser::LoadEventId(Int_t id) {
if (fEventViewer != NULL) {
fEventViewer->AddEvent(r->GetInputEvent());
fEventViewer->Plot(fPlotOptionTextBox->GetText());
}
r->GetAnalysisTree()->PrintObservables();
fCanDefault->cd();
return kTRUE;
}
void TRestBrowser::ExitAction() { gSystem->Exit(0); }
Bool_t TRestBrowser::OpenFile(TString filename) {
if (TRestTools::fileExists(filename.Data())) {
fInputFileName = filename;
r->OpenInputFile(fInputFileName);
TFile* f = r->GetInputFile();
TTree* t = r->GetEventTree();
TGeoManager* geometry = gGeoManager;
if (t != NULL) {
// init viewer
pureAnalysis = kFALSE;
if (fEventViewer == NULL) SetViewer("TRestEventViewer");
if (geometry != NULL && fEventViewer != NULL) fEventViewer->SetGeometry(geometry);
RowValueChangedAction(0);
} else {
pureAnalysis = kTRUE;
}
void TRestBrowser::InitFromConfigFile() { cout << __PRETTY_FUNCTION__ << endl; }
TRestEvent* ev = r->GetInputEvent();
if (!ev) {
ferr << "internal error!" << endl;
} else {
fEventRowNumberBox->SetIntNumber(r->GetCurrentEntry());
fEventIdNumberBox->SetIntNumber(ev->GetID());
fEventSubIdNumberBox->SetIntNumber(ev->GetSubID());
}
}
}
void TRestBrowser::NextPlotOptionAction() {
string text = fPlotOptionTextBox->GetText();
if (text == "") {
text = "0";
} else if (isANumber(text)) {
text = ToString(StringToInteger(text) + 1);
}
fPlotOptionTextBox->SetText(text.c_str());
PlotAction();
}
void TRestBrowser::PreviousPlotOptionAction() {
string text = fPlotOptionTextBox->GetText();
if (text == "") {
text = "0";
} else if (isANumber(text)) {
text = ToString(StringToInteger(text) - 1);
}
fPlotOptionTextBox->SetText(text.c_str());
PlotAction();
}
void TRestBrowser::PlotAction() {
if (fEventViewer != NULL) {
fEventViewer->Plot(fPlotOptionTextBox->GetText());
}
}
void TRestBrowser::RowValueChangedAction(Long_t val) {
int entryN = (Int_t)fEventRowNumberBox->GetNumber();
debug << "TRestBrowser::LoadEventAction. Entry:" << entryN << endl;
LoadEventEntry(entryN);
}
void TRestBrowser::IdValueChangedAction(Long_t val) {
int eventN = (Int_t)fEventIdNumberBox->GetNumber();
int eventsubN = (Int_t)fEventSubIdNumberBox->GetNumber();
debug << "TRestBrowser::LoadEventAction. Event ID: " << eventN << ", Sub ID: " << eventsubN << endl;
LoadEventId(eventN, eventsubN);
}
void TRestBrowser::LoadFileAction() {
TGFileInfo fi;
new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDOpen, &fi);
TString dir = fi.fFilename;
cout << "Opening " << dir.Data() << endl;
OpenFile(dir);
}
void TRestBrowser::ExitAction() { gSystem->Exit(0); }
......@@ -39,80 +39,26 @@ void TRestEventViewer::Initialize() {
fCanvas = new TCanvas("Event Viewer", "Event Viewer");
fCanvas->SetWindowPosition(350, 10);
if (fController == NULL) {
return;
}
auto frame = fController->generateNewFrame();
fLabel = new TGLabel(frame, "Plot Options:");
frame->AddFrame(fLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
fOptwindow = new TGTextEntry(frame, "");
fOptwindow->SetText("");
frame->AddFrame(fOptwindow, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
auto frame1 = new TGHorizontalFrame(frame);
{
fButPrev = new TGTextButton(frame1, "<<Previous"); ///< Load Event button
fButPrev->Connect("Clicked()", "TRestEventViewer", this, "PreviousOption()");
frame1->AddFrame(fButPrev, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
fButOpt = new TGTextButton(frame1, "Plot"); ///< Load Event button
fButOpt->Connect("Clicked()", "TRestEventViewer", this, "OptionPlot()");
frame1->AddFrame(fButOpt, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
fButNext = new TGTextButton(frame1, "Next>>"); ///< Load Event button
fButNext->Connect("Clicked()", "TRestEventViewer", this, "NextOption()");
frame1->AddFrame(fButNext, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
}
frame->AddFrame(frame1, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
fController->addFrame(frame);
// fEvent = new TRestSignalEvent();
}
void TRestEventViewer::AddEvent(TRestEvent* ev) {
// fEvent=(TRestSignalEvent *)ev;
fEvent = ev;
// fOptwindow->SetText("");
OptionPlot();
}
void TRestEventViewer::NextOption() {
string text = fOptwindow->GetText();
if (text == "") {
text = "0";
} else if (isANumber(text)) {
text = ToString(StringToInteger(text) + 1);
}
fOptwindow->SetText(text.c_str());
OptionPlot();
}
void TRestEventViewer::PreviousOption() {
string text = fOptwindow->GetText();
if (text == "") {
text = "0";
} else if (isANumber(text)) {
text = ToString(StringToInteger(text) - 1);
}
fOptwindow->SetText(text.c_str());
OptionPlot();
}
void TRestEventViewer::OptionPlot() {
fPad = fEvent->DrawEvent(fOptwindow->GetText());
void TRestEventViewer::Plot(const char* option) {
if (fPad == NULL) fPad = new TPad();
fCanvas->cd();
fPad->Draw();
fPad->Update();
fCanvas->Update();
if (fEvent != NULL) {
fPad = fEvent->DrawEvent(option);
fCanvas->cd();
fPad->Draw();
fPad->Update();
fCanvas->Update();
} else {
fCanvas->cd();
fPad->Clear();
fPad->Update();
fCanvas->Update();
}
}
void TRestEventViewer::DeleteCurrentEvent() { delete fEvent; }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment