CMS 3D CMS Logo

DQMMessageLogger.cc
Go to the documentation of this file.
1 // system includes
2 #include <cmath>
3 #include <vector>
4 #include <string>
5 #include <map>
6 
7 // user includes
24 #include "TPad.h"
25 
26 using namespace std;
27 using namespace edm;
28 
30 public:
33 
35  ~DQMMessageLogger() override = default;
36 
38  void analyze(const edm::Event &, const edm::EventSetup &) override;
39 
40 protected:
41  void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
42 
43 private:
44  // ----------member data ---------------------------
45 
46  // Switch for verbosity
48 
49  std::map<std::string, int> moduleMap;
50  std::map<std::string, int> categoryMap;
51  std::map<std::string, int> categoryWCount;
52  std::map<std::string, int> categoryECount;
53  // from parameters
54  std::vector<std::string> categories_vector;
57 
58  //The histos
65 };
66 
68  categories_errors = nullptr;
69  categories_warnings = nullptr;
70  modules_errors = nullptr;
71  modules_warnings = nullptr;
72  total_errors = nullptr;
73  total_warnings = nullptr;
74 
75  //Get from cfg file
76  categories_vector = parameters.getParameter<vector<string> >("Categories");
77  directoryName = parameters.getParameter<string>("Directory");
78  errorSummary_ = consumes<std::vector<edm::ErrorSummaryEntry> >(
79  parameters.getUntrackedParameter<std::string>("errorSummary", "logErrorHarvester"));
80 }
81 
82 void DQMMessageLogger::bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &iRun, edm::EventSetup const &iSetup) {
83  metname = "errorAnalyzer";
84 
85  // MAKE CATEGORYMAP USING INPUT FROM CFG FILE
86  for (unsigned int i = 0; i < categories_vector.size(); i++) {
87  categoryMap.insert(pair<string, int>(categories_vector[i], i + 1));
88  }
89 
90  // MAKE MODULEMAP
92  using stringvec = vector<std::string>;
93  TNS tns;
94  stringvec const &trigpaths = tns->getTrigPaths();
95 
96  for (auto const &trigpath : trigpaths) {
97  stringvec strings = tns->getTrigPathModules(trigpath);
98 
99  for (auto &k : strings) {
100  moduleMap.insert(pair<string, int>(k, moduleMap.size() + 1));
101  }
102  }
103 
104  // BOOK THE HISTOGRAMS
105  LogTrace(metname) << "[DQMMessageLogger] Parameters initialization";
106 
107  if (!moduleMap.empty()) {
108  ibooker.setCurrentFolder(directoryName + "/Errors");
109  modules_errors = ibooker.book1D("modules_errors", "Errors per module", moduleMap.size(), 0, moduleMap.size());
110  ibooker.setCurrentFolder(directoryName + "/Warnings");
111 
112  modules_warnings = ibooker.book1D("modules_warnings", "Warnings per module", moduleMap.size(), 0, moduleMap.size());
113 
114  for (auto it = moduleMap.begin(); it != moduleMap.end(); ++it) {
115  modules_errors->setBinLabel((*it).second, (*it).first);
116  modules_warnings->setBinLabel((*it).second, (*it).first);
117  }
118  modules_errors->getTH1()->GetXaxis()->LabelsOption("v");
119  modules_warnings->getTH1()->GetXaxis()->LabelsOption("v");
120  }
121 
122  if (!categoryMap.empty()) {
123  ibooker.setCurrentFolder(directoryName + "/Errors");
124  categories_errors =
125  ibooker.book1D("categories_errors", "Errors per category", categoryMap.size(), 0, categoryMap.size());
126  ibooker.setCurrentFolder(directoryName + "/Warnings");
127  categories_warnings =
128  ibooker.book1D("categories_warnings", "Warnings per category", categoryMap.size(), 0, categoryMap.size());
129 
130  for (auto it = categoryMap.begin(); it != categoryMap.end(); ++it) {
131  categories_errors->setBinLabel((*it).second, (*it).first);
132  categories_warnings->setBinLabel((*it).second, (*it).first);
133  }
134  categories_warnings->getTH1()->GetXaxis()->LabelsOption("v");
135  categories_errors->getTH1()->GetXaxis()->LabelsOption("v");
136  }
137 
138  // HOW MANY BINS SHOULD THE ERROR HIST HAVE?
139  int nbins = 11;
140  total_warnings = ibooker.book1D("total_warnings", "Total warnings per event", nbins, -0.5, nbins + 0.5);
141  ibooker.setCurrentFolder(directoryName + "/Errors");
142  total_errors = ibooker.book1D("total_errors", "Total errors per event", nbins, -0.5, nbins + 0.5);
143 
144  for (int i = 0; i < nbins; ++i) {
145  stringstream out;
146  out << i;
147  string s = out.str();
148  total_errors->setBinLabel(i + 1, s);
149  total_warnings->setBinLabel(i + 1, s);
150  }
151 }
152 
153 void DQMMessageLogger::analyze(const Event &iEvent, const EventSetup &iSetup) {
154  LogTrace(metname) << "[DQMMessageLogger] Analysis of event # ";
155 
156  // Take the ErrorSummaryEntry container
158  iEvent.getByToken(errorSummary_, errors);
159  // Check that errors is valid
160  if (!errors.isValid()) {
161  return;
162  }
163  // Compare severity level of error with ELseveritylevel instance el : "-e" should be the lowest error
164  ELseverityLevel el(ELseverityLevel::ELsev_error);
165 
166  // Find the total number of errors in iEvent
167  if (errors->empty()) {
168  if (total_errors != nullptr) {
169  total_errors->Fill(0);
170  }
171  if (total_warnings != nullptr) {
172  total_warnings->Fill(0);
173  }
174  } else {
175  int e = 0;
176  int w = 0;
177  for (int i = 0, n = errors->size(); i < n; i++) {
178  if ((*errors)[i].severity.getLevel() < el.getLevel()) {
179  w += (*errors)[i].count;
180  } else {
181  e += (*errors)[i].count;
182  }
183  }
184  if (total_errors != nullptr) {
185  total_errors->Fill(e);
186  }
187  if (total_warnings != nullptr) {
188  total_warnings->Fill(w);
189  }
190  }
191 
192  for (int i = 0, n = errors->size(); i < n; i++) {
193  //cout << "Severity for error/warning: " << (*errors)[i].severity << " " <<(*errors)[i].module << endl;
194 
195  if (!errors->empty()) {
196  // IF THIS IS AN ERROR on the ELseverityLevel SCALE, FILL ERROR HISTS
197  if ((*errors)[i].severity.getLevel() >= el.getLevel()) {
198  if (categories_errors != nullptr) {
199  auto it = categoryMap.find((*errors)[i].category);
200  if (it != categoryMap.end()) {
201  // FILL THE RIGHT BIN
202  categories_errors->Fill((*it).second - 1, (*errors)[i].count);
203  }
204  }
205  // if (categoryECount.size()<=40)
206  // categoryECount[(*errors)[i].category]+=(*errors)[i].count;
207 
208  if (modules_errors != nullptr) {
209  // remove the first part of the module string, what is before ":"
210  string s = (*errors)[i].module;
211  size_t pos = s.find(':');
212  string s_temp = s.substr(pos + 1, s.size());
213  auto it = moduleMap.find(s_temp);
214  if (it != moduleMap.end()) {
215  // FILL THE RIGHT BIN
216  modules_errors->Fill((*it).second - 1, (*errors)[i].count);
217  }
218  }
219  // IF ONLY WARNING, FILL WARNING HISTS
220  } else {
221  if (categories_warnings != nullptr) {
222  auto it = categoryMap.find((*errors)[i].category);
223  if (it != categoryMap.end()) {
224  // FILL THE RIGHT BIN
225  categories_warnings->Fill((*it).second - 1, (*errors)[i].count);
226  }
227  }
228 
229  // if (categoryWCount.size()<=40)
230  // categoryWCount[(*errors)[i].category]+=(*errors)[i].count;
231 
232  if (modules_warnings != nullptr) {
233  // remove the first part of the module string, what is before ":"
234  string s = (*errors)[i].module;
235  size_t pos = s.find(':');
236  string s_temp = s.substr(pos + 1, s.size());
237  auto it = moduleMap.find(s_temp);
238  if (it != moduleMap.end()) {
239  // FILL THE RIGHT BIN
240  modules_warnings->Fill((*it).second - 1, (*errors)[i].count);
241  }
242  }
243  }
244  }
245  }
246 }
247 
std::map< std::string, int > categoryMap
MonitorElement * total_warnings
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
T w() const
const std::string metname
edm::EDGetTokenT< std::vector< edm::ErrorSummaryEntry > > errorSummary_
MonitorElement * total_errors
MonitorElement * modules_warnings
MonitorElement * categories_errors
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
#define LogTrace(id)
void analyze(const edm::Event &, const edm::EventSetup &) override
Get the analysis.
example_stream void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
int iEvent
Definition: GenABIO.cc:224
std::map< std::string, int > categoryECount
std::string directoryName
constexpr int getLevel() const noexcept
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::map< std::string, int > moduleMap
virtual void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
std::vector< std::string > categories_vector
MonitorElement * modules_errors
MonitorElement * categories_warnings
std::map< std::string, int > categoryWCount
HLT enums.
DQMMessageLogger(const edm::ParameterSet &)
Constructor.
Definition: errors.py:1
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: Run.h:45