Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-28 03:09:56

0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Framework/interface/Frameworkfwd.h"
0003 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0004 #include "FWCore/Framework/interface/MakerMacros.h"
0005 #include "FWCore/MessageLogger/interface/LoggedErrorsSummary.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 
0009 #include <sstream>
0010 #include <vector>
0011 
0012 namespace edmtest {
0013 
0014   class UTC_T1 : public edm::one::EDAnalyzer<> {
0015   public:
0016     explicit UTC_T1(edm::ParameterSet const& ps) : ev(0) {
0017       identifier = ps.getUntrackedParameter<int>("identifier", 99);
0018     }
0019 
0020     void analyze(edm::Event const&, edm::EventSetup const&) override;
0021 
0022   private:
0023     int identifier;
0024     int ev;
0025   };
0026 
0027   class UTC_T2 : public edm::one::EDAnalyzer<> {
0028   public:
0029     explicit UTC_T2(edm::ParameterSet const& ps) : ev(0) {
0030       identifier = ps.getUntrackedParameter<int>("identifier", 98);
0031     }
0032 
0033     void analyze(edm::Event const&, edm::EventSetup const&) override;
0034 
0035   private:
0036     int identifier;
0037     int ev;
0038     void printLES(std::vector<edm::messagelogger::ErrorSummaryEntry> const& v);
0039   };
0040 
0041   void UTC_T1::analyze(edm::Event const&, edm::EventSetup const&) {
0042     if (ev == 0)
0043       edm::EnableLoggedErrorsSummary();
0044     edm::LogError("cat_A") << "T1 error with identifier " << identifier << " event " << ev;
0045     edm::LogWarning("cat_A") << "T1 warning with identifier " << identifier << " event " << ev;
0046     edm::LogError("timer") << "T1 timer error with identifier " << identifier << " event " << ev;
0047     ev++;
0048   }
0049 
0050   void UTC_T2::analyze(edm::Event const& iEvent, edm::EventSetup const& /*unused*/
0051   ) {
0052     const auto index = iEvent.streamID().value();
0053     edm::LogError("cat_A") << "T2 error with identifier " << identifier << " event " << ev;
0054     edm::LogWarning("cat_A") << "T2 warning with identifier " << identifier << " event " << ev;
0055     edm::LogError("timer") << "T2 timer error with identifier " << identifier << " event " << ev;
0056     if (ev == 9) {
0057       if (edm::FreshErrorsExist(index)) {
0058         edm::LogInfo("summary") << "At ev = " << ev << "FreshErrorsExist() returns true";
0059       } else {
0060         edm::LogError("summary") << "At ev = " << ev << "FreshErrorsExist() returns false"
0061                                  << " which is unexpected";
0062       }
0063       auto v = edm::LoggedErrorsSummary(index);
0064       printLES(v);
0065     }
0066     if (ev == 15) {
0067       if (edm::FreshErrorsExist(index)) {
0068         edm::LogInfo("summary") << "At ev = " << ev << "FreshErrorsExist() returns true";
0069       } else {
0070         edm::LogError("summary") << "At ev = " << ev << "FreshErrorsExist() returns false"
0071                                  << " which is unexpected";
0072       }
0073       auto v = edm::LoggedErrorsOnlySummary(index);
0074       printLES(v);
0075     }
0076     ev++;
0077   }
0078 
0079   void UTC_T2::printLES(std::vector<edm::messagelogger::ErrorSummaryEntry> const& v) {
0080     std::ostringstream s;
0081     auto end = v.end();
0082     s << "Error Summary Vector with " << v.size() << " entries:\n";
0083     for (auto i = v.begin(); i != end; ++i) {
0084       s << "Category " << i->category << "   Module " << i->module << "   Severity " << (i->severity).getName()
0085         << "   Count " << i->count << "\n";
0086     }
0087     s << "-------------------------- \n";
0088     edm::LogVerbatim("summary") << s.str();
0089   }
0090 
0091 }  // namespace edmtest
0092 
0093 using edmtest::UTC_T1;
0094 using edmtest::UTC_T2;
0095 DEFINE_FWK_MODULE(UTC_T1);
0096 DEFINE_FWK_MODULE(UTC_T2);