Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:43

0001 // -*- C++ -*-
0002 //
0003 // Package:    ArbitraryLogError
0004 // Class:      ArbitraryLogError
0005 //
0006 /**\class ArbitraryLogError ArbitraryLogError.cc HLTrigger/ArbitraryLogError/src/ArbitraryLogError.cc
0007 
0008 Description: <one line class summary>
0009 
0010 Implementation:
0011 <Notes on implementation>
0012  */
0013 //
0014 // Original Author:  Andrea Bocci,Bld. 40 Room 4-A01,+41227671545,
0015 //         Created:  Tue Nov 10 12:00:46 CET 2009
0016 //
0017 //
0018 
0019 // system include files
0020 #include <stdint.h>
0021 #include <atomic>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0029 
0030 //
0031 // class decleration
0032 //
0033 
0034 class ArbitraryLogError : public edm::global::EDAnalyzer<> {
0035 public:
0036   explicit ArbitraryLogError(const edm::ParameterSet&);
0037   ~ArbitraryLogError() override;
0038 
0039 private:
0040   void beginJob() override;
0041   void analyze(edm::StreamID, const edm::Event&, const edm::EventSetup&) const override;
0042   void endJob() override;
0043 
0044   const std::string m_category;
0045   const bool m_severity;
0046   const uint32_t m_rate;
0047   mutable std::atomic<uint32_t> m_counter;
0048 };
0049 
0050 // CTOR
0051 ArbitraryLogError::ArbitraryLogError(const edm::ParameterSet& config)
0052     : m_category(config.getParameter<std::string>("category")),
0053       m_severity(config.getParameter<std::string>("severity") == "Error"),
0054       m_rate(config.getParameter<uint32_t>("rate")),
0055       m_counter(0) {}
0056 
0057 // DTOR
0058 ArbitraryLogError::~ArbitraryLogError() = default;
0059 
0060 // ------------ method called to for each event  ------------
0061 void ArbitraryLogError::analyze(edm::StreamID, const edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0062   if (not(++m_counter % m_rate)) {
0063     if (m_severity)
0064       (edm::LogError(m_category));
0065     else
0066       (edm::LogWarning(m_category));
0067   }
0068 }
0069 
0070 // ------------ method called once each job just before starting event loop  ------------
0071 void ArbitraryLogError::beginJob() {}
0072 
0073 // ------------ method called once each job just after ending the event loop  ------------
0074 void ArbitraryLogError::endJob() {}
0075 
0076 // declare this class as a framework plugin
0077 #include "FWCore/Framework/interface/MakerMacros.h"
0078 DEFINE_FWK_MODULE(ArbitraryLogError);