CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
92  //now do what ever initialization is needed
93  lumiDetails_ = new GetLumi( iConfig.getParameter<edm::ParameterSet>("BXlumiSetup"), c );
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.getByLabel("logErrorHarvester",errors);
128  iEvent.getByToken(errorToken_,errors);
129  // Check that errors is valid
130  if(!errors.isValid()) return;
131  // Compare severity level of error with ELseveritylevel instance el : "-e" should be the lowest error
132  edm::ELseverityLevel el("-e");
133 
134  // Find the total number of errors in iEvent
135  if(errors->size()==0){
136  if ( doPUmonitoring_ ) {
137  for(size_t i = 0; i < modulesMap.size(); i++) {
138  ModulesErrorsVsBXlumi[i] -> Fill(BXlumi,0.);
139  if ( doWarningsPlots_ )
140  ModulesWarningsVsBXlumi[i] -> Fill(BXlumi,0.);
141  }
142  }
143  } else {
144 
145  size_t nCategories = categories_vector_.size();
146 
147  for( size_t i = 0, n = errors->size(); i < n ; i++){
148 
149  // std::cout << "LogMessageMonitor::analyze] Severity for error/warning: " << (*errors)[i].severity << " " <<(*errors)[i].module << std::endl;
150  // remove the first part of the module string, what is before ":"
151  std::string s = (*errors)[i].module;
152  size_t pos = s.find(':');
153  std::string s_module = s.substr(pos+1,s.size());
154  std::map<std::string,int>::const_iterator it = modulesMap.find(s_module);
155  if (it!=modulesMap.end()){
156  // std::cout << "LogMessageMonitor::analyze] it: " << " --> " << s_module << std::endl;
157 
158  // IF THIS IS AN ERROR on the ELseverityLevel SCALE, FILL ERROR HISTS
159  if((*errors)[i].severity.getLevel() >= edm::ELseverityLevel::ELsev_error) {
160  if ( doPUmonitoring_ )
161  ModulesErrorsVsBXlumi[it->second]->Fill (BXlumi, (*errors)[i].count);
162 
163  // loop over the different categories of errors
164  // defined by configuration file
165  // if the category is not in the given list
166  // it fills the bin "others"
167  TString module = it->first;
168  TString category = (*errors)[i].category;
169  int ibinX = CategoriesVsModules->getTH1()->GetXaxis()->FindBin(module);
170  int ibinY = CategoriesVsModules->getTH1()->GetYaxis()->FindBin(category);
171  /*
172  std::cout << "LogMessageMonitor::analyze] ibinX: " << ibinX << " it->second: " << it->second << " it->first: " << it->first << std::endl;
173  std::cout << "LogMessageMonitor::analyze] ibinY: " << ibinY << " (*errors)[i].category: " << (*errors)[i].category << std::endl;
174  size_t nbinsX = CategoriesVsModules->getTH1()->GetNbinsX();
175  for (size_t bin = 1; bin<=nbinsX; bin++) {
176  std::cout << "binX" << bin << ": " << CategoriesVsModules->getTH1()->GetXaxis()->GetBinLabel(bin) << std::endl;
177  }
178  size_t nbinsY = CategoriesVsModules->getTH1()->GetNbinsY();
179  for (size_t bin = 1; bin<=nbinsY; bin++) {
180  std::cout << "binY" << bin << ": " << CategoriesVsModules->getTH1()->GetYaxis()->GetBinLabel(bin) << std::endl;
181  }
182  */
183  if ( ibinY>0 ) {
184  int ncount = CategoriesVsModules->getTH1()->GetBinContent(ibinX,ibinY)+1;
185  CategoriesVsModules->getTH1()->SetBinContent(ibinX,ibinY,ncount);
186  } else {
187  int ncount = CategoriesVsModules->getTH1()->GetBinContent(ibinX,nCategories)+1;
188  CategoriesVsModules->getTH1()->SetBinContent(ibinX,nCategories,ncount);
189  }
190  } else {
191  // IF ONLY WARNING, FILL WARNING HISTS
192  if ( doWarningsPlots_ )
193  if ( doPUmonitoring_ )
194  ModulesWarningsVsBXlumi[it->second]->Fill(BXlumi, (*errors)[i].count);
195  }
196  }
197  }
198  }
199 }
200 
201 
202 // ------------ method called once each job just before starting event loop ------------
203 void
205 {
206  std::string MEFolderName = conf_.getParameter<std::string>("LogFolderName");
207 
208  dqmStore_->setCurrentFolder(MEFolderName);
209 
210  categories_vector_.push_back("others");
211  size_t nModules = modules_vector_.size();
212  size_t nCategories = categories_vector_.size();
213 
214  histname = pluginsMonName_+"ErrorsVsModules";
215  CategoriesVsModules = dqmStore_->book2D(histname, histname, nModules, 0., double(nModules), nCategories, 0., double(nCategories) );
216  CategoriesVsModules->setAxisTitle("modules",1);
217  for (size_t imodule = 0; imodule < nModules; imodule++)
218  CategoriesVsModules->setBinLabel(imodule+1,modules_vector_[imodule],1);
219  CategoriesVsModules->setAxisTitle("categories",2);
220  // CategoriesVsModules->getTH1()->GetXaxis()->LabelsOption("v");
221  for (size_t icategories = 0; icategories < nCategories; icategories++)
222  CategoriesVsModules->setBinLabel(icategories+1,categories_vector_[icategories],2);
223 
224  // MAKE MODULEMAP USING INPUT FROM CFG FILE
225  for (size_t i = 0; i < modules_vector_.size(); i++){
226  modulesMap.insert( std::pair<std::string,int>(modules_vector_[i],i) );
227  }
228 
229  if ( doPUmonitoring_ ) {
230  // BOOK THE HISTOGRAMS
231  // get binning from the configuration
232  edm::ParameterSet BXlumiParameters = conf_.getParameter<edm::ParameterSet>("BXlumiSetup");
233  int BXlumiBin = BXlumiParameters.getParameter<int>("BXlumiBin");
234  double BXlumiMin = BXlumiParameters.getParameter<double>("BXlumiMin");
235  double BXlumiMax = BXlumiParameters.getParameter<double>("BXlumiMax");
236 
237  size_t i = 0;
238  for(std::map<std::string,int>::const_iterator it = modulesMap.begin();
239  it != modulesMap.end(); ++it, i++){
240 
241  dqmStore_->setCurrentFolder(MEFolderName + "/PUmonitoring/Errors");
242 
243  histname = "errorsVsBXlumi_" + it->first;
244  ModulesErrorsVsBXlumi.push_back( dynamic_cast<MonitorElement*>(dqmStore_->bookProfile( histname, histname, BXlumiBin, BXlumiMin, BXlumiMax, 0.,100, "")) );
245  ModulesErrorsVsBXlumi[i] -> setAxisTitle("BXlumi [10^{30} Hz cm^{-2}]", 1);
246  ModulesErrorsVsBXlumi[i] -> setAxisTitle("Mean number of errors", 2);
247 
248  if ( doWarningsPlots_ ) {
249  dqmStore_->setCurrentFolder(MEFolderName + "/PUmonitoring/Warnings");
250 
251  histname = "warningVsBXlumi_" + it->first;
252  ModulesWarningsVsBXlumi.push_back( dynamic_cast<MonitorElement*>(dqmStore_->bookProfile( histname, histname, BXlumiBin, BXlumiMin, BXlumiMax, 0.,100, "")) );
253  ModulesWarningsVsBXlumi[i] -> setAxisTitle("BXlumi [10^{30} Hz cm^{-2}]", 1);
254  ModulesWarningsVsBXlumi[i] -> setAxisTitle("Mean number of warnings", 2);
255  }
256  }
257  }
258 
259 }
260 
261 // ------------ method called once each job just after ending the event loop ------------
262 void
264 {
265  bool outputMEsInRootFile = conf_.getParameter<bool>("OutputMEsInRootFile");
267  if(outputMEsInRootFile)
268  {
270  dqmStore_->save(outputFileName);
271  }
272 }
273 
274 // ------------ method called when starting to processes a run ------------
275 void
277 {
278  if ( genTriggerEventFlag_->on() ) genTriggerEventFlag_->initRun( iRun, iSetup );
279 }
280 
281 // ------------ method called when ending the processing of a run ------------
282 void
284 {
285 }
286 
287 // ------------ method called when starting to processes a luminosity block ------------
288 void
290 {
291 }
292 
293 // ------------ method called when ending the processing of a luminosity block ------------
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
int i
Definition: DBlmapReader.cc:9
virtual void endJob()
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
LogMessageMonitor(const edm::ParameterSet &)
MonitorElement * CategoriesVsModules
std::vector< std::string > categories_vector_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< MonitorElement * > ModulesWarningsVsBXlumi
virtual void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup 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_
virtual void endRun(edm::Run const &, edm::EventSetup const &)
double getValue(const edm::Event &)
Definition: GetLumi.cc:65
int iEvent
Definition: GenABIO.cc:243
void addDefault(ParameterSetDescription const &psetDescription)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
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.
TH1 * getTH1(void) const
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2296
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
Definition: DQMStore.cc:1186
edm::EDGetTokenT< std::vector< edm::ErrorSummaryEntry > > errorToken_
bool isValid() const
Definition: HandleBase.h:76
virtual void beginJob()
GenericTriggerEventFlag * genTriggerEventFlag_
std::vector< std::string > modules_vector_
virtual void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
std::string pluginsMonName_
void showDirStructure(void) const
Definition: DQMStore.cc:2961
void initRun(const edm::Run &run, const edm::EventSetup &setup)
To be called from beginRun() methods.
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1000
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
virtual void beginRun(edm::Run const &, edm::EventSetup const &)
Definition: vlib.h:208
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584
Definition: Run.h:41