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