CMS 3D CMS Logo

ThreadSafeLogMessageLoggerScribe.h
Go to the documentation of this file.
1 #ifndef FWCore_MessageService_ThreadSafeLogMessageLoggerScribe_h
2 #define FWCore_MessageService_ThreadSafeLogMessageLoggerScribe_h
3 
6 
11 
13 
14 #include <memory>
15 
16 #include <iosfwd>
17 #include <vector>
18 #include <map>
19 
20 #include <iostream>
21 #include <atomic>
22 #include "oneapi/tbb/concurrent_queue.h"
23 
24 namespace edm {
25  namespace service {
26 
27  // ----------------------------------------------------------------------
28  //
29  // ThreadSafeLogMessageLoggerScribe.h
30  //
31  // OpCodeLOG_A_MESSAGE messages can be handled from multiple threads
32  //
33  // -----------------------------------------------------------------------
34 
35  class ELadministrator;
36  class ELstatistics;
37 
39  public:
40  // --- birth/death:
41 
42  // ChangeLog 12
45 
47 
48  // --- receive and act on messages:
49  // changelog 10
50  void runCommand(MessageLoggerQ::OpCode opcode, void* operand) override;
51  // changeLog 9
52 
54  static constexpr int NO_VALUE_SET = -45654;
58 
60  int limit_;
62  int timespan_;
66  };
67 
68  private:
70 
71  // --- convenience typedefs
72  using vString = std::vector<std::string>;
73 
74  // --- log one consumed message
75  void log(ErrorObj* errorobj_p);
76 
77  // --- cause statistics destinations to output
79  void triggerFJRmessageSummary(std::map<std::string, double>& sm);
80 
81  // --- handle details of configuring via a ParameterSet:
84  std::vector<std::string> configure_ordinary_destinations(edm::ParameterSet const&,
86  vString const& categories);
89  vString const& categories,
90  std::vector<std::string> const& destination_names);
91  void configure_statistics_dest(edm::ParameterSet const& job_pset,
93  vString const& categories,
94  edm::ParameterSet const& stat_pset,
95  std::string const& psetname,
96  std::string const& filename);
97  void configure_dest(edm::ParameterSet const& job_pset,
98  ConfigurableDefaults const&,
99  vString const& categories,
100  std::shared_ptr<ELdestination> dest_ctrl,
101  edm::ParameterSet const& dest_pset,
102  std::string const& filename);
103 
104  template <class T>
105  static T getAparameter(edm::ParameterSet const& p, std::string const& id, T const& def) {
106  T t = def;
107  try {
108  t = p.template getUntrackedParameter<T>(id, def);
109  } catch (...) {
110  try {
111  t = p.template getParameter<T>(id);
112  } catch (...) {
113  // Since PSetValidation will catch such errors, we simply proceed as
114  // best we can in case we are setting up the logger just to contain the
115  // validation-caught error messages.
116  }
117  }
118  return t;
119  }
120 
121  // --- other helpers
122  void parseCategories(std::string const& s, std::vector<std::string>& cats);
124  std::shared_ptr<ELdestination> makeDestinationCtrl(std::string const& filename);
125 
126  void validate(edm::ParameterSet&) const;
127  // --- data:
129  std::shared_ptr<ELdestination> m_early_dest;
130  std::vector<edm::propagate_const<std::shared_ptr<std::ofstream>>> m_file_ps;
131  std::map<std::string, edm::propagate_const<std::ostream*>> m_stream_ps;
132  std::vector<std::shared_ptr<ELstatistics>> m_statisticsDestControls;
133  std::vector<bool> m_statisticsResets;
136  bool m_active;
137  std::atomic<bool> m_purge_mode;
138  std::atomic<int> m_count;
139  std::atomic<bool> m_messageBeingSent;
140  oneapi::tbb::concurrent_queue<ErrorObj*> m_waitingMessages;
142  std::atomic<unsigned long> m_tooManyWaitingMessagesCount;
143 
144  }; // ThreadSafeLogMessageLoggerScribe
145 
146  } // end of namespace service
147 } // namespace edm
148 
149 #endif // FWCore_MessageService_ThreadSafeLogMessageLoggerScribe_h
int def(FILE *, FILE *, int)
void runCommand(MessageLoggerQ::OpCode opcode, void *operand) override
std::string destinationFileName(edm::ParameterSet const &, std::string const &) const
void triggerFJRmessageSummary(std::map< std::string, double > &sm)
std::vector< edm::propagate_const< std::shared_ptr< std::ofstream > > > m_file_ps
oneapi::tbb::concurrent_queue< ErrorObj * > m_waitingMessages
ThreadSafeLogMessageLoggerScribe()
— If queue is NULL, this sets singleThread true
static ConfigurableDefaults parseDefaults(edm::ParameterSet const &job_pset)
void configure_statistics_dest(edm::ParameterSet const &job_pset, ConfigurableDefaults const &defaults, vString const &categories, edm::ParameterSet const &stat_pset, std::string const &psetname, std::string const &filename)
std::map< std::string, edm::propagate_const< std::ostream * > > m_stream_ps
edm::propagate_const< std::shared_ptr< ELadministrator > > m_admin_p
std::vector< std::shared_ptr< ELstatistics > > m_statisticsDestControls
HLT enums.
std::vector< std::string > configure_ordinary_destinations(edm::ParameterSet const &, ConfigurableDefaults const &defaults, vString const &categories)
void parseCategories(std::string const &s, std::vector< std::string > &cats)
void configure_statistics(edm::ParameterSet const &, ConfigurableDefaults const &defaults, vString const &categories, std::vector< std::string > const &destination_names)
static T getAparameter(edm::ParameterSet const &p, std::string const &id, T const &def)
std::shared_ptr< ELdestination > makeDestinationCtrl(std::string const &filename)
void configure_dest(edm::ParameterSet const &job_pset, ConfigurableDefaults const &, vString const &categories, std::shared_ptr< ELdestination > dest_ctrl, edm::ParameterSet const &dest_pset, std::string const &filename)
long double T