File indexing completed on 2024-04-06 12:01:53
0001 #include "CondCore/Utilities/interface/PayloadInspectorModule.h"
0002 #include "CondCore/Utilities/interface/PayloadInspector.h"
0003 #include "CondFormats/Common/interface/BasicPayload.h"
0004 #include "CondCore/CondDB/interface/Time.h"
0005 #include "CondCore/CondDB/interface/PayloadReader.h"
0006 #include <memory>
0007 #include <sstream>
0008
0009 #include "TH2D.h"
0010 #include "TCanvas.h"
0011 #include "TLine.h"
0012 #include "TLatex.h"
0013
0014 namespace {
0015
0016 class BasicPayload_data0 : public cond::payloadInspector::HistoryPlot<cond::BasicPayload, float> {
0017 public:
0018 BasicPayload_data0() : cond::payloadInspector::HistoryPlot<cond::BasicPayload, float>("Example Trend", "data0") {}
0019 ~BasicPayload_data0() override = default;
0020 float getFromPayload(cond::BasicPayload& payload) override { return payload.m_data0; }
0021 };
0022
0023 class BasicPayload_data0_withInput : public cond::payloadInspector::HistoryPlot<cond::BasicPayload, float> {
0024 public:
0025 BasicPayload_data0_withInput()
0026 : cond::payloadInspector::HistoryPlot<cond::BasicPayload, float>("Example Trend", "data0") {
0027 cond::payloadInspector::PlotBase::addInputParam("Offset");
0028 cond::payloadInspector::PlotBase::addInputParam("Factor");
0029 cond::payloadInspector::PlotBase::addInputParam("Scale");
0030 }
0031 ~BasicPayload_data0_withInput() override = default;
0032 float getFromPayload(cond::BasicPayload& payload) override {
0033 float v = payload.m_data0;
0034 auto paramValues = cond::payloadInspector::PlotBase::inputParamValues();
0035 auto ip = paramValues.find("Factor");
0036 if (ip != paramValues.end()) {
0037 v = v * std::stof(ip->second);
0038 }
0039 ip = paramValues.find("Offset");
0040 if (ip != paramValues.end()) {
0041 v = v + std::stof(ip->second);
0042 }
0043 ip = paramValues.find("Scale");
0044 if (ip != paramValues.end()) {
0045 v = v * std::stof(ip->second);
0046 }
0047 return v;
0048 }
0049 };
0050
0051 class BasicPayload_data1 : public cond::payloadInspector::RunHistoryPlot<cond::BasicPayload, float> {
0052 public:
0053 BasicPayload_data1()
0054 : cond::payloadInspector::RunHistoryPlot<cond::BasicPayload, float>("Example Run-based Trend", "data0") {}
0055 ~BasicPayload_data1() override = default;
0056 float getFromPayload(cond::BasicPayload& payload) override { return payload.m_data0; }
0057 };
0058
0059 class BasicPayload_data2 : public cond::payloadInspector::TimeHistoryPlot<cond::BasicPayload, float> {
0060 public:
0061 BasicPayload_data2()
0062 : cond::payloadInspector::TimeHistoryPlot<cond::BasicPayload, float>("Example Time-based Trend", "data0") {}
0063 ~BasicPayload_data2() override = default;
0064
0065 float getFromPayload(cond::BasicPayload& payload) override { return payload.m_data0; }
0066 };
0067
0068 class BasicPayload_data3 : public cond::payloadInspector::ScatterPlot<cond::BasicPayload, float, float> {
0069 public:
0070 BasicPayload_data3()
0071 : cond::payloadInspector::ScatterPlot<cond::BasicPayload, float, float>("Example Scatter", "data0", "data1") {}
0072 ~BasicPayload_data3() override = default;
0073
0074 std::tuple<float, float> getFromPayload(cond::BasicPayload& payload) override {
0075 return std::make_tuple(payload.m_data0, payload.m_data1);
0076 }
0077 };
0078
0079 class BasicPayload_data4 : public cond::payloadInspector::Histogram1D<cond::BasicPayload> {
0080 public:
0081 BasicPayload_data4() : cond::payloadInspector::Histogram1D<cond::BasicPayload>("Example Histo1d", "x", 10, 0, 10) {
0082 Base::setSingleIov(true);
0083 }
0084 ~BasicPayload_data4() override = default;
0085
0086 bool fill() override {
0087 auto tag = PlotBase::getTag<0>();
0088 for (auto iov : tag.iovs) {
0089 std::shared_ptr<cond::BasicPayload> payload = Base::fetchPayload(std::get<1>(iov));
0090 if (payload.get()) {
0091 for (size_t j = 0; j < 100; j++) {
0092 fillWithValue(j, payload->m_vec[j]);
0093 }
0094 }
0095 }
0096 return true;
0097 }
0098 };
0099
0100 class BasicPayload_data5
0101 : public cond::payloadInspector::Histogram2D<cond::BasicPayload, cond::payloadInspector::SINGLE_IOV> {
0102 public:
0103 BasicPayload_data5()
0104 : cond::payloadInspector::Histogram2D<cond::BasicPayload, cond::payloadInspector::SINGLE_IOV>(
0105 "Example Histo2d", "x", 10, 0, 10, "y", 10, 0, 10) {}
0106 ~BasicPayload_data5() override = default;
0107
0108 bool fill() override {
0109 auto tag = PlotBase::getTag<0>();
0110 for (auto iov : tag.iovs) {
0111 std::shared_ptr<cond::BasicPayload> payload = Base::fetchPayload(std::get<1>(iov));
0112 if (payload.get()) {
0113 for (size_t i = 0; i < 10; i++)
0114 for (size_t j = 0; j < 10; j++) {
0115 fillWithValue(j, i, payload->m_vec[i * 10 + j]);
0116 }
0117 }
0118 }
0119 return true;
0120 }
0121 };
0122
0123 class BasicPayload_data6
0124 : public cond::payloadInspector::PlotImage<cond::BasicPayload, cond::payloadInspector::SINGLE_IOV> {
0125 public:
0126 BasicPayload_data6()
0127 : cond::payloadInspector::PlotImage<cond::BasicPayload, cond::payloadInspector::SINGLE_IOV>(
0128 "Example delivery picture") {}
0129
0130 bool fill() override {
0131 auto tag = PlotBase::getTag<0>();
0132 auto iov = tag.iovs.front();
0133 std::shared_ptr<cond::BasicPayload> payload = fetchPayload(std::get<1>(iov));
0134
0135 double xmax(100.), ymax(100.);
0136
0137 TH2D h2D("h2D", "Example", 100, 0., xmax, 100, 0., ymax);
0138
0139 if (payload.get()) {
0140 if (payload->m_vec.size() == 10000) {
0141 for (size_t i = 0; i < 100; i++)
0142 for (size_t j = 0; j < 100; j++) {
0143 h2D.Fill(i, j, payload->m_vec[i * 100 + j]);
0144 }
0145 h2D.SetStats(false);
0146 }
0147 }
0148
0149 TCanvas c("c", "", 10, 10, 900, 500);
0150 c.cd();
0151 c.SetLogz();
0152 h2D.SetNdivisions(18, "X");
0153 h2D.GetXaxis()->SetTickLength(0.00);
0154 h2D.GetYaxis()->SetTickLength(0.00);
0155 h2D.GetXaxis()->SetTitle("iphi");
0156 h2D.GetYaxis()->SetTitle("ieta");
0157 h2D.Draw("col");
0158
0159
0160
0161
0162 TLine l;
0163 l.SetLineStyle(2);
0164 l.DrawLine(0., ymax / 2., xmax, ymax / 2.);
0165 for (int m = 0; m < int(xmax); m += 10) {
0166 l.DrawLine(m, 0., m, 100.);
0167 }
0168
0169 c.RedrawAxis();
0170
0171
0172
0173
0174 TLatex Tl;
0175 TLatex Tll;
0176 Tl.SetTextAlign(23);
0177 Tl.SetTextSize(0.04);
0178
0179 Tll.SetTextAlign(23);
0180 Tll.SetTextSize(0.04);
0181
0182 int j = 0;
0183 for (int i = 1; i <= 10; i++) {
0184 std::string s = "+" + std::to_string(i);
0185 char const* pchar = s.c_str();
0186 j += 10;
0187 Tl.DrawLatex(j - 5, int(ymax) / 1.33, pchar);
0188 }
0189
0190 int z = 0;
0191 for (int g = -10; g < 0; g++) {
0192 std::string ss = std::to_string(g);
0193 char const* pchar1 = ss.c_str();
0194 z += 10;
0195 Tll.DrawLatex(z - 5, int(ymax) / 4, pchar1);
0196 }
0197
0198
0199 std::string fileName(m_imageFileName);
0200 c.SaveAs(fileName.c_str());
0201
0202 return true;
0203 }
0204 };
0205
0206 class BasicPayload_data7 : public cond::payloadInspector::PlotImage<cond::BasicPayload> {
0207 public:
0208 BasicPayload_data7() : cond::payloadInspector::PlotImage<cond::BasicPayload>("Example delivery picture") {
0209 setTwoTags(true);
0210 }
0211
0212 bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash>>& iovs) override {
0213 auto iov0 = iovs.front();
0214 auto iov1 = iovs.back();
0215 std::shared_ptr<cond::BasicPayload> payload0 = fetchPayload(std::get<1>(iov0));
0216 std::shared_ptr<cond::BasicPayload> payload1 = fetchPayload(std::get<1>(iov1));
0217
0218 double xmax(100.), ymax(100.);
0219
0220 TH2D h2D("h2D", "Example", 100, 0., xmax, 100, 0., ymax);
0221
0222 if (payload0.get() && payload1.get()) {
0223 if (payload0->m_vec.size() == 10000 && payload1->m_vec.size() == 10000) {
0224 for (size_t i = 0; i < 100; i++)
0225 for (size_t j = 0; j < 100; j++) {
0226 auto diff = abs(payload0->m_vec[i * 100 + j] - payload1->m_vec[i * 100 + j]);
0227 h2D.Fill(i, j, diff);
0228 }
0229 h2D.SetStats(false);
0230 }
0231 }
0232
0233 TCanvas c("c", "", 20, 20, 900, 500);
0234 c.cd();
0235 c.SetLogz();
0236 h2D.SetNdivisions(18, "X");
0237 h2D.GetXaxis()->SetTickLength(0.00);
0238 h2D.GetYaxis()->SetTickLength(0.00);
0239 h2D.GetXaxis()->SetTitle("iphi");
0240 h2D.GetYaxis()->SetTitle("ieta");
0241 h2D.Draw("col");
0242
0243
0244
0245
0246 TLine l;
0247 l.SetLineStyle(2);
0248 l.DrawLine(0., ymax / 2., xmax, ymax / 2.);
0249 for (int m = 0; m < int(xmax); m += 10) {
0250 l.DrawLine(m, 0., m, 100.);
0251 }
0252
0253 c.RedrawAxis();
0254
0255
0256
0257
0258 TLatex Tl;
0259 TLatex Tll;
0260 Tl.SetTextAlign(23);
0261 Tl.SetTextSize(0.04);
0262
0263 Tll.SetTextAlign(23);
0264 Tll.SetTextSize(0.04);
0265
0266 int j = 0;
0267 for (int i = 1; i <= 10; i++) {
0268 std::string s = "+" + std::to_string(i);
0269 char const* pchar = s.c_str();
0270 j += 10;
0271 Tl.DrawLatex(j - 5, int(ymax) / 1.33, pchar);
0272 }
0273
0274 int z = 0;
0275 for (int g = -10; g < 0; g++) {
0276 std::string ss = std::to_string(g);
0277 char const* pchar1 = ss.c_str();
0278 z += 10;
0279 Tll.DrawLatex(z - 5, int(ymax) / 4, pchar1);
0280 }
0281
0282
0283 std::string fileName(m_imageFileName);
0284 c.SaveAs(fileName.c_str());
0285
0286 return true;
0287 }
0288 };
0289
0290 }
0291
0292 PAYLOAD_INSPECTOR_MODULE(BasicPayload) {
0293 PAYLOAD_INSPECTOR_CLASS(BasicPayload_data0);
0294 PAYLOAD_INSPECTOR_CLASS(BasicPayload_data0_withInput);
0295 PAYLOAD_INSPECTOR_CLASS(BasicPayload_data1);
0296 PAYLOAD_INSPECTOR_CLASS(BasicPayload_data2);
0297 PAYLOAD_INSPECTOR_CLASS(BasicPayload_data3);
0298 PAYLOAD_INSPECTOR_CLASS(BasicPayload_data4);
0299 PAYLOAD_INSPECTOR_CLASS(BasicPayload_data5);
0300 PAYLOAD_INSPECTOR_CLASS(BasicPayload_data6);
0301 PAYLOAD_INSPECTOR_CLASS(BasicPayload_data7);
0302 }