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 
59  public:
60  StandAloneScribe() {}
61 
62  // ---------- member functions ---------------------------
63 
64  void runCommand(edm::MessageLoggerQ::OpCode opcode, void * operand) override;
65 
66  private:
67  StandAloneScribe(const StandAloneScribe&) = delete; // stop default
68 
69  const StandAloneScribe& operator=(const StandAloneScribe&) = delete; // stop default
70 
71  // ---------- member data --------------------------------
72 
73  };
74 
75  void
76  StandAloneScribe::runCommand(edm::MessageLoggerQ::OpCode opcode, void * operand) {
77  //even though we don't print, have to clean up memory
78  switch (opcode) {
80  edm::ErrorObj * errorobj_p = static_cast<edm::ErrorObj *>(operand);
81  if ( MessageLoggerQ::ignore // ChangeLog 13
82  (errorobj_p->xid().severity, errorobj_p->xid().id) ) {
83  delete errorobj_p;
84  break;
85  }
86  if (errorobj_p->is_verbatim()) {
87  std::cerr<< errorobj_p->fullText() << std::endl;
88  } else {
89  std::cerr<< "%MSG" << errorobj_p->xid().severity.getSymbol()
90  << " " << errorobj_p->xid().id << ": \n"
91  << errorobj_p->fullText() << "\n"
92  << "%MSG"
93  << std::endl;
94  }
95  delete errorobj_p;
96  break;
97  }
100  {
101  std::string* string_p = static_cast<std::string*> (operand);
102  delete string_p;
103  break;
104  }
105  default:
106  break;
107  }
108  }
109 
110  // Changelog 14
111  std::shared_ptr<StandAloneScribe> obtainStandAloneScribePtr() {
112  static auto standAloneScribe_ptr = std::make_shared<StandAloneScribe>();
113  return standAloneScribe_ptr;
114  }
115 
116 
117 } // end of anonymous namespace
118 
119 std::shared_ptr<edm::service::AbstractMLscribe>
120  MessageLoggerQ::mlscribe_ptr = obtainStandAloneScribePtr();
121  // changeLog 8, 11, 14
122 
124 { }
125 
126 
128 { }
129 
130 
133 {
135  return &queue;
136 } // MessageLoggerQ::instance()
137 
138 void
140  (std::shared_ptr<edm::service::AbstractMLscribe> m) // changeLog 8, 14
141 {
142  if (!m) {
143  mlscribe_ptr = obtainStandAloneScribePtr();
144  } else {
145  mlscribe_ptr = m;
146  }
147 } // MessageLoggerQ::setMLscribe_ptr(m)
148 
149 void
150  MessageLoggerQ::simpleCommand(OpCode opcode, void * operand)// changeLog 8, 10
151 {
152  mlscribe_ptr->runCommand(opcode, operand);
153 } // simpleCommand
154 
155 void
157  OpCode opcode,
158  void * operand,
159  std::string const & commandMnemonic )
160 { // Change Log 10
161  try {
162  mlscribe_ptr->runCommand(opcode, operand);
163  }
164  catch(edm::Exception& ex)
165  {
166  ex << "\n The preceding exception was thrown in MessageLoggerScribe\n";
167  ex << "and forwarded to the main thread from the Messages thread.";
168  std::cerr << "exception from MessageLoggerQ::"
169  << commandMnemonic << " - exception what() is \n"
170  << ex.what();
171  // TODO - get the above text into the what itself
172  throw ex;
173  }
174 } // handshakedCommand
175 
176 void
178 {
179  simpleCommand (END_THREAD, (void *)nullptr);
180 } // MessageLoggerQ::END()
181 
182 void
184 {
185  simpleCommand (SHUT_UP, (void *)nullptr);
186 } // MessageLoggerQ::SHT()
187 
188 void
190 {
191  simpleCommand (LOG_A_MESSAGE, static_cast<void *>(p));
192 } // MessageLoggerQ::LOG()
193 
194 
195 void
197 {
198  handshakedCommand(CONFIGURE, p, "CFG" );
199 } // MessageLoggerQ::CFG()
200 
201 void
203 {
204  simpleCommand (SUMMARIZE, nullptr);
205 } // MessageLoggerQ::SUM()
206 
207 void
209 {
210  simpleCommand (JOBMODE, static_cast<void *>(jm));
211 } // MessageLoggerQ::MOD()
212 
213 
214 void
215  MessageLoggerQ::MLqFLS( ) // Change Log 5
216 {
217  // The ConfigurationHandshake, developed for synchronous CFG, contains a
218  // place to convey exception information. FLS does not need this, nor does
219  // it need the parameter set, but we are reusing ConfigurationHandshake
220  // rather than reinventing the mechanism.
221  handshakedCommand(FLUSH_LOG_Q, nullptr, "FLS" );
222 } // MessageLoggerQ::FLS()
223 
224 void
225  MessageLoggerQ::MLqGRP( std::string * cat_p ) // Change Log 6
226 {
227  simpleCommand (GROUP_STATS, static_cast<void *>(cat_p));
228 } // MessageLoggerQ::GRP()
229 
230 void
231  MessageLoggerQ::MLqJRS( std::map<std::string, double> * sum_p )
232 {
233  handshakedCommand(FJR_SUMMARY, sum_p, "JRS" );
234 } // MessageLoggerQ::CFG()
235 
236 
237 bool
239 {
240  return ( (op == CONFIGURE) || (op == FLUSH_LOG_Q) || (op == FJR_SUMMARY) );
241 } // MessageLoggerQ::handshaked(op)
242 
243 // change Log 13:
245 std::set<std::string> MessageLoggerQ::squelchSet;
248 }
250  squelchSet.insert(category);
251 }
253  std::string const & category ) {
254  if ( severity < threshold ) return true;
255  if ( squelchSet.count(category) > 0 ) return true;
256  return false;
257 }
ELseverityLevel severity
Definition: ELextendedID.h:35
static bool handshaked(const OpCode &op)
char const * what() const override
Definition: Exception.cc:141
static bool ignore(edm::ELseverityLevel const &severity, std::string const &category)
static void squelch(std::string const &category)
const ELstring getSymbol() const
const ELextendedID & xid() const
Definition: ErrorObj.cc:148
static void MLqCFG(ParameterSet *p)
static void MLqFLS()
static edm::ELseverityLevel threshold
#define CMS_THREAD_SAFE
static MessageLoggerQ * instance()
ELstring fullText() const
Definition: ErrorObj.cc:159
static void MLqEND()
static void setMLscribe_ptr(std::shared_ptr< edm::service::AbstractMLscribe > m)
static void handshakedCommand(OpCode opcode, void *operand, std::string const &commandMnemonic)
static void MLqJRS(std::map< std::string, double > *sum_p)
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 standAloneThreshold(edm::ELseverityLevel const &severity)
static void MLqSUM()
bool is_verbatim() const
Definition: ErrorObj.cc:153
static std::shared_ptr< edm::service::AbstractMLscribe > mlscribe_ptr
static void simpleCommand(OpCode opcode, void *operand)
static void MLqSHT()