Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include "FWCore/MessageLogger/interface/ErrorObj.h"
00046
00047 #ifndef IOSTREAM_INCLUDED
00048 #endif
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 namespace edm
00064 {
00065
00066
00067
00068
00069
00070
00071 int ErrorObj::ourSerial( 0 );
00072 const unsigned int maxIDlength( 200 );
00073
00074
00075
00076
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 }
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 }
00110
00111
00112 ErrorObj::~ErrorObj() {
00113
00114 #ifdef ErrorObjCONSTRUCTOR_TRACE
00115 std::cerr << "Destructor for ErrorObj\n";
00116 #endif
00117
00118 }
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
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 }
00167
00168
00169
00170
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 }
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 }
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() );
00269 myReactedTo = false;
00270
00271 }
00272
00273 ErrorObj &
00274 ErrorObj::opltlt ( const char s[] ) {
00275
00276
00277
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 }