CMS 3D CMS Logo

DQMMessageLoggerClient.cc
Go to the documentation of this file.
3 #include <string>
4 #include <vector>
5 
6 
7 using namespace std;
8 using namespace edm;
9 
10 
11 // -----------------------------
12 // constructors and destructor
13 // -----------------------------
14 
16 
17  parameters = ps;
18  theDbe = nullptr;
19  modulesErrorsFound = nullptr;
20  modulesWarningsFound = nullptr;
21  categoriesWarningsFound = nullptr;
22  categoriesErrorsFound = nullptr;
23  directoryName = parameters.getParameter<string>("Directory");
24 
25 }
26 
27 
29 
30 
31 
33 
34  //LogTrace(metname)<<"[DQMMessageLoggerClient] Parameters initialization";
35  theDbe = Service<DQMStore>().operator->();
36 
37  if(theDbe!=nullptr){
38  theDbe->setCurrentFolder(directoryName);
39  }
40 
41 }
42 
44 }
45 
46 
47 
49 }
50 
51 
52 
54 
55 
56  // directoryName should be the same as for DQMMessageLogger
57  //theDbe->setCurrentFolder(directoryName);
58  /*
59  cout << theDbe->pwd() << endl;
60  vector<string> vec = theDbe->getSubdirs();
61  for(int i=0; i<vec.size(); i++){
62  cout << vec[i] << endl;
63  }
64  */
65  theDbe->goUp();
66 
67 
68 
69  vector<string> entries;
70  entries.push_back(directoryName + "/Warnings/modules_warnings");
71  entries.push_back(directoryName + "/Errors/modules_errors");
72  entries.push_back(directoryName + "/Warnings/categories_warnings");
73  entries.push_back(directoryName + "/Errors/categories_errors");
74 
75 
76  int mel = 0;
77 
78  for(auto ent = entries.begin();
79  ent != entries.end(); ++ent) {
80  mel++;
81  //RESET VECTORS
82  binContent.clear();
83  binLabel.clear();
84 
85 
86  // RETURN ME
87 
88 
89  MonitorElement *me = theDbe->get(*ent);
90  // GET TH1F
91  if(theDbe->get(*ent)){
92  if (TH1 *rootHisto = me->getTH1()) {
93  int nonzeros = 0;
94  int Nbins = me->getNbinsX();
95 
96 
97  // LOOP OVER TH1F
98  for(int bin = 1; bin <= Nbins ; ++bin) {
99  if( rootHisto->GetBinContent(bin)>0){
100  nonzeros++;
101  binContent.push_back(rootHisto->GetBinContent(bin));
102  binLabel.emplace_back(rootHisto->GetXaxis()->GetBinLabel(bin));
103  }
104 
105  }
106 
107  switch(mel){
108  case 1:
109  theDbe->setCurrentFolder(directoryName + "/Warnings");
110  modulesWarningsFound = theDbe->get(directoryName + "/Warnings/modulesWarningsFound");
111  if (modulesWarningsFound) theDbe->removeElement(modulesWarningsFound->getName());
112  if(nonzeros>0){
113  modulesWarningsFound = theDbe->book1D("modulesWarningsFound", "Warnings per module", binContent.size(), 0, binContent.size());
114  }else{
115  modulesWarningsFound = theDbe->book1D("modulesWarningsFound", "Warnings per module", 1, 0, 1);
116  modulesWarningsFound->setBinLabel(1,"Module name");
117  }
118  for (int i=0; i<nonzeros; ++i){
119  if(modulesWarningsFound!=nullptr){
120  //gPad->SetBottomMargin(2);
121  //cout << binContent[i] <<" "<<binLabel[i] << endl;
122  modulesWarningsFound->setBinContent(i+1,binContent[i]);
123  modulesWarningsFound->setBinLabel(i+1,binLabel[i]);
124  }
125  }
126  if(nonzeros>4) modulesWarningsFound->getTH1()->GetXaxis()->LabelsOption("v");
127  break;
128  case 2:
129  theDbe->setCurrentFolder(directoryName + "/Errors");
130  modulesErrorsFound = theDbe->get(directoryName + "/Errors/modulesErrorsFound");
131  if (modulesErrorsFound) theDbe->removeElement(modulesErrorsFound->getName());
132  if(nonzeros>0){
133  modulesErrorsFound = theDbe->book1D("modulesErrorsFound", "Errors per module",binContent.size(), 0, binContent.size() );
134  }else{
135  modulesErrorsFound = theDbe->book1D("modulesErrorsFound", "Errors per module",1, 0, 1 );
136  modulesErrorsFound->setBinLabel(1,"Module name");
137  }
138  for (int i=0; i<nonzeros; ++i){
139  if(modulesErrorsFound!=nullptr){
140  //gPad->SetBottomMargin(2);
141  modulesErrorsFound->setBinContent(i+1,binContent[i]);
142  modulesErrorsFound->setBinLabel(i+1,binLabel[i]);
143  }
144  }
145  if(nonzeros>4) modulesErrorsFound->getTH1()->GetXaxis()->LabelsOption("v");
146  break;
147  case 3:
148  theDbe->setCurrentFolder(directoryName + "/Warnings");
149  categoriesWarningsFound = theDbe->get(directoryName + "/Warnings/categoriesWarningsFound");
150  if (categoriesWarningsFound) theDbe->removeElement(categoriesWarningsFound->getName());
151  if(nonzeros>0){
152  categoriesWarningsFound = theDbe->book1D("categoriesWarningsFound", "Warnings per category", binContent.size(),0,binContent.size());
153  } else{
154  categoriesWarningsFound = theDbe->book1D("categoriesWarningsFound", "Warnings per category", 1,0,1);
155  categoriesWarningsFound->setBinLabel(1,"Category name");
156  }
157  for (int i=0; i<nonzeros; ++i){
158  if(categoriesWarningsFound!=nullptr){
159  //gPad->SetBottomMargin(2);
160  //cout << binContent[i] <<" " <<binLabel[i] << endl;
161  categoriesWarningsFound->setBinContent(i+1,binContent[i]);
162  categoriesWarningsFound->setBinLabel(i+1,binLabel[i]);
163  }
164  }
165  if(nonzeros>4) categoriesWarningsFound->getTH1()->GetXaxis()->LabelsOption("v");
166  break;
167  case 4:
168  theDbe->setCurrentFolder(directoryName + "/Errors");
169  categoriesErrorsFound = theDbe->get(directoryName + "/Errors/categoriesErrorsFound");
170  if (categoriesErrorsFound) theDbe->removeElement(categoriesErrorsFound->getName());
171  if(nonzeros>0){
172  categoriesErrorsFound = theDbe->book1D("categoriesErrorsFound", "Errors per category", binContent.size(),0,binContent.size());
173  }else{
174  categoriesErrorsFound = theDbe->book1D("categoriesErrorsFound", "Errors per category", 1,0,1);
175  categoriesErrorsFound->setBinLabel(1,"Category name");
176  }
177  for (int i=0; i<nonzeros; ++i){
178  if(categoriesErrorsFound!=nullptr){
179  //gPad->SetBottomMargin(2);
180  categoriesErrorsFound->setBinContent(i+1,binContent[i]);
181  categoriesErrorsFound->setBinLabel(i+1,binLabel[i]);
182  }
183  }
184  if(nonzeros>4) categoriesErrorsFound->getTH1()->GetXaxis()->LabelsOption("v");
185  break;
186  }
187 
188  }
189  }
190  }
191 }
192 
193 
194 
196  fillHistograms();
197 }
198 
199 
201 
202  //LogTrace(metname)<<"[DQMMessageLoggerClient] EndJob";
203 }
T getParameter(std::string const &) const
TH1 * getTH1() const
DQMMessageLoggerClient(const edm::ParameterSet &)
void analyze(const edm::Event &, const edm::EventSetup &) override
void beginRun(const edm::Run &, const edm::EventSetup &) override
bin
set the eta bin as selection string.
~DQMMessageLoggerClient() override
HLT enums.
int getNbinsX() const
get # of bins in X-axis
void endRun(const edm::Run &, const edm::EventSetup &) override
Definition: Run.h:45