File indexing completed on 2024-04-06 12:12:48
0001 #include "FWCore/Framework/interface/Frameworkfwd.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0004 #include "FWCore/Framework/interface/MakerMacros.h"
0005 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0006 #include "FWCore/MessageLogger/interface/LoggedErrorsSummary.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/Utilities/interface/StreamID.h"
0010
0011 #include <sstream>
0012
0013 namespace edmtest {
0014
0015 class UTC_S1 : public edm::one::EDAnalyzer<> {
0016 public:
0017 explicit UTC_S1(edm::ParameterSet const &pset) {
0018 identifier = pset.getUntrackedParameter<int>("identifier", 99);
0019 edm::GroupLogStatistics("grouped_cat");
0020 }
0021
0022 void analyze(edm::Event const &, edm::EventSetup const &) override;
0023
0024 private:
0025 int identifier;
0026 bool enableNotYetCalled = true;
0027 int n = 0;
0028 };
0029
0030 class UTC_S2 : public edm::one::EDAnalyzer<> {
0031 public:
0032 explicit UTC_S2(edm::ParameterSet const &p) { identifier = p.getUntrackedParameter<int>("identifier", 98); }
0033
0034 void analyze(edm::Event const &, edm::EventSetup const &) override;
0035
0036 private:
0037 int identifier;
0038 int n = 0;
0039 };
0040
0041 class UTC_SUMMARY : public edm::global::EDAnalyzer<> {
0042 public:
0043 explicit UTC_SUMMARY(edm::ParameterSet const &) {}
0044
0045 void analyze(edm::StreamID, edm::Event const &, edm::EventSetup const &) const override;
0046 };
0047
0048 void UTC_S1::analyze(edm::Event const &, edm::EventSetup const &) {
0049 if (enableNotYetCalled) {
0050 edm::EnableLoggedErrorsSummary();
0051 enableNotYetCalled = false;
0052 }
0053 n++;
0054 if (n <= 2)
0055 return;
0056 edm::LogError("cat_A") << "S1 with identifier " << identifier << " n = " << n;
0057 edm::LogError("grouped_cat") << "S1 timer with identifier " << identifier;
0058 }
0059
0060 void UTC_S2::analyze(edm::Event const &, edm::EventSetup const &) {
0061 n++;
0062 if (n <= 2)
0063 return;
0064 edm::LogError("cat_A") << "S2 with identifier " << identifier;
0065 edm::LogError("grouped_cat") << "S2 timer with identifier " << identifier;
0066 edm::LogError("cat_B") << "S2B with identifier " << identifier;
0067 for (int i = 0; i < n; ++i) {
0068 edm::LogError("cat_B") << "more S2B";
0069 }
0070 }
0071
0072 void UTC_SUMMARY::analyze(edm::StreamID, edm::Event const &iEvent, edm::EventSetup const &) const {
0073 const auto index = iEvent.streamID().value();
0074 if (!edm::FreshErrorsExist(index)) {
0075 edm::LogInfo("NoFreshErrors") << "Not in this event, anyway";
0076 }
0077 auto es = edm::LoggedErrorsSummary(index);
0078 std::ostringstream os;
0079 for (unsigned int i = 0; i != es.size(); ++i) {
0080 os << es[i].category << " " << es[i].module << " " << es[i].count << "\n";
0081 }
0082 edm::LogVerbatim("ErrorsInEvent") << os.str();
0083 }
0084
0085 }
0086
0087 using edmtest::UTC_S1;
0088 using edmtest::UTC_S2;
0089 using edmtest::UTC_SUMMARY;
0090 DEFINE_FWK_MODULE(UTC_S1);
0091 DEFINE_FWK_MODULE(UTC_S2);
0092 DEFINE_FWK_MODULE(UTC_SUMMARY);