CMS 3D CMS Logo

L1TUtmTriggerMenuPayloadInspectorHelper.h
Go to the documentation of this file.
1 #ifndef CondCore_L1TPlugins_L1TUtmTriggerMenuPayloadInspectorHelper_H
2 #define CondCore_L1TPlugins_L1TUtmTriggerMenuPayloadInspectorHelper_H
3 
4 #include "TH1.h"
5 #include "TH2.h"
6 #include "TStyle.h"
7 #include "TCanvas.h"
8 #include "TLatex.h"
9 #include "TLine.h"
10 
12 
14 
15  using l1tUtmAlgoMap = std::map<std::string, L1TUtmAlgorithm>;
16  using l1tUtmConditionMap = std::map<std::string, L1TUtmCondition>;
17 
19  public:
20  // constructor
22  m_algoMap = l1utmMenu->getAlgorithmMap();
23  m_condMap = l1utmMenu->getConditionMap();
24  }
25 
26  // destructor
27  ~L1UtmTriggerMenuInfo() = default;
28 
29  public:
30  //___________________________________________________________________
31  const std::vector<std::string> listOfAlgos() const {
32  std::vector<std::string> output;
33  std::transform(m_algoMap.begin(),
34  m_algoMap.end(),
35  std::back_inserter(output),
36  [](const std::pair<std::string, L1TUtmAlgorithm>& pair) {
37  return pair.first; // Extracting the string key using lambda
38  });
39  return output;
40  }
41 
42  //___________________________________________________________________
43  const std::vector<std::string> listOfConditions() const {
44  std::vector<std::string> output;
45  std::transform(m_condMap.begin(),
46  m_condMap.end(),
47  std::back_inserter(output),
48  [](const std::pair<std::string, L1TUtmCondition>& pair) {
49  return pair.first; // Extracting the string key using lambda
50  });
51  return output;
52  }
53 
54  //___________________________________________________________________
55  template <typename T>
56  const std::vector<std::string> listOfCommonKeys(const L1TUtmTriggerMenu* other) const {
57  const auto& otherMap = getOtherMap<T>(other);
58  const auto& thisMap = getThisMap<T>();
59 
60  std::vector<std::string> commonKeys;
61 
62  // Lambda function to find common keys and store them in commonKeys vector
63  std::for_each(thisMap.begin(), thisMap.end(), [&commonKeys, &otherMap](const std::pair<std::string, T>& pair) {
64  const std::string& key = pair.first;
65 
66  // Check if the key exists in map2
67  if (otherMap.find(key) != otherMap.end()) {
68  commonKeys.push_back(key);
69  }
70  });
71  return commonKeys;
72  }
73 
74  //___________________________________________________________________
75  template <typename T>
76  const std::vector<std::string> onlyInThis(const L1TUtmTriggerMenu* other) const {
77  const auto& otherMap = getOtherMap<T>(other);
78  const auto& thisMap = getThisMap<T>();
79 
80  std::vector<std::string> stringsOnlyInFirstMap;
81 
82  // Lambda function to extract only the strings present in thisMap but not in otherMap
83  std::for_each(
84  thisMap.begin(), thisMap.end(), [&stringsOnlyInFirstMap, &otherMap](const std::pair<std::string, T>& pair) {
85  const std::string& key = pair.first;
86  // Check if the key exists in otherMap
87  if (otherMap.find(key) == otherMap.end()) {
88  stringsOnlyInFirstMap.push_back(key); // Add key to the vector
89  }
90  });
91 
92  return stringsOnlyInFirstMap;
93  }
94 
95  //___________________________________________________________________
96  template <typename T>
97  const std::vector<std::string> onlyInOther(const L1TUtmTriggerMenu* other) const {
98  const auto& otherMap = getOtherMap<T>(other);
99  const auto& thisMap = getThisMap<T>();
100 
101  std::vector<std::string> stringsOnlyInSecondMap;
102 
103  // Lambda function capturing 'this' to access the member variable 'thisMap'
104  std::for_each(
105  otherMap.begin(), otherMap.end(), [thisMap, &stringsOnlyInSecondMap](const std::pair<std::string, T>& pair) {
106  const std::string& key = pair.first;
107 
108  // Check if the key exists in thisMap
109  if (thisMap.find(key) == thisMap.end()) {
110  stringsOnlyInSecondMap.push_back(key); // Add key to the vector
111  }
112  });
113 
114  return stringsOnlyInSecondMap;
115  }
116 
117  private:
120 
121  // Helper function to get otherMap based on T
122  template <typename T>
123  decltype(auto) getOtherMap(const L1TUtmTriggerMenu* other) const {
125  return other->getConditionMap();
126  } else {
127  return other->getAlgorithmMap();
128  }
129  }
130 
131  // Helper function to get this Map based on T
132  template <typename T>
133  decltype(auto) getThisMap() const {
135  return m_condMap;
136  } else {
137  return m_algoMap;
138  }
139  }
140  };
141 
142  template <typename T>
144  public:
146  : m_info(thisMenu), m_tagName(theTag), m_IOVsinceDisplay(theIOV) {}
147  ~L1TUtmTriggerMenuDisplay() = default;
148 
149  void setImageFileName(const std::string& theFileName) {
150  m_imageFileName = theFileName;
151  return;
152  }
153 
154  // Function to set label based on the type T
155  std::string getLabel() const;
156 
157  //___________________________________________________________________
159  const auto& vec_only_in_this = m_info.template onlyInThis<T>(other);
160  const auto& vec_only_in_other = m_info.template onlyInOther<T>(other);
161 
162  // preparations for plotting
163  // starting table at y=1.0 (top of the canvas)
164  // first column is at 0.03, second column at 0.22 NDC
165  unsigned int mapsize = vec_only_in_this.size() + vec_only_in_other.size();
166  float pitch = 1. / (mapsize * 1.1);
167  float y, x1, x2;
168  std::vector<float> y_x1, y_x2, y_line;
169  std::vector<std::string> s_x1, s_x2, s_x3;
170  y = 1.0;
171  x1 = 0.02;
172  x2 = x1 + 0.37;
173  y -= pitch;
174 
175  // title for plot
176  y_x1.push_back(y);
177  s_x1.push_back(getLabel());
178  y_x2.push_back(y);
179  s_x2.push_back("#scale[1.1]{Target tag / IOV: #color[2]{" + m_tagName + "} / " + m_IOVsinceDisplay + "}");
180 
181  y -= pitch;
182  y_x1.push_back(y);
183  s_x1.push_back("");
184  y_x2.push_back(y);
185  s_x2.push_back("#scale[1.1]{Refer tag / IOV: #color[4]{" + theRefTag + "} / " + theRefIOV + "}");
186 
187  y -= pitch / 2.;
188  y_line.push_back(y);
189 
190  // First, check if there are records in reference which are not in target
191  for (const auto& ref : vec_only_in_other) {
192  y -= pitch;
193  y_x1.push_back(y);
194  s_x1.push_back("#scale[0.7]{" + ref + "}");
195  y_x2.push_back(y);
196  s_x2.push_back("#color[4]{#bf{Only in reference, not in target.}}");
197  y_line.push_back(y - (pitch / 2.));
198  }
199 
200  // Second, check if there are records in target which are not in reference
201  for (const auto& tar : vec_only_in_this) {
202  y -= pitch;
203  y_x1.push_back(y);
204  s_x1.push_back("#scale[0.7]{" + tar + "}");
205  y_x2.push_back(y);
206  s_x2.push_back("#color[2]{#bf{Only in target, not in reference.}}");
207  y_line.push_back(y - (pitch / 2.));
208  }
209 
210  // Finally, print text to TCanvas
211  TCanvas canvas("L1TUtmMenuData", "L1TUtmMenuData", 2000, std::max(y_x1.size(), y_x2.size()) * 40);
212  TLatex l;
213  // Draw the columns titles
214  l.SetTextAlign(12);
215 
216  float newpitch = 1 / (std::max(y_x1.size(), y_x2.size()) * 1.1);
217  float factor = newpitch / pitch;
218  l.SetTextSize(newpitch - 0.002);
219  canvas.cd();
220  for (unsigned int i = 0; i < y_x1.size(); i++) {
221  l.DrawLatexNDC(x1, 1 - (1 - y_x1[i]) * factor, s_x1[i].c_str());
222  }
223 
224  for (unsigned int i = 0; i < y_x2.size(); i++) {
225  l.DrawLatexNDC(x2, 1 - (1 - y_x2[i]) * factor, s_x2[i].c_str());
226  }
227 
228  canvas.cd();
229  canvas.Update();
230 
231  // Draw horizontal lines separating records
232  TLine lines[y_line.size()];
233  unsigned int iL = 0;
234  for (const auto& line : y_line) {
235  lines[iL] = TLine(gPad->GetUxmin(), 1 - (1 - line) * factor, gPad->GetUxmax(), 1 - (1 - line) * factor);
236  lines[iL].SetLineWidth(1);
237  lines[iL].SetLineStyle(9);
238  lines[iL].SetLineColor(2);
239  lines[iL].Draw("same");
240  iL++;
241  }
242 
243  std::string fileName("L1UtmMenuData_Compare.png");
244  if (!m_imageFileName.empty())
246  canvas.SaveAs(fileName.c_str());
247  }
248 
249  private:
254  };
255 
256  // Explicit specialization outside the class
257  template <>
259  return "#scale[1.1]{Condition Name}";
260  }
261 
262  template <>
264  return "#scale[1.1]{Algo Name}";
265  }
266 } // namespace L1TUtmTriggerMenuInspectorHelper
267 
268 #endif
L1UtmTriggerMenuInfo m_info
map of the record / metadata associations
void plotDiffWithOtherMenu(const L1TUtmTriggerMenu *other, std::string theRefTag, std::string theRefIOV)
const std::vector< std::string > onlyInThis(const L1TUtmTriggerMenu *other) const
std::map< std::string, L1TUtmCondition > l1tUtmConditionMap
key
prepare the HTCondor submission files and eventually submit them
L1TUtmTriggerMenuDisplay(const L1TUtmTriggerMenu *thisMenu, std::string theTag, std::string theIOV)
const std::map< std::string, L1TUtmCondition > & getConditionMap() const
decltype(auto) getOtherMap(const L1TUtmTriggerMenu *other) const
const std::vector< std::string > listOfCommonKeys(const L1TUtmTriggerMenu *other) const
def canvas(sub, attr)
Definition: svgfig.py:482
Definition: output.py:1
const std::vector< std::string > onlyInOther(const L1TUtmTriggerMenu *other) const
const std::map< std::string, L1TUtmAlgorithm > & getAlgorithmMap() const
std::map< std::string, L1TUtmAlgorithm > l1tUtmAlgoMap
unsigned transform(const HcalDetId &id, unsigned transformCode)