CMS 3D CMS Logo

hcalLUT.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <stdexcept>
3 #include <sstream>
4 #include "TString.h"
8 
9 using namespace std;
10 
11 void mergeLUTs(const char *flist, const char *out) {
12  LutXml xmls;
13  stringstream ss(flist);
14  while (ss.good()) {
15  string file;
16  ss >> file;
17  xmls += LutXml(file);
18  }
19  xmls.write(out);
20 }
21 
22 void dumpLutDiff(LutXml &xmls1, LutXml &xmls2, bool testFormat = true, int detail = 0) {
23  const int ndet = 5;
24  const char *DET[ndet] = {"HB", "HE", "HO", "HF", "HT"};
25  const int dtype[ndet] = {0, 1, 2, 3, 4};
26 
27  const int nvar = 4;
28  enum vtype { total, extra, zeros, match };
29 
30  std::array<int, nvar> n[ndet];
31 
32  for (auto &d : n) {
33  for (auto &v : d) {
34  v = 0;
35  }
36  }
37 
38  for (auto &x1 : xmls1) {
39  HcalGenericDetId id(x1.first);
40  auto x2 = xmls2.find(id.rawId());
41  auto subdet = id.genericSubdet();
42  if (subdet == 0 or subdet == 6)
43  continue; //'empty' or 'other'
44 
45  auto &m = n[subdet - 1];
46 
47  m[total]++;
48  if (x2 == xmls2.end()) {
49  m[extra]++;
50  if (testFormat)
51  cout << "Extra detId: " << id << endl;
52  else
53  continue;
54  }
55 
56  const auto &lut1 = x1.second;
57  size_t size = lut1.size();
58 
59  bool zero = true;
60  for (auto &i : lut1) {
61  if (i > 0) {
62  zero = false;
63  break;
64  }
65  }
66  if (zero) {
67  m[zeros]++;
68  if (detail == 1 and testFormat) {
69  cout << "Zero LUT: " << id << endl;
70  }
71  }
72 
73  if (testFormat)
74  continue;
75 
76  const auto &lut2 = x2->second;
77  bool good = size == lut2.size();
78  for (size_t i = 0; i < size and good; ++i) {
79  if (lut1[i] != lut2[i]) {
80  good = false;
81  if (detail == 2) {
82  cout << Form("Mismatach in index=%3d, %4d!=%4d, ", int(i), lut1[i], lut2[i]) << id << endl;
83  }
84  }
85  }
86  if (good)
87  m[match]++;
88  }
89 
90  if (testFormat) {
91  cout << Form("%3s: %8s %8s %8s", "Det", "total", "zeroes", "extra") << endl;
92  for (auto i : dtype)
93  cout << Form("%3s: %8d %8d %8d", DET[i], n[i][total], n[i][zeros], n[i][extra]) << endl;
94  cout << "--------------------------------------------" << endl;
95  } else {
96  bool good = true;
97  for (auto &d : n) {
98  if (d[total] != d[match]) {
99  good = false;
100  }
101  }
102  cout << Form("%3s: %8s %8s %8s", "Det", "total", "match", "mismatch") << endl;
103  for (auto i : dtype)
104  cout << Form("%3s: %8d %8d %8d", DET[i], n[i][total], n[i][match], n[i][total] - n[i][match]) << endl;
105  cout << "--------------------------------------------" << endl;
106  cout << (good ? "PASS!" : "FAIL!") << endl;
107  }
108 }
109 
110 int main(int argc, char **argv) {
111  optutl::CommandLineParser parser("runTestParameters");
112  parser.parseArguments(argc, argv, true);
113  if (argc < 2) {
114  std::cerr << "runTest: missing input command" << std::endl;
115  } else if (strcmp(argv[1], "merge") == 0) {
116  std::string flist_ = parser.stringValue("storePrepend");
117  std::string out_ = parser.stringValue("outputFile");
118  mergeLUTs(flist_.c_str(), out_.c_str());
119  } else if (strcmp(argv[1], "diff") == 0) {
120  auto files = parser.stringVector("inputFiles");
121  auto detail = parser.integerValue("section");
122 
123  LutXml xmls1(edm::FileInPath(files[0]).fullPath());
124  LutXml xmls2(edm::FileInPath(files[1]).fullPath());
125 
126  xmls1.create_lut_map();
127  xmls2.create_lut_map();
128 
129  cout << files[0] << endl;
130  dumpLutDiff(xmls1, xmls2, true, detail);
131 
132  cout << files[1] << endl;
133  dumpLutDiff(xmls2, xmls1, true, detail);
134 
135  cout << "Comparison" << endl;
136  dumpLutDiff(xmls1, xmls2, false, detail);
137  } else if (strcmp(argv[1], "create-lut-loader") == 0) {
138  std::string _file_list = parser.stringValue("outputFile");
139  std::string _tag = parser.stringValue("tag");
140  std::string _comment = parser.stringValue("storePrepend");
141  const std::string &_prefix = _tag;
142  std::string _version = "1";
143  int _subversion = 0;
144  HcalLutManager manager;
145  manager.create_lut_loader(_file_list, _prefix, _tag, _comment, _tag, _subversion);
146  } else {
147  throw std::invalid_argument(Form("Unknown command: %s", argv[1]));
148  }
149 
150  return 0;
151 }
size
Write out results.
Definition: LutXml.h:27
int write(std::string target="stdout")
Definition: XMLDOMBlock.cc:272
int main(int argc, char **argv)
Definition: hcalLUT.cc:110
int create_lut_map(void)
Definition: LutXml.cc:338
Various manipulations with trigger Lookup Tables.
const_iterator find(uint32_t) const
Definition: LutXml.cc:450
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< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
d
Definition: ztail.py:151
auto const good
min quality of good
int create_lut_loader(std::string file_list, std::string _prefix, std::string tag_name, std::string comment="default comment", std::string version="V00-01-01", int subversion=1)
const_iterator end() const
Definition: LutXml.cc:448
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
void dumpLutDiff(LutXml &xmls1, LutXml &xmls2, bool testFormat=true, int detail=0)
Definition: hcalLUT.cc:22
void mergeLUTs(const char *flist, const char *out)
Definition: hcalLUT.cc:11