Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:17

0001 // -*- C++ -*-
0002 //
0003 // Package:    ErrorSummaryFilter
0004 // Class:      ErrorSummaryFilter
0005 //
0006 /**\class ErrorSummaryFilter ErrorSummaryFilter.cc PhysicsTools/UtilAlgos/plugins/ErrorSummaryFilter.cc
0007 
0008  Description: Filter to remove events with given error types
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Benedikt Hegner
0015 //         Created:  Thu May 10 20:23:28 CET 2010
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/global/EDFilter.h"
0025 
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 
0031 #include "DataFormats/Common/interface/ErrorSummaryEntry.h"
0032 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0033 
0034 //
0035 // class declaration
0036 //
0037 
0038 class ErrorSummaryFilter : public edm::global::EDFilter<> {
0039 public:
0040   explicit ErrorSummaryFilter(edm::ParameterSet const&);
0041 
0042 private:
0043   bool filter(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
0044 
0045   // ----------member data ---------------------------
0046   edm::EDGetTokenT<std::vector<edm::ErrorSummaryEntry> > srcToken_;
0047   std::vector<std::string> modules_;
0048   std::string severityName_;
0049   std::vector<std::string> avoidCategories_;
0050   typedef std::vector<edm::ErrorSummaryEntry> ErrorSummaryEntries;
0051 };
0052 
0053 //
0054 // constants, enums and typedefs
0055 //
0056 
0057 //
0058 // static data member definitions
0059 //
0060 
0061 //
0062 // constructors and destructor
0063 //
0064 ErrorSummaryFilter::ErrorSummaryFilter(edm::ParameterSet const& iConfig)
0065     : srcToken_(consumes<std::vector<edm::ErrorSummaryEntry> >(iConfig.getParameter<edm::InputTag>("src"))),
0066       modules_(iConfig.getParameter<std::vector<std::string> >("modules")),
0067       severityName_(iConfig.getParameter<std::string>("severity")),
0068       avoidCategories_(iConfig.getParameter<std::vector<std::string> >("avoidCategories")) {
0069   if (!(severityName_ == "error" || severityName_ == "warning")) {
0070     throw edm::Exception(edm::errors::Configuration) << "Severity parameter needs to be 'error' or 'warning'.\n";
0071   }
0072 }
0073 
0074 //
0075 // member functions
0076 //
0077 
0078 // ------------ method called on each new Event  ------------
0079 bool ErrorSummaryFilter::filter(edm::StreamID, edm::Event& iEvent, edm::EventSetup const& iSetup) const {
0080   edm::Handle<std::vector<edm::ErrorSummaryEntry> > errorSummaryEntry;
0081   iEvent.getByToken(srcToken_, errorSummaryEntry);
0082 
0083   for (ErrorSummaryEntries::const_iterator i = errorSummaryEntry->begin(), end = errorSummaryEntry->end(); i != end;
0084        ++i) {
0085     if (std::find(modules_.begin(), modules_.end(), i->module) != modules_.end()) {
0086       if (std::find(avoidCategories_.begin(), avoidCategories_.end(), i->category) != avoidCategories_.end()) {
0087         continue;
0088       } else {
0089         edm::ELseverityLevel const& severity = i->severity;
0090         if (severityName_ == "error") {
0091           if (severity.getLevel() == edm::ELseverityLevel::ELsev_error ||
0092               severity.getLevel() == edm::ELseverityLevel::ELsev_warning) {
0093             return (false);
0094           }
0095         } else if (severityName_ == "warning") {
0096           if (severity.getLevel() == edm::ELseverityLevel::ELsev_warning) {
0097             return (false);
0098           }
0099         } else {
0100           continue;
0101         }
0102       }
0103     }
0104   }
0105   return (true);
0106 }
0107 
0108 //define this as a plug-in
0109 DEFINE_FWK_MODULE(ErrorSummaryFilter);