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 
60 
65 
68 //
69 // constants, enums and typedefs
70 //
71 
72 //
73 // static data member definitions
74 //
75 
76 //
77 // constructors and destructor
78 //
80  : dqmStore_( edm::Service<DQMStore>().operator->() )
81  , conf_ ( iConfig )
82  , pluginsMonName_ ( iConfig.getParameter<std::string> ("pluginsMonName") )
83  , modules_vector_ ( iConfig.getParameter<std::vector<std::string> >("modules") )
84  , categories_vector_ ( iConfig.getParameter<std::vector<std::string> >("categories") )
85  , doWarningsPlots_ ( iConfig.getParameter<bool> ("doWarningsPlots") )
86  , doPUmonitoring_ ( iConfig.getParameter<bool> ("doPUmonitoring") )
87 {
88 
89  errorToken_ = consumes<std::vector<edm::ErrorSummaryEntry> >(edm::InputTag("logErrorHarvester") );
90 
91  edm::ConsumesCollector c{ consumesCollector() };
92  //now do what ever initialization is needed
93  lumiDetails_ = new GetLumi( iConfig.getParameter<edm::ParameterSet>("BXlumiSetup"), c );
94  genTriggerEventFlag_ = new GenericTriggerEventFlag(iConfig.getParameter<edm::ParameterSet>("genericTriggerEventPSet"),consumesCollector(), *this);
95 }
96 
97 
99 {
100 
101  // do anything here that needs to be done at desctruction time
102  // (e.g. close files, deallocate resources etc.)
103  // if ( lumiDetails_ ) delete lumiDetails_;
105 
106 }
107 
108 
109 //
110 // member functions
111 //
112 
113 // ------------ method called for each event ------------
114 void
116 {
117 
118  // Filter out events if Trigger Filtering is requested
119  if (genTriggerEventFlag_->on()&& ! genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
120 
121  double BXlumi = -1.;
122  if ( doPUmonitoring_ )
123  lumiDetails_->getValue(iEvent);
124 
125  // Take the ErrorSummaryEntry container
127  iEvent.getByToken(errorToken_,errors);
128  // Check that errors is valid
129  if(!errors.isValid()) return;
130  // Compare severity level of error with ELseveritylevel instance el : "-e" should be the lowest error
131  edm::ELseverityLevel el("-e");
132 
133  // Find the total number of errors in iEvent
134  if(errors->empty()){
135  if ( doPUmonitoring_ ) {
136  for(size_t i = 0; i < modulesMap.size(); i++) {
137  ModulesErrorsVsBXlumi[i] -> Fill(BXlumi,0.);
138  if ( doWarningsPlots_ )
139  ModulesWarningsVsBXlumi[i] -> Fill(BXlumi,0.);
140  }
141  }
142  } else {
143 
144  size_t nCategories = categories_vector_.size();
145 
146  for( size_t i = 0, n = errors->size(); i < n ; i++){
147 
148  // std::cout << "LogMessageMonitor::analyze] Severity for error/warning: " << (*errors)[i].severity << " " <<(*errors)[i].module << std::endl;
149  // remove the first part of the module string, what is before ":"
150  std::string s = (*errors)[i].module;
151  size_t pos = s.find(':');
152  std::string s_module = s.substr(pos+1,s.size());
153  std::map<std::string,int>::const_iterator it = modulesMap.find(s_module);
154  if (it!=modulesMap.end()){
155  // std::cout << "LogMessageMonitor::analyze] it: " << " --> " << s_module << std::endl;
156 
157  // IF THIS IS AN ERROR on the ELseverityLevel SCALE, FILL ERROR HISTS
158  if((*errors)[i].severity.getLevel() >= edm::ELseverityLevel::ELsev_error) {
159  if ( doPUmonitoring_ )
160  ModulesErrorsVsBXlumi[it->second]->Fill (BXlumi, (*errors)[i].count);
161 
162  // loop over the different categories of errors
163  // defined by configuration file
164  // if the category is not in the given list
165  // it fills the bin "others"
166  TString module = it->first;
167  TString category = (*errors)[i].category;
168  int ibinX = CategoriesVsModules->getTH1()->GetXaxis()->FindBin(module);
169  int ibinY = CategoriesVsModules->getTH1()->GetYaxis()->FindBin(category);
170  /*
171  std::cout << "LogMessageMonitor::analyze] ibinX: " << ibinX << " it->second: " << it->second << " it->first: " << it->first << std::endl;
172  std::cout << "LogMessageMonitor::analyze] ibinY: " << ibinY << " (*errors)[i].category: " << (*errors)[i].category << std::endl;
173  size_t nbinsX = CategoriesVsModules->getTH1()->GetNbinsX();
174  for (size_t bin = 1; bin<=nbinsX; bin++) {
175  std::cout << "binX" << bin << ": " << CategoriesVsModules->getTH1()->GetXaxis()->GetBinLabel(bin) << std::endl;
176  }
177  size_t nbinsY = CategoriesVsModules->getTH1()->GetNbinsY();
178  for (size_t bin = 1; bin<=nbinsY; bin++) {
179  std::cout << "binY" << bin << ": " << CategoriesVsModules->getTH1()->GetYaxis()->GetBinLabel(bin) << std::endl;
180  }
181  */
182  if ( ibinY>0 ) {
183  int ncount = CategoriesVsModules->getTH1()->GetBinContent(ibinX,ibinY)+1;
184  CategoriesVsModules->getTH1()->SetBinContent(ibinX,ibinY,ncount);
185  } else {
186  int ncount = CategoriesVsModules->getTH1()->GetBinContent(ibinX,nCategories)+1;
187  CategoriesVsModules->getTH1()->SetBinContent(ibinX,nCategories,ncount);
188  }
189  } else {
190  // IF ONLY WARNING, FILL WARNING HISTS
191  if ( doWarningsPlots_ )
192  if ( doPUmonitoring_ )
193  ModulesWarningsVsBXlumi[it->second]->Fill(BXlumi, (*errors)[i].count);
194  }
195  }
196  }
197  }
198 }
199 
201  edm::Run const & iRun,
202  edm::EventSetup const & iSetup)
203 {
204 
205  if ( genTriggerEventFlag_->on() ) genTriggerEventFlag_->initRun( iRun, iSetup );
206 
207  std::string MEFolderName = conf_.getParameter<std::string>("LogFolderName");
208 
209  ibooker.setCurrentFolder(MEFolderName);
210 
211  categories_vector_.push_back("others");
212  size_t nModules = modules_vector_.size();
213  size_t nCategories = categories_vector_.size();
214 
215  histname = pluginsMonName_+"ErrorsVsModules";
216  CategoriesVsModules = ibooker.book2D(histname, histname, nModules, 0., double(nModules), nCategories, 0., double(nCategories) );
217  CategoriesVsModules->getTH1()->GetXaxis()->SetNoAlphanumeric();
218  CategoriesVsModules->getTH1()->GetYaxis()->SetNoAlphanumeric();
219  CategoriesVsModules->setAxisTitle("modules",1);
220  for (size_t imodule = 0; imodule < nModules; imodule++)
221  CategoriesVsModules->setBinLabel(imodule+1,modules_vector_[imodule],1);
222  CategoriesVsModules->setAxisTitle("categories",2);
223  // CategoriesVsModules->getTH1()->GetXaxis()->LabelsOption("v");
224  for (size_t icategories = 0; icategories < nCategories; icategories++)
225  CategoriesVsModules->setBinLabel(icategories+1,categories_vector_[icategories],2);
226 
227  // MAKE MODULEMAP USING INPUT FROM CFG FILE
228  for (size_t i = 0; i < modules_vector_.size(); i++){
229  modulesMap.insert( std::pair<std::string,int>(modules_vector_[i],i) );
230  }
231 
232  if ( doPUmonitoring_ ) {
233  // BOOK THE HISTOGRAMS
234  // get binning from the configuration
235  edm::ParameterSet BXlumiParameters = conf_.getParameter<edm::ParameterSet>("BXlumiSetup");
236  int BXlumiBin = BXlumiParameters.getParameter<int>("BXlumiBin");
237  double BXlumiMin = BXlumiParameters.getParameter<double>("BXlumiMin");
238  double BXlumiMax = BXlumiParameters.getParameter<double>("BXlumiMax");
239 
240  size_t i = 0;
241  for(std::map<std::string,int>::const_iterator it = modulesMap.begin();
242  it != modulesMap.end(); ++it, i++){
243 
244  ibooker.setCurrentFolder(MEFolderName + "/PUmonitoring/Errors");
245 
246  histname = "errorsVsBXlumi_" + it->first;
247  ModulesErrorsVsBXlumi.push_back( dynamic_cast<MonitorElement*>(ibooker.bookProfile( histname, histname, BXlumiBin, BXlumiMin, BXlumiMax, 0.,100, "")) );
248  ModulesErrorsVsBXlumi[i] -> setAxisTitle("BXlumi [10^{30} Hz cm^{-2}]", 1);
249  ModulesErrorsVsBXlumi[i] -> setAxisTitle("Mean number of errors", 2);
250 
251  if ( doWarningsPlots_ ) {
252  ibooker.setCurrentFolder(MEFolderName + "/PUmonitoring/Warnings");
253 
254  histname = "warningVsBXlumi_" + it->first;
255  ModulesWarningsVsBXlumi.push_back( dynamic_cast<MonitorElement*>(ibooker.bookProfile( histname, histname, BXlumiBin, BXlumiMin, BXlumiMax, 0.,100, "")) );
256  ModulesWarningsVsBXlumi[i] -> setAxisTitle("BXlumi [10^{30} Hz cm^{-2}]", 1);
257  ModulesWarningsVsBXlumi[i] -> setAxisTitle("Mean number of warnings", 2);
258  }
259  }
260  }
261 
262 }
263 
264 /*
265 // ------------ method called once each job just before starting event loop ------------
266 void
267 LogMessageMonitor::beginJob()
268 {
269 
270 }
271 */
272 // ------------ method called once each job just after ending the event loop ------------
273 void
275 {
276  bool outputMEsInRootFile = conf_.getParameter<bool>("OutputMEsInRootFile");
278  if(outputMEsInRootFile)
279  {
281  dqmStore_->save(outputFileName);
282  }
283 }
284 
285 /*
286 // ------------ method called when starting to processes a run ------------
287 void
288 LogMessageMonitor::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
289 {
290 
291 }
292 */
293 // ------------ method called when ending the processing of a run ------------
294 void
296 {
297 }
298 
299 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
300 void
302  //The following says we do not know what parameters are allowed so do no validation
303  // Please change this to state exactly what you do use, even if it is no parameters
305  desc.setUnknown();
306  descriptions.addDefault(desc);
307 }
308 
T getParameter(std::string const &) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
LogMessageMonitor(const edm::ParameterSet &)
MonitorElement * CategoriesVsModules
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:113
std::vector< std::string > categories_vector_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
void endJob() override
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::vector< MonitorElement * > ModulesWarningsVsBXlumi
TH1 * getTH1() const
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::map< std::string, int > modulesMap
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:64
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void addDefault(ParameterSetDescription const &psetDescription)
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
bool accept(const edm::Event &event, const edm::EventSetup &setup)
To be called from analyze/filter() methods.
void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< std::vector< edm::ErrorSummaryEntry > > errorToken_
bool isValid() const
Definition: HandleBase.h:74
void showDirStructure() const
Definition: DQMStore.cc:3307
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
GenericTriggerEventFlag * genTriggerEventFlag_
std::vector< std::string > modules_vector_
void save(std::string const &filename, std::string const &path="", std::string const &pattern="", std::string const &rewrite="", uint32_t run=0, uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, std::string const &fileupdate="RECREATE")
Definition: DQMStore.cc:2465
std::string pluginsMonName_
HLT enums.
void endRun(edm::Run const &, edm::EventSetup const &) override
void initRun(const edm::Run &run, const edm::EventSetup &setup)
To be called from beginRun() methods.
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
Definition: vlib.h:208
~LogMessageMonitor() override
Definition: Run.h:45