CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/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 ErrorObj& ErrorObj::operator=( const ErrorObj & other ) {
00121   ErrorObj temp(other);
00122   this->swap(temp);
00123   return *this;
00124 }
00125 
00126 void ErrorObj::swap( ErrorObj& other ) {
00127   std::swap(mySerial, other.mySerial);
00128   std::swap(myXid, other.myXid);
00129   myIdOverflow.swap(other.myIdOverflow);
00130   std::swap(myTimestamp, other.myTimestamp);
00131   myItems.swap(other.myItems);
00132   std::swap(myReactedTo, other.myReactedTo);
00133   myContext.swap(other.myContext);
00134   std::string temp(other.myOs.str());
00135   other.myOs.str(myOs.str());
00136   myOs.str(temp);
00137   emptyString.swap(other.emptyString);
00138   std::swap(verbatim, other.verbatim);
00139 }
00140 
00141 // ----------------------------------------------------------------------
00142 // Accessors:
00143 // ----------------------------------------------------------------------
00144 
00145 int                   ErrorObj::serial()     const  { return mySerial; }
00146 const ELextendedID &  ErrorObj::xid()        const  { return myXid; }
00147 const ELstring &      ErrorObj::idOverflow() const  { return myIdOverflow; }
00148 time_t                ErrorObj::timestamp()  const  { return myTimestamp; }
00149 const ELlist_string & ErrorObj::items()      const  { return myItems; }
00150 bool                  ErrorObj::reactedTo()  const  { return myReactedTo; }
00151 bool                  ErrorObj::is_verbatim()const  { return verbatim; }
00152 
00153 ELstring ErrorObj::context() const {
00154   return myContext;
00155 }
00156 
00157 ELstring ErrorObj::fullText() const  {
00158 
00159   ELstring result;
00160   for ( ELlist_string::const_iterator it = myItems.begin();
00161         it != myItems.end();
00162         ++it )
00163     result +=  *it;
00164   return result;
00165 
00166 }  // fullText()
00167 
00168 
00169 // ----------------------------------------------------------------------
00170 // Mutators:
00171 // ----------------------------------------------------------------------
00172 
00173 void ErrorObj::setSeverity( const ELseverityLevel & sev )  {
00174   myXid.severity = (sev <= ELzeroSeverity   ) ? (ELseverityLevel)ELincidental
00175                  : (sev >= ELhighestSeverity) ? (ELseverityLevel)ELfatal
00176                  :                              sev
00177                  ;
00178 }
00179 
00180 
00181 void ErrorObj::setID( const ELstring & id )  {
00182   myXid.id = ELstring( id, 0, maxIDlength );
00183   if ( id.length() > maxIDlength )
00184     myIdOverflow = ELstring( id, maxIDlength, id.length()-maxIDlength );
00185 }
00186 
00187 
00188 void ErrorObj::setModule( const ELstring & module )  { myXid.module = module; }
00189 
00190 void ErrorObj::setContext( const ELstring & c )  { myContext = c; }
00191 
00192 
00193 void ErrorObj::setSubroutine( const ELstring & subroutine )  {
00194   #ifdef ErrorObj_SUB_TRACE
00195     std::cerr << "=:=:=: ErrorObj::setSubroutine(" << subroutine << ")\n";
00196   #endif
00197   myXid.subroutine = (subroutine[0] == ' ')
00198                    ? subroutine.substr(1)
00199                    : subroutine;
00200 }
00201 
00202 
00203 void ErrorObj::setProcess( const ELstring & proc )  {
00204   myXid.process = proc;
00205   #if 0
00206     std::cerr << "ErrorObj process set to \"" << proc << "\"\n";
00207   #endif
00208 }
00209 
00210 void ErrorObj::setReactedTo( bool r )  {
00211   myReactedTo = r;
00212 }
00213 
00214 
00215 #ifdef ErrorObj_SUB_TRACE
00216   static int subN = 0;
00217 #endif
00218 
00219 
00220 ErrorObj & ErrorObj::emitToken( const ELstring & s )  {
00221 
00222   #ifdef ErrorObj_EMIT_TRACE
00223     std::cerr << "=:=:=: ErrorObj::emitToken( " << s << " )\n";
00224   #endif
00225 
00226   #ifdef ErrorObj_SUB_TRACE
00227     if ( subN > 0 )  {
00228       std::cerr << "=:=:=: subN ErrorObj::emitToken( " << s << " )\n";
00229       subN--;
00230     }
00231   #endif
00232 
00233   if ( eq_nocase(s.substr(0,5), "@SUB=" ) )  {
00234     #ifdef ErrorObj_SUB_TRACE
00235       std::cerr << "=:=:=: ErrorObj::@SUB s.substr(5) is: " << s.substr(5)
00236                 << '\n';
00237     #endif
00238     setSubroutine(s.substr(5));
00239   }
00240   else  {
00241     myItems.push_back( s );
00242   }
00243 
00244   return * this;
00245 
00246 }  // emitToken()
00247 
00248 
00249 void ErrorObj::set( const ELseverityLevel & sev, const ELstring & id )  {
00250 
00251   clear();
00252 
00253   myTimestamp = time( 0 );
00254   mySerial = ++ ourSerial;
00255 
00256   setID( id );
00257   setSeverity( sev );
00258 
00259 }  // set()
00260 
00261 
00262 void ErrorObj::clear()  {
00263 
00264   mySerial     = 0;
00265   myXid.clear();
00266   myIdOverflow = "";
00267   myTimestamp  = 0;
00268   myItems.erase( myItems.begin(), myItems.end() );  // myItems.clear();
00269   myReactedTo  = false;
00270 
00271 }  // clear()
00272 
00273 ErrorObj & 
00274 ErrorObj::opltlt ( const char s[] ) {
00275   // Exactly equivalent to the general template. 
00276   // If this is not provided explicitly, then the template will
00277   // be instantiated once for each length of string ever used.
00278   myOs.str(emptyString); 
00279   myOs << s;
00280 #ifdef OLD_STYLE_AUTOMATIC_SPACES
00281   if ( ! myOs.str().empty() ) {
00282     if ( !verbatim ) {
00283       emitToken( myOs.str() + ' ' );
00284     } else {
00285        emitToken( myOs.str() );
00286     }
00287   }
00288 #else
00289   if ( ! myOs.str().empty() ) emitToken( myOs.str() );
00290 #endif
00291   return *this;
00292 }
00293 
00294 ErrorObj & operator<<( ErrorObj & e, const char s[] ) {
00295   return e.opltlt(s);
00296 }
00297 
00298 } // end of namespace edm  */