Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:46

0001 #ifndef FWCore_MessageService_ThreadSafeLogMessageLoggerScribe_h
0002 #define FWCore_MessageService_ThreadSafeLogMessageLoggerScribe_h
0003 
0004 #include "FWCore/Utilities/interface/value_ptr.h"
0005 #include "FWCore/Utilities/interface/propagate_const.h"
0006 
0007 #include "FWCore/MessageService/src/ELdestination.h"
0008 #include "FWCore/MessageService/src/MessageLoggerDefaults.h"
0009 #include "FWCore/MessageLogger/interface/MessageLoggerQ.h"
0010 #include "FWCore/MessageLogger/interface/AbstractMLscribe.h"
0011 
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 
0014 #include <memory>
0015 
0016 #include <iosfwd>
0017 #include <vector>
0018 #include <map>
0019 
0020 #include <iostream>
0021 #include <atomic>
0022 #include "oneapi/tbb/concurrent_queue.h"
0023 
0024 namespace edm {
0025   namespace service {
0026 
0027     // ----------------------------------------------------------------------
0028     //
0029     // ThreadSafeLogMessageLoggerScribe.h
0030     //
0031     // OpCodeLOG_A_MESSAGE messages can be handled from multiple threads
0032     //
0033     // -----------------------------------------------------------------------
0034 
0035     class ELadministrator;
0036     class ELstatistics;
0037 
0038     class ThreadSafeLogMessageLoggerScribe : public AbstractMLscribe {
0039     public:
0040       // ---  birth/death:
0041 
0042       // ChangeLog 12
0043       /// --- If queue is NULL, this sets singleThread true
0044       explicit ThreadSafeLogMessageLoggerScribe();
0045 
0046       ~ThreadSafeLogMessageLoggerScribe() override;
0047 
0048       // --- receive and act on messages:
0049       // changelog 10
0050       void runCommand(MessageLoggerQ::OpCode opcode, void* operand) override;
0051       // changeLog 9
0052 
0053       struct ConfigurableDefaults {
0054         static constexpr int NO_VALUE_SET = -45654;
0055         static constexpr int COMMON_DEFAULT_LIMIT = NO_VALUE_SET;
0056         static constexpr int COMMON_DEFAULT_INTERVAL = NO_VALUE_SET;
0057         static constexpr int COMMON_DEFAULT_TIMESPAN = NO_VALUE_SET;
0058 
0059         std::string threshold_;
0060         int limit_;
0061         int reportEvery_;
0062         int timespan_;
0063         int lineLength_;
0064         bool noLineBreaks_;
0065         bool noTimeStamps_;
0066       };
0067 
0068     private:
0069       static ConfigurableDefaults parseDefaults(edm::ParameterSet const& job_pset);
0070 
0071       // --- convenience typedefs
0072       using vString = std::vector<std::string>;
0073 
0074       // --- log one consumed message
0075       void log(ErrorObj* errorobj_p);
0076 
0077       // --- cause statistics destinations to output
0078       void triggerStatisticsSummaries();
0079       void triggerFJRmessageSummary(std::map<std::string, double>& sm);
0080 
0081       // --- handle details of configuring via a ParameterSet:
0082       void configure_errorlog(edm::ParameterSet&);
0083       void configure_errorlog_new(edm::ParameterSet&);
0084       std::vector<std::string> configure_ordinary_destinations(edm::ParameterSet const&,
0085                                                                ConfigurableDefaults const& defaults,
0086                                                                vString const& categories);
0087       void configure_statistics(edm::ParameterSet const&,
0088                                 ConfigurableDefaults const& defaults,
0089                                 vString const& categories,
0090                                 std::vector<std::string> const& destination_names);
0091       void configure_statistics_dest(edm::ParameterSet const& job_pset,
0092                                      ConfigurableDefaults const& defaults,
0093                                      vString const& categories,
0094                                      edm::ParameterSet const& stat_pset,
0095                                      std::string const& psetname,
0096                                      std::string const& filename);
0097       void configure_dest(edm::ParameterSet const& job_pset,
0098                           ConfigurableDefaults const&,
0099                           vString const& categories,
0100                           std::shared_ptr<ELdestination> dest_ctrl,
0101                           edm::ParameterSet const& dest_pset,
0102                           std::string const& filename);
0103 
0104       template <class T>
0105       static T getAparameter(edm::ParameterSet const& p, std::string const& id, T const& def) {
0106         T t = def;
0107         try {
0108           t = p.template getUntrackedParameter<T>(id, def);
0109         } catch (...) {
0110           try {
0111             t = p.template getParameter<T>(id);
0112           } catch (...) {
0113             // Since PSetValidation will catch such errors, we simply proceed as
0114             // best we can in case we are setting up the logger just to contain the
0115             // validation-caught error messages.
0116           }
0117         }
0118         return t;
0119       }
0120 
0121       // --- other helpers
0122       void parseCategories(std::string const& s, std::vector<std::string>& cats);
0123       std::string destinationFileName(edm::ParameterSet const&, std::string const&) const;
0124       std::shared_ptr<ELdestination> makeDestinationCtrl(std::string const& filename);
0125 
0126       void validate(edm::ParameterSet&) const;
0127       // --- data:
0128       edm::propagate_const<std::shared_ptr<ELadministrator>> m_admin_p;
0129       std::shared_ptr<ELdestination> m_early_dest;
0130       std::vector<edm::propagate_const<std::shared_ptr<std::ofstream>>> m_file_ps;
0131       std::map<std::string, edm::propagate_const<std::ostream*>> m_stream_ps;
0132       std::vector<std::shared_ptr<ELstatistics>> m_statisticsDestControls;
0133       std::vector<bool> m_statisticsResets;
0134       bool m_clean_slate_configuration;
0135       value_ptr<MessageLoggerDefaults> m_messageLoggerDefaults;
0136       bool m_active;
0137       std::atomic<bool> m_purge_mode;
0138       std::atomic<int> m_count;
0139       std::atomic<bool> m_messageBeingSent;
0140       oneapi::tbb::concurrent_queue<ErrorObj*> m_waitingMessages;
0141       size_t m_waitingThreshold;
0142       std::atomic<unsigned long> m_tooManyWaitingMessagesCount;
0143 
0144     };  // ThreadSafeLogMessageLoggerScribe
0145 
0146   }  // end of namespace service
0147 }  // namespace edm
0148 
0149 #endif  // FWCore_MessageService_ThreadSafeLogMessageLoggerScribe_h