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  // Calculate the total number of entries
163  unsigned int mapsize = vec_only_in_this.size() + vec_only_in_other.size();
164 
165  // Dynamically calculate the pitch based on the number of entries
166  float canvasHeight = std::max(800.0f, mapsize * 30.0f); // Adjust canvas height based on the number of entries
167  float pitch = 1.0 / (mapsize + 3.0); // Pitch for spacing between lines (extra space for headers)
168 
169  float y = 1.0;
170  float x1 = 0.02, x2 = x1 + 0.37;
171  std::vector<float> y_x1, y_x2, y_line;
172  std::vector<std::string> s_x1, s_x2;
173 
174  // Title for plot
175  y -= pitch;
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.0;
188  y_line.push_back(y);
189 
190  // Records only in reference (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.0));
198  }
199 
200  // Records only in target (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.0));
208  }
209 
210  // Adjust canvas size dynamically
211  TCanvas canvas("L1TUtmMenuData", "L1TUtmMenuData", 2000, static_cast<int>(canvasHeight));
212  TLatex l;
213  l.SetTextAlign(12);
214 
215  // Set the text size dynamically based on pitch
216  float textSize = std::clamp(pitch, 0.015f, 0.035f);
217  l.SetTextSize(textSize);
218 
219  canvas.cd();
220  for (unsigned int i = 0; i < y_x1.size(); i++) {
221  l.DrawLatexNDC(x1, y_x1[i], s_x1[i].c_str());
222  }
223  for (unsigned int i = 0; i < y_x2.size(); i++) {
224  l.DrawLatexNDC(x2, y_x2[i], s_x2[i].c_str());
225  }
226 
227  // Draw horizontal lines separating records
228  TLine lines[y_line.size()];
229  for (unsigned int i = 0; i < y_line.size(); i++) {
230  lines[i] = TLine(gPad->GetUxmin(), y_line[i], gPad->GetUxmax(), y_line[i]);
231  lines[i].SetLineWidth(1);
232  lines[i].SetLineStyle(9);
233  lines[i].SetLineColor(2);
234  lines[i].Draw("same");
235  }
236 
237  // Save the canvas as an image
238  std::string fileName = "L1UtmMenuData_Compare.png";
239  if (!m_imageFileName.empty()) {
241  }
242  canvas.SaveAs(fileName.c_str());
243  }
244 
245  private:
250  };
251 
252  // Explicit specialization outside the class
253  template <>
255  return "#scale[1.1]{Condition Name}";
256  }
257 
258  template <>
260  return "#scale[1.1]{Algo Name}";
261  }
262 } // namespace L1TUtmTriggerMenuInspectorHelper
263 
264 #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
double f[11][100]
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)