CMS 3D CMS Logo

LogMessageMonitor.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: LogMessageMonitor
4 // Class: LogMessageMonitor
5 //
49 //
50 // Original Author: Mia Tosi,40 3-B32,+41227671609,
51 // Created: Thu Mar 8 14:34:13 CET 2012
52 //
53 //
54 
56 
59 
63 
66 //
67 // constants, enums and typedefs
68 //
69 
70 //
71 // static data member definitions
72 //
73 
74 //
75 // constructors and destructor
76 //
78  : dqmStore_(edm::Service<DQMStore>().operator->()),
79  conf_(iConfig),
80  pluginsMonName_(iConfig.getParameter<std::string>("pluginsMonName")),
81  modules_vector_(iConfig.getParameter<std::vector<std::string> >("modules")),
82  categories_vector_(iConfig.getParameter<std::vector<std::string> >("categories")),
83  doWarningsPlots_(iConfig.getParameter<bool>("doWarningsPlots")),
84  doPUmonitoring_(iConfig.getParameter<bool>("doPUmonitoring")) {
85  errorToken_ = consumes<std::vector<edm::ErrorSummaryEntry> >(edm::InputTag("logErrorHarvester"));
86 
88  //now do what ever initialization is needed
89  lumiDetails_ = new GetLumi(iConfig.getParameter<edm::ParameterSet>("BXlumiSetup"), c);
91  iConfig.getParameter<edm::ParameterSet>("genericTriggerEventPSet"), consumesCollector(), *this);
92 }
93 
95  // do anything here that needs to be done at desctruction time
96  // (e.g. close files, deallocate resources etc.)
97  // if ( lumiDetails_ ) delete lumiDetails_;
99  delete genTriggerEventFlag_;
100 }
101 
102 //
103 // member functions
104 //
105 
106 // ------------ method called for each event ------------
108  // Filter out events if Trigger Filtering is requested
110  return;
111 
112  double BXlumi = -1.;
113  if (doPUmonitoring_)
115 
116  // Take the ErrorSummaryEntry container
118  // Check that errors is valid
119  if (!errors.isValid())
120  return;
121 
122  // Find the total number of errors in iEvent
123  if (errors->empty()) {
124  if (doPUmonitoring_) {
125  for (size_t i = 0; i < modulesMap.size(); i++) {
126  ModulesErrorsVsBXlumi[i]->Fill(BXlumi, 0.);
127  if (doWarningsPlots_)
128  ModulesWarningsVsBXlumi[i]->Fill(BXlumi, 0.);
129  }
130  }
131  } else {
132  size_t nCategories = categories_vector_.size();
133 
134  for (size_t i = 0, n = errors->size(); i < n; i++) {
135  // std::cout << "LogMessageMonitor::analyze] Severity for error/warning: " << (*errors)[i].severity << " " <<(*errors)[i].module << std::endl;
136  // remove the first part of the module string, what is before ":"
137  std::string s = (*errors)[i].module;
138  size_t pos = s.find(':');
139  std::string s_module = s.substr(pos + 1, s.size());
140  std::map<std::string, int>::const_iterator it = modulesMap.find(s_module);
141  if (it != modulesMap.end()) {
142  // std::cout << "LogMessageMonitor::analyze] it: " << " --> " << s_module << std::endl;
143 
144  // IF THIS IS AN ERROR on the ELseverityLevel SCALE, FILL ERROR HISTS
145  if ((*errors)[i].severity.getLevel() >= edm::ELseverityLevel::ELsev_error) {
146  if (doPUmonitoring_)
147  ModulesErrorsVsBXlumi[it->second]->Fill(BXlumi, (*errors)[i].count);
148 
149  // loop over the different categories of errors
150  // defined by configuration file
151  // if the category is not in the given list
152  // it fills the bin "others"
153  TString module = it->first;
154  TString category = (*errors)[i].category;
155  int ibinX = CategoriesVsModules->getTH1()->GetXaxis()->FindBin(module);
156  int ibinY = CategoriesVsModules->getTH1()->GetYaxis()->FindBin(category);
157  /*
158  std::cout << "LogMessageMonitor::analyze] ibinX: " << ibinX << " it->second: " << it->second << " it->first: " << it->first << std::endl;
159  std::cout << "LogMessageMonitor::analyze] ibinY: " << ibinY << " (*errors)[i].category: " << (*errors)[i].category << std::endl;
160  size_t nbinsX = CategoriesVsModules->getTH1()->GetNbinsX();
161  for (size_t bin = 1; bin<=nbinsX; bin++) {
162  std::cout << "binX" << bin << ": " << CategoriesVsModules->getTH1()->GetXaxis()->GetBinLabel(bin) << std::endl;
163  }
164  size_t nbinsY = CategoriesVsModules->getTH1()->GetNbinsY();
165  for (size_t bin = 1; bin<=nbinsY; bin++) {
166  std::cout << "binY" << bin << ": " << CategoriesVsModules->getTH1()->GetYaxis()->GetBinLabel(bin) << std::endl;
167  }
168  */
169  if (ibinY > 0) {
170  int ncount = CategoriesVsModules->getTH1()->GetBinContent(ibinX, ibinY) + 1;
171  CategoriesVsModules->getTH1()->SetBinContent(ibinX, ibinY, ncount);
172  } else {
173  int ncount = CategoriesVsModules->getTH1()->GetBinContent(ibinX, nCategories) + 1;
174  CategoriesVsModules->getTH1()->SetBinContent(ibinX, nCategories, ncount);
175  }
176  } else {
177  // IF ONLY WARNING, FILL WARNING HISTS
178  if (doWarningsPlots_)
179  if (doPUmonitoring_)
180  ModulesWarningsVsBXlumi[it->second]->Fill(BXlumi, (*errors)[i].count);
181  }
182  }
183  }
184  }
185 }
186 
188  edm::Run const& iRun,
189  edm::EventSetup const& iSetup) {
190  if (genTriggerEventFlag_->on())
191  genTriggerEventFlag_->initRun(iRun, iSetup);
192 
193  std::string MEFolderName = conf_.getParameter<std::string>("LogFolderName");
194 
195  ibooker.setCurrentFolder(MEFolderName);
196 
197  categories_vector_.push_back("others");
198  size_t nModules = modules_vector_.size();
199  size_t nCategories = categories_vector_.size();
200 
201  histname = pluginsMonName_ + "ErrorsVsModules";
203  ibooker.book2D(histname, histname, nModules, 0., double(nModules), nCategories, 0., double(nCategories));
204  CategoriesVsModules->getTH1()->GetXaxis()->SetNoAlphanumeric();
205  CategoriesVsModules->getTH1()->GetYaxis()->SetNoAlphanumeric();
206  CategoriesVsModules->setAxisTitle("modules", 1);
207  for (size_t imodule = 0; imodule < nModules; imodule++)
208  CategoriesVsModules->setBinLabel(imodule + 1, modules_vector_[imodule], 1);
209  CategoriesVsModules->setAxisTitle("categories", 2);
210  // CategoriesVsModules->getTH1()->GetXaxis()->LabelsOption("v");
211  for (size_t icategories = 0; icategories < nCategories; icategories++)
212  CategoriesVsModules->setBinLabel(icategories + 1, categories_vector_[icategories], 2);
213 
214  // MAKE MODULEMAP USING INPUT FROM CFG FILE
215  for (size_t i = 0; i < modules_vector_.size(); i++) {
216  modulesMap.insert(std::pair<std::string, int>(modules_vector_[i], i));
217  }
218 
219  if (doPUmonitoring_) {
220  // BOOK THE HISTOGRAMS
221  // get binning from the configuration
222  edm::ParameterSet BXlumiParameters = conf_.getParameter<edm::ParameterSet>("BXlumiSetup");
223  int BXlumiBin = BXlumiParameters.getParameter<int>("BXlumiBin");
224  double BXlumiMin = BXlumiParameters.getParameter<double>("BXlumiMin");
225  double BXlumiMax = BXlumiParameters.getParameter<double>("BXlumiMax");
226 
227  size_t i = 0;
228  for (std::map<std::string, int>::const_iterator it = modulesMap.begin(); it != modulesMap.end(); ++it, i++) {
229  ibooker.setCurrentFolder(MEFolderName + "/PUmonitoring/Errors");
230 
231  histname = "errorsVsBXlumi_" + it->first;
232  ModulesErrorsVsBXlumi.push_back(dynamic_cast<MonitorElement*>(
233  ibooker.bookProfile(histname, histname, BXlumiBin, BXlumiMin, BXlumiMax, 0., 100, "")));
234  ModulesErrorsVsBXlumi[i]->setAxisTitle("BXlumi [10^{30} Hz cm^{-2}]", 1);
235  ModulesErrorsVsBXlumi[i]->setAxisTitle("Mean number of errors", 2);
236 
237  if (doWarningsPlots_) {
238  ibooker.setCurrentFolder(MEFolderName + "/PUmonitoring/Warnings");
239 
240  histname = "warningVsBXlumi_" + it->first;
241  ModulesWarningsVsBXlumi.push_back(dynamic_cast<MonitorElement*>(
242  ibooker.bookProfile(histname, histname, BXlumiBin, BXlumiMin, BXlumiMax, 0., 100, "")));
243  ModulesWarningsVsBXlumi[i]->setAxisTitle("BXlumi [10^{30} Hz cm^{-2}]", 1);
244  ModulesWarningsVsBXlumi[i]->setAxisTitle("Mean number of warnings", 2);
245  }
246  }
247  }
248 }
249 
250 /*
251 // ------------ method called once each job just before starting event loop ------------
252 void
253 LogMessageMonitor::beginJob()
254 {
255 
256 }
257 */
258 // ------------ method called once each job just after ending the event loop ------------
260  bool outputMEsInRootFile = conf_.getParameter<bool>("OutputMEsInRootFile");
262  if (outputMEsInRootFile) {
264  }
265 }
266 
267 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
269  //The following says we do not know what parameters are allowed so do no validation
270  // Please change this to state exactly what you do use, even if it is no parameters
272  desc.setUnknown();
273  descriptions.addDefault(desc);
274 }
275 
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
LogMessageMonitor(const edm::ParameterSet &)
MonitorElement * CategoriesVsModules
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
std::vector< std::string > categories_vector_
void endJob() override
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::vector< MonitorElement * > ModulesWarningsVsBXlumi
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
std::vector< MonitorElement * > ModulesErrorsVsBXlumi
edm::ParameterSet conf_
double getValue(const edm::Event &)
Definition: GetLumi.cc:48
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:399
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
bool accept(const edm::Event &event, const edm::EventSetup &setup)
To be called from analyze/filter() methods.
std::map< std::string, int > modulesMap
void analyze(const edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< std::vector< edm::ErrorSummaryEntry > > errorToken_
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)
GenericTriggerEventFlag * genTriggerEventFlag_
std::vector< std::string > modules_vector_
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
std::string pluginsMonName_
DQM_DEPRECATED void save(std::string const &filename, std::string const &path="")
Definition: DQMStore.cc:824
HLT enums.
Definition: errors.py:1
void initRun(const edm::Run &run, const edm::EventSetup &setup)
To be called from beginRun() methods.
~LogMessageMonitor() override
Definition: Run.h:45
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)