CMS 3D CMS Logo

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