Skip to content

Commit

Permalink
[COMMON] customize BigScreen colors (#2448)
Browse files Browse the repository at this point in the history
Add customization of the foreground and backgound colors
for the BigScreen. The colors can be modified via two new
custom parameters (`foregroundColor` and `backgroundColor`),
both accepting only ROOT color indexes as values.

The code has also been updated to use the `getFromExtendedConfig()`
function to extract the custom parameter values.
  • Loading branch information
aferrero2707 authored Oct 10, 2024
1 parent e707f66 commit b9e95b3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 44 deletions.
6 changes: 5 additions & 1 deletion Modules/Common/include/Common/BigScreenCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ struct BigScreenElement;
class BigScreenCanvas : public TCanvas
{
public:
BigScreenCanvas(std::string name, std::string title, int nRows, int nCols, int borderWidth);
BigScreenCanvas(std::string name, std::string title, int nRows, int nCols, int borderWidth,
int foregroundColor = kBlack, int backgroundColor = kWhite);
~BigScreenCanvas() = default;

/// \brief add a box in the canvas at a given index, with "name" displayed above the box
Expand Down Expand Up @@ -60,6 +61,9 @@ class BigScreenCanvas : public TCanvas
float mLabelOffset{ 0.05 };
/// \brief colors associated to each quality state (Good/Medium/Bad/Null)
std::unordered_map<std::string, int> mColors;
int mForegroundColor{ kBlack }; /// ROOT color index for the foreground text
int mBackgroundColor{ kWhite }; /// ROOT color index for the canvas backgound
std::shared_ptr<TPad> mBackgoundPad; /// TPad used to draw the background color
/// \brief elements (colored boxes + labels) displayed in the canvas
std::unordered_map<std::string, std::shared_ptr<BigScreenElement>> mBoxes;
};
Expand Down
45 changes: 11 additions & 34 deletions Modules/Common/src/BigScreen.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
///

#include "Common/BigScreen.h"
#include "Common/Utils.h"
#include "QualityControl/QcInfoLogger.h"
#include "QualityControl/DatabaseInterface.h"
#include "QualityControl/ActivityHelpers.h"
Expand Down Expand Up @@ -54,46 +55,22 @@ std::string getParameter(o2::quality_control::core::CustomParameters customParam

void BigScreen::initialize(quality_control::postprocessing::Trigger t, framework::ServiceRegistryRef services)
{
int nRows = 1;
int nCols = 1;
int borderWidth = 5;
int nRows = getFromExtendedConfig<int>(t.activity, mCustomParameters, "nRows", 1);
int nCols = getFromExtendedConfig<int>(t.activity, mCustomParameters, "nCols", 1);
int borderWidth = getFromExtendedConfig<int>(t.activity, mCustomParameters, "borderWidth", 5);
int foregroundColor = getFromExtendedConfig<int>(t.activity, mCustomParameters, "foregroundColor", 1);
int backgroundColor = getFromExtendedConfig<int>(t.activity, mCustomParameters, "backgroundColor", 0);

std::string parValue;
parValue = getParameter(mCustomParameters, "nRows", t.activity);
if (!parValue.empty()) {
nRows = std::stoi(parValue);
}

parValue = getParameter(mCustomParameters, "nCols", t.activity);
if (!parValue.empty()) {
nCols = std::stoi(parValue);
}

parValue = getParameter(mCustomParameters, "borderWidth", t.activity);
if (!parValue.empty()) {
borderWidth = std::stoi(parValue);
}

parValue = getParameter(mCustomParameters, "maxObjectTimeShift", t.activity);
if (!parValue.empty()) {
mMaxObjectTimeShift = std::stoi(parValue);
}

parValue = getParameter(mCustomParameters, "ignoreActivity", t.activity);
if (!parValue.empty()) {
mIgnoreActivity = (std::stoi(parValue) != 0);
}

// get the list of labels
parValue = getParameter(mCustomParameters, "labels", t.activity);
auto labels = o2::utils::Str::tokenize(parValue, ',', false, false);
mMaxObjectTimeShift = getFromExtendedConfig<int>(t.activity, mCustomParameters, "maxObjectTimeShift", mMaxObjectTimeShift);
mIgnoreActivity = getFromExtendedConfig<bool>(t.activity, mCustomParameters, "maxObjectTimeShift", mIgnoreActivity);

auto labels = o2::utils::Str::tokenize(getFromExtendedConfig<std::string>(t.activity, mCustomParameters, "labels"), ',', false, false);
if (labels.size() > (nRows * nCols)) {
ILOG(Warning, Support) << "Number of labels larger than nRos*nCols, some labels will not be displayed correctly" << ENDM;
ILOG(Warning, Support) << "Number of labels larger than nRows*nCols, some labels will not be displayed correctly" << ENDM;
}

mCanvas.reset();
mCanvas = std::make_unique<BigScreenCanvas>("BigScreen", "QC Big Screen", nRows, nCols, borderWidth);
mCanvas = std::make_unique<BigScreenCanvas>("BigScreen", "QC Big Screen", nRows, nCols, borderWidth, foregroundColor, backgroundColor);

int index = 0;
// add the paves associated to each quality source
Expand Down
35 changes: 26 additions & 9 deletions Modules/Common/src/BigScreenCanvas.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ namespace o2::quality_control_modules::common
{

struct BigScreenElement {
BigScreenElement(std::string name, int index, float padding, float labelOffset, int borderWidth)
BigScreenElement(std::string name, int index, float padding, float labelOffset, int borderWidth,
int foregroundColor)
: mLabel(padding, 1.0 - padding, name.c_str()),
mPave(padding, padding, 1.0 - padding, 1.0 - padding - labelOffset, "NB NDC"),
mBox(padding, padding, 1.0 - padding, 1.0 - padding - labelOffset),
Expand All @@ -36,6 +37,7 @@ struct BigScreenElement {
mLabel.SetTextAlign(11);
mLabel.SetTextSize(0.2);
mLabel.SetTextFont(42);
mLabel.SetTextColor(foregroundColor);

mPave.SetBorderSize(0);
mPave.SetFillColor(kWhite);
Expand All @@ -45,9 +47,9 @@ struct BigScreenElement {
mBox.SetFillStyle(0);
}

void DrawInCanvas(TCanvas& c)
void DrawInCanvas(TPad* c)
{
c.cd(mPadIndex);
c->cd(mPadIndex);
mPave.Draw();
mBox.Draw();
mLabel.Draw();
Expand All @@ -59,18 +61,27 @@ struct BigScreenElement {
int mPadIndex;
};

BigScreenCanvas::BigScreenCanvas(std::string name, std::string title, int nRows, int nCols, int borderWidth)
: TCanvas(name.c_str(), title.c_str(), 800, 600), mNRows(nRows), mNCols(nCols), mBorderWidth(borderWidth)
BigScreenCanvas::BigScreenCanvas(std::string name, std::string title, int nRows, int nCols, int borderWidth,
int foregroundColor, int backgroundColor)
: TCanvas(name.c_str(), title.c_str(), 800, 600), mNRows(nRows), mNCols(nCols), mBorderWidth(borderWidth), mForegroundColor(foregroundColor), mBackgroundColor(backgroundColor)
{
mColors[Quality::Null.getName()] = kViolet - 6;
mColors[Quality::Bad.getName()] = kRed;
mColors[Quality::Medium.getName()] = kOrange - 3;
mColors[Quality::Good.getName()] = kGreen + 2;

// TPad filling the whole canvas and used to draw the background color
mBackgoundPad = std::make_shared<TPad>((name + "_pad").c_str(), (title + "_pad").c_str(), 0, 0, 1, 1);
mBackgoundPad->SetBorderSize(0);
mBackgoundPad->SetBorderMode(0);
mBackgoundPad->SetMargin(0, 0, 0, 0);
mBackgoundPad->SetFillColor(mBackgroundColor);
mBackgoundPad->Draw();
}

void BigScreenCanvas::addBox(std::string boxName, int index)
{
mBoxes[boxName] = std::make_shared<BigScreenElement>(boxName, index, mPadding, mLabelOffset, mBorderWidth);
mBoxes[boxName] = std::make_shared<BigScreenElement>(boxName, index, mPadding, mLabelOffset, mBorderWidth, mForegroundColor);
}

void BigScreenCanvas::setText(std::string boxName, int color, std::string text)
Expand All @@ -95,11 +106,17 @@ void BigScreenCanvas::setQuality(std::string boxName, Quality quality)

void BigScreenCanvas::update()
{
Clear();
Divide(mNCols, mNRows);
mBackgoundPad->Clear();
mBackgoundPad->Divide(mNCols, mNRows, 0, 0);

// set the sub-pads as fully transparent to show the color of the main backgound pad
for (int padIndex = 1; padIndex <= (mNCols * mNRows); padIndex++) {
mBackgoundPad->cd(padIndex);
gPad->SetFillStyle(4000);
}

for (auto& [key, box] : mBoxes) {
box->DrawInCanvas(*this);
box->DrawInCanvas(mBackgoundPad.get());
}
}

Expand Down
5 changes: 5 additions & 0 deletions doc/PostProcessing.md
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,8 @@ The system names are displayed above each box, while the quality flag is display

In addition, the boxes are filled with a grey color is the corresponding QualityObjects cannot be retrieved or are too old.

The color of the canvas background and of the detector labels can be customized with the `"foregroundColor"` and `"backgroundColor"` parameters. They accept interger values corresponding to the indexes of the [default ROOT colors](https://root.cern.ch/doc/master/classTColor.html#C01) or the indexes defined in the [color wheel](https://root.cern.ch/doc/master/classTColor.html#C02). The example below shows a color combination with white text over a dark gray background.

The task is configured as follows:
```json
{
Expand All @@ -909,6 +911,9 @@ The task is configured as follows:
"nRows": "4",
"nCols": "5",
"borderWidth": "1",
"": "white text over dark gray background",
"foregroundColor": "0",
"backgroundColor": "923",
"maxObjectTimeShift": "10000",
"ignoreActivity": "0",
"labels": "CPV,EMC,FDD,FT0,FV0,HMP,ITS,MCH,MFT,MID,PHS,TPC,TOF,TRD,,TRK,MTK,VTX,PID"
Expand Down

0 comments on commit b9e95b3

Please sign in to comment.