CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DropBoxMetaDataPayloadInspectorHelper.h
Go to the documentation of this file.
1 #ifndef DropBoxMetaDataPayloadInspectorHelper_H
2 #define DropBoxMetaDataPayloadInspectorHelper_H
3 
4 #include "TH1.h"
5 #include "TH2.h"
6 #include "TStyle.h"
7 #include "TCanvas.h"
8 
9 #include <fmt/printf.h>
10 #include <fstream>
11 #include <boost/tokenizer.hpp>
12 #include <boost/range/adaptor/indexed.hpp>
15 
16 namespace DBoxMetadataHelper {
18  public:
21  const auto& theParameters = params.getParameterMap();
22  for (const auto& [key, val] : theParameters) {
23  if (key.find("prep") != std::string::npos) {
25  } else if (key.find("prod") != std::string::npos) {
27  } else if (key.find("mult") != std::string::npos) {
29  }
30  }
31  }
33  ~RecordMetaDataInfo() = default;
34 
35  public:
36  const std::string getPrepMetaData() const { return m_prepmetadata; }
37  const std::string getProdMetaData() const { return m_prodmetadata; }
38  const std::string getMultiMetaData() const { return m_multimetadata; }
39  const bool hasMultiMetaData() const { return !m_multimetadata.empty(); }
40 
41  private:
45  };
46 
47  using recordMap = std::map<std::string, RecordMetaDataInfo>;
48 
49  inline const std::vector<std::string> getAllRecords(const DBoxMetadataHelper::recordMap& recordSet) {
50  std::vector<std::string> records;
51  std::transform(recordSet.begin(),
52  recordSet.end(),
53  std::inserter(records, records.end()),
54  [](std::pair<std::string, DBoxMetadataHelper::RecordMetaDataInfo> recordSetEntry) -> std::string {
55  return recordSetEntry.first;
56  });
57  return records;
58  }
59 
60  inline std::vector<std::string> set_difference(std::vector<std::string> const& v1,
61  std::vector<std::string> const& v2) {
62  std::vector<std::string> diff;
63  std::set_difference(std::begin(v1), std::end(v1), std::begin(v2), std::end(v2), std::back_inserter(diff));
64  return diff;
65  }
66 
67  inline std::vector<std::string> set_intersection(std::vector<std::string> const& v1,
68  std::vector<std::string> const& v2) {
69  std::vector<std::string> common;
70  std::set_intersection(std::begin(v1), std::end(v1), std::begin(v2), std::end(v2), std::back_inserter(common));
71  return common;
72  }
73 
75  public:
77  ~DBMetaDataTableDisplay() = default;
78 
79  void printMetaDatas() {
80  for (const auto& [key, val] : m_Map) {
81  edm::LogPrint("DropBoxMetadataPIHelper") << "key: " << key << "\n\n" << std::endl;
82  edm::LogPrint("DropBoxMetadataPIHelper") << "prep: " << cleanJson(val.getPrepMetaData()) << "\n" << std::endl;
83  edm::LogPrint("DropBoxMetadataPIHelper") << "prod: " << cleanJson(val.getProdMetaData()) << "\n" << std::endl;
84  // check, since it's optional
85  if (val.hasMultiMetaData()) {
86  edm::LogPrint("DropBoxMetadataPIHelper") << "multi: " << cleanJson(val.getMultiMetaData()) << "\n"
87  << std::endl;
88  }
89  }
90  }
91 
93  edm::LogPrint("DropBoxMetadataPIHelper") << "prep: " << cleanJson(oneKey.getPrepMetaData()) << std::endl;
94  edm::LogPrint("DropBoxMetadataPIHelper") << "prod: " << cleanJson(oneKey.getProdMetaData()) << std::endl;
95  // check, since it's optional
96  if (oneKey.hasMultiMetaData()) {
97  edm::LogPrint("DropBoxMetadataPIHelper") << "multi: " << cleanJson(oneKey.getMultiMetaData()) << std::endl;
98  }
99  edm::LogPrint("DropBoxMetadataPIHelper") << "\n" << std::endl;
100  }
101 
103  edm::LogPrint("DropBoxMetadataPIHelper")
104  << "Target has: " << m_Map.size() << " records, reference has: " << theRefMap.size() << " records"
105  << std::endl;
106 
107  const auto& ref_records = DBoxMetadataHelper::getAllRecords(theRefMap);
108  const auto& tar_records = DBoxMetadataHelper::getAllRecords(m_Map);
109 
110  const auto& diff = DBoxMetadataHelper::set_difference(ref_records, tar_records);
111  const auto& common = DBoxMetadataHelper::set_intersection(ref_records, tar_records);
112 
113  // do first the common parts
114  for (const auto& key : common) {
115  edm::LogPrint("DropBoxMetadataPIHelper") << "key: " << key << "\n" << std::endl;
116  const auto& val = m_Map.at(key);
117  const auto& refval = theRefMap.at(key);
118 
119  if ((val.getPrepMetaData()).compare(refval.getPrepMetaData()) != 0) {
120  edm::LogPrint("DropBoxMetadataPIHelper") << "found difference in prep metadata!" << std::endl;
121  edm::LogPrint("DropBoxMetadataPIHelper") << " in target: " << cleanJson(val.getPrepMetaData()) << std::endl;
122  edm::LogPrint("DropBoxMetadataPIHelper")
123  << " in reference: " << cleanJson(refval.getPrepMetaData()) << std::endl;
124  }
125  if ((val.getProdMetaData()).compare(refval.getProdMetaData()) != 0) {
126  edm::LogPrint("DropBoxMetadataPIHelper") << "found difference in prod metadata!" << std::endl;
127  edm::LogPrint("DropBoxMetadataPIHelper") << " in target: " << cleanJson(val.getProdMetaData()) << std::endl;
128  edm::LogPrint("DropBoxMetadataPIHelper")
129  << " in reference: " << cleanJson(refval.getProdMetaData()) << std::endl;
130  }
131  if ((val.getMultiMetaData()).compare(refval.getMultiMetaData()) != 0) {
132  edm::LogPrint("DropBoxMetadataPIHelper") << "found difference in multi metadata!" << std::endl;
133  edm::LogPrint("DropBoxMetadataPIHelper") << " in target: " << cleanJson(val.getMultiMetaData()) << std::endl;
134  edm::LogPrint("DropBoxMetadataPIHelper")
135  << " in reference: " << cleanJson(refval.getMultiMetaData()) << std::endl;
136  }
137  edm::LogPrint("DropBoxMetadataPIHelper") << "\n" << std::endl;
138  }
139 
140  // if interesction is not the union check for extra differences
141  if (!diff.empty()) {
142  // check if the reference has more records than target
143  if (ref_records.size() > tar_records.size()) {
144  for (const auto& ref : ref_records) {
145  if (std::find(tar_records.begin(), tar_records.end(), ref) == tar_records.end()) {
146  const auto& refval = theRefMap.at(ref);
147  edm::LogPrint("DropBoxMetadataPIHelper") << "key: " << ref << " not present in target! \n" << std::endl;
148  printOneKey(refval);
149  }
150  }
151  }
152  // then check if the target has more records than the reference
153  else if (tar_records.size() > ref_records.size()) {
154  for (const auto& tar : tar_records) {
155  if (std::find(ref_records.begin(), ref_records.end(), tar) == ref_records.end()) {
156  const auto& tarval = m_Map.at(tar);
157  edm::LogPrint("DropBoxMetadataPIHelper") << "key: " << tar << " not present in reference! \n"
158  << std::endl;
159  printOneKey(tarval);
160  }
161  }
162  }
163  }
164  }
165 
166  private:
168 
170  size_t start_pos = 0;
171  while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
172  str.replace(start_pos, from.length(), to);
173  start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
174  }
175  return str;
176  }
177 
179  std::string out = replaceAll(str, std::string("&quot;"), std::string("'"));
180  return out;
181  }
182  };
183 } // namespace DBoxMetadataHelper
184 #endif
bool compare(const P &i, const P &j)
std::string replaceAll(std::string str, const std::string &from, const std::string &to)
const std::vector< std::string > getAllRecords(const DBoxMetadataHelper::recordMap &recordSet)
std::map< std::string, RecordMetaDataInfo > recordMap
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
DBMetaDataTableDisplay(DBoxMetadataHelper::recordMap theMap)
const std::map< std::string, std::string > & getParameterMap() const
tuple key
prepare the HTCondor submission files and eventually submit them
void printDiffWithMetadata(const DBoxMetadataHelper::recordMap &theRefMap)
Log< level::Warning, true > LogPrint
RecordMetaDataInfo(DropBoxMetadata::Parameters params)
Constructor.
void printOneKey(const DBoxMetadataHelper::RecordMetaDataInfo &oneKey)
string end
Definition: dataset.py:937
~RecordMetaDataInfo()=default
Destructor.
#define str(s)
std::vector< std::string > set_difference(std::vector< std::string > const &v1, std::vector< std::string > const &v2)
std::vector< std::string > set_intersection(std::vector< std::string > const &v1, std::vector< std::string > const &v2)
unsigned transform(const HcalDetId &id, unsigned transformCode)