CMS 3D CMS Logo

DropBoxMetadata_PayloadInspector.cc
Go to the documentation of this file.
1 
12 
13 // the data format of the condition to be inspected
16 
17 // helper classes
19 
20 // system includes
21 #include <memory>
22 #include <sstream>
23 #include <iostream>
24 #include <boost/algorithm/string/replace.hpp>
25 
26 // include ROOT
27 #include "TProfile.h"
28 #include "TH2F.h"
29 #include "TLegend.h"
30 #include "TCanvas.h"
31 #include "TLine.h"
32 #include "TStyle.h"
33 #include "TLatex.h"
34 #include "TPave.h"
35 #include "TPaveStats.h"
36 #include "TPaletteAxis.h"
37 
38 namespace {
39 
40  using namespace cond::payloadInspector;
41 
42  /************************************************
43  DropBoxMetadata Payload Inspector of 1 IOV
44  *************************************************/
45  class DropBoxMetadataTest : public Histogram1D<DropBoxMetadata, SINGLE_IOV> {
46  public:
47  DropBoxMetadataTest()
48  : Histogram1D<DropBoxMetadata, SINGLE_IOV>("Test DropBoxMetadata", "Test DropBoxMetadata", 1, 0.0, 1.0) {}
49 
50  bool fill() override {
51  auto tag = PlotBase::getTag<0>();
52  for (auto const& iov : tag.iovs) {
53  std::shared_ptr<DropBoxMetadata> payload = Base::fetchPayload(std::get<1>(iov));
54  if (payload.get()) {
55  std::vector<std::string> records = payload->getAllRecords();
56  for (const auto& record : records) {
57  edm::LogPrint("DropBoxMetadata_PayloadInspector") << "record: " << record << std::endl;
58  const auto& parameters = payload->getRecordParameters(record);
59  const auto& recordParams = parameters.getParameterMap();
60  for (const auto& [key, val] : recordParams) {
61  if (val.find("&quot;") != std::string::npos) {
62  const auto& replaced = replaceAll(val, std::string("&quot;"), std::string("'"));
63  edm::LogPrint("DropBoxMetadata_PayloadInspector") << key << " : " << replaced << std::endl;
64  } else {
65  edm::LogPrint("DropBoxMetadata_PayloadInspector") << key << " : " << val << std::endl;
66  }
67  }
68  }
69  }
70  }
71  return true;
72  }
73 
74  private:
76  size_t start_pos = 0;
77  while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
78  str.replace(start_pos, from.length(), to);
79  start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
80  }
81  return str;
82  }
83  };
84 
85  /************************************************
86  DropBoxMetadata Payload Inspector of 1 IOV
87  *************************************************/
88  class DropBoxMetadata_Display : public PlotImage<DropBoxMetadata, SINGLE_IOV> {
89  public:
90  DropBoxMetadata_Display() : PlotImage<DropBoxMetadata, SINGLE_IOV>("DropBoxMetadata Display of contents") {}
91 
92  bool fill() override {
93  auto tag = PlotBase::getTag<0>();
94  auto iov = tag.iovs.front();
95  std::shared_ptr<DropBoxMetadata> payload = fetchPayload(std::get<1>(iov));
96 
97  std::vector<std::string> records = payload->getAllRecords();
98 
99  DBoxMetadataHelper::recordMap theRecordMap;
100  for (const auto& record : records) {
101  edm::LogPrint("DropBoxMetadata_PayloadInspector") << "record: " << record << std::endl;
102  const auto& parameters = payload->getRecordParameters(record);
103  theRecordMap.insert(std::make_pair(record, DBoxMetadataHelper::RecordMetaDataInfo(parameters)));
104  }
105 
106  DBoxMetadataHelper::DBMetaDataTableDisplay theDisplay(theRecordMap);
107  theDisplay.printMetaDatas();
108 
109  DBoxMetadataHelper::DBMetaDataPlotDisplay thePlot(theRecordMap, tag.name, std::to_string(std::get<0>(iov)));
110  thePlot.setImageFileName(this->m_imageFileName);
111  thePlot.plotMetaDatas();
112 
113  return true;
114  }
115  };
116 
117  /************************************************
118  DropBoxMetadata Payload Comparator of 2 IOVs
119  *************************************************/
120  template <IOVMultiplicity nIOVs, int ntags>
121  class DropBoxMetadata_CompareBase : public PlotImage<DropBoxMetadata, nIOVs, ntags> {
122  public:
123  DropBoxMetadata_CompareBase()
124  : PlotImage<DropBoxMetadata, nIOVs, ntags>("DropBoxMetadata comparison of contents") {}
125 
126  bool fill() override {
127  // trick to deal with the multi-ioved tag and two tag case at the same time
128  auto theIOVs = PlotBase::getTag<0>().iovs;
129  auto f_tagname = PlotBase::getTag<0>().name;
130  std::string l_tagname = "";
131  auto firstiov = theIOVs.front();
132  std::tuple<cond::Time_t, cond::Hash> lastiov;
133 
134  // we don't support (yet) comparison with more than 2 tags
135  assert(this->m_plotAnnotations.ntags < 3);
136 
137  if (this->m_plotAnnotations.ntags == 2) {
138  auto tag2iovs = PlotBase::getTag<1>().iovs;
139  l_tagname = PlotBase::getTag<1>().name;
140  lastiov = tag2iovs.front();
141  } else {
142  lastiov = theIOVs.back();
143  }
144 
145  std::shared_ptr<DropBoxMetadata> last_payload = this->fetchPayload(std::get<1>(lastiov));
146  std::shared_ptr<DropBoxMetadata> first_payload = this->fetchPayload(std::get<1>(firstiov));
147 
148  std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
149  std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
150 
151  // first payload
152  std::vector<std::string> f_records = first_payload->getAllRecords();
153  DBoxMetadataHelper::recordMap f_theRecordMap;
154  for (const auto& record : f_records) {
155  //edm::LogPrint("DropBoxMetadata_PayloadInspector") << "record: " << record << std::endl;
156  const auto& parameters = first_payload->getRecordParameters(record);
157  f_theRecordMap.insert(std::make_pair(record, DBoxMetadataHelper::RecordMetaDataInfo(parameters)));
158  }
159 
160  DBoxMetadataHelper::DBMetaDataTableDisplay f_theDisplay(f_theRecordMap);
161  //f_theDisplay.printMetaDatas();
162 
163  // last payload
164  std::vector<std::string> l_records = last_payload->getAllRecords();
165  DBoxMetadataHelper::recordMap l_theRecordMap;
166  for (const auto& record : l_records) {
167  //edm::LogPrint("DropBoxMetadata_PayloadInspector") << "record: " << record << std::endl;
168  const auto& parameters = last_payload->getRecordParameters(record);
169  l_theRecordMap.insert(std::make_pair(record, DBoxMetadataHelper::RecordMetaDataInfo(parameters)));
170  }
171 
172  DBoxMetadataHelper::DBMetaDataTableDisplay l_theDisplay(l_theRecordMap);
173  //l_theDisplay.printMetaDatas();
174 
175  l_theDisplay.printDiffWithMetadata(f_theRecordMap);
176 
177  // In case of only one tag, use f_tagname for both target and reference
178  std::string tmpTagName = l_tagname;
179  if (tmpTagName.empty())
180  tmpTagName = f_tagname;
181  DBoxMetadataHelper::DBMetaDataPlotDisplay thePlot(l_theRecordMap, tmpTagName, lastIOVsince);
182  thePlot.setImageFileName(this->m_imageFileName);
183  thePlot.plotDiffWithMetadata(f_theRecordMap, f_tagname, firstIOVsince);
184 
185  return true;
186  }
187  };
188 
189  using DropBoxMetadata_Compare = DropBoxMetadata_CompareBase<MULTI_IOV, 1>;
190  using DropBoxMetadata_CompareTwoTags = DropBoxMetadata_CompareBase<SINGLE_IOV, 2>;
191 
192 } // namespace
193 
195  PAYLOAD_INSPECTOR_CLASS(DropBoxMetadataTest);
196  PAYLOAD_INSPECTOR_CLASS(DropBoxMetadata_Display);
197  PAYLOAD_INSPECTOR_CLASS(DropBoxMetadata_Compare);
198  PAYLOAD_INSPECTOR_CLASS(DropBoxMetadata_CompareTwoTags);
199 }
std::map< std::string, RecordMetaDataInfo > recordMap
assert(be >=bs)
static std::string to_string(const XMLCh *ch)
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
void replaceAll(std::string &str, const std::string &from, const std::string &to)
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
Log< level::Warning, true > LogPrint
#define str(s)