CMS 3D CMS Logo

DQMMessageLogger.cc
Go to the documentation of this file.
1 
2 
3 #include "DQMMessageLogger.h"
25 #include "TPad.h"
26 #include <cmath>
27 
28 using namespace std;
29 using namespace edm;
30 
32  categories_errors = nullptr;
33  categories_warnings = nullptr;
34  modules_errors = nullptr;
35  modules_warnings = nullptr;
36  total_errors = nullptr;
37  total_warnings = nullptr;
38 
39  //Get from cfg file
40  categories_vector = parameters.getParameter<vector<string> >("Categories");
41  directoryName = parameters.getParameter<string>("Directory");
42  errorSummary_ = consumes<std::vector<edm::ErrorSummaryEntry> >(
43  parameters.getUntrackedParameter<std::string>("errorSummary", "logErrorHarvester"));
44 }
45 
47  // Should the pointers be deleted?
48 }
49 
50 void DQMMessageLogger::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) {
51  metname = "errorAnalyzer";
52 
53  // MAKE CATEGORYMAP USING INPUT FROM CFG FILE
54  for (unsigned int i = 0; i < categories_vector.size(); i++) {
55  categoryMap.insert(pair<string, int>(categories_vector[i], i + 1));
56  }
57 
58  // MAKE MODULEMAP
60  using stringvec = vector<std::string>;
61  TNS tns;
62  stringvec const& trigpaths = tns->getTrigPaths();
63 
64  for (auto const& trigpath : trigpaths) {
65  stringvec strings = tns->getTrigPathModules(trigpath);
66 
67  for (auto& k : strings) {
68  moduleMap.insert(pair<string, int>(k, moduleMap.size() + 1));
69  }
70  }
71 
72  // BOOK THE HISTOGRAMS
73  LogTrace(metname) << "[DQMMessageLogger] Parameters initialization";
74 
75  if (!moduleMap.empty()) {
76  ibooker.setCurrentFolder(directoryName + "/Errors");
77  modules_errors = ibooker.book1D("modules_errors", "Errors per module", moduleMap.size(), 0, moduleMap.size());
78  ibooker.setCurrentFolder(directoryName + "/Warnings");
79 
80  modules_warnings = ibooker.book1D("modules_warnings", "Warnings per module", moduleMap.size(), 0, moduleMap.size());
81 
82  for (auto it = moduleMap.begin(); it != moduleMap.end(); ++it) {
83  modules_errors->setBinLabel((*it).second, (*it).first);
84  modules_warnings->setBinLabel((*it).second, (*it).first);
85  }
86  modules_errors->getTH1()->GetXaxis()->LabelsOption("v");
87  modules_warnings->getTH1()->GetXaxis()->LabelsOption("v");
88  }
89 
90  if (!categoryMap.empty()) {
91  ibooker.setCurrentFolder(directoryName + "/Errors");
92  categories_errors =
93  ibooker.book1D("categories_errors", "Errors per category", categoryMap.size(), 0, categoryMap.size());
94  ibooker.setCurrentFolder(directoryName + "/Warnings");
95  categories_warnings =
96  ibooker.book1D("categories_warnings", "Warnings per category", categoryMap.size(), 0, categoryMap.size());
97 
98  for (auto it = categoryMap.begin(); it != categoryMap.end(); ++it) {
99  categories_errors->setBinLabel((*it).second, (*it).first);
100  categories_warnings->setBinLabel((*it).second, (*it).first);
101  }
102  categories_warnings->getTH1()->GetXaxis()->LabelsOption("v");
103  categories_errors->getTH1()->GetXaxis()->LabelsOption("v");
104  }
105 
106  // HOW MANY BINS SHOULD THE ERROR HIST HAVE?
107  int nbins = 11;
108  total_warnings = ibooker.book1D("total_warnings", "Total warnings per event", nbins, -0.5, nbins + 0.5);
109  ibooker.setCurrentFolder(directoryName + "/Errors");
110  total_errors = ibooker.book1D("total_errors", "Total errors per event", nbins, -0.5, nbins + 0.5);
111 
112  for (int i = 0; i < nbins; ++i) {
113  stringstream out;
114  out << i;
115  string s = out.str();
116  total_errors->setBinLabel(i + 1, s);
117  total_warnings->setBinLabel(i + 1, s);
118  }
119 }
120 
121 void DQMMessageLogger::analyze(const Event& iEvent, const EventSetup& iSetup) {
122  LogTrace(metname) << "[DQMMessageLogger] Analysis of event # ";
123 
124  // Take the ErrorSummaryEntry container
126  iEvent.getByToken(errorSummary_, errors);
127  // Check that errors is valid
128  if (!errors.isValid()) {
129  return;
130  }
131  // Compare severity level of error with ELseveritylevel instance el : "-e" should be the lowest error
132  ELseverityLevel el("-e");
133 
134  // Find the total number of errors in iEvent
135  if (errors->empty()) {
136  if (total_errors != nullptr) {
137  total_errors->Fill(0);
138  }
139  if (total_warnings != nullptr) {
140  total_warnings->Fill(0);
141  }
142  } else {
143  int e = 0;
144  int w = 0;
145  for (int i = 0, n = errors->size(); i < n; i++) {
146  if ((*errors)[i].severity.getLevel() < el.getLevel()) {
147  w += (*errors)[i].count;
148  } else {
149  e += (*errors)[i].count;
150  }
151  }
152  if (total_errors != nullptr) {
153  total_errors->Fill(e);
154  }
155  if (total_warnings != nullptr) {
156  total_warnings->Fill(w);
157  }
158  }
159 
160  for (int i = 0, n = errors->size(); i < n; i++) {
161  //cout << "Severity for error/warning: " << (*errors)[i].severity << " " <<(*errors)[i].module << endl;
162 
163  if (!errors->empty()) {
164  // IF THIS IS AN ERROR on the ELseverityLevel SCALE, FILL ERROR HISTS
165  if ((*errors)[i].severity.getLevel() >= el.getLevel()) {
166  if (categories_errors != nullptr) {
167  auto it = categoryMap.find((*errors)[i].category);
168  if (it != categoryMap.end()) {
169  // FILL THE RIGHT BIN
170  categories_errors->Fill((*it).second - 1, (*errors)[i].count);
171  }
172  }
173  // if (categoryECount.size()<=40)
174  // categoryECount[(*errors)[i].category]+=(*errors)[i].count;
175 
176  if (modules_errors != nullptr) {
177  // remove the first part of the module string, what is before ":"
178  string s = (*errors)[i].module;
179  size_t pos = s.find(':');
180  string s_temp = s.substr(pos + 1, s.size());
181  auto it = moduleMap.find(s_temp);
182  if (it != moduleMap.end()) {
183  // FILL THE RIGHT BIN
184  modules_errors->Fill((*it).second - 1, (*errors)[i].count);
185  }
186  }
187  // IF ONLY WARNING, FILL WARNING HISTS
188  } else {
189  if (categories_warnings != nullptr) {
190  auto it = categoryMap.find((*errors)[i].category);
191  if (it != categoryMap.end()) {
192  // FILL THE RIGHT BIN
193  categories_warnings->Fill((*it).second - 1, (*errors)[i].count);
194  }
195  }
196 
197  // if (categoryWCount.size()<=40)
198  // categoryWCount[(*errors)[i].category]+=(*errors)[i].count;
199 
200  if (modules_warnings != nullptr) {
201  // remove the first part of the module string, what is before ":"
202  string s = (*errors)[i].module;
203  size_t pos = s.find(':');
204  string s_temp = s.substr(pos + 1, s.size());
205  auto it = moduleMap.find(s_temp);
206  if (it != moduleMap.end()) {
207  // FILL THE RIGHT BIN
208  modules_warnings->Fill((*it).second - 1, (*errors)[i].count);
209  }
210  }
211  }
212  }
213  }
214 }
taus_updatedMVAIds_cff.category
category
Definition: taus_updatedMVAIds_cff.py:30
Handle.h
edm::ELseverityLevel::getLevel
int getLevel() const
Definition: ELseverityLevel.cc:123
DQMMessageLogger.h
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
Handle.h
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
TriggerNamesService.h
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
pos
Definition: PixelAliasList.h:18
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
Algorithms.h
MessageLogger_cfi.errors
errors
Definition: MessageLogger_cfi.py:18
DQMStore.h
EDAnalyzer.h
edm::Handle
Definition: AssociativeIterator.h:50
parameters
parameters
Definition: BeamSpot_PayloadInspector.cc:14
nano_cff.strings
strings
Definition: nano_cff.py:28
MakerMacros.h
alignCSCRings.s
s
Definition: alignCSCRings.py:92
errors
Definition: errors.py:1
Service.h
w
const double w
Definition: UKUtility.cc:23
LaserClient_cfi.nbins
nbins
Definition: LaserClient_cfi.py:51
ErrorSummaryEntry.h
dqmdumpme.k
k
Definition: dqmdumpme.py:60
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
edm::Service
Definition: Service.h:30
iEvent
int iEvent
Definition: GenABIO.cc:224
dqm::impl::MonitorElement::setBinLabel
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)
Definition: MonitorElement.cc:771
edm::EventSetup
Definition: EventSetup.h:57
DQMMessageLogger::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: DQMMessageLogger.cc:50
ELseverityLevel.h
Registry.h
DQMMessageLogger::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Get the analysis.
Definition: DQMMessageLogger.cc:121
std
Definition: JetResolutionObject.h:76
edm::ELseverityLevel
Definition: ELseverityLevel.h:96
Frameworkfwd.h
Event.h
DQMMessageLogger::DQMMessageLogger
DQMMessageLogger(const edm::ParameterSet &)
Constructor.
Definition: DQMMessageLogger.cc:31
EventSetup.h
dqm::implementation::IBooker
Definition: DQMStore.h:43
ELstring.h
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
DQMMessageLogger::~DQMMessageLogger
~DQMMessageLogger() override
Destructor.
Definition: DQMMessageLogger.cc:46
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
ParameterSet.h
edm::Event
Definition: Event.h:73
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
metname
const std::string metname
Definition: MuonSeedOrcaPatternRecognition.cc:43