CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DQMMessageLogger.cc
Go to the documentation of this file.
1 
2 
26 #include "TPad.h"
27 #include <cmath>
28 
29 using namespace std;
30 using namespace edm;
31 
32 
33 
35 
36  // the services
37  theDbe = NULL;
38 
39  categories_errors = NULL;
40  categories_warnings = NULL;
41  modules_errors = NULL;
42  modules_warnings = NULL;
43  total_errors = NULL;
44  total_warnings = NULL;
45 
46  //Get from cfg file
47  categories_vector = parameters.getParameter< vector<string> >("Categories");
48  directoryName = parameters.getParameter<string>("Directory");
49  errorSummary_ = consumes<std::vector<edm::ErrorSummaryEntry> >(parameters.getUntrackedParameter<std::string>("errorSummary","logErrorHarvester"));
50 
51 
52 }
53 
55  // Should the pointers be deleted?
56 }
57 
58 
60 
61  metname = "errorAnalyzer";
62 
63 
64 
65  // MAKE CATEGORYMAP USING INPUT FROM CFG FILE
66  for(unsigned int i=0; i<categories_vector.size(); i++){
67  categoryMap.insert(pair<string,int>(categories_vector[i],i+1));
68  }
69 
70 
71  // MAKE MODULEMAP
73  typedef vector<std::string> stringvec;
74  TNS tns;
75  stringvec const& trigpaths = tns->getTrigPaths();
76 
77 
78  for (stringvec::const_iterator i = trigpaths.begin(), e =trigpaths.end() ; i != e; ++i){
79  stringvec strings = tns->getTrigPathModules(*i);
80 
81  for(unsigned int k=0; k<strings.size(); ++k){
82  moduleMap.insert(pair<string,int>(strings[k],moduleMap.size()+1));
83  }
84  }
85 
86  // BOOK THE HISTOGRAMS
87  LogTrace(metname)<<"[DQMMessageLogger] Parameters initialization";
88  theDbe = Service<DQMStore>().operator->();
89  if(theDbe!=NULL){
90 
91 
92 
93  if(moduleMap.size()!=0){
94  theDbe->setCurrentFolder(directoryName + "/Errors");
95  modules_errors = theDbe->book1D("modules_errors", "Errors per module", moduleMap.size(), 0, moduleMap.size());
96  theDbe->setCurrentFolder(directoryName + "/Warnings");
97 
98  modules_warnings = theDbe->book1D("modules_warnings","Warnings per module",moduleMap.size(),0,moduleMap.size());
99 
100  for(map<string,int>::const_iterator it = moduleMap.begin(); it!=moduleMap.end();++it){
101  modules_errors->setBinLabel((*it).second,(*it).first);
102  modules_warnings->setBinLabel((*it).second,(*it).first);
103  }
104  modules_errors->getTH1()->GetXaxis()->LabelsOption("v");
105  modules_warnings->getTH1()->GetXaxis()->LabelsOption("v");
106 
107 
108 
109 
110  }
111 
112  if(categoryMap.size()!=0){
113  theDbe->setCurrentFolder(directoryName + "/Errors");
114  categories_errors = theDbe->book1D("categories_errors", "Errors per category", categoryMap.size(), 0, categoryMap.size());
115  theDbe->setCurrentFolder(directoryName +"/Warnings");
116  categories_warnings = theDbe->book1D("categories_warnings", "Warnings per category", categoryMap.size(), 0, categoryMap.size());
117 
118 
119  for(map<string,int>::const_iterator it = categoryMap.begin(); it!=categoryMap.end();++it){
120  categories_errors->setBinLabel((*it).second,(*it).first);
121  categories_warnings->setBinLabel((*it).second,(*it).first);
122  }
123  categories_warnings->getTH1()->GetXaxis()->LabelsOption("v");
124  categories_errors->getTH1()->GetXaxis()->LabelsOption("v");
125  }
126 
127  // HOW MANY BINS SHOULD THE ERROR HIST HAVE?
128  int nbins = 11;
129  total_warnings = theDbe->book1D("total_warnings","Total warnings per event",nbins,-0.5,nbins+0.5);
130  theDbe->setCurrentFolder(directoryName + "/Errors");
131  total_errors = theDbe->book1D("total_errors", "Total errors per event", nbins, -0.5, nbins+0.5);
132 
133  for(int i=0; i<nbins; ++i){
134  stringstream out;
135  out<< i;
136  string s = out.str();
137  total_errors->setBinLabel(i+1,s);
138  total_warnings->setBinLabel(i+1,s);
139  }
140  }
141 }
142 
143 
144 void DQMMessageLogger::analyze(const Event& iEvent, const EventSetup& iSetup) {
145 
146  LogTrace(metname)<<"[DQMMessageLogger] Analysis of event # ";
147 
148 
149  // Take the ErrorSummaryEntry container
151  iEvent.getByToken(errorSummary_,errors);
152  // Check that errors is valid
153  if(!errors.isValid()){ return; }
154  // Compare severity level of error with ELseveritylevel instance el : "-e" should be the lowest error
155  ELseverityLevel el("-e");
156 
157 
158 
159  // Find the total number of errors in iEvent
160  if(errors->size()==0){
161  if(total_errors!=NULL){
162  total_errors->Fill(0);
163  }
164  if(total_warnings!=NULL){
165  total_warnings->Fill(0);
166  }
167  }else{
168 
169  int e = 0;
170  int w = 0;
171  for (int i=0, n=errors->size(); i<n; i++){
172  if((*errors)[i].severity.getLevel() < el.getLevel()){
173  w+= (*errors)[i].count;
174  }else{
175  e+= (*errors)[i].count;
176  }
177  }
178  if(total_errors!=NULL){
179  total_errors->Fill(e);
180  }
181  if(total_warnings!=NULL){
182  total_warnings->Fill(w);
183  }
184  }
185 
186 
187 
188 
189  for(int i=0, n=errors->size(); i< n ; i++){
190 
191  //cout << "Severity for error/warning: " << (*errors)[i].severity << " " <<(*errors)[i].module << endl;
192 
193  if(errors->size()>0){
194  // IF THIS IS AN ERROR on the ELseverityLevel SCALE, FILL ERROR HISTS
195  if((*errors)[i].severity.getLevel() >= el.getLevel()){
196  if(categories_errors!=NULL){
197  map<string,int>::const_iterator it = categoryMap.find((*errors)[i].category);
198  if (it!=categoryMap.end()){
199  // FILL THE RIGHT BIN
200  categories_errors->Fill((*it).second - 1, (*errors)[i].count);
201  }
202  }
203  // if (categoryECount.size()<=40)
204  // categoryECount[(*errors)[i].category]+=(*errors)[i].count;
205 
206  if(modules_errors!=NULL){
207  // remove the first part of the module string, what is before ":"
208  string s = (*errors)[i].module;
209  size_t pos = s.find(':');
210  string s_temp = s.substr(pos+1,s.size());
211  map<string,int>::const_iterator it = moduleMap.find(s_temp);
212  if(it!=moduleMap.end()){
213  // FILL THE RIGHT BIN
214  modules_errors->Fill((*it).second - 1, (*errors)[i].count);
215  }
216  }
217  // IF ONLY WARNING, FILL WARNING HISTS
218  }else{
219  if(categories_warnings!=NULL){
220  map<string,int>::const_iterator it = categoryMap.find((*errors)[i].category);
221  if (it!=categoryMap.end()){
222  // FILL THE RIGHT BIN
223  categories_warnings->Fill((*it).second - 1, (*errors)[i].count);
224  }
225  }
226 
227  // if (categoryWCount.size()<=40)
228  // categoryWCount[(*errors)[i].category]+=(*errors)[i].count;
229 
230  if(modules_warnings!=NULL){
231  // remove the first part of the module string, what is before ":"
232  string s = (*errors)[i].module;
233  size_t pos = s.find(':');
234  string s_temp = s.substr(pos+1,s.size());
235  map<string,int>::const_iterator it = moduleMap.find(s_temp);
236  if(it!=moduleMap.end()){
237  // FILL THE RIGHT BIN
238  modules_warnings->Fill((*it).second - 1, (*errors)[i].count);
239  }
240  }
241  }
242  }
243  }
244 }
245 
247  /*
248  theDbe = Service<DQMStore>().operator->();
249  if(theDbe!=NULL){
250  std::map<std::string,int>::iterator it;
251  uint i=0;
252  theDbe->setCurrentFolder(directoryName + "/Errors");
253  if (categoryECount.empty()){
254  MonitorElement * catECount = theDbe->book1D("categoryCount_errors","Errors per Category",1,0,1);
255  catECount->setBinLabel(1,"No Errors");
256  }else{
257  MonitorElement * catECount = theDbe->book1D("categoryCount_errors","Errors per Category",categoryECount.size(),0,categoryECount.size());
258  for (i=1,it=categoryECount.begin();it!=categoryECount.end();++it,++i){
259  catECount->setBinLabel(i,it->first);
260  catECount->setBinContent(i,it->second);
261  }
262  }
263  theDbe->setCurrentFolder(directoryName + "/Warnings");
264  if (categoryWCount.empty()){
265  MonitorElement * catWCount = theDbe->book1D("categoryCount_warnings","Warnings per Category",categoryWCount.size(),0,categoryWCount.size());
266  catWCount->setBinLabel(1,"No Warnings");
267  }else{
268  MonitorElement * catWCount = theDbe->book1D("categoryCount_warnings","Warnings per Category",categoryWCount.size(),0,categoryWCount.size());
269  for (i=1,it=categoryWCount.begin();it!=categoryWCount.end();++it,++i){
270  catWCount->setBinLabel(i,it->first);
271  catWCount->setBinContent(i,it->second);
272  }
273  }
274  }
275  categoryWCount.clear();
276  categoryECount.clear();
277  */
278 }
279 
281  LogTrace(metname)<<"[DQMMessageLogger] EndJob";
282 
283 }
284 
285 
286 
287 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
const double w
Definition: UKUtility.cc:23
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
const std::string metname
virtual ~DQMMessageLogger()
Destructor.
#define NULL
Definition: scimark2.h:8
void endJob()
Save the histos.
int iEvent
Definition: GenABIO.cc:230
void endRun(const edm::Run &r, const edm::EventSetup &c)
collate categories in summary plots
bool isValid() const
Definition: HandleBase.h:75
#define LogTrace(id)
tuple out
Definition: dbtoconf.py:99
void analyze(const edm::Event &, const edm::EventSetup &)
Get the analysis.
void beginJob()
Inizialize parameters for histo binning.
DQMMessageLogger(const edm::ParameterSet &)
Constructor.
Definition: Run.h:41