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  virtual ~BasicPayload_data0() = default;
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  virtual ~BasicPayload_data1() = default;
31  float getFromPayload( cond::BasicPayload& payload ){
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  virtual ~BasicPayload_data2() = default;
41 
42  float getFromPayload( cond::BasicPayload& payload ){
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  virtual ~BasicPayload_data3() = default;
52 
53  std::tuple<float,float> getFromPayload( cond::BasicPayload& payload ){
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  virtual ~BasicPayload_data4() = default;
64 
65  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ){
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  virtual ~BasicPayload_data5() = default;
84 
85  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ){
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 ){
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(0);
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 }
181 
182 PAYLOAD_INSPECTOR_MODULE( BasicPayload ){
183  PAYLOAD_INSPECTOR_CLASS( BasicPayload_data0 );
184  PAYLOAD_INSPECTOR_CLASS( BasicPayload_data1 );
185  PAYLOAD_INSPECTOR_CLASS( BasicPayload_data2 );
186  PAYLOAD_INSPECTOR_CLASS( BasicPayload_data3 );
187  PAYLOAD_INSPECTOR_CLASS( BasicPayload_data4 );
188  PAYLOAD_INSPECTOR_CLASS( BasicPayload_data5 );
189  PAYLOAD_INSPECTOR_CLASS( BasicPayload_data6 );
190 }
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)
payload
payload postfix for testing
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
virtual Y getFromPayload(PayloadType &payload)=0
Definition: plugin.cc:24