CMS 3D CMS Logo

RunInfo_PayloadInspector.cc
Go to the documentation of this file.
1 
12 
13 // the data format of the condition to be inspected
16 
17 // helper
19 
20 // system includes
21 #include <memory>
22 #include <sstream>
23 #include <iostream>
24 
25 // include ROOT
26 #include "TProfile.h"
27 #include "TH2F.h"
28 #include "TLegend.h"
29 #include "TCanvas.h"
30 #include "TLine.h"
31 #include "TStyle.h"
32 #include "TLatex.h"
33 #include "TPave.h"
34 #include "TPaveStats.h"
35 #include "TPaletteAxis.h"
36 
37 namespace {
38 
39  using namespace cond::payloadInspector;
40 
41  /************************************************
42  RunInfo Payload Inspector of 1 IOV
43  *************************************************/
44  class RunInfoTest : public Histogram1D<RunInfo, SINGLE_IOV> {
45  public:
46  RunInfoTest() : Histogram1D<RunInfo, SINGLE_IOV>("Test RunInfo", "Test RunInfo", 1, 0.0, 1.0) {}
47 
48  bool fill() override {
49  auto tag = PlotBase::getTag<0>();
50  for (auto const& iov : tag.iovs) {
51  std::shared_ptr<RunInfo> payload = Base::fetchPayload(std::get<1>(iov));
52  if (payload.get()) {
53  payload->printAllValues();
54  }
55  }
56  return true;
57  }
58  };
59 
60  /************************************************
61  Summary of RunInfo of 1 IOV
62  *************************************************/
63  class RunInfoParameters : public PlotImage<RunInfo, SINGLE_IOV> {
64  public:
65  RunInfoParameters() : PlotImage<RunInfo, SINGLE_IOV>("Display of RunInfo parameters") {}
66 
67  bool fill() override {
68  gStyle->SetPaintTextFormat("g");
69  auto tag = PlotBase::getTag<0>();
70  auto iovs = tag.iovs;
71  auto iov = iovs.front();
72  std::shared_ptr<RunInfo> payload = fetchPayload(std::get<1>(iov));
73 
74  TCanvas canvas("RunInfo Parameters Summary", "RunInfo Parameters summary", 1000, 1000);
75  canvas.cd();
76 
77  gStyle->SetHistMinimumZero();
78 
79  canvas.SetTopMargin(0.13);
80  canvas.SetBottomMargin(0.06);
81  canvas.SetLeftMargin(0.3);
82  canvas.SetRightMargin(0.02);
83  canvas.Modified();
84  canvas.SetGrid();
85 
86  auto h2_RunInfoParameters = std::make_unique<TH2F>("Parameters", "", 1, 0.0, 1.0, 11, 0, 11.);
87  auto h2_RunInfoState = std::make_unique<TH2F>("State", "", 1, 0.0, 1.0, 11, 0, 11.);
88  h2_RunInfoParameters->SetStats(false);
89  h2_RunInfoState->SetStats(false);
90 
91  std::function<float(RunInfoPI::parameters)> cutFunctor = [&payload](RunInfoPI::parameters my_param) {
92  float ret(-999.);
93  switch (my_param) {
94  case RunInfoPI::m_run:
95  return float(payload->m_run);
97  return float(payload->m_start_time_ll * 1.0e-6);
99  return float(payload->m_stop_time_ll * 1.0e-6);
101  return payload->m_start_current;
103  return payload->m_stop_current;
105  return payload->m_avg_current;
107  return payload->m_max_current;
109  return payload->m_min_current;
112  case RunInfoPI::m_BField:
113  return RunInfoPI::theBField(payload->m_avg_current); //fieldIntensity;
114  case RunInfoPI::m_fedIN:
115  return float((payload->m_fed_in).size());
117  return ret;
118  default:
119  return ret;
120  }
121  };
122 
123  h2_RunInfoParameters->GetXaxis()->SetBinLabel(1, "Value");
124  h2_RunInfoState->GetXaxis()->SetBinLabel(1, "Value");
125 
126  RunInfoPI::state theState;
127 
128  unsigned int yBin = 11;
129  for (int foo = RunInfoPI::m_run; foo != RunInfoPI::END_OF_TYPES; foo++) {
130  RunInfoPI::parameters param = static_cast<RunInfoPI::parameters>(foo);
132  h2_RunInfoState->GetYaxis()->SetBinLabel(yBin, theLabel.c_str());
133  h2_RunInfoParameters->GetYaxis()->SetBinLabel(yBin, theLabel.c_str());
134  h2_RunInfoParameters->SetBinContent(1, yBin, cutFunctor(param));
135  // non-fake payload
136  if ((payload->m_run) != -1) {
137  if ((payload->m_avg_current) <= -1) {
138  // go in error state
139  h2_RunInfoState->SetBinContent(1, yBin, 0.);
140  theState = RunInfoPI::k_invalid;
141  } else {
142  // all is OK
143  h2_RunInfoState->SetBinContent(1, yBin, 1.);
144  theState = RunInfoPI::k_valid;
145  }
146  } else {
147  // this is a fake payload
148  h2_RunInfoState->SetBinContent(1, yBin, 0.9);
149  theState = RunInfoPI::k_fake;
150  }
151  yBin--;
152  }
153 
154  h2_RunInfoParameters->GetXaxis()->LabelsOption("h");
155  h2_RunInfoParameters->GetYaxis()->SetLabelSize(0.05);
156  h2_RunInfoParameters->GetXaxis()->SetLabelSize(0.05);
157  h2_RunInfoParameters->SetMarkerSize(1.5);
158 
159  h2_RunInfoState->GetXaxis()->LabelsOption("h");
160  h2_RunInfoState->GetYaxis()->SetLabelSize(0.05);
161  h2_RunInfoState->GetXaxis()->SetLabelSize(0.05);
162  h2_RunInfoState->SetMarkerSize(1.5);
163 
164  RunInfoPI::reportSummaryMapPalette(h2_RunInfoState.get());
165  h2_RunInfoState->Draw("col");
166 
167  h2_RunInfoParameters->Draw("TEXTsame");
168 
169  TLatex t1;
170  t1.SetNDC();
171  t1.SetTextAlign(12);
172  t1.SetTextSize(0.03);
173  t1.DrawLatex(0.1, 0.98, "RunInfo parameters:");
174  t1.DrawLatex(0.1, 0.95, "payload:");
175  t1.DrawLatex(0.1, 0.92, "start time:");
176  t1.DrawLatex(0.1, 0.89, "end time:");
177 
178  t1.SetTextFont(42);
179  t1.SetTextColor(4);
180  t1.DrawLatex(0.37, 0.982, Form("IOV %s", std::to_string(+std::get<0>(iov)).c_str()));
181  t1.DrawLatex(0.21, 0.952, Form(" %s", (std::get<1>(iov)).c_str()));
182  t1.DrawLatex(0.23, 0.922, Form(" %s", (RunInfoPI::runStartTime(payload)).c_str()));
183  t1.DrawLatex(0.23, 0.892, Form(" %s", (RunInfoPI::runEndTime(payload)).c_str()));
184 
185  TPaveText ksPt(0, 0, 0.35, 0.04, "NDC");
186  ksPt.SetBorderSize(0);
187  ksPt.SetFillColor(0);
188  const char* textToAdd;
189  switch (theState) {
190  case RunInfoPI::k_fake:
191  textToAdd = "This is a fake RunInfoPayload";
192  break;
193  case RunInfoPI::k_valid:
194  textToAdd = "This is a valid RunInfoPayload";
195  break;
197  textToAdd = "This is an invalid RunInfoPayload";
198  break;
199  default:
200  throw cms::Exception("PayloadInspector") << "an invalid state has been found";
201  }
202 
203  ksPt.AddText(textToAdd);
204  ksPt.Draw();
205 
206  std::string fileName(m_imageFileName);
207  canvas.SaveAs(fileName.c_str());
208 
209  return true;
210  }
211  };
212 
213  /************************************************
214  time history of Magnet currents from RunInfo
215  *************************************************/
216  template <RunInfoPI::parameters param>
217  class RunInfoCurrentHistory : public HistoryPlot<RunInfo, std::pair<bool, float> > {
218  public:
219  RunInfoCurrentHistory()
221  getStringFromTypeEnum(param) + " value") {}
222  ~RunInfoCurrentHistory() override = default;
223 
224  std::pair<bool, float> getFromPayload(RunInfo& payload) override {
225  bool isRealRun = ((payload.m_run) != -1);
226 
227  switch (param) {
229  return std::make_pair(isRealRun, payload.m_start_current);
231  return std::make_pair(isRealRun, payload.m_stop_current);
233  return std::make_pair(isRealRun, payload.m_avg_current);
235  return std::make_pair(isRealRun, payload.m_max_current);
237  return std::make_pair(isRealRun, payload.m_min_current);
238  case RunInfoPI::m_BField:
239  return std::make_pair(isRealRun, RunInfoPI::theBField(payload.m_avg_current));
240  default:
241  edm::LogWarning("LogicError") << "Unknown parameter: " << param;
242  break;
243  }
244  return std::make_pair(isRealRun, -1.0);
245  } // payload
246 
247  /************************************************/
249  switch (parameter) {
251  return "Magent start current [A]";
253  return "Magnet stop current [A]";
255  return "Magnet average current [A]";
257  return "Magnet max current [A]";
259  return "Magnet min current [A]";
260  case RunInfoPI::m_BField:
261  return "B-field intensity [T]";
262  default:
263  return "should never be here";
264  }
265  }
266  };
267 
268  typedef RunInfoCurrentHistory<RunInfoPI::m_start_current> RunInfoStartCurrentHistory;
269  typedef RunInfoCurrentHistory<RunInfoPI::m_stop_current> RunInfoStopCurrentHistory;
270  typedef RunInfoCurrentHistory<RunInfoPI::m_avg_current> RunInfoAverageCurrentHistory;
271  typedef RunInfoCurrentHistory<RunInfoPI::m_max_current> RunInfoMaxCurrentHistory;
272  typedef RunInfoCurrentHistory<RunInfoPI::m_min_current> RunInfoMinCurrentHistory;
273  typedef RunInfoCurrentHistory<RunInfoPI::m_BField> RunInfoBFieldHistory;
274 
275  /************************************************
276  time history of Magnet currents from RunInfo
277  *************************************************/
278  template <RunInfoPI::DET theDet>
279  class RunInfoDetHistory : public HistoryPlot<RunInfo, std::pair<bool, float> > {
280  public:
281  RunInfoDetHistory() : HistoryPlot<RunInfo, std::pair<bool, float> >("Det Status History", "Det Status History") {}
282  ~RunInfoDetHistory() override = default;
283 
284  std::pair<bool, float> getFromPayload(RunInfo& payload) override {
285  bool isRealRun = ((payload.m_run) != -1);
286  float returnValue = 0.;
287  // early return in case the run is fake
288  if (!isRealRun) {
289  return std::make_pair(isRealRun, returnValue);
290  }
291 
292  const auto fedBounds = RunInfoPI::buildFEDBounds();
293  const auto limits = fedBounds.at(theDet);
294  const auto& FEDsIn = payload.m_fed_in;
295  for (const auto& FED : FEDsIn) {
296  if (FED > limits.first && FED < limits.second) {
297  returnValue = 1.;
298  break; // break the loop to speed up time
299  }
300  }
301  return std::make_pair(isRealRun, returnValue);
302  } // payload
303  };
304 
305  using RunInfoTrackerHistory = RunInfoDetHistory<RunInfoPI::SISTRIP>;
306  using RunInfoSiPixelHistory = RunInfoDetHistory<RunInfoPI::SIPIXEL>;
307  using RunInfoSiPixelPhase1History = RunInfoDetHistory<RunInfoPI::SIPIXELPHASE1>;
308  //.... other could be implemented
309 } // namespace
310 
312  PAYLOAD_INSPECTOR_CLASS(RunInfoTest);
313  PAYLOAD_INSPECTOR_CLASS(RunInfoParameters);
314  PAYLOAD_INSPECTOR_CLASS(RunInfoStopCurrentHistory);
315  PAYLOAD_INSPECTOR_CLASS(RunInfoAverageCurrentHistory);
316  PAYLOAD_INSPECTOR_CLASS(RunInfoMaxCurrentHistory);
317  PAYLOAD_INSPECTOR_CLASS(RunInfoMinCurrentHistory);
318  PAYLOAD_INSPECTOR_CLASS(RunInfoBFieldHistory);
319  PAYLOAD_INSPECTOR_CLASS(RunInfoTrackerHistory);
320  PAYLOAD_INSPECTOR_CLASS(RunInfoSiPixelHistory);
321  PAYLOAD_INSPECTOR_CLASS(RunInfoSiPixelPhase1History);
322 }
ret
prodAgent to be discontinued
void reportSummaryMapPalette(TH2 *obj)
const std::string getStringFromTypeEnum(const types &type)
float runDuration(const std::shared_ptr< RunInfo > &payload)
std::string runEndTime(const std::shared_ptr< RunInfo > &payload)
static std::string to_string(const XMLCh *ch)
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
std::string getStringFromTypeEnum(const parameters &parameter)
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
def canvas(sub, attr)
Definition: svgfig.py:482
float theBField(const float current)
Log< level::Warning, false > LogWarning
std::string runStartTime(const std::shared_ptr< RunInfo > &payload)