CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ELtsErrorLog.cc
Go to the documentation of this file.
1 // ----------------------------------------------------------------------
2 //
3 // ELtsErrorLog.cc
4 //
5 // Created 5/31/01 mf Base implementations for all the templates in
6 // ThreadSafeErrorLog<Mutex>
7 //
8 // 11/15/01 mf static_cast to unsigned int and long in comparisons in
9 // operator<<( ErrorLog & e, unsigned int n) and long, and
10 // also rwriting 0xFFFFFFFF as 0xFFFFFFFFL when comparing to a
11 // long. THese cure warnings when -Wall -pedantic are turned on.
12 // 3/06/01 mf getELdestControl() which forwards to *a
13 //
14 // ----------------------------------------------------------------------
15 
20 
22 
23 #include <iostream>
24 #include <iomanip>
25 #include <sstream>
26 
27 
28 // Possible Traces:
29 // #define ErrorLogCONSTRUCTOR_TRACE
30 // #define ErrorLogOUTPUT_TRACE
31 // #define ErrorLogENDMSG_TRACE
32 #ifdef ErrorLogEMIT_TRACE
33  #include <string>
34 #endif
35 
36 namespace edm {
37 namespace service {
38 
39 
40 // ----------------------------------------------------------------------
41 // Birth and Death:
42 // ----------------------------------------------------------------------
43 
46 , e()
47 , process("")
48 , msgIsActive (false)
49 , msg(ELunspecified, "...")
50 {
51  #ifdef ErrorLogCONSTRUCTOR_TRACE
52  std::cout << "Constructor for ThreadSafeErrorLog\n";
53  #endif
54 }
55 
58 , e(pkgName)
59 , process("")
60 , msgIsActive (false)
61 , msg(ELunspecified, "...")
62 {
63  #ifdef ErrorLogCONSTRUCTOR_TRACE
64  std::cout << "Constructor for ThreadSafeErrorLog (with pkgName = "
65  << pkgName << ")\n";
66  #endif
67 }
68 
71 , e(ee)
72 , process("")
73 , msgIsActive (false)
74 , msg(ELunspecified, "...")
75 {
76  #ifdef ErrorLogCONSTRUCTOR_TRACE
77  std::cout << "Constructor for ThreadSafeErrorLog from ErrorLog\n";
78  #endif
79 }
80 
83 , e(ee.e)
84 , process(ee.process)
85 , msgIsActive (ee.msgIsActive)
86 , msg(ee.msg)
87 {
88  #ifdef ErrorLogCONSTRUCTOR_TRACE
89  std::cout << "Copy constructor for ThreadSafeErrorLog \n";
90  #endif
91 }
92 
94 {
95  #ifdef ErrorLogCONSTRUCTOR_TRACE
96  std::cout << "Destructor for ThreadSafeErrorLog\n";
97  #endif
98 }
99 
101 {
102  std::swap(a, other.a);
103  std::swap(e, other.e);
104  process.swap(other.process);
106  msg.swap(other.msg);
107 }
108 
110 {
111  ELtsErrorLog temp(other);
112  this->swap(temp);
113  return *this;
114 }
115 
116 // ----------------------------------------------------------------------
117 // Setup for preamble parts
118 // ----------------------------------------------------------------------
119 
120 void ELtsErrorLog::setSubroutine( const ELstring & subName ) {
121  e.setSubroutine (subName);
122 } // setSubroutine()
123 
124 void ELtsErrorLog::setModule( const ELstring & modName ) {
125  e.setModule (modName);
126 } // setModule()
127 
128 void ELtsErrorLog::setPackage( const ELstring & pkgName ) {
129  e.setModule (pkgName);
130 } // setPackage()
131 
132 void ELtsErrorLog::setProcess( const ELstring & procName ) {
133  process = procName;
134 } // setProcess()
135 
136 int ELtsErrorLog::setHexTrigger (int trigger) {
137  return e.setHexTrigger (trigger);
138 }
139 
141  return e.setDiscardThreshold(sev);
142 }
143 
145  e.setDebugVerbosity (debugVerbosity);
146 }
147 
149  e.setDebugMessages (sev, id);
150 }
151 
152 // ----------------------------------------------------------------------
153 // Recovery of an ELdestControl handle
154 // ----------------------------------------------------------------------
155 
157  ELdestControl & theDestControl) const {
158  return a->getELdestControl ( name, theDestControl );
159 }
160 
161 
162 // ----------------------------------------------------------------------
163 // Message Initiation
164 // ----------------------------------------------------------------------
165 
167 {
168  if ( sev < e.discardThreshold ) {
169  e.discarding = true;
170  return;
171  }
172  e.discarding = false;
173  #ifdef ErrorLogENDMSG_TRACE
174  std::cout << "=:=:=: precautionary endmsg ( "
175  << sev.getName() << ", " << id << ")\n";
176  #endif
177 
178  // Unlike the case for ErrorLog, it is not necessary to check
179  // msgIsActive because the calling code was forced to do that
180  // (since if it WAS active, ELtsErrorLog can't do the Mutex LOCK.)
181 
182  // ----- form ErrorObj for this new message:
183  //
184  msg.clear();
185  msgIsActive = true;
186  msg.set ( sev, id );
187  msg.setProcess ( process );
188  msg.setModule ( e.module );
190  msg.setReactedTo ( false );
191 
192  return;
193 
194 } // operator()( )
195 
196 // ----------------------------------------------------------------------
197 // Message Continuation:
198 // item() method used by emitToken(string)
199 // ----------------------------------------------------------------------
200 
201 
202 void ELtsErrorLog::item ( const ELstring & s ) {
203  if ( ! msgIsActive )
204  initiateMsg ( ELunspecified, "..." );
205  msg.emitToken( s );
206 } // emitToken()
207 
208 // ----------------------------------------------------------------------
209 // Message Continuation:
210 // item() methods used by operator<< for integer types
211 // ----------------------------------------------------------------------
212 
213 void ELtsErrorLog::item ( int n ) {
214  if (e.discarding) return;
215  std::ostringstream ost;
216  ost << n << ' ';
217  int m = (n<0) ? -n : n;
218  if ( (e.hexTrigger >= 0) && (m >= e.hexTrigger) ) {
219  ost << "[0x"
220  << std::hex << std::setw(8) << std::setfill('0')
221  << n << "] ";
222  }
223  msg.emitToken( ost.str() );
224 }
225 
226 void ELtsErrorLog::item ( unsigned int n ) {
227  if (e.discarding) return;
228  std::ostringstream ost;
229  ost << n << ' ';
230  if ( (e.hexTrigger >= 0) &&
231  (n >= static_cast<unsigned int>(e.hexTrigger)) ) {
232  ost << "[0x"
233  << std::hex << std::setw(8) << std::setfill('0')
234  << n << "] ";
235  }
236  msg.emitToken( ost.str() );
237 }
238 
239 void ELtsErrorLog::item ( long n ) {
240  if (e.discarding) return;
241  std::ostringstream ost;
242  ost << n << ' ';
243  long m = (n<0) ? -n : n;
244  if ( (e.hexTrigger >= 0) && (m >= e.hexTrigger) ) {
245  int width = 8;
246  if ( static_cast<unsigned long>(n) > 0xFFFFFFFFL ) width = 16;
247  ost << "[0x"
248  << std::hex << std::setw(width) << std::setfill('0')
249  << n << "] ";
250  }
251  msg.emitToken( ost.str() );
252 }
253 
254 void ELtsErrorLog::item ( unsigned long n ) {
255  if (e.discarding) return;
256  std::ostringstream ost;
257  ost << n << ' ';
258  if ( (e.hexTrigger >= 0) &&
259  (n >= static_cast<unsigned long>(e.hexTrigger)) ) {
260  int width = 8;
261  if ( n > 0xFFFFFFFFL ) width = 16;
262  ost << "[0x"
263  << std::hex << std::setw(width) << std::setfill('0')
264  << n << "] ";
265  }
266  msg.emitToken( ost.str() );
267 }
268 
269 void ELtsErrorLog::item ( short n ) {
270  if (e.discarding) return;
271  std::ostringstream ost;
272  ost << n << ' ';
273  short m = (n<0) ? -n : n;
274  if ( (e.hexTrigger >= 0) && (m >= e.hexTrigger) ) {
275  ost << "[0x"
276  << std::hex << std::setw(4) << std::setfill('0')
277  << n << "] ";
278  }
279  msg.emitToken( ost.str() );
280 }
281 
282 void ELtsErrorLog::item ( unsigned short n ) {
283  if (e.discarding) return;
284  std::ostringstream ost;
285  ost << n << ' ';
286  if ( (e.hexTrigger >= 0) && (n >= e.hexTrigger) ) {
287  ost << "[0x"
288  << std::hex << std::setw(4) << std::setfill('0')
289  << n << "] ";
290  }
291  msg.emitToken( ost.str() );
292 }
293 
294 // ----------------------------------------------------------------------
295 // Message Completion:
296 // ----------------------------------------------------------------------
297 
299 
300  // ----- will we need to poke/restore info into the message?
301  //
302  bool updateProcess ( msg.xid().process .length() == 0 );
303  bool updateModule ( msg.xid().module .length() == 0 );
304  bool updateSubroutine( msg.xid().subroutine.length() == 0 );
305 
306  // ----- poke, if needed:
307  //
308  if ( updateProcess ) msg.setProcess ( process );
309  if ( updateModule ) msg.setModule ( e.module );
310  if ( updateSubroutine ) msg.setSubroutine( e.subroutine );
311 
312  return ( updateProcess || updateModule || updateSubroutine );
313 
314 }
315 
316 static inline void msgabort() {
318  "msgabort - MessageLogger tsErrorLog requested to abort");
319  throw e;
320 }
321 
323 
324  // NOTE -- this is never called except in cases where a <Mutex> LOCK
325  // is in scope. That is, this code should be treated as a
326  // critical section.
327 
328  // severity level statistics keeping:
329  int lev = msg.xid().severity.getLevel();
330  ++ a->severityCounts_[lev];
331  if ( lev > a->highSeverity_.getLevel() )
332  a->highSeverity_ = msg.xid().severity;
333 
334  // context-based editing (if specified; usually just returns)
335  a->context_->editErrorObj( msg );
336 
337  // ----- send the message to each destination:
338  //
339  if (a->sinks().begin() == a->sinks().end()) {
340  std::cerr << "\nERROR LOGGED WITHOUT DESTINATION!\n";
341  std::cerr << "Attaching destination \"cerr\" to ELadministrator by default\n"
342  << std::endl;
344  }
345  std::list<boost::shared_ptr<ELdestination> >::iterator d;
346  for ( d = a->sinks().begin(); d != a->sinks().end(); ++d )
347  if ( (*d)->log( msg ) )
348  msg.setReactedTo (true );
349 
350 
351  if ( msg.xid().severity.getLevel() >= a->abortThreshold().getLevel()
352  &&
354  msgabort();
355  }
356 
357 }
358 
359 } // end of namespace service
360 } // end of namespace edm
void setModule(const ELstring &modName)
Definition: ErrorLog.cc:236
ELseverityLevel severity
Definition: ELextendedID.h:36
std::list< boost::shared_ptr< ELdestination > > & sinks()
int severityCounts_[ELseverityLevel::nLevels]
virtual void clear()
Definition: ErrorObj.cc:262
virtual void set(const ELseverityLevel &sev, const ELstring &id)
Definition: ErrorObj.cc:249
void setDebugVerbosity(int debugVerbosity)
void setPackage(const ELstring &pkgName)
ELseverityLevel setDiscardThreshold(ELseverityLevel sev)
static PFTauRenderPlugin instance
virtual ErrorObj & emitToken(const ELstring &txt)
Definition: ErrorObj.cc:220
void swap(ErrorObj &other)
Definition: ErrorObj.cc:126
bool getELdestControl(const ELstring &name, ELdestControl &theDestControl) const
int setHexTrigger(int trigger)
ELslProxy< ELunspecifiedGen > const ELunspecified
virtual void setSubroutine(const ELstring &subroutine)
Definition: ErrorObj.cc:193
static void msgabort()
bool pokeMsg(edm::ErrorObj &msg)
ELslProxy< ELhighestSeverityGen > const ELhighestSeverity
ELseverityLevel setDiscardThreshold(ELseverityLevel sev)
Definition: ErrorLog.cc:326
virtual void setReactedTo(bool r)
Definition: ErrorObj.cc:210
void setProcess(const ELstring &procName)
const ELextendedID & xid() const
Definition: ErrorObj.cc:146
void setDebugMessages(ELseverityLevel sev, ELstring id)
Definition: ErrorLog.cc:336
ELseverityLevel discardThreshold
Definition: ErrorLog.h:129
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
const ELstring getName() const
void setDebugMessages(ELseverityLevel sev, ELstring id)
void setSubroutine(const ELstring &subName)
void setSubroutine(const ELstring &subName)
Definition: ErrorLog.cc:149
void setDebugVerbosity(int debugVerbosity)
Definition: ErrorLog.cc:332
bool getELdestControl(const ELstring &name, ELdestControl &theControl)
boost::shared_ptr< ELcontextSupplier > context_
ELstring subroutine
Definition: ELextendedID.h:38
void setModule(const ELstring &modName)
int setHexTrigger(int trigger)
Definition: ErrorLog.cc:320
void dispatch(edm::ErrorObj &msg)
virtual void setProcess(const ELstring &proc)
Definition: ErrorObj.cc:203
double a
Definition: hdecay.h:121
void initiateMsg(const ELseverityLevel &sev, const ELstring &id)
tuple cout
Definition: gather_cfg.py:121
ELdestControl attach(const ELdestination &sink)
tuple process
Definition: LaserDQM_cfg.py:3
std::string ELstring
Definition: ELstring.h:26
ELtsErrorLog & operator=(const ELtsErrorLog &)
const ELseverityLevel & abortThreshold() const
virtual void setModule(const ELstring &module)
Definition: ErrorObj.cc:188
void swap(ELtsErrorLog &)