Skip to content

Commit b9e95b3

Browse files
authored
[COMMON] customize BigScreen colors (#2448)
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.
1 parent e707f66 commit b9e95b3

4 files changed

Lines changed: 47 additions & 44 deletions

File tree

Modules/Common/include/Common/BigScreenCanvas.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ struct BigScreenElement;
3131
class BigScreenCanvas : public TCanvas
3232
{
3333
public:
34-
BigScreenCanvas(std::string name, std::string title, int nRows, int nCols, int borderWidth);
34+
BigScreenCanvas(std::string name, std::string title, int nRows, int nCols, int borderWidth,
35+
int foregroundColor = kBlack, int backgroundColor = kWhite);
3536
~BigScreenCanvas() = default;
3637

3738
/// \brief add a box in the canvas at a given index, with "name" displayed above the box
@@ -60,6 +61,9 @@ class BigScreenCanvas : public TCanvas
6061
float mLabelOffset{ 0.05 };
6162
/// \brief colors associated to each quality state (Good/Medium/Bad/Null)
6263
std::unordered_map<std::string, int> mColors;
64+
int mForegroundColor{ kBlack }; /// ROOT color index for the foreground text
65+
int mBackgroundColor{ kWhite }; /// ROOT color index for the canvas backgound
66+
std::shared_ptr<TPad> mBackgoundPad; /// TPad used to draw the background color
6367
/// \brief elements (colored boxes + labels) displayed in the canvas
6468
std::unordered_map<std::string, std::shared_ptr<BigScreenElement>> mBoxes;
6569
};

Modules/Common/src/BigScreen.cxx

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
///
1717

1818
#include "Common/BigScreen.h"
19+
#include "Common/Utils.h"
1920
#include "QualityControl/QcInfoLogger.h"
2021
#include "QualityControl/DatabaseInterface.h"
2122
#include "QualityControl/ActivityHelpers.h"
@@ -54,46 +55,22 @@ std::string getParameter(o2::quality_control::core::CustomParameters customParam
5455

5556
void BigScreen::initialize(quality_control::postprocessing::Trigger t, framework::ServiceRegistryRef services)
5657
{
57-
int nRows = 1;
58-
int nCols = 1;
59-
int borderWidth = 5;
58+
int nRows = getFromExtendedConfig<int>(t.activity, mCustomParameters, "nRows", 1);
59+
int nCols = getFromExtendedConfig<int>(t.activity, mCustomParameters, "nCols", 1);
60+
int borderWidth = getFromExtendedConfig<int>(t.activity, mCustomParameters, "borderWidth", 5);
61+
int foregroundColor = getFromExtendedConfig<int>(t.activity, mCustomParameters, "foregroundColor", 1);
62+
int backgroundColor = getFromExtendedConfig<int>(t.activity, mCustomParameters, "backgroundColor", 0);
6063

61-
std::string parValue;
62-
parValue = getParameter(mCustomParameters, "nRows", t.activity);
63-
if (!parValue.empty()) {
64-
nRows = std::stoi(parValue);
65-
}
66-
67-
parValue = getParameter(mCustomParameters, "nCols", t.activity);
68-
if (!parValue.empty()) {
69-
nCols = std::stoi(parValue);
70-
}
71-
72-
parValue = getParameter(mCustomParameters, "borderWidth", t.activity);
73-
if (!parValue.empty()) {
74-
borderWidth = std::stoi(parValue);
75-
}
76-
77-
parValue = getParameter(mCustomParameters, "maxObjectTimeShift", t.activity);
78-
if (!parValue.empty()) {
79-
mMaxObjectTimeShift = std::stoi(parValue);
80-
}
81-
82-
parValue = getParameter(mCustomParameters, "ignoreActivity", t.activity);
83-
if (!parValue.empty()) {
84-
mIgnoreActivity = (std::stoi(parValue) != 0);
85-
}
86-
87-
// get the list of labels
88-
parValue = getParameter(mCustomParameters, "labels", t.activity);
89-
auto labels = o2::utils::Str::tokenize(parValue, ',', false, false);
64+
mMaxObjectTimeShift = getFromExtendedConfig<int>(t.activity, mCustomParameters, "maxObjectTimeShift", mMaxObjectTimeShift);
65+
mIgnoreActivity = getFromExtendedConfig<bool>(t.activity, mCustomParameters, "maxObjectTimeShift", mIgnoreActivity);
9066

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

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

9875
int index = 0;
9976
// add the paves associated to each quality source

Modules/Common/src/BigScreenCanvas.cxx

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ namespace o2::quality_control_modules::common
2626
{
2727

2828
struct BigScreenElement {
29-
BigScreenElement(std::string name, int index, float padding, float labelOffset, int borderWidth)
29+
BigScreenElement(std::string name, int index, float padding, float labelOffset, int borderWidth,
30+
int foregroundColor)
3031
: mLabel(padding, 1.0 - padding, name.c_str()),
3132
mPave(padding, padding, 1.0 - padding, 1.0 - padding - labelOffset, "NB NDC"),
3233
mBox(padding, padding, 1.0 - padding, 1.0 - padding - labelOffset),
@@ -36,6 +37,7 @@ struct BigScreenElement {
3637
mLabel.SetTextAlign(11);
3738
mLabel.SetTextSize(0.2);
3839
mLabel.SetTextFont(42);
40+
mLabel.SetTextColor(foregroundColor);
3941

4042
mPave.SetBorderSize(0);
4143
mPave.SetFillColor(kWhite);
@@ -45,9 +47,9 @@ struct BigScreenElement {
4547
mBox.SetFillStyle(0);
4648
}
4749

48-
void DrawInCanvas(TCanvas& c)
50+
void DrawInCanvas(TPad* c)
4951
{
50-
c.cd(mPadIndex);
52+
c->cd(mPadIndex);
5153
mPave.Draw();
5254
mBox.Draw();
5355
mLabel.Draw();
@@ -59,18 +61,27 @@ struct BigScreenElement {
5961
int mPadIndex;
6062
};
6163

62-
BigScreenCanvas::BigScreenCanvas(std::string name, std::string title, int nRows, int nCols, int borderWidth)
63-
: TCanvas(name.c_str(), title.c_str(), 800, 600), mNRows(nRows), mNCols(nCols), mBorderWidth(borderWidth)
64+
BigScreenCanvas::BigScreenCanvas(std::string name, std::string title, int nRows, int nCols, int borderWidth,
65+
int foregroundColor, int backgroundColor)
66+
: TCanvas(name.c_str(), title.c_str(), 800, 600), mNRows(nRows), mNCols(nCols), mBorderWidth(borderWidth), mForegroundColor(foregroundColor), mBackgroundColor(backgroundColor)
6467
{
6568
mColors[Quality::Null.getName()] = kViolet - 6;
6669
mColors[Quality::Bad.getName()] = kRed;
6770
mColors[Quality::Medium.getName()] = kOrange - 3;
6871
mColors[Quality::Good.getName()] = kGreen + 2;
72+
73+
// TPad filling the whole canvas and used to draw the background color
74+
mBackgoundPad = std::make_shared<TPad>((name + "_pad").c_str(), (title + "_pad").c_str(), 0, 0, 1, 1);
75+
mBackgoundPad->SetBorderSize(0);
76+
mBackgoundPad->SetBorderMode(0);
77+
mBackgoundPad->SetMargin(0, 0, 0, 0);
78+
mBackgoundPad->SetFillColor(mBackgroundColor);
79+
mBackgoundPad->Draw();
6980
}
7081

7182
void BigScreenCanvas::addBox(std::string boxName, int index)
7283
{
73-
mBoxes[boxName] = std::make_shared<BigScreenElement>(boxName, index, mPadding, mLabelOffset, mBorderWidth);
84+
mBoxes[boxName] = std::make_shared<BigScreenElement>(boxName, index, mPadding, mLabelOffset, mBorderWidth, mForegroundColor);
7485
}
7586

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

96107
void BigScreenCanvas::update()
97108
{
98-
Clear();
99-
Divide(mNCols, mNRows);
109+
mBackgoundPad->Clear();
110+
mBackgoundPad->Divide(mNCols, mNRows, 0, 0);
111+
112+
// set the sub-pads as fully transparent to show the color of the main backgound pad
113+
for (int padIndex = 1; padIndex <= (mNCols * mNRows); padIndex++) {
114+
mBackgoundPad->cd(padIndex);
115+
gPad->SetFillStyle(4000);
116+
}
100117

101118
for (auto& [key, box] : mBoxes) {
102-
box->DrawInCanvas(*this);
119+
box->DrawInCanvas(mBackgoundPad.get());
103120
}
104121
}
105122

doc/PostProcessing.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,8 @@ The system names are displayed above each box, while the quality flag is display
890890

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

893+
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.
894+
893895
The task is configured as follows:
894896
```json
895897
{
@@ -909,6 +911,9 @@ The task is configured as follows:
909911
"nRows": "4",
910912
"nCols": "5",
911913
"borderWidth": "1",
914+
"": "white text over dark gray background",
915+
"foregroundColor": "0",
916+
"backgroundColor": "923",
912917
"maxObjectTimeShift": "10000",
913918
"ignoreActivity": "0",
914919
"labels": "CPV,EMC,FDD,FT0,FV0,HMP,ITS,MCH,MFT,MID,PHS,TPC,TOF,TRD,,TRK,MTK,VTX,PID"

0 commit comments

Comments
 (0)