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  /************************************************
40  RunInfo Payload Inspector of 1 IOV
41  *************************************************/
42  class RunInfoTest : public cond::payloadInspector::Histogram1D<RunInfo> {
43 
44  public:
45  RunInfoTest() : cond::payloadInspector::Histogram1D<RunInfo>( "Test RunInfo", "Test RunInfo",10,0.0,10.0)
46  {
47  Base::setSingleIov( true );
48  }
49 
50  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
51  auto iov = iovs.front();
52  std::shared_ptr<RunInfo> payload = Base::fetchPayload( std::get<1>(iov) );
53 
54  if(payload.get() ) {
55  payload->printAllValues();
56  }
57  return true;
58  }
59  };
60 
61  /************************************************
62  Summary of RunInfo of 1 IOV
63  *************************************************/
64  class RunInfoParameters : public cond::payloadInspector::PlotImage<RunInfo> {
65  public:
66  RunInfoParameters() : cond::payloadInspector::PlotImage<RunInfo>( "Display of RunInfo parameters" ){
67  setSingleIov( true );
68  }
69 
70  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
71  auto iov = iovs.front();
72  std::shared_ptr<RunInfo> payload = fetchPayload( std::get<1>(iov) );
73 
74  TCanvas canvas("Beam Spot Parameters Summary","RunInfo Parameters summary",1000,1000);
75  canvas.cd();
76 
77  gStyle->SetHistMinimumZero();
78 
79  canvas.SetTopMargin(0.08);
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::unique_ptr<TH2F>(new TH2F("Parameters","",1,0.0,1.0,11,0,11.));
87  auto h2_RunInfoState = std::unique_ptr<TH2F>(new TH2F("State","",1,0.0,1.0,11,0,11.));
88  h2_RunInfoParameters->SetStats(false);
89  h2_RunInfoState->SetStats(false);
90 
91  float fieldIntensity = RunInfoPI::theBField(payload->m_avg_current);
92 
93  std::function<float(RunInfoPI::parameters)> cutFunctor = [&payload,fieldIntensity](RunInfoPI::parameters my_param) {
94  float ret(-999.);
95  switch(my_param){
96  case RunInfoPI::m_run : return float(payload->m_run);
97  case RunInfoPI::m_start_time_ll : return float(payload->m_start_time_ll);
98  case RunInfoPI::m_stop_time_ll : return float(payload->m_stop_time_ll);
99  case RunInfoPI::m_start_current : return payload->m_start_current;
100  case RunInfoPI::m_stop_current : return payload->m_stop_current;
101  case RunInfoPI::m_avg_current : return payload->m_avg_current;
102  case RunInfoPI::m_max_current : return payload->m_max_current;
103  case RunInfoPI::m_min_current : return payload->m_min_current;
104  case RunInfoPI::m_run_intervall_micros : return payload->m_run_intervall_micros;
105  case RunInfoPI::m_BField : return fieldIntensity;
106  case RunInfoPI::m_fedIN : return float((payload->m_fed_in).size());
107  case RunInfoPI::END_OF_TYPES : return ret;
108  default : return ret;
109  }
110  };
111 
112  h2_RunInfoParameters->GetXaxis()->SetBinLabel(1,"Value");
113  h2_RunInfoState->GetXaxis()->SetBinLabel(1,"Value");
114 
115  unsigned int yBin=11;
116  for(int foo = RunInfoPI::m_run; foo != RunInfoPI::END_OF_TYPES; foo++ ){
117  RunInfoPI::parameters param = static_cast<RunInfoPI::parameters>(foo);
119  h2_RunInfoState->GetYaxis()->SetBinLabel(yBin,theLabel.c_str());
120  h2_RunInfoParameters->GetYaxis()->SetBinLabel(yBin,theLabel.c_str());
121  h2_RunInfoParameters->SetBinContent(1,yBin,cutFunctor(param));
122  // non-fake payload
123  if((payload->m_run)!=-1){
124  if ((payload->m_avg_current)<=-1){
125  // go in error state
126  h2_RunInfoState->SetBinContent(1,yBin,0.);
127  } else {
128  // all is OK
129  h2_RunInfoState->SetBinContent(1,yBin,1.);
130  }
131  } else {
132  // this is a fake payload
133  h2_RunInfoState->SetBinContent(1,yBin,0.9);
134  }
135  yBin--;
136 
137  }
138 
139  h2_RunInfoParameters->GetXaxis()->LabelsOption("h");
140  h2_RunInfoParameters->GetYaxis()->SetLabelSize(0.05);
141  h2_RunInfoParameters->GetXaxis()->SetLabelSize(0.05);
142  h2_RunInfoParameters->SetMarkerSize(1.5);
143 
144  h2_RunInfoState->GetXaxis()->LabelsOption("h");
145  h2_RunInfoState->GetYaxis()->SetLabelSize(0.05);
146  h2_RunInfoState->GetXaxis()->SetLabelSize(0.05);
147  h2_RunInfoState->SetMarkerSize(1.5);
148 
149  RunInfoPI::reportSummaryMapPalette(h2_RunInfoState.get());
150  h2_RunInfoState->Draw("col");
151 
152  h2_RunInfoParameters->Draw("TEXTsame");
153 
154  TLatex t1;
155  t1.SetNDC();
156  t1.SetTextAlign(12);
157  t1.SetTextSize(0.03);
158  t1.DrawLatex(0.1, 0.98,"RunInfo parameters:");
159  t1.DrawLatex(0.1, 0.95,"payload:");
160 
161  t1.SetTextFont(42);
162  t1.SetTextColor(4);
163  t1.DrawLatex(0.37, 0.982,Form("IOV %s",std::to_string(+std::get<0>(iov)).c_str()));
164  t1.DrawLatex(0.21, 0.952,Form(" %s",(std::get<1>(iov)).c_str()));
165 
166  std::string fileName(m_imageFileName);
167  canvas.SaveAs(fileName.c_str());
168 
169  return true;
170  }
171 
172 
173  };
174 
175  /************************************************
176  time history of Magnet currents from RunInfo
177  *************************************************/
178 
179  template<RunInfoPI::parameters param> class RunInfoCurrentHistory : public cond::payloadInspector::HistoryPlot<RunInfo,float> {
180  public:
181  RunInfoCurrentHistory() : cond::payloadInspector::HistoryPlot<RunInfo,float>(getStringFromTypeEnum(param),getStringFromTypeEnum(param)+" value"){}
182  ~RunInfoCurrentHistory() override = default;
183 
184  float getFromPayload( RunInfo& payload ) override{
185 
186  float fieldIntensity = RunInfoPI::theBField(payload.m_avg_current);
187 
188  switch(param){
189  case RunInfoPI::m_start_current : return payload.m_start_current;
190  case RunInfoPI::m_stop_current : return payload.m_stop_current;
191  case RunInfoPI::m_avg_current : return payload.m_avg_current;
192  case RunInfoPI::m_max_current : return payload.m_max_current;
193  case RunInfoPI::m_min_current : return payload.m_min_current;
194  case RunInfoPI::m_BField : return fieldIntensity;
195  default:
196  edm::LogWarning("LogicError") << "Unknown parameter: " << param;
197  break;
198  }
199 
200  } // payload
201 
202  /************************************************/
204  switch(parameter){
205  case RunInfoPI::m_start_current : return "Magent start current [A]";
206  case RunInfoPI::m_stop_current : return "Magnet stop current [A]";
207  case RunInfoPI::m_avg_current : return "Magnet average current [A]";
208  case RunInfoPI::m_max_current : return "Magnet max current [A]";
209  case RunInfoPI::m_min_current : return "Magnet min current [A]";
210  case RunInfoPI::m_BField : return "B-field intensity [T]";
211  default: return "should never be here";
212  }
213  }
214  };
215 
216  typedef RunInfoCurrentHistory<RunInfoPI::m_start_current> RunInfoStartCurrentHistory;
217  typedef RunInfoCurrentHistory<RunInfoPI::m_stop_current> RunInfoStopCurrentHistory;
218  typedef RunInfoCurrentHistory<RunInfoPI::m_avg_current> RunInfoAverageCurrentHistory;
219  typedef RunInfoCurrentHistory<RunInfoPI::m_max_current> RunInfoMaxCurrentHistory;
220  typedef RunInfoCurrentHistory<RunInfoPI::m_min_current> RunInfoMinCurrentHistory;
221  typedef RunInfoCurrentHistory<RunInfoPI::m_BField> RunInfoBFieldHistory;
222 
223 } // close namespace
224 
226  PAYLOAD_INSPECTOR_CLASS( RunInfoTest );
227  PAYLOAD_INSPECTOR_CLASS( RunInfoParameters ) ;
228  PAYLOAD_INSPECTOR_CLASS( RunInfoStopCurrentHistory ) ;
229  PAYLOAD_INSPECTOR_CLASS( RunInfoAverageCurrentHistory) ;
230  PAYLOAD_INSPECTOR_CLASS( RunInfoMaxCurrentHistory ) ;
231  PAYLOAD_INSPECTOR_CLASS( RunInfoMinCurrentHistory ) ;
232  PAYLOAD_INSPECTOR_CLASS( RunInfoBFieldHistory ) ;
233 }
void reportSummaryMapPalette(TH2 *obj)
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
std::string getStringFromTypeEnum(const parameters &parameter)
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
float m_stop_current
Definition: RunInfo.h:28
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
float m_min_current
Definition: RunInfo.h:31
float m_avg_current
Definition: RunInfo.h:29
float m_max_current
Definition: RunInfo.h:30
Definition: plugin.cc:24
float m_start_current
Definition: RunInfo.h:27
bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
def canvas(sub, attr)
Definition: svgfig.py:481
float theBField(const float current)
yBin
Definition: cuy.py:892