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  const int HBandHE_fgBits = 0xFC00;
27 
28  const int nvar = 5;
29  enum vtype { total, extra, zeros, match, fgMatch };
30 
31  std::array<int, nvar> n[ndet];
32 
33  for (auto &d : n) {
34  for (auto &v : d) {
35  v = 0;
36  }
37  }
38 
39  for (auto &x1 : xmls1) {
40  HcalGenericDetId id(x1.first);
41  auto x2 = xmls2.find(id.rawId());
42  auto subdet = id.genericSubdet();
43  if (subdet == 0 or subdet == 6)
44  continue; //'empty' or 'other'
45 
46  auto &m = n[subdet - 1];
47 
48  m[total]++;
49  if (x2 == xmls2.end()) {
50  m[extra]++;
51  if (testFormat)
52  cout << "Extra detId: " << id << endl;
53  else
54  continue;
55  }
56 
57  const auto &lut1 = x1.second;
58  size_t size = lut1.size();
59 
60  bool zero = true;
61  for (auto &i : lut1) {
62  if (i > 0) {
63  zero = false;
64  break;
65  }
66  }
67  if (zero) {
68  m[zeros]++;
69  if (detail == 1 and testFormat) {
70  cout << "Zero LUT: " << id << endl;
71  }
72  }
73 
74  if (testFormat)
75  continue;
76 
77  const auto &lut2 = x2->second;
78  bool good = size == lut2.size();
79  bool fgGood = size == lut2.size();
80  for (size_t i = 0; i < size and (good or fgGood); ++i) {
81  if (lut1[i] != lut2[i]) {
82  good = false;
83  //Only check fine grain bits in HB and HE
84  if (subdet == 1 || subdet == 2) {
85  if ((lut1[i] & HBandHE_fgBits) != (lut2[i] & HBandHE_fgBits))
86  fgGood = false;
87  }
88  if (detail == 2) {
89  cout << Form("Mismatach in index=%3d, %4d!=%4d, ", int(i), lut1[i], lut2[i]) << id << endl;
90  }
91  }
92  }
93  if (good)
94  m[match]++;
95  if (fgGood)
96  m[fgMatch]++;
97  }
98 
99  if (testFormat) {
100  cout << Form("%3s: %8s %8s %8s", "Det", "total", "zeroes", "extra") << endl;
101  for (auto i : dtype)
102  cout << Form("%3s: %8d %8d %8d", DET[i], n[i][total], n[i][zeros], n[i][extra]) << endl;
103  cout << "--------------------------------------------" << endl;
104  } else {
105  bool good = true;
106  for (auto &d : n) {
107  if (d[total] != d[match]) {
108  good = false;
109  }
110  }
111  cout << Form("%3s: %8s %8s %8s %8s %8s", "Det", "total", "match", "mismatch", "FG match", "FG mismatch")
112  << endl;
113  for (auto i : dtype)
114  cout << Form("%3s: %8d %8d %8d %8d %8d",
115  DET[i],
116  n[i][total],
117  n[i][match],
118  n[i][total] - n[i][match],
119  n[i][fgMatch],
120  n[i][total] - n[i][fgMatch])
121  << endl;
122  cout << "--------------------------------------------" << endl;
123  cout << (good ? "PASS!" : "FAIL!") << endl;
124  }
125 }
126 
127 int main(int argc, char **argv) {
128  optutl::CommandLineParser parser("runTestParameters");
129  parser.parseArguments(argc, argv, true);
130  if (argc < 2) {
131  std::cerr << "runTest: missing input command" << std::endl;
132  } else if (strcmp(argv[1], "merge") == 0) {
133  std::string flist_ = parser.stringValue("storePrepend");
134  std::string out_ = parser.stringValue("outputFile");
135  mergeLUTs(flist_.c_str(), out_.c_str());
136  } else if (strcmp(argv[1], "diff") == 0) {
137  auto files = parser.stringVector("inputFiles");
138  auto detail = parser.integerValue("section");
139 
140  LutXml xmls1(edm::FileInPath(files[0]).fullPath());
141  LutXml xmls2(edm::FileInPath(files[1]).fullPath());
142 
143  xmls1.create_lut_map();
144  xmls2.create_lut_map();
145 
146  cout << files[0] << endl;
147  dumpLutDiff(xmls1, xmls2, true, detail);
148 
149  cout << files[1] << endl;
150  dumpLutDiff(xmls2, xmls1, true, detail);
151 
152  cout << "Comparison" << endl;
153  dumpLutDiff(xmls1, xmls2, false, detail);
154  } else if (strcmp(argv[1], "create-lut-loader") == 0) {
155  std::string _file_list = parser.stringValue("outputFile");
156  std::string _tag = parser.stringValue("tag");
157  std::string _comment = parser.stringValue("storePrepend");
158  const std::string &_prefix = _tag;
159  std::string _version = "1";
160  int _subversion = 0;
161  HcalLutManager manager;
162  manager.create_lut_loader(_file_list, _prefix, _tag, _comment, _tag, _subversion);
163  } else {
164  throw std::invalid_argument(Form("Unknown command: %s", argv[1]));
165  }
166 
167  return 0;
168 }
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:127
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
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
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