CMS 3D CMS Logo

BasicP_PayloadInspector.cc
Go to the documentation of this file.
6 #include <memory>
7 #include <sstream>
8 
9 #include "TH2D.h"
10 #include "TCanvas.h"
11 #include "TLine.h"
12 #include "TLatex.h"
13 
14 namespace {
15 
16  class BasicPayload_data0 : public cond::payloadInspector::HistoryPlot<cond::BasicPayload,float> {
17  public:
18  BasicPayload_data0() : cond::payloadInspector::HistoryPlot<cond::BasicPayload,float>( "Example Trend", "data0"){
19  }
20  ~BasicPayload_data0() override = default;
21  float getFromPayload( cond::BasicPayload& payload ) override{
22  return payload.m_data0;
23  }
24  };
25 
26  class BasicPayload_data1 : public cond::payloadInspector::RunHistoryPlot<cond::BasicPayload,float> {
27  public:
28  BasicPayload_data1() : cond::payloadInspector::RunHistoryPlot<cond::BasicPayload,float>( "Example Run-based Trend", "data0"){
29  }
30  ~BasicPayload_data1() override = default;
31  float getFromPayload( cond::BasicPayload& payload ) override{
32  return payload.m_data0;
33  }
34  };
35 
36  class BasicPayload_data2 : public cond::payloadInspector::TimeHistoryPlot<cond::BasicPayload,float> {
37  public:
38  BasicPayload_data2() : cond::payloadInspector::TimeHistoryPlot<cond::BasicPayload,float>( "Example Time-based Trend", "data0"){
39  }
40  ~BasicPayload_data2() override = default;
41 
42  float getFromPayload( cond::BasicPayload& payload ) override{
43  return payload.m_data0;
44  }
45  };
46 
47  class BasicPayload_data3 : public cond::payloadInspector::ScatterPlot<cond::BasicPayload,float,float> {
48  public:
49  BasicPayload_data3() : cond::payloadInspector::ScatterPlot<cond::BasicPayload,float,float>( "Example Scatter", "data0","data1"){
50  }
51  ~BasicPayload_data3() override = default;
52 
53  std::tuple<float,float> getFromPayload( cond::BasicPayload& payload ) override{
54  return std::make_tuple(payload.m_data0,payload.m_data1);
55  }
56  };
57 
58  class BasicPayload_data4 : public cond::payloadInspector::Histogram1D<cond::BasicPayload> {
59  public:
60  BasicPayload_data4() : cond::payloadInspector::Histogram1D<cond::BasicPayload>( "Example Histo1d", "x",10,0,10){
61  Base::setSingleIov( true );
62  }
63  ~BasicPayload_data4() override = default;
64 
65  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
66  for( auto iov : iovs ) {
67  std::shared_ptr<cond::BasicPayload> payload = Base::fetchPayload( std::get<1>(iov) );
68  if( payload.get() ){
69  for( size_t j=0;j<100;j++ ) {
70  fillWithValue( j, payload->m_vec[j] );
71  }
72  }
73  }
74  return true;
75  }
76  };
77 
78  class BasicPayload_data5 : public cond::payloadInspector::Histogram2D<cond::BasicPayload> {
79  public:
80  BasicPayload_data5() : cond::payloadInspector::Histogram2D<cond::BasicPayload>( "Example Histo2d", "x",10,0,10,"y",10,0,10){
81  Base::setSingleIov( true );
82  }
83  ~BasicPayload_data5() override = default;
84 
85  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
86  for( auto iov : iovs ) {
87  std::shared_ptr<cond::BasicPayload> payload = Base::fetchPayload( std::get<1>(iov) );
88  if( payload.get() ){
89  for( size_t i=0;i<10;i++ )
90  for( size_t j=0;j<10;j++ ) {
91  fillWithValue( j, i, payload->m_vec[i*10+j] );
92  }
93  }
94  }
95  return true;
96  }
97  };
98 
99  class BasicPayload_data6 : public cond::payloadInspector::PlotImage<cond::BasicPayload> {
100  public:
101  BasicPayload_data6() : cond::payloadInspector::PlotImage<cond::BasicPayload>( "Example delivery picture" ){
102  setSingleIov( true );
103  }
104 
105  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
106  auto iov = iovs.front();
107  std::shared_ptr<cond::BasicPayload> payload = fetchPayload( std::get<1>(iov) );
108 
109  double xmax(100.),ymax(100.);
110 
111  TH2D h2D("h2D","Example",100,0.,xmax,100,0.,ymax);
112 
113  if( payload.get() ){
114  if(payload->m_vec.size()==10000){
115  for( size_t i=0;i<100;i++ )
116  for( size_t j=0;j<100;j++ ) {
117  h2D.Fill(i,j,payload->m_vec[i*100+j]);
118  }
119  h2D.SetStats(false);
120  }
121  }
122 
123  TCanvas c("c","",10,10,900,500);
124  c.cd();
125  c.SetLogz();
126  h2D.SetNdivisions(18, "X");
127  h2D.GetXaxis()->SetTickLength(0.00);
128  h2D.GetYaxis()->SetTickLength(0.00);
129  h2D.GetXaxis()->SetTitle("iphi");
130  h2D.GetYaxis()->SetTitle("ieta");
131  h2D.Draw("col");
132 
133  //======= drawing lines ========
135 
136  TLine l;
137  l.SetLineStyle(2);
138  l.DrawLine(0., ymax/2., xmax, ymax/2.);
139  for(int m = 0; m < int(xmax); m+=10) {
140  l.DrawLine(m, 0., m, 100.);
141  }
142 
143  c.RedrawAxis();
144 
145  //========== writing text in the canvas==============
147 
148  TLatex Tl;
149  TLatex Tll;
150  Tl.SetTextAlign(23);
151  Tl.SetTextSize(0.04);
152 
153  Tll.SetTextAlign(23);
154  Tll.SetTextSize(0.04);
155 
156  int j = 0;
157  for(int i = 1; i <=10; i++){
158  std::string s = "+" + std::to_string(i);
159  char const *pchar = s.c_str();
160  j+=10;
161  Tl.DrawLatex(j-5,int(ymax)/1.33,pchar);
162  }
163 
164  int z = 0;
165  for(int g = -10; g <0; g++){
166  std::string ss = std::to_string(g);
167  char const *pchar1 = ss.c_str();
168  z+= 10;
169  Tll.DrawLatex(z-5,int(ymax)/4,pchar1);
170  }
171  //=========================
172 
173  std::string fileName(m_imageFileName);
174  c.SaveAs(fileName.c_str());
175 
176  return true;
177  }
178  };
179 
180  class BasicPayload_data7 : public cond::payloadInspector::PlotImage<cond::BasicPayload> {
181  public:
182  BasicPayload_data7() : cond::payloadInspector::PlotImage<cond::BasicPayload>( "Example delivery picture" ){
183  setTwoTags( true );
184  }
185 
186  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
187  auto iov0 = iovs.front();
188  auto iov1 = iovs.back();
189  std::shared_ptr<cond::BasicPayload> payload0 = fetchPayload( std::get<1>(iov0) );
190  std::shared_ptr<cond::BasicPayload> payload1 = fetchPayload( std::get<1>(iov1) );
191 
192  double xmax(100.),ymax(100.);
193 
194  TH2D h2D("h2D","Example",100,0.,xmax,100,0.,ymax);
195 
196  if( payload0.get() && payload1.get() ){
197  if(payload0->m_vec.size()==10000 && payload1->m_vec.size()==10000 ){
198  for( size_t i=0;i<100;i++ )
199  for( size_t j=0;j<100;j++ ) {
200  auto diff = abs(payload0->m_vec[i*100+j] - payload1->m_vec[i*100+j]);
201  h2D.Fill(i,j,diff);
202  }
203  h2D.SetStats(false);
204  }
205  }
206 
207  TCanvas c("c","",20,20,900,500);
208  c.cd();
209  c.SetLogz();
210  h2D.SetNdivisions(18, "X");
211  h2D.GetXaxis()->SetTickLength(0.00);
212  h2D.GetYaxis()->SetTickLength(0.00);
213  h2D.GetXaxis()->SetTitle("iphi");
214  h2D.GetYaxis()->SetTitle("ieta");
215  h2D.Draw("col");
216 
217  //======= drawing lines ========
219 
220  TLine l;
221  l.SetLineStyle(2);
222  l.DrawLine(0., ymax/2., xmax, ymax/2.);
223  for(int m = 0; m < int(xmax); m+=10) {
224  l.DrawLine(m, 0., m, 100.);
225  }
226 
227  c.RedrawAxis();
228 
229  //========== writing text in the canvas==============
231 
232  TLatex Tl;
233  TLatex Tll;
234  Tl.SetTextAlign(23);
235  Tl.SetTextSize(0.04);
236 
237  Tll.SetTextAlign(23);
238  Tll.SetTextSize(0.04);
239 
240  int j = 0;
241  for(int i = 1; i <=10; i++){
242  std::string s = "+" + std::to_string(i);
243  char const *pchar = s.c_str();
244  j+=10;
245  Tl.DrawLatex(j-5,int(ymax)/1.33,pchar);
246  }
247 
248  int z = 0;
249  for(int g = -10; g <0; g++){
250  std::string ss = std::to_string(g);
251  char const *pchar1 = ss.c_str();
252  z+= 10;
253  Tll.DrawLatex(z-5,int(ymax)/4,pchar1);
254  }
255  //=========================
256 
257  std::string fileName(m_imageFileName);
258  c.SaveAs(fileName.c_str());
259 
260  return true;
261  }
262  };
263 
264 }
265 
266 PAYLOAD_INSPECTOR_MODULE( BasicPayload ){
267  PAYLOAD_INSPECTOR_CLASS( BasicPayload_data0 );
268  PAYLOAD_INSPECTOR_CLASS( BasicPayload_data1 );
269  PAYLOAD_INSPECTOR_CLASS( BasicPayload_data2 );
270  PAYLOAD_INSPECTOR_CLASS( BasicPayload_data3 );
271  PAYLOAD_INSPECTOR_CLASS( BasicPayload_data4 );
272  PAYLOAD_INSPECTOR_CLASS( BasicPayload_data5 );
273  PAYLOAD_INSPECTOR_CLASS( BasicPayload_data6 );
274  PAYLOAD_INSPECTOR_CLASS( BasicPayload_data7 );
275 }
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
virtual Y getFromPayload(PayloadType &payload)=0
Definition: plugin.cc:24