CMS 3D CMS Logo

L1TUtmTriggerMenu_PayloadInspector.cc
Go to the documentation of this file.
1 
10 
14 
15 // the data format of the condition to be inspected
18 
19 #include <memory>
20 #include <sstream>
21 #include <iostream>
22 
23 // include ROOT
24 #include "TH2F.h"
25 #include "TLegend.h"
26 #include "TCanvas.h"
27 #include "TLine.h"
28 #include "TGraph.h"
29 #include "TStyle.h"
30 #include "TLatex.h"
31 #include "TPave.h"
32 #include "TPaveStats.h"
33 
34 namespace {
35 
36  using namespace cond::payloadInspector;
37 
38  class L1TUtmTriggerMenuDisplayAlgos : public PlotImage<L1TUtmTriggerMenu, SINGLE_IOV> {
39  public:
40  L1TUtmTriggerMenuDisplayAlgos() : PlotImage<L1TUtmTriggerMenu, SINGLE_IOV>("L1TUtmTriggerMenu plot") {}
41 
42  bool fill() override {
43  auto tag = PlotBase::getTag<0>();
44  auto iov = tag.iovs.front();
45  std::string IOVsince = std::to_string(std::get<0>(iov));
46  auto tagname = tag.name;
47  std::shared_ptr<L1TUtmTriggerMenu> payload = fetchPayload(std::get<1>(iov));
48  if (payload.get()) {
50  const auto& theMap = payload->getAlgorithmMap();
51 
52  unsigned int mapsize = theMap.size();
53  float pitch = 1. / (mapsize);
54 
55  float y, x1, x2;
56  std::vector<float> y_x1, y_x2, y_line;
57  std::vector<std::string> s_x1, s_x2, s_x3;
58 
59  // starting table at y=1.0 (top of the canvas)
60  // first column is at 0.02, second column at 0.32 NDC
61  y = 1.0;
62  x1 = 0.02;
63  x2 = x1 + 0.15;
64 
65  y -= pitch;
66  y_x1.push_back(y);
67  s_x1.push_back("#scale[1.2]{Algo Name}");
68  y_x2.push_back(y);
69  s_x2.push_back("#scale[1.2]{tag: " + tag.name + " in IOV: " + IOVsince + "}");
70 
71  y -= pitch / 2.;
72  y_line.push_back(y);
73 
74  for (const auto& [name, algo] : theMap) {
75  y -= pitch;
76  y_x1.push_back(y);
77  s_x1.push_back("''");
78 
79  y_x2.push_back(y);
80  s_x2.push_back("#color[2]{" + name + "}");
81  y_line.push_back(y - (pitch / 2.));
82  }
83 
84  TCanvas canvas("L1TriggerAlgos", "L1TriggerAlgos", 2000, mapsize * 40);
85  TLatex l;
86  // Draw the columns titles
87  l.SetTextAlign(12);
88  l.SetTextSize(pitch * 10);
89  canvas.cd();
90  for (unsigned int i = 0; i < y_x1.size(); i++) {
91  l.DrawLatexNDC(x1, 1 - (1 - y_x1[i]), s_x1[i].c_str());
92  }
93 
94  for (unsigned int i = 0; i < y_x2.size(); i++) {
95  l.DrawLatexNDC(x2, 1 - (1 - y_x2[i]), s_x2[i].c_str());
96  }
97 
98  canvas.cd();
99  canvas.Update();
100 
101  TLine lines[y_line.size()];
102  unsigned int iL = 0;
103  for (const auto& line : y_line) {
104  lines[iL] = TLine(gPad->GetUxmin(), 1 - (1 - line), gPad->GetUxmax(), 1 - (1 - line));
105  lines[iL].SetLineWidth(1);
106  lines[iL].SetLineStyle(9);
107  lines[iL].SetLineColor(2);
108  lines[iL].Draw("same");
109  iL++;
110  }
111 
112  std::string fileName(m_imageFileName);
113  canvas.SaveAs(fileName.c_str());
114  } // payload
115  return true;
116  } // fill
117  };
118 
119  template <IOVMultiplicity nIOVs, int ntags>
120  class L1TUtmTriggerMenu_CompareAlgosBase : public PlotImage<L1TUtmTriggerMenu, nIOVs, ntags> {
121  public:
122  L1TUtmTriggerMenu_CompareAlgosBase()
123  : PlotImage<L1TUtmTriggerMenu, nIOVs, ntags>("L1TUtmTriggerMenu comparison of contents") {}
124 
125  bool fill() override {
126  // trick to deal with the multi-ioved tag and two tag case at the same time
127  auto theIOVs = PlotBase::getTag<0>().iovs;
128  auto f_tagname = PlotBase::getTag<0>().name;
129  std::string l_tagname = "";
130  auto firstiov = theIOVs.front();
131  std::tuple<cond::Time_t, cond::Hash> lastiov;
132 
133  // we don't support (yet) comparison with more than 2 tags
134  assert(this->m_plotAnnotations.ntags < 3);
135 
136  if (this->m_plotAnnotations.ntags == 2) {
137  auto tag2iovs = PlotBase::getTag<1>().iovs;
138  l_tagname = PlotBase::getTag<1>().name;
139  lastiov = tag2iovs.front();
140  } else {
141  lastiov = theIOVs.back();
142  }
143 
144  std::shared_ptr<L1TUtmTriggerMenu> last_payload = this->fetchPayload(std::get<1>(lastiov));
145  std::shared_ptr<L1TUtmTriggerMenu> first_payload = this->fetchPayload(std::get<1>(firstiov));
146 
147  std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
148  std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
149 
150  // In case of only one tag, use f_tagname for both target and reference
151  std::string tmpTagName = l_tagname;
152  if (tmpTagName.empty())
153  tmpTagName = f_tagname;
154 
155  L1TUtmTriggerMenuInspectorHelper::L1TUtmTriggerMenuDisplay thePlot(last_payload.get(), tmpTagName, lastIOVsince);
156  thePlot.setImageFileName(this->m_imageFileName);
157  thePlot.plotDiffWithOtherMenu(first_payload.get(), f_tagname, firstIOVsince);
158 
159  return true;
160  }
161  };
162 
163  using L1TUtmTriggerMenu_CompareAlgos = L1TUtmTriggerMenu_CompareAlgosBase<MULTI_IOV, 1>;
164  using L1TUtmTriggerMenu_CompareAlgosTwoTags = L1TUtmTriggerMenu_CompareAlgosBase<SINGLE_IOV, 2>;
165 
166 } // namespace
167 
169  PAYLOAD_INSPECTOR_CLASS(L1TUtmTriggerMenuDisplayAlgos);
170  PAYLOAD_INSPECTOR_CLASS(L1TUtmTriggerMenu_CompareAlgos);
171  PAYLOAD_INSPECTOR_CLASS(L1TUtmTriggerMenu_CompareAlgosTwoTags);
172 }
assert(be >=bs)
static std::string to_string(const XMLCh *ch)
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
def canvas(sub, attr)
Definition: svgfig.py:482