Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-05-23 23:48:35

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