CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/FWCore/MessageLogger/src/ErrorObj.cc

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------
00002 //
00003 // ErrorObj.cc
00004 //
00005 // History:
00006 //
00007 // Created 7/8/98 mf
00008 // 6/16/99  mf, jvr     ErrorObj::operator<<( void (* f)(ErrorLog &) )
00009 //                      allows an "ErrorObj << endmsg;"
00010 // 7/16/99  jvr         Added setSeverity() and setID functions
00011 // 6/7/00   web         Forbid setting extreme severities; guard against
00012 //                      too-long ID's
00013 // 9/21/00  mf          Added copy constructor for use by ELerrorList
00014 // 5/7/01   mf          operator<< (const char[])
00015 // 6/5/01   mf          setReactedTo
00016 // 11/01/01 web         maxIDlength now unsigned
00017 //
00018 // 2/14/06  mf          Removed oerator<<(endmsg) which is not needed for
00019 //                      MessageLogger for CMS
00020 //
00021 // 3/13/06  mf          Instrumented for automatic suppression of spaces.
00022 // 3/20/06  mf          Instrumented for universal suppression of spaces
00023 //                      (that is, items no longer contain any space added
00024 //                      by the MessageLogger stack)
00025 //
00026 // 4/28/06  mf          maxIDlength changed from 20 to 200
00027 //                      If a category name exceeds that, then the 
00028 //                      limit not taking effect bug will occur again... 
00029 //
00030 // 6/6/06  mf           verbatim
00031 //
00032 // ErrorObj( const ELseverityLevel & sev, const ELstring & id )
00033 // ~ErrorObj()
00034 // set( const ELseverityLevel & sev, const ELstring & id )
00035 // clear()
00036 // setProcess   ( const ELstring & proc )
00037 // setModule    ( const ELstring & module )
00038 // setSubroutine( const ELstring & subroutine )
00039 // emitToken( const ELstring & txt )
00040 // operator<<( void (* f)(ErrorLog &) )
00041 //
00042 // ----------------------------------------------------------------------
00043 
00044 
00045 #include "FWCore/MessageLogger/interface/ErrorObj.h"
00046 
00047 #ifndef IOSTREAM_INCLUDED
00048 #endif
00049 
00050 
00051 // ----------------------------------------------------------------------
00052 
00053 
00054 // Possible Traces
00055 // #define ErrorObjCONSTRUCTOR_TRACE
00056 // #define ErrorObj_EMIT_TRACE
00057 // #define ErrorObj_SUB_TRACE
00058 
00059 
00060 // ----------------------------------------------------------------------
00061 
00062 
00063 namespace edm
00064 {
00065 
00066 
00067 // ----------------------------------------------------------------------
00068 // Class static and class-wide parameter:
00069 // ----------------------------------------------------------------------
00070 
00071 int  ErrorObj::ourSerial(  0 );
00072 const unsigned int  maxIDlength( 200 );         // changed 4/28/06 from 20
00073 
00074 
00075 // ----------------------------------------------------------------------
00076 // Birth/death:
00077 // ----------------------------------------------------------------------
00078 
00079 ErrorObj::ErrorObj( const ELseverityLevel & sev, 
00080                     const ELstring & id,
00081                     bool verbat )  : verbatim(verbat) {
00082 
00083   #ifdef ErrorObjCONSTRUCTOR_TRACE
00084     std::cerr << "Constructor for ErrorObj\n";
00085   #endif
00086 
00087   clear();
00088   set( sev, id );
00089 
00090 }  // ErrorObj()
00091 
00092 
00093 ErrorObj::ErrorObj( const ErrorObj & orig )  :
00094           mySerial        ( orig.mySerial )
00095         , myXid           ( orig.myXid )
00096         , myIdOverflow    ( orig.myIdOverflow )
00097         , myTimestamp     ( orig.myTimestamp )
00098         , myItems         ( orig.myItems )
00099         , myReactedTo     ( orig.myReactedTo )
00100         , myOs            ( )
00101         , emptyString     ( )
00102         , verbatim        ( orig.verbatim )
00103 {
00104 
00105   #ifdef ErrorObjCONSTRUCTOR_TRACE
00106     std::cerr << "Copy Constructor for ErrorObj\n";
00107   #endif
00108 
00109 }  // ErrorObj(ErrorObj)
00110 
00111 
00112 ErrorObj::~ErrorObj()  {
00113 
00114   #ifdef ErrorObjCONSTRUCTOR_TRACE
00115     std::cerr << "Destructor for ErrorObj\n";
00116   #endif
00117 
00118 }  // ~ErrorObj()
00119 
00120 
00121 // ----------------------------------------------------------------------
00122 // Accessors:
00123 // ----------------------------------------------------------------------
00124 
00125 int                   ErrorObj::serial()     const  { return mySerial; }
00126 const ELextendedID &  ErrorObj::xid()        const  { return myXid; }
00127 const ELstring &      ErrorObj::idOverflow() const  { return myIdOverflow; }
00128 time_t                ErrorObj::timestamp()  const  { return myTimestamp; }
00129 const ELlist_string & ErrorObj::items()      const  { return myItems; }
00130 bool                  ErrorObj::reactedTo()  const  { return myReactedTo; }
00131 bool                  ErrorObj::is_verbatim()const  { return verbatim; }
00132 
00133 ELstring ErrorObj::context() const {
00134   return myContext;
00135 }
00136 
00137 ELstring ErrorObj::fullText() const  {
00138 
00139   ELstring result;
00140   for ( ELlist_string::const_iterator it = myItems.begin();
00141         it != myItems.end();
00142         ++it )
00143     result +=  *it;
00144   return result;
00145 
00146 }  // fullText()
00147 
00148 
00149 // ----------------------------------------------------------------------
00150 // Mutators:
00151 // ----------------------------------------------------------------------
00152 
00153 void ErrorObj::setSeverity( const ELseverityLevel & sev )  {
00154   myXid.severity = (sev <= ELzeroSeverity   ) ? (ELseverityLevel)ELincidental
00155                  : (sev >= ELhighestSeverity) ? (ELseverityLevel)ELfatal
00156                  :                              sev
00157                  ;
00158 }
00159 
00160 
00161 void ErrorObj::setID( const ELstring & id )  {
00162   myXid.id = ELstring( id, 0, maxIDlength );
00163   if ( id.length() > maxIDlength )
00164     myIdOverflow = ELstring( id, maxIDlength, id.length()-maxIDlength );
00165 }
00166 
00167 
00168 void ErrorObj::setModule( const ELstring & module )  { myXid.module = module; }
00169 
00170 void ErrorObj::setContext( const ELstring & c )  { myContext = c; }
00171 
00172 
00173 void ErrorObj::setSubroutine( const ELstring & subroutine )  {
00174   #ifdef ErrorObj_SUB_TRACE
00175     std::cerr << "=:=:=: ErrorObj::setSubroutine(" << subroutine << ")\n";
00176   #endif
00177   myXid.subroutine = (subroutine[0] == ' ')
00178                    ? subroutine.substr(1)
00179                    : subroutine;
00180 }
00181 
00182 
00183 void ErrorObj::setProcess( const ELstring & proc )  {
00184   myXid.process = proc;
00185   #if 0
00186     std::cerr << "ErrorObj process set to \"" << proc << "\"\n";
00187   #endif
00188 }
00189 
00190 void ErrorObj::setReactedTo( bool r )  {
00191   myReactedTo = r;
00192 }
00193 
00194 
00195 #ifdef ErrorObj_SUB_TRACE
00196   static int subN = 0;
00197 #endif
00198 
00199 
00200 ErrorObj & ErrorObj::emitToken( const ELstring & s )  {
00201 
00202   #ifdef ErrorObj_EMIT_TRACE
00203     std::cerr << "=:=:=: ErrorObj::emitToken( " << s << " )\n";
00204   #endif
00205 
00206   #ifdef ErrorObj_SUB_TRACE
00207     if ( subN > 0 )  {
00208       std::cerr << "=:=:=: subN ErrorObj::emitToken( " << s << " )\n";
00209       subN--;
00210     }
00211   #endif
00212 
00213   if ( eq_nocase(s.substr(0,5), "@SUB=" ) )  {
00214     #ifdef ErrorObj_SUB_TRACE
00215       std::cerr << "=:=:=: ErrorObj::@SUB s.substr(5) is: " << s.substr(5)
00216                 << '\n';
00217     #endif
00218     setSubroutine(s.substr(5));
00219   }
00220   else  {
00221     myItems.push_back( s );
00222   }
00223 
00224   return * this;
00225 
00226 }  // emitToken()
00227 
00228 
00229 void ErrorObj::set( const ELseverityLevel & sev, const ELstring & id )  {
00230 
00231   clear();
00232 
00233   myTimestamp = time( 0 );
00234   mySerial = ++ ourSerial;
00235 
00236   setID( id );
00237   setSeverity( sev );
00238 
00239 }  // set()
00240 
00241 
00242 void ErrorObj::clear()  {
00243 
00244   mySerial     = 0;
00245   myXid.clear();
00246   myIdOverflow = "";
00247   myTimestamp  = 0;
00248   myItems.erase( myItems.begin(), myItems.end() );  // myItems.clear();
00249   myReactedTo  = false;
00250 
00251 }  // clear()
00252 
00253 ErrorObj & 
00254 ErrorObj::opltlt ( const char s[] ) {
00255   // Exactly equivalent to the general template. 
00256   // If this is not provided explicitly, then the template will
00257   // be instantiated once for each length of string ever used.
00258   myOs.str(emptyString); 
00259   myOs << s;
00260 #ifdef OLD_STYLE_AUTOMATIC_SPACES
00261   if ( ! myOs.str().empty() ) {
00262     if ( !verbatim ) {
00263       emitToken( myOs.str() + ' ' );
00264     } else {
00265        emitToken( myOs.str() );
00266     }
00267   }
00268 #else
00269   if ( ! myOs.str().empty() ) emitToken( myOs.str() );
00270 #endif
00271   return *this;
00272 }
00273 
00274 ErrorObj & operator<<( ErrorObj & e, const char s[] ) {
00275   return e.opltlt(s);
00276 }
00277 
00278 } // end of namespace edm  */