Commit 7eb5be2e authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Merge branch 'onlinemon' into 'master'

OnlineMonitor: Pausing, Multiple DUTs, Button Grouping

Closes #41

See merge request !79
parents 88be2cdb b81423bc
Pipeline #639063 failed with stages
in 4 minutes and 22 seconds
#include "OnlineMonitor.h"
#include <TGButtonGroup.h>
#include <TVirtualPadEditor.h>
#include <regex>
......@@ -58,34 +59,56 @@ void OnlineMonitor::initialise() {
gui = new GuiDisplay();
// Make the main window object and set the attributes
gui->m_mainFrame = new TGMainFrame(gClient->GetRoot(), 800, 600);
gui->buttonMenu = new TGHorizontalFrame(gui->m_mainFrame, 800, 50);
gui->canvas = new TRootEmbeddedCanvas("canvas", gui->m_mainFrame, 800, 600);
gui->m_mainFrame = new TGMainFrame(gClient->GetRoot(), 1200, 600);
gui->buttonMenu = new TGHorizontalFrame(gui->m_mainFrame, 1200, 50);
gui->canvas = new TRootEmbeddedCanvas("canvas", gui->m_mainFrame, 1200, 600);
gui->m_mainFrame->AddFrame(gui->canvas, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10, 10, 10, 10));
gui->m_mainFrame->SetCleanup(kDeepCleanup);
gui->m_mainFrame->DontCallClose();
// Add canvases and histograms
AddCanvas("Overview", canvas_overview);
AddCanvas("Tracking", canvas_tracking);
AddCanvas("HitMaps", canvas_hitmaps);
AddCanvas("Residuals", canvas_residuals);
AddCanvas("EventTimes", canvas_time);
AddCanvas("ChargeDistributions", canvas_charge);
AddCanvasGroup("Tracking");
AddCanvas("Overview", "Tracking", canvas_overview);
AddCanvas("Tracking Performance", "Tracking", canvas_tracking);
AddCanvas("Residuals", "Tracking", canvas_residuals);
AddCanvasGroup("Detectors");
AddCanvas("Hitmaps", "Detectors", canvas_hitmaps);
AddCanvas("Event Times", "Detectors", canvas_time);
AddCanvas("Charge Distributions", "Detectors", canvas_charge);
AddCanvasGroup("Correlations 1D");
AddCanvas("1D X", "Correlations 1D", canvas_cx);
AddCanvas("1D Y", "Correlations 1D", canvas_cy);
AddCanvasGroup("Correlations 2D");
AddCanvas("2D X", "Correlations 2D", canvas_cx2d);
AddCanvas("2D Y", "Correlations 2D", canvas_cy2d);
AddCanvasGroup("DUTs");
for(auto& detector : get_detectors()) {
if(detector->isDUT()) {
AddCanvas(detector->name(), "DUTs", canvas_dutplots, detector->name());
}
}
AddCanvas("CorrelationsX", canvas_cx);
AddCanvas("CorrelationsY", canvas_cy);
AddCanvas("CorrelationsX2D", canvas_cx2d);
AddCanvas("CorrelationsY2D", canvas_cy2d);
// Set up the main frame before drawing
AddCanvasGroup("Controls");
ULong_t color;
AddCanvas("DUTPlots", canvas_dutplots);
// Pause button
gClient->GetColorByName("green", color);
gui->buttons["pause"] = new TGTextButton(gui->buttonGroups["Controls"], " &Pause Monitoring ");
gui->buttons["pause"]->ChangeBackground(color);
gui->buttons["pause"]->Connect("Pressed()", "corryvreckan::GuiDisplay", gui, "TogglePause()");
gui->buttonGroups["Controls"]->AddFrame(gui->buttons["pause"], new TGLayoutHints(kLHintsTop | kLHintsExpandX));
// Set up the main frame before drawing
// Exit button
string exitButton = "StopMonitoring";
gui->buttons[exitButton] = new TGTextButton(gui->buttonMenu, exitButton.c_str());
gui->buttonMenu->AddFrame(gui->buttons[exitButton], new TGLayoutHints(kLHintsLeft, 10, 10, 10, 10));
gui->buttons[exitButton]->Connect("Pressed()", "corryvreckan::GuiDisplay", gui, "Exit()");
gClient->GetColorByName("yellow", color);
gui->buttons["exit"] = new TGTextButton(gui->buttonGroups["Controls"], "&Exit Monitor");
gui->buttons["exit"]->ChangeBackground(color);
gui->buttons["exit"]->Connect("Pressed()", "corryvreckan::GuiDisplay", gui, "Exit()");
gui->buttonGroups["Controls"]->AddFrame(gui->buttons["exit"], new TGLayoutHints(kLHintsTop | kLHintsExpandX));
// Main frame resizing
gui->m_mainFrame->AddFrame(gui->buttonMenu, new TGLayoutHints(kLHintsLeft, 10, 10, 10, 10));
......@@ -111,10 +134,11 @@ void OnlineMonitor::initialise() {
StatusCode OnlineMonitor::run(std::shared_ptr<Clipboard>) {
// Draw all histograms
if(eventNumber % updateNumber == 0) {
gui->Update();
eventNumber++;
if(!gui->isPaused()) {
// Draw all histograms
if(eventNumber % updateNumber == 0) {
gui->Update();
}
}
gSystem->ProcessEvents();
......@@ -123,19 +147,35 @@ StatusCode OnlineMonitor::run(std::shared_ptr<Clipboard>) {
return StatusCode::Success;
}
void OnlineMonitor::AddCanvas(std::string canvas_title, Matrix<std::string> canvas_plots) {
void OnlineMonitor::AddCanvasGroup(std::string group_title) {
gui->buttonGroups[group_title] = new TGVButtonGroup(gui->buttonMenu, group_title.c_str());
gui->buttonMenu->AddFrame(gui->buttonGroups[group_title], new TGLayoutHints(kLHintsLeft | kLHintsTop, 10, 10, 10, 10));
gui->buttonGroups[group_title]->Show();
}
void OnlineMonitor::AddCanvas(std::string canvas_title,
std::string canvasGroup,
Matrix<std::string> canvas_plots,
std::string detector_name) {
std::string canvas_name = canvas_title + "Canvas";
gui->buttons[canvas_title] = new TGTextButton(gui->buttonMenu, canvas_title.c_str());
gui->buttonMenu->AddFrame(gui->buttons[canvas_title], new TGLayoutHints(kLHintsLeft, 10, 10, 10, 10));
if(canvasGroup.empty()) {
gui->buttons[canvas_title] = new TGTextButton(gui->buttonMenu, canvas_title.c_str());
gui->buttonMenu->AddFrame(gui->buttons[canvas_title], new TGLayoutHints(kLHintsLeft, 10, 10, 10, 10));
} else {
gui->buttons[canvas_title] = new TGTextButton(gui->buttonGroups[canvasGroup], canvas_title.c_str());
gui->buttonGroups[canvasGroup]->AddFrame(gui->buttons[canvas_title],
new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 0, 0));
}
string command = "Display(=\"" + canvas_name + "\")";
LOG(INFO) << "Connecting button with command " << command.c_str();
gui->buttons[canvas_title]->Connect("Pressed()", "corryvreckan::GuiDisplay", gui, command.c_str());
AddPlots(canvas_name, canvas_plots);
AddPlots(canvas_name, canvas_plots, detector_name);
}
void OnlineMonitor::AddPlots(std::string canvas_name, Matrix<std::string> canvas_plots) {
void OnlineMonitor::AddPlots(std::string canvas_name, Matrix<std::string> canvas_plots, std::string detector_name) {
for(auto plot : canvas_plots) {
// Add default plotting style if not set:
......@@ -150,22 +190,41 @@ void OnlineMonitor::AddPlots(std::string canvas_name, Matrix<std::string> canvas
// Parse other placeholders:
if(name.find("%DUT%") != std::string::npos) {
// Do we have a DUT placeholder?
LOG(DEBUG) << "Adding plot " << name << " for all DUTs.";
for(auto& detector : get_detectors()) {
if(!detector->isDUT()) {
continue;
}
if(!detector_name.empty()) {
LOG(DEBUG) << "Adding plot " << name << " for detector " << detector_name;
auto detector = get_detector(detector_name);
AddHisto(
canvas_name, std::regex_replace(name, std::regex("%DUT%"), detector->name()), plot.back(), log_scale);
} else {
LOG(DEBUG) << "Adding plot " << name << " for all DUTs.";
for(auto& detector : get_detectors()) {
if(!detector->isDUT()) {
continue;
}
AddHisto(canvas_name,
std::regex_replace(name, std::regex("%DUT%"), detector->name()),
plot.back(),
log_scale);
}
}
} else if(name.find("%DETECTOR%") != std::string::npos) {
// Do we have a detector placeholder?
LOG(DEBUG) << "Adding plot " << name << " for all detectors.";
for(auto& detector : get_detectors()) {
if(!detector_name.empty()) {
LOG(DEBUG) << "Adding plot " << name << " for detector " << detector_name;
auto detector = get_detector(detector_name);
AddHisto(canvas_name,
std::regex_replace(name, std::regex("%DETECTOR%"), detector->name()),
plot.back(),
log_scale);
} else {
LOG(DEBUG) << "Adding plot " << name << " for all detectors.";
for(auto& detector : get_detectors()) {
AddHisto(canvas_name,
std::regex_replace(name, std::regex("%DETECTOR%"), detector->name()),
plot.back(),
log_scale);
}
}
} else {
// Single histogram only.
......
......@@ -40,8 +40,12 @@ namespace corryvreckan {
GuiDisplay* gui;
private:
void AddCanvas(std::string canvas_title, Matrix<std::string> canvas_plots);
void AddPlots(std::string canvas_name, Matrix<std::string> canvas_plots);
void AddCanvasGroup(std::string group_title);
void AddCanvas(std::string canvas_title,
std::string canvasGroup,
Matrix<std::string> canvas_plots,
std::string detector_name = "");
void AddPlots(std::string canvas_name, Matrix<std::string> canvas_plots, std::string detector_name = "");
void AddHisto(std::string, std::string, std::string style = "", bool logy = false);
// Member variables
......
......@@ -35,9 +35,11 @@ namespace corryvreckan {
public:
// Constructors and destructors
GuiDisplay(){};
GuiDisplay() : running_(true){};
~GuiDisplay() {}
bool isPaused() { return !running_; }
// Graphics associated with GUI
TGMainFrame* m_mainFrame;
TRootEmbeddedCanvas* canvas;
......@@ -45,9 +47,12 @@ namespace corryvreckan {
std::map<TH1*, std::string> styles;
std::map<TH1*, bool> logarithmic;
std::map<std::string, TGTextButton*> buttons;
std::map<std::string, TGButtonGroup*> buttonGroups;
std::map<TRootEmbeddedCanvas*, bool> stackedCanvas;
TGHorizontalFrame* buttonMenu;
bool running_;
// Button functions
inline void Display(char* canvasNameC) {
std::string canvasName(canvasNameC);
......@@ -85,13 +90,32 @@ namespace corryvreckan {
// Exit the monitoring
inline void Exit() { raise(SIGINT); }
// Pause monitoring
void TogglePause() {
running_ = !running_;
auto button = buttons["pause"];
button->SetState(kButtonDown);
ULong_t color;
if(!running_) {
button->SetText("&Resume Monitoring");
gClient->GetColorByName("gray", color);
} else {
button->SetText("&Pause Monitoring ");
gClient->GetColorByName("green", color);
}
button->ChangeBackground(color);
button->SetState(kButtonUp);
}
inline void Update() {
canvas->GetCanvas()->Paint();
canvas->GetCanvas()->Update();
}
// ROOT I/O class definition - update version number when you change this class!
ClassDef(GuiDisplay, 2)
ClassDef(GuiDisplay, 3)
};
} // namespace corryvreckan
......
Markdown is supported
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