Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-23 03:25:09

0001 //
0002 // Package:    LogErrorHarvester
0003 // Class:      LogErrorHarvester
0004 
0005 /**\class LogErrorHarvester LogErrorHarvester.cc FWCore/Modules/src/LogErrorHarvester.cc
0006 
0007  Description: Harvestes LogError messages and puts them into the Event
0008 
0009  Implementation:
0010    This simple implementation writes the std::vector<ErrorSummaryEntry> in the event,
0011    without any fancy attempt of encoding the strings or mapping them to ints
0012 */
0013 //
0014 // Original Author:  Giovanni Petrucciani
0015 //         Created:  Thu Dec  4 16:22:40 CET 2008
0016 //
0017 
0018 // user include files
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/MakerMacros.h"
0021 #include "FWCore/Framework/interface/global/EDProducer.h"
0022 #include "DataFormats/Common/interface/ErrorSummaryEntry.h"
0023 #include "FWCore/MessageLogger/interface/LoggedErrorsSummary.h"
0024 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0026 #include "DataFormats/Common/interface/EndPathStatus.h"
0027 #include "DataFormats/Common/interface/PathStatus.h"
0028 #include "DataFormats/Common/interface/TriggerResults.h"
0029 #include "FWCore/Utilities/interface/EDPutToken.h"
0030 
0031 // system include files
0032 #include <memory>
0033 #include <unordered_set>
0034 #include <string>
0035 
0036 //
0037 // class decleration
0038 //
0039 
0040 namespace edm {
0041   class LogErrorHarvester : public global::EDProducer<> {
0042   public:
0043     explicit LogErrorHarvester(ParameterSet const&);
0044     static void fillDescriptions(ConfigurationDescriptions& descriptions);
0045 
0046   private:
0047     void beginJob() override;
0048     void produce(StreamID, Event&, EventSetup const&) const override;
0049     void endJob() override;
0050     EDPutTokenT<std::vector<ErrorSummaryEntry>> token_;
0051   };
0052 
0053   LogErrorHarvester::LogErrorHarvester(ParameterSet const& iPSet) : token_{produces()} {
0054     const edm::TypeID endPathStatusType{typeid(edm::EndPathStatus)};
0055     const edm::TypeID pathStatusType{typeid(edm::PathStatus)};
0056     const edm::TypeID triggerResultsType{typeid(edm::TriggerResults)};
0057 
0058     auto const& ignore = iPSet.getUntrackedParameter<std::vector<std::string>>("excludeModules");
0059     const std::unordered_set<std::string> excludedModules(ignore.begin(), ignore.end());
0060 
0061     auto const& includeM = iPSet.getUntrackedParameter<std::vector<std::string>>("includeModules");
0062     const std::unordered_set<std::string> includeModules(includeM.begin(), includeM.end());
0063 
0064     //Need to be sure to run only after all other EDProducers have run
0065     callWhenNewProductsRegistered(
0066         [this, endPathStatusType, pathStatusType, triggerResultsType, excludedModules, includeModules](
0067             edm::BranchDescription const& iBD) {
0068           if ((iBD.branchType() == edm::InEvent and moduleDescription().processName() == iBD.processName()) and
0069               ((includeModules.empty() or includeModules.end() != includeModules.find(iBD.moduleLabel())) and
0070                (iBD.unwrappedTypeID() != endPathStatusType and iBD.unwrappedTypeID() != pathStatusType and
0071                 iBD.unwrappedTypeID() != triggerResultsType))) {
0072             if (excludedModules.end() == excludedModules.find(iBD.moduleLabel())) {
0073               consumes(edm::TypeToGet{iBD.unwrappedTypeID(), edm::PRODUCT_TYPE},
0074                        edm::InputTag{iBD.moduleLabel(), iBD.productInstanceName(), iBD.processName()});
0075             }
0076           }
0077         });
0078   }
0079 
0080   void LogErrorHarvester::produce(StreamID const sid, Event& iEvent, EventSetup const&) const {
0081     const auto index = sid.value();
0082     if (!FreshErrorsExist(index)) {
0083       //puts a default constructed product in the event
0084       iEvent.emplace(token_);
0085     } else {
0086       auto mlSummary = LoggedErrorsSummary(index);
0087       std::vector<edm::ErrorSummaryEntry> summary;
0088       summary.reserve(mlSummary.size());
0089       for (auto& entry : mlSummary) {
0090         edm::ErrorSummaryEntry e;
0091         e.category = std::move(entry.category);
0092         e.module = std::move(entry.module);
0093         e.severity = edm::ELseverityLevel(entry.severity.getLevel());
0094         e.count = entry.count;
0095         summary.emplace_back(std::move(e));
0096       }
0097       iEvent.emplace(token_, summary);
0098     }
0099   }
0100 
0101   // ------------ method called once each job just before starting event loop  ------------
0102   void LogErrorHarvester::beginJob() { EnableLoggedErrorsSummary(); }
0103 
0104   // ------------ method called once each job just after ending the event loop  ------------
0105   void LogErrorHarvester::endJob() { DisableLoggedErrorsSummary(); }
0106 
0107   // ------------ method called once each job for validation  ------------
0108   void LogErrorHarvester::fillDescriptions(ConfigurationDescriptions& descriptions) {
0109     ParameterSetDescription desc;
0110     desc.addUntracked<std::vector<std::string>>("excludeModules", std::vector<std::string>{})
0111         ->setComment("List of module labels to exclude from consumes.");
0112     desc.addUntracked<std::vector<std::string>>("includeModules", std::vector<std::string>{})
0113         ->setComment("List of the only module labels to include in consumes. The empty list will include all.");
0114     descriptions.add("logErrorHarvester", desc);
0115   }
0116 }  // namespace edm
0117 
0118 //define this as a plug-in
0119 using edm::LogErrorHarvester;
0120 DEFINE_FWK_MODULE(LogErrorHarvester);