Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:26

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/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::EDFilter {
0039 public:
0040   explicit ErrorSummaryFilter(edm::ParameterSet const&);
0041   ~ErrorSummaryFilter() override;
0042 
0043 private:
0044   bool filter(edm::Event&, edm::EventSetup const&) override;
0045 
0046   // ----------member data ---------------------------
0047   edm::EDGetTokenT<std::vector<edm::ErrorSummaryEntry> > srcToken_;
0048   std::vector<std::string> modules_;
0049   std::string severityName_;
0050   std::vector<std::string> avoidCategories_;
0051   typedef std::vector<edm::ErrorSummaryEntry> ErrorSummaryEntries;
0052 };
0053 
0054 //
0055 // constants, enums and typedefs
0056 //
0057 
0058 //
0059 // static data member definitions
0060 //
0061 
0062 //
0063 // constructors and destructor
0064 //
0065 ErrorSummaryFilter::ErrorSummaryFilter(edm::ParameterSet const& iConfig)
0066     : srcToken_(consumes<std::vector<edm::ErrorSummaryEntry> >(iConfig.getParameter<edm::InputTag>("src"))),
0067       modules_(iConfig.getParameter<std::vector<std::string> >("modules")),
0068       severityName_(iConfig.getParameter<std::string>("severity")),
0069       avoidCategories_(iConfig.getParameter<std::vector<std::string> >("avoidCategories")) {
0070   if (!(severityName_ == "error" || severityName_ == "warning")) {
0071     throw edm::Exception(edm::errors::Configuration) << "Severity parameter needs to be 'error' or 'warning'.\n";
0072   }
0073 }
0074 
0075 ErrorSummaryFilter::~ErrorSummaryFilter() {
0076   // do anything here that needs to be done at desctruction time
0077   // (e.g. close files, deallocate resources etc.)
0078 }
0079 
0080 //
0081 // member functions
0082 //
0083 
0084 // ------------ method called on each new Event  ------------
0085 bool ErrorSummaryFilter::filter(edm::Event& iEvent, edm::EventSetup const& iSetup) {
0086   edm::Handle<std::vector<edm::ErrorSummaryEntry> > errorSummaryEntry;
0087   iEvent.getByToken(srcToken_, errorSummaryEntry);
0088 
0089   for (ErrorSummaryEntries::const_iterator i = errorSummaryEntry->begin(), end = errorSummaryEntry->end(); i != end;
0090        ++i) {
0091     if (std::find(modules_.begin(), modules_.end(), i->module) != modules_.end()) {
0092       if (std::find(avoidCategories_.begin(), avoidCategories_.end(), i->category) != avoidCategories_.end()) {
0093         continue;
0094       } else {
0095         edm::ELseverityLevel const& severity = i->severity;
0096         if (severityName_ == "error") {
0097           if (severity.getLevel() == edm::ELseverityLevel::ELsev_error ||
0098               severity.getLevel() == edm::ELseverityLevel::ELsev_warning) {
0099             return (false);
0100           }
0101         } else if (severityName_ == "warning") {
0102           if (severity.getLevel() == edm::ELseverityLevel::ELsev_warning) {
0103             return (false);
0104           }
0105         } else {
0106           continue;
0107         }
0108       }
0109     }
0110   }
0111   return (true);
0112 }
0113 
0114 //define this as a plug-in
0115 DEFINE_FWK_MODULE(ErrorSummaryFilter);