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 = 10;
127  total_warnings = theDbe->book1D("total warnings","Total warnings per event",nbins,0,nbins);
128  theDbe->setCurrentFolder(directoryName + "/Errors");
129  total_errors = theDbe->book1D("total_errors", "Total errors per event", nbins, 0, nbins);
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 
202  if(modules_errors!=NULL){
203  // remove the first part of the module string, what is before ":"
204  string s = (*errors)[i].module;
205  size_t pos = s.find(':');
206  string s_temp = s.substr(pos+1,s.size());
207  map<string,int>::const_iterator it = moduleMap.find(s_temp);
208  if(it!=moduleMap.end()){
209  // FILL THE RIGHT BIN
210  modules_errors->Fill((*it).second - 1, (*errors)[i].count);
211  }
212  }
213  // IF ONLY WARNING, FILL WARNING HISTS
214  }else{
215  if(categories_warnings!=NULL){
216  map<string,int>::const_iterator it = categoryMap.find((*errors)[i].category);
217  if (it!=categoryMap.end()){
218  // FILL THE RIGHT BIN
219  categories_warnings->Fill((*it).second - 1, (*errors)[i].count);
220  }
221  }
222 
223  if(modules_warnings!=NULL){
224  // remove the first part of the module string, what is before ":"
225  string s = (*errors)[i].module;
226  size_t pos = s.find(':');
227  string s_temp = s.substr(pos+1,s.size());
228  map<string,int>::const_iterator it = moduleMap.find(s_temp);
229  if(it!=moduleMap.end()){
230  // FILL THE RIGHT BIN
231  modules_warnings->Fill((*it).second - 1, (*errors)[i].count);
232  }
233  }
234  }
235  }
236  }
237 }
238 
239 
241  LogTrace(metname)<<"[DQMMessageLogger] EndJob";
242 
243 }
244 
245 
246 
247 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
const std::string metname
virtual ~DQMMessageLogger()
Destructor.
#define NULL
Definition: scimark2.h:8
void endJob()
Save the histos.
int iEvent
Definition: GenABIO.cc:243
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
#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.
static const std::string category("Muon|RecoMuon|L3MuonCandidateProducerFromMuons")
DQMMessageLogger(const edm::ParameterSet &)
Constructor.
string s
Definition: asciidump.py:422