CMS 3D CMS Logo

AlCaRecoTriggerBits_PayloadInspector.cc
Go to the documentation of this file.
5 
6 #include <memory>
7 #include <sstream>
8 #include <iostream>
9 #include "TCanvas.h"
10 #include "TLatex.h"
11 #include "TLine.h"
12 
13 namespace {
14 
15  /************************************************
16  Display AlCaRecoTriggerBits mapping
17  *************************************************/
18  class AlCaRecoTriggerBits_Display: public cond::payloadInspector::PlotImage<AlCaRecoTriggerBits> {
19  public:
20  AlCaRecoTriggerBits_Display() : cond::payloadInspector::PlotImage<AlCaRecoTriggerBits>( "Table of AlCaRecoTriggerBits" ){
21  setSingleIov( true );
22  }
23 
24  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
25  auto iov = iovs.front();
26  std::shared_ptr<AlCaRecoTriggerBits> payload = fetchPayload( std::get<1>(iov) );
27 
28  std::string IOVsince = std::to_string(std::get<0>(iov));
29 
30  // Get map of strings to concatenated list of names of HLT paths:
31  typedef std::map<std::string, std::string> TriggerMap;
32  const TriggerMap &triggerMap = payload->m_alcarecoToTrig;
33 
34  unsigned int mapsize = triggerMap.size();
35  float pitch = 1./(mapsize*1.1);
36 
37  float y, x1, x2;
38  std::vector<float> y_x1,y_x2,y_line;
39  std::vector<std::string> s_x1,s_x2,s_x3;
40 
41  // starting table at y=1.0 (top of the canvas)
42  // first column is at 0.02, second column at 0.32 NDC
43  y = 1.0; x1 = 0.02; x2 = x1+0.30;
44 
45  y -= pitch;
46  y_x1.push_back(y);
47  s_x1.push_back("#scale[1.2]{Key}");
48  y_x2.push_back(y);
49  s_x2.push_back("#scale[1.2]{in IOV: "+IOVsince+"}");
50 
51  y -= pitch/2.;
52  y_line.push_back(y);
53 
54  for(const auto &element : triggerMap){
55 
56  y -= pitch;
57  y_x1.push_back(y);
58  s_x1.push_back(element.first);
59 
60  std::vector<std::string> output;
61  std::string toAppend="";
62  const std::vector<std::string> paths = payload->decompose(element.second);
63  for (unsigned int iPath = 0; iPath < paths.size(); ++iPath) {
64  // if the line to be added has less than 60 chars append to current
65  if((toAppend+paths[iPath]).length()<60){
66  toAppend+=paths[iPath]+";";
67  } else {
68  // else if the line exceeds 60 chars, dump in the vector and resume from scratch
69  output.push_back(toAppend);
70  toAppend.clear();
71  toAppend+=paths[iPath]+";";
72  }
73  // if it's the last, dump it
74  if(iPath==paths.size()-1) output.push_back(toAppend);
75  }
76 
77  for (unsigned int br=0; br<output.size();br++){
78  y_x2.push_back(y);
79  s_x2.push_back("#color[2]{"+output[br]+"}");
80  if(br!=output.size()-1) y-=pitch;
81  }
82 
83  y_line.push_back(y-(pitch/2.));
84 
85  }
86 
87  TCanvas canvas("AlCaRecoTriggerBits","AlCaRecoTriggerBits",2000,std::max(y_x1.size(),y_x2.size())*40);
88  TLatex l;
89  // Draw the columns titles
90  l.SetTextAlign(12);
91 
92  float newpitch = 1/(std::max(y_x1.size(),y_x2.size())*1.1);
93  float factor = newpitch/pitch;
94  l.SetTextSize(newpitch-0.002);
95  canvas.cd();
96  for(unsigned int i=0;i<y_x1.size();i++){
97  l.DrawLatexNDC(x1,1-(1-y_x1[i])*factor,s_x1[i].c_str());
98  }
99 
100  for(unsigned int i=0;i<y_x2.size();i++){
101  l.DrawLatexNDC(x2,1-(1-y_x2[i])*factor,s_x2[i].c_str());
102  }
103 
104  canvas.cd();
105  canvas.Update();
106 
107  TLine lines[y_line.size()];
108  unsigned int iL=0;
109  for (const auto & line : y_line){
110  lines[iL] = TLine(gPad->GetUxmin(),1-(1-line)*factor,gPad->GetUxmax(),1-(1-line)*factor);
111  lines[iL].SetLineWidth(1);
112  lines[iL].SetLineStyle(9);
113  lines[iL].SetLineColor(2);
114  lines[iL].Draw("same");
115  iL++;
116  }
117 
118  std::string fileName(m_imageFileName);
119  canvas.SaveAs(fileName.c_str());
120  return true;
121  }
122  };
123 
124  /************************************************
125  Compare AlCaRecoTriggerBits mapping
126  *************************************************/
127  class AlCaRecoTriggerBits_Compare: public cond::payloadInspector::PlotImage<AlCaRecoTriggerBits> {
128  public:
129  AlCaRecoTriggerBits_Compare() : cond::payloadInspector::PlotImage<AlCaRecoTriggerBits>( "Table of AlCaRecoTriggerBits comparison" ){
130  setSingleIov( false );
131  }
132 
133  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
134 
135  std::vector<std::tuple<cond::Time_t,cond::Hash> > sorted_iovs = iovs;
136 
137  // make absolute sure the IOVs are sortd by since
138  std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
139  return std::get<0>(t1) < std::get<0>(t2);
140  });
141 
142  auto firstiov = sorted_iovs.front();
143  auto lastiov = sorted_iovs.back();
144 
145  std::shared_ptr<AlCaRecoTriggerBits> last_payload = fetchPayload( std::get<1>(lastiov) );
146  std::shared_ptr<AlCaRecoTriggerBits> first_payload = fetchPayload( std::get<1>(firstiov) );
147 
148  std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
149  std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
150 
151  // Get map of strings to concatenated list of names of HLT paths:
152  typedef std::map<std::string, std::string> TriggerMap;
153  const TriggerMap &first_triggerMap = first_payload->m_alcarecoToTrig;
154  const TriggerMap &last_triggerMap = last_payload->m_alcarecoToTrig;
155 
156  std::vector<std::string> first_keys, not_in_first_keys;
157  std::vector<std::string> last_keys, not_in_last_keys;
158 
159  // fill the vector of first keys
160  for (const auto& element : first_triggerMap){
161  first_keys.push_back(element.first);
162  }
163 
164  // fill the vector of last keys
165  for (const auto& element : last_triggerMap){
166  last_keys.push_back(element.first);
167  }
168 
169  // find the elements not in common
170  std::set_difference(first_keys.begin(),first_keys.end(),last_keys.begin(),last_keys.end(),
171  std::inserter(not_in_last_keys, not_in_last_keys.begin()));
172 
173  std::set_difference(last_keys.begin(),last_keys.end(),first_keys.begin(),first_keys.end(),
174  std::inserter(not_in_first_keys, not_in_first_keys.begin()));
175 
176  float pitch = 0.013;
177  float y, x1, x2, x3;
178 
179  std::vector<float> y_x1,y_x2,y_x3,y_line;
180  std::vector<std::string> s_x1,s_x2,s_x3;
181 
182  y = 1.0;
183  x1 = 0.02;
184  x2 = x1+0.20;
185  x3 = x2+0.30;
186 
187  y -= pitch;
188  y_x1.push_back(y);
189  s_x1.push_back("#scale[1.2]{Key}");
190  y_x2.push_back(y);
191  s_x2.push_back("#scale[1.2]{in IOV: "+firstIOVsince+"}");
192  y_x3.push_back(y);
193  s_x3.push_back("#scale[1.2]{in IOV: "+lastIOVsince+"}");
194  y -= pitch/3;
195 
196  // print the ones missing in the last key
197  for(const auto& key : not_in_last_keys ) {
198  y -= pitch;
199  y_x1.push_back(y);
200  s_x1.push_back(key);
201 
202  const std::vector<std::string> missing_in_last_paths = first_payload->decompose(first_triggerMap.at(key));
203 
204  std::vector<std::string> output;
205  std::string toAppend="";
206  for (unsigned int iPath = 0; iPath < missing_in_last_paths.size(); ++iPath) {
207  // if the line to be added has less than 60 chars append to current
208  if((toAppend+missing_in_last_paths[iPath]).length()<60){
209  toAppend+=missing_in_last_paths[iPath]+";";
210  } else {
211  // else if the line exceeds 60 chars, dump in the vector and resume from scratch
212  output.push_back(toAppend);
213  toAppend.clear();
214  toAppend+=missing_in_last_paths[iPath]+";";
215  }
216  // if it's the last, dump it
217  if(iPath==missing_in_last_paths.size()-1) output.push_back(toAppend);
218  }
219 
220  for (unsigned int br=0; br<output.size();br++){
221  y_x2.push_back(y);
222  s_x2.push_back("#color[2]{"+output[br]+"}");
223  if(br!=output.size()-1) y -=pitch;
224  }
225  y_line.push_back(y-0.008);
226 
227  }
228 
229  // print the ones missing in the first key
230  for(const auto& key : not_in_first_keys ) {
231  y -= pitch;
232  y_x1.push_back(y);
233  s_x1.push_back(key);
234  const std::vector<std::string> missing_in_first_paths = last_payload->decompose(last_triggerMap.at(key));
235 
236  std::vector<std::string> output;
237  std::string toAppend="";
238  for (unsigned int iPath = 0; iPath < missing_in_first_paths.size(); ++iPath) {
239  // if the line to be added has less than 60 chars append to current
240  if((toAppend+missing_in_first_paths[iPath]).length()<60){
241  toAppend+=missing_in_first_paths[iPath]+";";
242  } else {
243  // else if the line exceeds 60 chars, dump in the vector and resume from scratch
244  output.push_back(toAppend);
245  toAppend.clear();
246  toAppend+=missing_in_first_paths[iPath]+";";
247  }
248  // if it's the last, dump it
249  if(iPath==missing_in_first_paths.size()-1) output.push_back(toAppend);
250  }
251 
252  for (unsigned int br=0; br<output.size();br++){
253  y_x3.push_back(y);
254  s_x3.push_back("#color[4]{"+output[br]+"}");
255  if(br!=output.size()-1) y -= pitch;
256  }
257  y_line.push_back(y-0.008);
258 
259  }
260 
261  for(const auto &element : first_triggerMap){
262 
263  if(last_triggerMap.find(element.first)!=last_triggerMap.end()){
264 
265  auto lastElement = last_triggerMap.find(element.first);
266 
268  const std::vector<std::string> first_paths = first_payload->decompose(element.second);
269  const std::vector<std::string> last_paths = last_payload->decompose(lastElement->second);
270 
271  std::vector<std::string> not_in_first;
272  std::vector<std::string> not_in_last;
273 
274  std::set_difference(first_paths.begin(),first_paths.end(),last_paths.begin(),last_paths.end(),
275  std::inserter(not_in_last, not_in_last.begin()));
276 
277  std::set_difference(last_paths.begin(),last_paths.end(),first_paths.begin(),first_paths.end(),
278  std::inserter(not_in_first, not_in_first.begin()));
279 
280  if(!not_in_last.empty() || !not_in_first.empty()) {
281 
282  y -= pitch;
283  y_x1.push_back(y);
284  s_x1.push_back(element.first);
285 
286  std::vector<std::string> output;
287  std::string toAppend="";
288  for (unsigned int iPath = 0; iPath < not_in_last.size(); ++iPath) {
289  // if the line to be added has less than 60 chars append to current
290  if((toAppend+not_in_last[iPath]).length()<60){
291  toAppend+=not_in_last[iPath]+";";
292  } else {
293  // else if the line exceeds 60 chars, dump in the vector and resume from scratch
294  output.push_back(toAppend);
295  toAppend.clear();
296  toAppend+=not_in_last[iPath]+";";
297  }
298  // if it's the last and not empty, dump it
299  if(toAppend.length()>0 && iPath==not_in_last.size()-1) output.push_back(toAppend);
300  }
301 
302  unsigned int count = output.size();
303 
304  for (unsigned int br=0; br<count;br++){
305  y_x2.push_back(y-(br*pitch));
306  s_x2.push_back("#color[6]{"+output[br]+"}");
307  }
308 
309  // clear vector and string
310  toAppend.clear();
311  output.clear();
312  for (unsigned int jPath = 0; jPath < not_in_first.size(); ++jPath) {
313  // if the line to be added has less than 60 chars append to current
314  if((toAppend+not_in_first[jPath]).length()<60){
315  toAppend+=not_in_first[jPath]+";";
316  } else {
317  // else if the line exceeds 60 chars, dump in the vector and resume from scratch
318  output.push_back(toAppend);
319  toAppend.clear();
320  toAppend+=not_in_first[jPath]+";";
321  }
322  // if it's the last and not empty, dump it
323  if(toAppend.length()>0 && jPath==not_in_first.size()-1) output.push_back(toAppend);
324  }
325 
326  unsigned int count1 = output.size();
327 
328  for (unsigned int br=0; br<count1;br++){
329  y_x3.push_back(y-(br*pitch));
330  s_x3.push_back("#color[8]{"+output[br]+"}");
331  }
332 
333  // decrease the y position to the maximum of the two lists
334  y-=(std::max(count,count1)-1)*pitch;
335  //y-=count*pitch;
336  y_line.push_back(y-0.008);
337 
338  } // close if there is at least a difference
339  } // if there is a common key
340  }//loop on the keys
341 
342  TCanvas canvas("AlCaRecoTriggerBits","AlCaRecoTriggerBits",2500.,std::max(y_x1.size(),y_x2.size())*40);
343 
344  TLatex l;
345  // Draw the columns titles
346  l.SetTextAlign(12);
347 
348  // rescale the width of the table row to fit into the canvas
349  float newpitch = 1/(std::max(y_x1.size(),y_x2.size())*1.65);
350  float factor = newpitch/pitch;
351  l.SetTextSize(newpitch-0.002);
352  canvas.cd();
353  for(unsigned int i=0;i<y_x1.size();i++){
354  l.DrawLatexNDC(x1,1-(1-y_x1[i])*factor,s_x1[i].c_str());
355  }
356 
357  for(unsigned int i=0;i<y_x2.size();i++){
358  l.DrawLatexNDC(x2,1-(1-y_x2[i])*factor,s_x2[i].c_str());
359  }
360 
361  for(unsigned int i=0;i<y_x3.size();i++){
362  l.DrawLatexNDC(x3,1-(1-y_x3[i])*factor,s_x3[i].c_str());
363  }
364 
365  canvas.cd();
366  canvas.Update();
367 
368  TLine lines[y_line.size()];
369  unsigned int iL=0;
370  for (const auto & line : y_line){
371  lines[iL] = TLine(gPad->GetUxmin(),1-(1-line)*factor,gPad->GetUxmax(),1-(1-line)*factor);
372  lines[iL].SetLineWidth(1);
373  lines[iL].SetLineStyle(9);
374  lines[iL].SetLineColor(2);
375  lines[iL].Draw("same");
376  iL++;
377  }
378 
379  //canvas.SetCanvasSize(2000,(1-y)*1000);
380  std::string fileName(m_imageFileName);
381  canvas.SaveAs(fileName.c_str());
382  return true;
383  }
384  };
385 
386 }
387 
388 
390  PAYLOAD_INSPECTOR_CLASS( AlCaRecoTriggerBits_Display );
391  PAYLOAD_INSPECTOR_CLASS( AlCaRecoTriggerBits_Compare );
392 }
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
virtual bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)=0
#define end
Definition: vmac.h:39
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
Definition: plugin.cc:24
#define begin
Definition: vmac.h:32
def canvas(sub, attr)
Definition: svgfig.py:481