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 }
good
const auto good
min quality of good
Definition: CAHitNtupletGeneratorKernelsImpl.h:760
cmsBatch.argv
argv
Definition: cmsBatch.py:279
CommandLineParser.h
mps_fire.i
i
Definition: mps_fire.py:428
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
main
int main(int argc, char **argv)
Definition: hcalLUT.cc:110
HcalGenericDetId
Definition: HcalGenericDetId.h:15
dir2webdir.argc
argc
Definition: dir2webdir.py:39
LutXml::create_lut_map
int create_lut_map(void)
Definition: LutXml.cc:338
XMLDOMBlock::write
int write(std::string target="stdout")
Definition: XMLDOMBlock.cc:272
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
gather_cfg.cout
cout
Definition: gather_cfg.py:144
writedatasetfile.parser
parser
Definition: writedatasetfile.py:7
SiPixelPI::zero
Definition: SiPixelPayloadInspectorHelper.h:39
detail
Definition: ConvertingESProducerWithDependenciesT.h:23
LutXml::end
const_iterator end() const
Definition: LutXml.cc:448
findQualityFiles.v
v
Definition: findQualityFiles.py:179
HcalLutManager::create_lut_loader
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)
Definition: HcalLutManager.cc:1543
FileInPath.h
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
edm::FileInPath
Definition: FileInPath.h:61
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
submitPVResolutionJobs.files
files
Definition: submitPVResolutionJobs.py:373
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:79
mergeLUTs
void mergeLUTs(const char *flist, const char *out)
Definition: hcalLUT.cc:11
LutXml::find
const_iterator find(uint32_t) const
Definition: LutXml.cc:450
geometryDiff.file
file
Definition: geometryDiff.py:13
dumpLutDiff
void dumpLutDiff(LutXml &xmls1, LutXml &xmls2, bool testFormat=true, int detail=0)
Definition: hcalLUT.cc:22
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
runTauDisplay.dtype
dtype
Definition: runTauDisplay.py:121
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HcalLutManager
Various manipulations with trigger Lookup Tables.
Definition: HcalLutManager.h:39
std
Definition: JetResolutionObject.h:76
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
or
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
dqmMemoryStats.total
total
Definition: dqmMemoryStats.py:152
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
ztail.d
d
Definition: ztail.py:151
LutXml
Definition: LutXml.h:27
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
HcalLutManager.h
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
optutl::CommandLineParser
Definition: CommandLineParser.h:10