CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/FWCore/MessageService/src/ELtsErrorLog.cc

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------
00002 //
00003 // ELtsErrorLog.cc
00004 //
00005 // Created 5/31/01 mf   Base implementations for all the templates in
00006 //                      ThreadSafeErrorLog<Mutex>
00007 //
00008 // 11/15/01 mf  static_cast to unsigned int and long in comparisons in
00009 //              operator<<( ErrorLog & e, unsigned int n) and long, and
00010 //              also rwriting 0xFFFFFFFF as 0xFFFFFFFFL when comparing to a
00011 //              long.  THese cure warnings when -Wall -pedantic are turned on.
00012 // 3/06/01 mf   getELdestControl() which forwards to *a
00013 //
00014 // ----------------------------------------------------------------------
00015 
00016 #include "FWCore/MessageService/interface/ELtsErrorLog.h"
00017 #include "FWCore/MessageService/interface/ELadministrator.h"
00018 #include "FWCore/MessageService/interface/ELoutput.h"
00019 #include "FWCore/MessageService/interface/ELcontextSupplier.h"
00020 
00021 #include "FWCore/Utilities/interface/EDMException.h"
00022 
00023 #include <iostream>
00024 #include <iomanip>
00025 #include <sstream>
00026 
00027 
00028 // Possible Traces:
00029 // #define ErrorLogCONSTRUCTOR_TRACE
00030 // #define ErrorLogOUTPUT_TRACE
00031 // #define ErrorLogENDMSG_TRACE
00032 #ifdef ErrorLogEMIT_TRACE
00033   #include <string>
00034 #endif
00035 
00036 namespace edm {
00037 namespace service {
00038 
00039 
00040 // ----------------------------------------------------------------------
00041 // Birth and Death:
00042 // ----------------------------------------------------------------------
00043 
00044 ELtsErrorLog::ELtsErrorLog()
00045 : a( ELadministrator::instance() )
00046 , e()
00047 , process("")
00048 , msgIsActive (false)
00049 , msg(ELunspecified, "...")
00050 {
00051   #ifdef ErrorLogCONSTRUCTOR_TRACE
00052     std::cout << "Constructor for ThreadSafeErrorLog\n";
00053   #endif
00054 }
00055 
00056 ELtsErrorLog::ELtsErrorLog( const ELstring & pkgName )
00057 : a( ELadministrator::instance() )
00058 , e(pkgName)
00059 , process("")
00060 , msgIsActive (false)
00061 , msg(ELunspecified, "...")
00062 {
00063   #ifdef ErrorLogCONSTRUCTOR_TRACE
00064     std::cout << "Constructor for ThreadSafeErrorLog (with pkgName = "
00065                                                         << pkgName << ")\n";
00066   #endif
00067 }
00068 
00069 ELtsErrorLog::ELtsErrorLog( const ErrorLog & ee )
00070 : a( ELadministrator::instance() )
00071 , e(ee)
00072 , process("")
00073 , msgIsActive (false)
00074 , msg(ELunspecified, "...")
00075 {
00076   #ifdef ErrorLogCONSTRUCTOR_TRACE
00077     std::cout << "Constructor for ThreadSafeErrorLog from ErrorLog\n";
00078   #endif
00079 }
00080 
00081 ELtsErrorLog::ELtsErrorLog( const ELtsErrorLog & ee)
00082 : a( ELadministrator::instance() )
00083 , e(ee.e)
00084 , process(ee.process)
00085 , msgIsActive (ee.msgIsActive)
00086 , msg(ee.msg)
00087 {
00088   #ifdef ErrorLogCONSTRUCTOR_TRACE
00089     std::cout << "Copy constructor for ThreadSafeErrorLog \n";
00090   #endif
00091 }
00092 
00093 ELtsErrorLog::~ELtsErrorLog()
00094 {
00095   #ifdef ErrorLogCONSTRUCTOR_TRACE
00096     std::cout << "Destructor for ThreadSafeErrorLog\n";
00097   #endif
00098 }
00099 
00100 // ----------------------------------------------------------------------
00101 // Setup for preamble parts
00102 // ----------------------------------------------------------------------
00103 
00104 void ELtsErrorLog::setSubroutine( const ELstring & subName )  {
00105   e.setSubroutine (subName);
00106 }  // setSubroutine()
00107 
00108 void ELtsErrorLog::setModule( const ELstring & modName )  {
00109   e.setModule (modName);
00110 }  // setModule()
00111 
00112 void ELtsErrorLog::setPackage( const ELstring & pkgName )  {
00113   e.setModule (pkgName);
00114 }  // setPackage()
00115 
00116 void ELtsErrorLog::setProcess( const ELstring & procName )  {
00117   process = procName;
00118 }  // setProcess()
00119 
00120 int ELtsErrorLog::setHexTrigger (int trigger) {
00121   return e.setHexTrigger (trigger);
00122 }
00123 
00124 ELseverityLevel ELtsErrorLog::setDiscardThreshold (ELseverityLevel sev) {
00125   return e.setDiscardThreshold(sev);
00126 }
00127 
00128 void ELtsErrorLog::setDebugVerbosity (int debugVerbosity) {
00129   e.setDebugVerbosity (debugVerbosity);
00130 }
00131 
00132 void ELtsErrorLog::setDebugMessages (ELseverityLevel sev, ELstring id) {
00133   e.setDebugMessages (sev, id);
00134 }
00135 
00136 // ----------------------------------------------------------------------
00137 // Recovery of an ELdestControl handle
00138 // ----------------------------------------------------------------------
00139 
00140 bool ELtsErrorLog::getELdestControl (const ELstring & name,
00141                                      ELdestControl & theDestControl) const {
00142     return a->getELdestControl ( name, theDestControl );
00143 }
00144 
00145 
00146 // ----------------------------------------------------------------------
00147 // Message Initiation
00148 // ----------------------------------------------------------------------
00149 
00150 void ELtsErrorLog::initiateMsg(const ELseverityLevel& sev, const ELstring& id)
00151 {
00152   if ( sev < e.discardThreshold ) {
00153     e.discarding = true;
00154     return;
00155   }
00156   e.discarding = false;
00157   #ifdef ErrorLogENDMSG_TRACE
00158     std::cout << "=:=:=: precautionary endmsg ( "
00159               << sev.getName() << ", " << id << ")\n";
00160   #endif
00161 
00162   // Unlike the case for ErrorLog, it is not necessary to check
00163   // msgIsActive because the calling code was forced to do that
00164   // (since if it WAS active, ELtsErrorLog can't do the Mutex LOCK.)
00165 
00166   // -----  form ErrorObj for this new message:
00167   //
00168   msg.clear();
00169   msgIsActive = true;
00170   msg.set          ( sev, id );
00171   msg.setProcess   ( process );
00172   msg.setModule    ( e.module );
00173   msg.setSubroutine( e.subroutine );
00174   msg.setReactedTo ( false );
00175 
00176   return;
00177 
00178 }  // operator()( )
00179 
00180 // ----------------------------------------------------------------------
00181 // Message Continuation:
00182 //   item() method used by emitToken(string)
00183 // ----------------------------------------------------------------------
00184 
00185 
00186 void ELtsErrorLog::item ( const ELstring & s ) {
00187   if ( ! msgIsActive )
00188     initiateMsg ( ELunspecified, "..." );
00189   msg.emitToken( s );
00190 }  // emitToken()
00191 
00192 // ----------------------------------------------------------------------
00193 // Message Continuation:
00194 //   item() methods used by operator<< for integer types
00195 // ----------------------------------------------------------------------
00196 
00197 void ELtsErrorLog::item ( int n ) {
00198   if (e.discarding) return;
00199   std::ostringstream  ost;
00200   ost << n << ' ';
00201   int m = (n<0) ? -n : n;
00202   if ( (e.hexTrigger >= 0) && (m >= e.hexTrigger) ) {
00203     ost << "[0x"
00204         << std::hex << std::setw(8) << std::setfill('0')
00205         << n << "] ";
00206   }
00207   msg.emitToken( ost.str() );
00208 }
00209 
00210 void ELtsErrorLog::item ( unsigned int n )  {
00211   if (e.discarding) return;
00212   std::ostringstream  ost;
00213   ost << n << ' ';
00214   if ( (e.hexTrigger >= 0) &&
00215        (n >= static_cast<unsigned int>(e.hexTrigger)) ) {
00216     ost << "[0x"
00217         << std::hex << std::setw(8) << std::setfill('0')
00218         << n << "] ";
00219   }
00220   msg.emitToken( ost.str() );
00221 }
00222 
00223 void ELtsErrorLog::item ( long n )  {
00224   if (e.discarding) return;
00225   std::ostringstream  ost;
00226   ost << n << ' ';
00227   long m = (n<0) ? -n : n;
00228   if ( (e.hexTrigger >= 0) && (m >= e.hexTrigger) ) {
00229     int width = 8;
00230     if ( static_cast<unsigned long>(n) > 0xFFFFFFFFL ) width = 16;
00231     ost << "[0x"
00232         << std::hex << std::setw(width) << std::setfill('0')
00233         << n << "] ";
00234   }
00235   msg.emitToken( ost.str() );
00236 }
00237 
00238 void ELtsErrorLog::item ( unsigned long n )  {
00239   if (e.discarding) return;
00240   std::ostringstream  ost;
00241   ost << n << ' ';
00242   if ( (e.hexTrigger >= 0) &&
00243        (n >= static_cast<unsigned long>(e.hexTrigger)) ) {
00244     int width = 8;
00245     if ( n > 0xFFFFFFFFL ) width = 16;
00246     ost << "[0x"
00247         << std::hex << std::setw(width) << std::setfill('0')
00248         << n << "] ";
00249   }
00250   msg.emitToken( ost.str() );
00251 }
00252 
00253 void ELtsErrorLog::item ( short n )  {
00254   if (e.discarding) return;
00255   std::ostringstream  ost;
00256   ost << n << ' ';
00257   short m = (n<0) ? -n : n;
00258   if ( (e.hexTrigger >= 0) && (m >= e.hexTrigger) ) {
00259     ost << "[0x"
00260         << std::hex << std::setw(4) << std::setfill('0')
00261         << n << "] ";
00262   }
00263   msg.emitToken( ost.str() );
00264 }
00265 
00266 void ELtsErrorLog::item ( unsigned short n )  {
00267   if (e.discarding) return;
00268   std::ostringstream  ost;
00269   ost << n << ' ';
00270   if ( (e.hexTrigger >= 0) && (n >= e.hexTrigger) ) {
00271     ost << "[0x"
00272         << std::hex << std::setw(4) << std::setfill('0')
00273         << n << "] ";
00274   }
00275   msg.emitToken( ost.str() );
00276 }
00277 
00278 // ----------------------------------------------------------------------
00279 // Message Completion:
00280 // ----------------------------------------------------------------------
00281 
00282 bool ELtsErrorLog::pokeMsg ( edm::ErrorObj & msg )  {
00283 
00284   // -----  will we need to poke/restore info into the message?
00285   //
00286   bool updateProcess   ( msg.xid().process   .length() == 0 );
00287   bool updateModule    ( msg.xid().module    .length() == 0 );
00288   bool updateSubroutine( msg.xid().subroutine.length() == 0 );
00289 
00290   // -----  poke, if needed:
00291   //
00292   if ( updateProcess    )  msg.setProcess   ( process );
00293   if ( updateModule     )  msg.setModule    ( e.module );
00294   if ( updateSubroutine )  msg.setSubroutine( e.subroutine );
00295 
00296   return ( updateProcess || updateModule || updateSubroutine );
00297 
00298 }
00299 
00300 static inline void msgabort() {
00301   edm::Exception e(edm::errors::LogicError, 
00302         "msgabort - MessageLogger tsErrorLog requested to abort");
00303   throw e;
00304 }
00305 
00306 void ELtsErrorLog::dispatch ( edm::ErrorObj & msg )  {
00307 
00308   // NOTE -- this is never called except in cases where a <Mutex> LOCK
00309   //         is in scope.  That is, this code should be treated as a
00310   //         critical section.
00311 
00312   // severity level statistics keeping:
00313   int lev = msg.xid().severity.getLevel();
00314   ++ a->severityCounts_[lev];
00315   if ( lev > a->highSeverity_.getLevel() )
00316     a->highSeverity_ = msg.xid().severity;
00317 
00318   // context-based editing (if specified; usually just returns)
00319   a->context_->editErrorObj( msg );
00320 
00321   // -----  send the message to each destination:
00322   //
00323   if (a->sinks().begin() == a->sinks().end())  {
00324     std::cerr << "\nERROR LOGGED WITHOUT DESTINATION!\n";
00325     std::cerr << "Attaching destination \"cerr\" to ELadministrator by default\n"
00326               << std::endl;
00327     a->attach(ELoutput(std::cerr));
00328   }
00329   std::list<boost::shared_ptr<ELdestination> >::iterator d;
00330   for ( d = a->sinks().begin();  d != a->sinks().end();  ++d )
00331     if (  (*d)->log( msg )  )
00332       msg.setReactedTo (true );
00333 
00334 
00335   if ( msg.xid().severity.getLevel() >= a->abortThreshold().getLevel()
00336                        &&
00337         a->abortThreshold() != ELhighestSeverity) {
00338     msgabort();
00339   }
00340 
00341 }
00342 
00343 } // end of namespace service  
00344 } // end of namespace edm