CMS 3D CMS Logo

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