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);
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  }
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  boost::shared_ptr<StandAloneScribe> obtainStandAloneScribePtr() {
112  static boost::shared_ptr<StandAloneScribe>
113  standAloneScribe_ptr( new StandAloneScribe );
114  return standAloneScribe_ptr;
115  }
116 
117 
118 } // end of anonymous namespace
119 
120 boost::shared_ptr<edm::service::AbstractMLscribe>
121  MessageLoggerQ::mlscribe_ptr = obtainStandAloneScribePtr();
122  // changeLog 8, 11, 14
123 
125 { }
126 
127 
129 { }
130 
131 
134 {
135  static MessageLoggerQ queue;
136  return &queue;
137 } // MessageLoggerQ::instance()
138 
139 void
141  (boost::shared_ptr<edm::service::AbstractMLscribe> m) // changeLog 8, 14
142 {
143  if (!m) {
144  mlscribe_ptr = obtainStandAloneScribePtr();
145  } else {
146  mlscribe_ptr = m;
147  }
148 } // MessageLoggerQ::setMLscribe_ptr(m)
149 
150 void
151  MessageLoggerQ::simpleCommand(OpCode opcode, void * operand)// changeLog 8, 10
152 {
153  mlscribe_ptr->runCommand(opcode, operand);
154 } // simpleCommand
155 
156 void
158  OpCode opcode,
159  void * operand,
160  std::string const & commandMnemonic )
161 { // Change Log 10
162  try {
163  mlscribe_ptr->runCommand(opcode, operand);
164  }
165  catch(edm::Exception& ex)
166  {
167  ex << "\n The preceding exception was thrown in MessageLoggerScribe\n";
168  ex << "and forwarded to the main thread from the Messages thread.";
169  std::cerr << "exception from MessageLoggerQ::"
170  << commandMnemonic << " - exception what() is \n"
171  << ex.what();
172  // TODO - get the above text into the what itself
173  throw ex;
174  }
175 } // handshakedCommand
176 
177 void
179 {
180  simpleCommand (END_THREAD, (void *)0);
181 } // MessageLoggerQ::END()
182 
183 void
185 {
186  simpleCommand (SHUT_UP, (void *)0);
187 } // MessageLoggerQ::SHT()
188 
189 void
191 {
192  simpleCommand (LOG_A_MESSAGE, static_cast<void *>(p));
193 } // MessageLoggerQ::LOG()
194 
195 
196 void
198 {
199  handshakedCommand(CONFIGURE, p, "CFG" );
200 } // MessageLoggerQ::CFG()
201 
202 void
204 {
205  simpleCommand (EXTERN_DEST, static_cast<void *>(p));
206 }
207 
208 void
210 {
211  simpleCommand (SUMMARIZE, 0);
212 } // MessageLoggerQ::SUM()
213 
214 void
216 {
217  simpleCommand (JOBREPORT, static_cast<void *>(j));
218 } // MessageLoggerQ::JOB()
219 
220 void
222 {
223  simpleCommand (JOBMODE, static_cast<void *>(jm));
224 } // MessageLoggerQ::MOD()
225 
226 
227 void
228  MessageLoggerQ::MLqFLS( ) // Change Log 5
229 {
230  // The ConfigurationHandshake, developed for synchronous CFG, contains a
231  // place to convey exception information. FLS does not need this, nor does
232  // it need the parameter set, but we are reusing ConfigurationHandshake
233  // rather than reinventing the mechanism.
234  handshakedCommand(FLUSH_LOG_Q, 0, "FLS" );
235 } // MessageLoggerQ::FLS()
236 
237 void
238  MessageLoggerQ::MLqGRP( std::string * cat_p ) // Change Log 6
239 {
240  simpleCommand (GROUP_STATS, static_cast<void *>(cat_p));
241 } // MessageLoggerQ::GRP()
242 
243 void
244  MessageLoggerQ::MLqJRS( std::map<std::string, double> * sum_p )
245 {
246  handshakedCommand(FJR_SUMMARY, sum_p, "JRS" );
247 } // MessageLoggerQ::CFG()
248 
249 
250 bool
252 {
253  return ( (op == CONFIGURE) || (op == FLUSH_LOG_Q) || (op == FJR_SUMMARY) );
254 } // MessageLoggerQ::handshaked(op)
255 
256 // change Log 13:
258 std::set<std::string> MessageLoggerQ::squelchSet;
260  threshold = edm::ELseverityLevel(severity);
261 }
263  squelchSet.insert(category);
264 }
266  std::string const & category ) {
267  if ( severity < threshold ) return true;
268  if ( squelchSet.count(category) > 0 ) return true;
269  return false;
270 }
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:36
static bool handshaked(const OpCode &op)
static void MLqEXT(service::NamedDestination *p)
static void standAloneThreshold(std::string const &severity)
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:146
static void MLqCFG(ParameterSet *p)
static void MLqFLS()
static edm::ELseverityLevel threshold
int j
Definition: DBlmapReader.cc:9
static MessageLoggerQ * instance()
ELstring fullText() const
Definition: ErrorObj.cc:157
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 MLqJOB(std::string *j)
static void MLqSUM()
bool is_verbatim() const
Definition: ErrorObj.cc:151
static void simpleCommand(OpCode opcode, void *operand)
static void MLqSHT()