CMS 3D CMS Logo

LogErrorFilter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: LogErrorFilter
4 // Class: LogErrorFilter
5 //
13 //
14 // Original Author: Jean-Roch Vlimant
15 // Created: Thu Nov 12 15:59:28 CET 2009
16 //
17 //
18 
19 // user include files
27 
28 // system include files
29 #include <memory>
30 
31 //
32 // class declaration
33 //
34 
36 public:
37  explicit LogErrorFilter(edm::ParameterSet const&);
38  ~LogErrorFilter() override;
39  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
40 
41 private:
42  bool filter(edm::Event&, edm::EventSetup const&) override;
43 
44  void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
45 
46  // ----------member data ---------------------------
52 
53  unsigned int maxErrorKindsPerLumi_;
55 
56  std::vector<std::string> avoidCategories_;
57 
58  std::map<std::string, unsigned int> errorCounts_;
59  std::map<std::string, unsigned int> warningCounts_;
60 };
61 
62 //
63 // constants, enums and typedefs
64 //
65 
66 //
67 // static data member definitions
68 //
69 
70 //
71 // constructors and destructor
72 //
74  : atLeastOneError_(iConfig.getParameter<bool>("atLeastOneError")),
75  atLeastOneWarning_(iConfig.getParameter<bool>("atLeastOneWarning")),
77  useThresholdsPerKind_(iConfig.getParameter<bool>("useThresholdsPerKind")),
78  avoidCategories_(iConfig.getParameter<std::vector<std::string>>("avoidCategories")) {
81  << "Useless configuration of the error/warning filter. Need to select on an error or a warning or both.\n";
82  }
83  harvesterToken_ = consumes<std::vector<edm::ErrorSummaryEntry>>(iConfig.getParameter<edm::InputTag>("harvesterTag"));
84  maxErrorKindsPerLumi_ = 999999;
85  maxWarningKindsPerLumi_ = 999999;
87  maxErrorKindsPerLumi_ = iConfig.getParameter<unsigned int>("maxErrorKindsPerLumi");
88  maxWarningKindsPerLumi_ = iConfig.getParameter<unsigned int>("maxWarningKindsPerLumi");
89  }
90 }
91 
93  // do anything here that needs to be done at desctruction time
94  // (e.g. close files, deallocate resources etc.)
95 }
96 
97 //
98 // member functions
99 //
100 
101 // ------------ method called on each new Event ------------
103  if (auto errorsAndWarnings = iEvent.getHandle(harvesterToken_)) {
104  if (useThresholdsPerKind_) {
105  unsigned int errorsBelowThreshold = 0;
106  unsigned int warningsBelowThreshold = 0;
107  // update counters here
108  for (auto const& summary : *errorsAndWarnings) {
109  if (std::find(avoidCategories_.begin(), avoidCategories_.end(), summary.category) != avoidCategories_.end())
110  continue;
111  std::string kind = summary.category + ":" + summary.module;
112  int iSeverity = summary.severity.getLevel();
113  if (iSeverity == edm::ELseverityLevel::ELsev_error) {
114  unsigned int& iCount = errorCounts_[kind];
115  iCount++;
116  if (iCount <= maxErrorKindsPerLumi_)
117  errorsBelowThreshold++;
118  } else if (iSeverity == edm::ELseverityLevel::ELsev_warning) {
119  unsigned int& iCount = warningCounts_[kind];
120  iCount++;
121  if (iCount <= maxWarningKindsPerLumi_)
122  warningsBelowThreshold++;
123  }
124  }
125  return ((atLeastOneEntry_ && (errorsBelowThreshold > 0 || warningsBelowThreshold > 0)) ||
126  (atLeastOneError_ && errorsBelowThreshold > 0) || (atLeastOneWarning_ && warningsBelowThreshold > 0));
127  } else {
128  //no separation by kind, just count any errors/warnings
129  if (atLeastOneEntry_) {
130  for (auto const& summary : *errorsAndWarnings) {
131  edm::ELseverityLevel const& severity = summary.severity;
132  if (severity.getLevel() != edm::ELseverityLevel::ELsev_error and
134  continue;
135  }
136  if (!avoidCategories_.empty()) {
137  //veto categories from user input.
138  if (std::find(avoidCategories_.begin(), avoidCategories_.end(), summary.category) !=
139  avoidCategories_.end()) {
140  continue;
141  }
142  }
143  return true;
144  }
145  return false;
146  } else {
148  unsigned int nError = 0;
149  unsigned int nWarning = 0;
150  for (auto const& summary : *errorsAndWarnings) {
151  //veto categories from user input.
152  if (!avoidCategories_.empty()) {
153  if (std::find(avoidCategories_.begin(), avoidCategories_.end(), summary.category) !=
154  avoidCategories_.end()) {
155  continue;
156  }
157  }
158  edm::ELseverityLevel const& severity = summary.severity;
159  //count errors
160  if (severity.getLevel() == edm::ELseverityLevel::ELsev_error) {
161  ++nError;
162  }
163  //count warnings
164  if (severity.getLevel() == edm::ELseverityLevel::ELsev_warning) {
165  ++nWarning;
166  }
167  }
168  if (atLeastOneError_ && nError != 0) {
169  return (true);
170  }
171  if (atLeastOneWarning_ && nWarning != 0) {
172  return (true);
173  }
174  }
175  }
176  }
177  }
178  return (false);
179 }
180 
182  if (useThresholdsPerKind_) {
183  for (auto& err : errorCounts_) {
184  err.second = 0;
185  }
186  for (auto& err : warningCounts_) {
187  err.second = 0;
188  }
189  }
190 
191  return;
192 }
193 
196  desc.add<edm::InputTag>("harvesterTag");
197  desc.add<bool>("atLeastOneError");
198  desc.add<bool>("atLeastOneWarning");
199  desc.add<bool>("useThresholdsPerKind");
200  desc.add<unsigned int>("maxErrorKindsPerLumi", 999999);
201  desc.add<unsigned int>("maxWarningKindsPerLumi", 999999);
202  desc.add<std::vector<std::string>>("avoidCategories");
203  descriptions.add("logErrorFilter", desc);
204 }
205 
206 //define this as a plug-in
T getParameter(std::string const &) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
bool useThresholdsPerKind_
std::vector< std::string > avoidCategories_
unsigned int maxErrorKindsPerLumi_
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:539
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::map< std::string, unsigned int > errorCounts_
~LogErrorFilter() override
unsigned int maxWarningKindsPerLumi_
bool filter(edm::Event &, edm::EventSetup const &) override
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< std::vector< edm::ErrorSummaryEntry > > harvesterToken_
LogErrorFilter(edm::ParameterSet const &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::map< std::string, unsigned int > warningCounts_