CMS 3D CMS Logo

MessageLoggerQ.cc
Go to the documentation of this file.
6 
7 #include <cstring>
8 #include <iostream>
9 
11 //
12 // DO NOT replace the internal memcpy() calls by assignment or by
13 // any other form of copying unless you first understand in depth
14 // all of the alignment issues involved
15 //
17 
18 // Change Log
19 //
20 // 1 - 3/9/07 mf
21 // Addition of JOB command, to be used by --jobreport
22 // 2 - 6/19/07 mf
23 // Addition of MOD command, to be used by --mode
24 // 3 - 7/24/07 mf
25 // Addition of SHT command, to be used when no .cfg file was given
26 // 4 - 7/25/07 mf
27 // Change of each mommand function to start with MLq, e.g. MLqLOG
28 // 5 - 8/7/07 mf
29 // Addition of FLS command, to be used by FlushMessageLog
30 // 6 - 8/16/07 mf
31 // Addition of GRP command, to be used by GroupLogStatistics
32 // 7 - 6/18/08 mf
33 // Addition of JRS command, to be used by SummarizeInJobReport
34 // 8 - 10/24/08 mf
35 // Support for singleThread
36 // 9 - 8/6/09 mf
37 // handshaked() method to support cleaner abstraction of scribes
38 // 10 - 8/7/09 mf, crj
39 // major down-functioning: the actual dealing with buffer of the
40 // SingleConsumerQ is moved off into MainThreadMLscribe.
41 // 11 - 8/10/09 mf, cdj
42 // StandAloneScribe - a class that gets installed as the scribe if
43 // no presence is created at all. Enables easy stand-alone use of the
44 // logger
45 // 12 - 8/10/09 mf, cdj
46 // Removal of use of singleThread from this class - does not need it any
47 // longer
48 // 13 - 8/10/09 mf
49 // Special control of standAlone message logging
50 // 14 - 8/12/09 mf, cdj
51 // Better ownership management of standAlone or other scribe
52 
53 using namespace edm;
54 
55 // ChangeLog 11
56 namespace {
57  class StandAloneScribe : public edm::service::AbstractMLscribe {
58  public:
59  StandAloneScribe() {}
60 
61  StandAloneScribe(const StandAloneScribe &) = delete; // stop default
62 
63  const StandAloneScribe &operator=(const StandAloneScribe &) = delete; // stop default
64 
65  // ---------- member functions ---------------------------
66 
67  void runCommand(edm::MessageLoggerQ::OpCode opcode, void *operand) override;
68 
69  private:
70  // ---------- member data --------------------------------
71  };
72 
73  void StandAloneScribe::runCommand(edm::MessageLoggerQ::OpCode opcode, void *operand) {
74  //even though we don't print, have to clean up memory
75  switch (opcode) {
77  edm::ErrorObj *errorobj_p = static_cast<edm::ErrorObj *>(operand);
78  if (MessageLoggerQ::ignore // ChangeLog 13
79  (errorobj_p->xid().severity, errorobj_p->xid().id)) {
80  delete errorobj_p;
81  break;
82  }
83  if (errorobj_p->is_verbatim()) {
84  std::cerr << errorobj_p->fullText() << std::endl;
85  } else {
86  std::cerr << "%MSG" << errorobj_p->xid().severity.getSymbol() << " " << errorobj_p->xid().id << ": \n"
87  << errorobj_p->fullText() << "\n"
88  << "%MSG" << std::endl;
89  }
90  delete errorobj_p;
91  break;
92  }
95  std::string *string_p = static_cast<std::string *>(operand);
96  delete string_p;
97  break;
98  }
99  default:
100  break;
101  }
102  }
103 
104  // Changelog 14
105  std::shared_ptr<StandAloneScribe> obtainStandAloneScribePtr() {
106  static auto standAloneScribe_ptr = std::make_shared<StandAloneScribe>();
107  return standAloneScribe_ptr;
108  }
109 
110 } // end of anonymous namespace
111 
112 std::shared_ptr<edm::service::AbstractMLscribe> MessageLoggerQ::mlscribe_ptr = obtainStandAloneScribePtr();
113 // changeLog 8, 11, 14
114 
116 
118 
121  return &queue;
122 } // MessageLoggerQ::instance()
123 
124 void MessageLoggerQ::setMLscribe_ptr(std::shared_ptr<edm::service::AbstractMLscribe> m) // changeLog 8, 14
125 {
126  if (!m) {
127  mlscribe_ptr = obtainStandAloneScribePtr();
128  } else {
129  mlscribe_ptr = m;
130  }
131 } // MessageLoggerQ::setMLscribe_ptr(m)
132 
133 void MessageLoggerQ::simpleCommand(OpCode opcode, void *operand) // changeLog 8, 10
134 {
135  mlscribe_ptr->runCommand(opcode, operand);
136 } // simpleCommand
137 
139  void *operand,
140  std::string const &commandMnemonic) { // Change Log 10
141  try {
142  mlscribe_ptr->runCommand(opcode, operand);
143  } catch (edm::Exception &ex) {
144  ex << "\n The preceding exception was thrown in MessageLoggerScribe\n";
145  ex << "and forwarded to the main thread from the Messages thread.";
146  std::cerr << "exception from MessageLoggerQ::" << commandMnemonic << " - exception what() is \n" << ex.what();
147  // TODO - get the above text into the what itself
148  throw ex;
149  }
150 } // handshakedCommand
151 
152 void MessageLoggerQ::MLqEND() { simpleCommand(END_THREAD, (void *)nullptr); } // MessageLoggerQ::END()
153 
154 void MessageLoggerQ::MLqSHT() { simpleCommand(SHUT_UP, (void *)nullptr); } // MessageLoggerQ::SHT()
155 
157  simpleCommand(LOG_A_MESSAGE, static_cast<void *>(p));
158 } // MessageLoggerQ::LOG()
159 
160 void MessageLoggerQ::MLqCFG(ParameterSet *p) { handshakedCommand(CONFIGURE, p, "CFG"); } // MessageLoggerQ::CFG()
161 
162 void MessageLoggerQ::MLqSUM() { simpleCommand(SUMMARIZE, nullptr); } // MessageLoggerQ::SUM()
163 
165  simpleCommand(JOBMODE, static_cast<void *>(jm));
166 } // MessageLoggerQ::MOD()
167 
168 void MessageLoggerQ::MLqFLS() // Change Log 5
169 {
170  // The ConfigurationHandshake, developed for synchronous CFG, contains a
171  // place to convey exception information. FLS does not need this, nor does
172  // it need the parameter set, but we are reusing ConfigurationHandshake
173  // rather than reinventing the mechanism.
174  handshakedCommand(FLUSH_LOG_Q, nullptr, "FLS");
175 } // MessageLoggerQ::FLS()
176 
177 void MessageLoggerQ::MLqGRP(std::string *cat_p) // Change Log 6
178 {
179  simpleCommand(GROUP_STATS, static_cast<void *>(cat_p));
180 } // MessageLoggerQ::GRP()
181 
182 void MessageLoggerQ::MLqJRS(std::map<std::string, double> *sum_p) {
183  handshakedCommand(FJR_SUMMARY, sum_p, "JRS");
184 } // MessageLoggerQ::CFG()
185 
187 {
188  return ((op == CONFIGURE) || (op == FLUSH_LOG_Q) || (op == FJR_SUMMARY));
189 } // MessageLoggerQ::handshaked(op)
190 
191 // change Log 13:
193 std::set<std::string> MessageLoggerQ::squelchSet;
197  if (severity < threshold)
198  return true;
199  if (squelchSet.count(category) > 0)
200  return true;
201  return false;
202 }
messagelogger::ELseverityLevel severity
Definition: ELextendedID.h:30
static bool handshaked(const OpCode &op)
std::string fullText() const
Definition: ErrorObj.cc:151
static void squelch(std::string const &category)
static void MLqCFG(ParameterSet *p)
static void MLqFLS()
static edm::messagelogger::ELseverityLevel threshold
#define CMS_THREAD_SAFE
static MessageLoggerQ * instance()
static bool ignore(edm::messagelogger::ELseverityLevel const &severity, std::string const &category)
const ELextendedID & xid() const
Definition: ErrorObj.cc:142
static void MLqEND()
static void setMLscribe_ptr(std::shared_ptr< edm::service::AbstractMLscribe > m)
bool is_verbatim() const
Definition: ErrorObj.cc:147
std::string id
Definition: ELextendedID.h:29
static void handshakedCommand(OpCode opcode, void *operand, std::string const &commandMnemonic)
static void MLqJRS(std::map< std::string, double > *sum_p)
static void standAloneThreshold(edm::messagelogger::ELseverityLevel const &severity)
static void MLqMOD(std::string *jm)
static void MLqGRP(std::string *cat_p)
static void MLqLOG(ErrorObj *p)
HLT enums.
static std::set< std::string > squelchSet
static void MLqSUM()
char const * what() const noexcept override
Definition: Exception.cc:107
static std::shared_ptr< edm::service::AbstractMLscribe > mlscribe_ptr
static void simpleCommand(OpCode opcode, void *operand)
static void MLqSHT()
const std::string & getSymbol() const