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