Skip to content

Commit 2588dee

Browse files
authored
Merge pull request #46592 from mmusich/mm_dev_improve_AlCaRecoTriggerBits_PayloadInspector_14_2_X
improve graphical rendering of `AlCaRecoTriggerBits_PayloadInspector` pots
2 parents e945f3c + f9dc1ad commit 2588dee

File tree

1 file changed

+109
-80
lines changed

1 file changed

+109
-80
lines changed

CondCore/HLTPlugins/plugins/AlCaRecoTriggerBits_PayloadInspector.cc

Lines changed: 109 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
#include "CondCore/CondDB/interface/Time.h"
44
#include "CondFormats/HLTObjects/interface/AlCaRecoTriggerBits.h"
55

6-
#include <fmt/printf.h>
7-
#include <memory>
8-
#include <sstream>
9-
#include <iostream>
106
#include "TCanvas.h"
117
#include "TLatex.h"
128
#include "TLine.h"
9+
#include <fmt/printf.h>
10+
#include <iostream>
11+
#include <memory>
12+
#include <cmath>
13+
#include <numeric>
14+
#include <sstream>
1315

1416
namespace {
1517

@@ -22,106 +24,133 @@ namespace {
2224
public:
2325
AlCaRecoTriggerBits_Display() : PlotImage<AlCaRecoTriggerBits, SINGLE_IOV>("Table of AlCaRecoTriggerBits") {}
2426

27+
using TriggerMap = std::map<std::string, std::string>;
28+
2529
bool fill() override {
2630
auto tag = PlotBase::getTag<0>();
2731
auto iov = tag.iovs.front();
28-
std::shared_ptr<AlCaRecoTriggerBits> payload = fetchPayload(std::get<1>(iov));
29-
3032
std::string IOVsince = std::to_string(std::get<0>(iov));
33+
auto tagname = tag.name;
34+
std::shared_ptr<AlCaRecoTriggerBits> payload = fetchPayload(std::get<1>(iov));
3135

32-
// Get map of strings to concatenated list of names of HLT paths:
33-
typedef std::map<std::string, std::string> TriggerMap;
34-
const TriggerMap &triggerMap = payload->m_alcarecoToTrig;
36+
if (payload.get()) {
37+
const TriggerMap &triggerMap = payload->m_alcarecoToTrig;
3538

36-
unsigned int mapsize = triggerMap.size();
37-
float pitch = 1. / (mapsize * 1.1);
39+
// pre-compute how many time we break the line
40+
const int totalCarriageReturns = calculateTotalCarriageReturns(payload);
41+
LogDebug("AlCaRecoTriggerBits_Display") << "Total number of carriage returns: " << totalCarriageReturns;
3842

39-
float y, x1, x2;
40-
std::vector<float> y_x1, y_x2, y_line;
41-
std::vector<std::string> s_x1, s_x2, s_x3;
43+
// Dynamically calculate the pitch and canvas height
44+
float pitch = 1.0 / (totalCarriageReturns + 2.0); // Adjusted pitch for better spacing
4245

43-
// starting table at y=1.0 (top of the canvas)
44-
// first column is at 0.02, second column at 0.32 NDC
45-
y = 1.0;
46-
x1 = 0.02;
47-
x2 = x1 + 0.30;
46+
float y = 1.0;
47+
float x1 = 0.02, x2 = x1 + 0.25;
48+
std::vector<float> y_x1, y_x2, y_line;
49+
std::vector<std::string> s_x1, s_x2;
4850

49-
y -= pitch;
50-
y_x1.push_back(y);
51-
s_x1.push_back("#scale[1.2]{Key}");
52-
y_x2.push_back(y);
53-
s_x2.push_back("#scale[1.2]{tag: " + tag.name + " in IOV: " + IOVsince + "}");
54-
55-
y -= pitch / 2.;
56-
y_line.push_back(y);
57-
58-
for (const auto &element : triggerMap) {
51+
// Header row setup
5952
y -= pitch;
6053
y_x1.push_back(y);
61-
s_x1.push_back(element.first);
54+
s_x1.push_back("#scale[1.2]{Key}");
55+
y_x2.push_back(y);
56+
s_x2.push_back("#scale[1.2]{tag: " + tagname + " in IOV: " + IOVsince + "}");
57+
58+
y -= pitch / 2.0;
59+
y_line.push_back(y);
60+
61+
// Populate rows with data from the trigger map
62+
for (const auto &element : triggerMap) {
63+
y -= pitch;
64+
y_x1.push_back(y);
65+
s_x1.push_back(element.first);
66+
std::vector<std::string> output;
67+
68+
std::string toAppend = "";
69+
const std::vector<std::string> paths = payload->decompose(element.second);
70+
for (unsigned int iPath = 0; iPath < paths.size(); ++iPath) {
71+
if ((toAppend + paths[iPath]).length() < 80) { // Wider lines
72+
toAppend += paths[iPath] + ";";
73+
} else {
74+
output.push_back(toAppend);
75+
toAppend.clear();
76+
toAppend += paths[iPath] + ";";
77+
}
78+
if (iPath == paths.size() - 1)
79+
output.push_back(toAppend);
80+
}
6281

63-
std::vector<std::string> output;
64-
std::string toAppend = "";
65-
const std::vector<std::string> paths = payload->decompose(element.second);
66-
for (unsigned int iPath = 0; iPath < paths.size(); ++iPath) {
67-
// if the line to be added has less than 60 chars append to current
68-
if ((toAppend + paths[iPath]).length() < 60) {
69-
toAppend += paths[iPath] + ";";
70-
} else {
71-
// else if the line exceeds 60 chars, dump in the vector and resume from scratch
72-
output.push_back(toAppend);
73-
toAppend.clear();
74-
toAppend += paths[iPath] + ";";
82+
for (unsigned int br = 0; br < output.size(); br++) {
83+
y_x2.push_back(y);
84+
s_x2.push_back("#color[2]{" + output[br] + "}");
85+
if (br != output.size() - 1)
86+
y -= pitch;
7587
}
76-
// if it's the last, dump it
77-
if (iPath == paths.size() - 1)
78-
output.push_back(toAppend);
88+
89+
y_line.push_back(y - (pitch / 2.0));
7990
}
8091

81-
for (unsigned int br = 0; br < output.size(); br++) {
82-
y_x2.push_back(y);
83-
s_x2.push_back("#color[2]{" + output[br] + "}");
84-
if (br != output.size() - 1)
85-
y -= pitch;
92+
// Dynamically calculate the pitch and canvas height
93+
float canvasHeight = std::max(800.0f, totalCarriageReturns * 30.0f); // Adjust canvas height based on entries
94+
TCanvas canvas("AlCaRecoTriggerBits", "AlCaRecoTriggerBits", 2000, static_cast<int>(canvasHeight));
95+
96+
TLatex l;
97+
l.SetTextAlign(12);
98+
float textSize = std::clamp(pitch, 0.015f, 0.035f);
99+
l.SetTextSize(textSize);
100+
101+
// Draw the columns
102+
int totalPitches = 0;
103+
canvas.cd();
104+
for (unsigned int i = 0; i < y_x1.size(); i++) {
105+
l.DrawLatexNDC(x1, y_x1[i], s_x1[i].c_str());
106+
if (i != 0) {
107+
LogDebug("AlCaRecoTriggerBits_Display")
108+
<< "x1:" << x1 << " y_x1[" << std::setw(2) << i << "]: " << y_x1[i]
109+
<< " Delta = " << std::ceil((y_x1[i - 1] - y_x1[i]) / pitch) << " pitches " << s_x1[i].c_str();
110+
totalPitches += std::ceil((y_x1[i - 1] - y_x1[i]) / pitch);
111+
}
86112
}
87113

88-
y_line.push_back(y - (pitch / 2.));
89-
}
114+
LogDebug("AlCaRecoTriggerBits_Display") << "We've gone down by " << totalPitches << "pitches ";
90115

91-
TCanvas canvas("AlCaRecoTriggerBits", "AlCaRecoTriggerBits", 2000, std::max(y_x1.size(), y_x2.size()) * 40);
92-
TLatex l;
93-
// Draw the columns titles
94-
l.SetTextAlign(12);
116+
for (unsigned int i = 0; i < y_x2.size(); i++) {
117+
l.DrawLatexNDC(x2, y_x2[i], s_x2[i].c_str());
118+
}
95119

96-
float newpitch = 1 / (std::max(y_x1.size(), y_x2.size()) * 1.1);
97-
float factor = newpitch / pitch;
98-
l.SetTextSize(newpitch - 0.002);
99-
canvas.cd();
100-
for (unsigned int i = 0; i < y_x1.size(); i++) {
101-
l.DrawLatexNDC(x1, 1 - (1 - y_x1[i]) * factor, s_x1[i].c_str());
102-
}
120+
// Draw lines for row separation
121+
TLine lines[y_line.size()];
122+
for (unsigned int i = 0; i < y_line.size(); i++) {
123+
lines[i] = TLine(gPad->GetUxmin(), y_line[i], gPad->GetUxmax(), y_line[i]);
124+
lines[i].SetLineWidth(1);
125+
lines[i].SetLineStyle(9);
126+
lines[i].SetLineColor(2);
127+
lines[i].Draw("same");
128+
}
103129

104-
for (unsigned int i = 0; i < y_x2.size(); i++) {
105-
l.DrawLatexNDC(x2, 1 - (1 - y_x2[i]) * factor, s_x2[i].c_str());
130+
canvas.SaveAs(m_imageFileName.c_str());
106131
}
132+
return true;
133+
}
107134

108-
canvas.cd();
109-
canvas.Update();
135+
private:
136+
int calculateTotalCarriageReturns(std::shared_ptr<AlCaRecoTriggerBits> payload) {
137+
int totalCarriageReturns = 0;
138+
const TriggerMap &triggerMap = payload->m_alcarecoToTrig;
110139

111-
TLine lines[y_line.size()];
112-
unsigned int iL = 0;
113-
for (const auto &line : y_line) {
114-
lines[iL] = TLine(gPad->GetUxmin(), 1 - (1 - line) * factor, gPad->GetUxmax(), 1 - (1 - line) * factor);
115-
lines[iL].SetLineWidth(1);
116-
lines[iL].SetLineStyle(9);
117-
lines[iL].SetLineColor(2);
118-
lines[iL].Draw("same");
119-
iL++;
140+
for (const auto &element : triggerMap) {
141+
const auto &paths = payload->decompose(element.second);
142+
int lineLength = 0;
143+
144+
for (const auto &path : paths) {
145+
lineLength += path.length() + 1; // +1 for the semicolon
146+
if (lineLength >= 80) {
147+
totalCarriageReturns++;
148+
lineLength = path.length() + 1; // Reset for the next line segment
149+
}
150+
}
151+
totalCarriageReturns++; // Count the initial line for each element
120152
}
121-
122-
std::string fileName(m_imageFileName);
123-
canvas.SaveAs(fileName.c_str());
124-
return true;
153+
return totalCarriageReturns;
125154
}
126155
};
127156

0 commit comments

Comments
 (0)