CMS 3D CMS Logo

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