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