CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  boost::shared_ptr<StandAloneScribe> obtainStandAloneScribePtr() {
111  static boost::shared_ptr<StandAloneScribe>
112  standAloneScribe_ptr( new StandAloneScribe );
113  return standAloneScribe_ptr;
114  }
115 
116 
117 } // end of anonymous namespace
118 
119 boost::shared_ptr<edm::service::AbstractMLscribe>
120  MessageLoggerQ::mlscribe_ptr = obtainStandAloneScribePtr();
121  // changeLog 8, 11, 14
122 
124 { }
125 
126 
128 { }
129 
130 
133 {
134  [[cms::thread_safe]] static MessageLoggerQ queue;
135  return &queue;
136 } // MessageLoggerQ::instance()
137 
138 void
140  (boost::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 *)0);
180 } // MessageLoggerQ::END()
181 
182 void
184 {
185  simpleCommand (SHUT_UP, (void *)0);
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 (EXTERN_DEST, static_cast<void *>(p));
205 }
206 
207 void
209 {
210  simpleCommand (SUMMARIZE, 0);
211 } // MessageLoggerQ::SUM()
212 
213 void
215 {
216  simpleCommand (JOBMODE, static_cast<void *>(jm));
217 } // MessageLoggerQ::MOD()
218 
219 
220 void
221  MessageLoggerQ::MLqFLS( ) // Change Log 5
222 {
223  // The ConfigurationHandshake, developed for synchronous CFG, contains a
224  // place to convey exception information. FLS does not need this, nor does
225  // it need the parameter set, but we are reusing ConfigurationHandshake
226  // rather than reinventing the mechanism.
227  handshakedCommand(FLUSH_LOG_Q, 0, "FLS" );
228 } // MessageLoggerQ::FLS()
229 
230 void
231  MessageLoggerQ::MLqGRP( std::string * cat_p ) // Change Log 6
232 {
233  simpleCommand (GROUP_STATS, static_cast<void *>(cat_p));
234 } // MessageLoggerQ::GRP()
235 
236 void
237  MessageLoggerQ::MLqJRS( std::map<std::string, double> * sum_p )
238 {
239  handshakedCommand(FJR_SUMMARY, sum_p, "JRS" );
240 } // MessageLoggerQ::CFG()
241 
242 
243 bool
245 {
246  return ( (op == CONFIGURE) || (op == FLUSH_LOG_Q) || (op == FJR_SUMMARY) );
247 } // MessageLoggerQ::handshaked(op)
248 
249 // change Log 13:
251 std::set<std::string> MessageLoggerQ::squelchSet;
253  threshold = severity;
254 }
256  squelchSet.insert(category);
257 }
259  std::string const & category ) {
260  if ( severity < threshold ) return true;
261  if ( squelchSet.count(category) > 0 ) return true;
262  return false;
263 }
virtual char const * what() const
Definition: Exception.cc:141
static void setMLscribe_ptr(boost::shared_ptr< edm::service::AbstractMLscribe > m)
ELseverityLevel severity
Definition: ELextendedID.h:35
static bool handshaked(const OpCode &op)
static void MLqEXT(service::NamedDestination *p)
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 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)
static boost::shared_ptr< edm::service::AbstractMLscribe > mlscribe_ptr
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 void simpleCommand(OpCode opcode, void *operand)
static void MLqSHT()