File indexing completed on 2024-04-06 12:18:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <stdint.h>
0021 #include <atomic>
0022
0023
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
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
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
0058 ArbitraryLogError::~ArbitraryLogError() = default;
0059
0060
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
0071 void ArbitraryLogError::beginJob() {}
0072
0073
0074 void ArbitraryLogError::endJob() {}
0075
0076
0077 #include "FWCore/Framework/interface/MakerMacros.h"
0078 DEFINE_FWK_MODULE(ArbitraryLogError);