00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "FWCore/MessageService/interface/ELfwkJobReport.h"
00023 #include "FWCore/MessageLogger/interface/ErrorObj.h"
00024
00025
00026
00027
00028
00029
00030 #include <iostream>
00031 #include <fstream>
00032
00033 namespace edm {
00034 namespace service {
00035
00036
00037
00038
00039
00040 ELfwkJobReport::ELfwkJobReport()
00041 : ELdestination ( )
00042 , os ( &std::cerr )
00043 , osIsOwned ( false )
00044 , charsOnLine ( 0 )
00045 , xid ( )
00046 , wantTimestamp ( true )
00047 , wantModule ( true )
00048 , wantSubroutine ( true )
00049 , wantText ( true )
00050 , wantSomeContext ( true )
00051 , wantSerial ( false )
00052 , wantFullContext ( false )
00053 , wantTimeSeparate ( false )
00054 , wantEpilogueSeparate( false )
00055 {
00056
00057 #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
00058 std::cerr << "Constructor for ELfwkJobReport()\n";
00059 #endif
00060
00061
00062 emit( "<FrameworkJobReport>\n", true );
00063
00064 }
00065
00066
00067 ELfwkJobReport::ELfwkJobReport( std::ostream & os_ , bool emitAtStart )
00068 : ELdestination ( )
00069 , os ( &os_ )
00070 , osIsOwned ( false )
00071 , charsOnLine ( 0 )
00072 , xid ( )
00073 , wantTimestamp ( true )
00074 , wantModule ( true )
00075 , wantSubroutine ( true )
00076 , wantText ( true )
00077 , wantSomeContext ( true )
00078 , wantSerial ( false )
00079 , wantFullContext ( false )
00080 , wantTimeSeparate ( false )
00081 , wantEpilogueSeparate( false )
00082 {
00083
00084 #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
00085 std::cerr << "Constructor for ELfwkJobReport( os )\n";
00086 #endif
00087
00088
00089 emit( "<FrameworkJobReport>\n\n", true );
00090
00091 }
00092
00093
00094 ELfwkJobReport::ELfwkJobReport( const ELstring & fileName, bool emitAtStart )
00095 : ELdestination ( )
00096 , os ( new std::ofstream( fileName.c_str()
00097 , std::ios::app
00098 )
00099 )
00100 , osIsOwned ( false )
00101 , charsOnLine ( 0 )
00102 , xid ( )
00103 , wantTimestamp ( true )
00104 , wantModule ( true )
00105 , wantSubroutine ( true )
00106 , wantText ( true )
00107 , wantSomeContext ( true )
00108 , wantSerial ( false )
00109 , wantFullContext ( false )
00110 , wantTimeSeparate ( false )
00111 , wantEpilogueSeparate( false )
00112 {
00113
00114 #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
00115 std::cerr << "Constructor for ELfwkJobReport( " << fileName << " )\n";
00116 #endif
00117
00118 if ( os && *os ) {
00119 #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
00120 std::cerr << " Testing if os is owned\n";
00121 #endif
00122 osIsOwned = true;
00123 #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
00124 std::cerr << " About to do first emit\n";
00125 #endif
00126
00127 emit( "<FrameworkJobReport>\n");
00128 } else {
00129 #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
00130 std::cerr << " Deleting os\n";
00131 #endif
00132 delete os;
00133 os = & std::cerr;
00134 #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
00135 std::cerr << " about to emit to cerr\n";
00136 #endif
00137
00138 emit( "<FrameworkJobReport>\n\n" );
00139 }
00140
00141 #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
00142 std::cerr << "Constructor for ELfwkJobReport completed.\n";
00143 #endif
00144
00145 }
00146
00147
00148 ELfwkJobReport::ELfwkJobReport( const ELfwkJobReport & orig )
00149 : ELdestination ( )
00150 , os ( orig.os )
00151 , osIsOwned ( orig.osIsOwned )
00152 , charsOnLine ( orig.charsOnLine )
00153 , xid ( orig.xid )
00154 , wantTimestamp ( orig.wantTimestamp )
00155 , wantModule ( orig.wantModule )
00156 , wantSubroutine ( orig.wantSubroutine )
00157 , wantText ( orig.wantText )
00158 , wantSomeContext ( orig.wantSomeContext )
00159 , wantSerial ( orig.wantSerial )
00160 , wantFullContext ( orig.wantFullContext )
00161 , wantTimeSeparate ( orig.wantTimeSeparate )
00162 , wantEpilogueSeparate( orig.wantEpilogueSeparate )
00163 {
00164
00165 #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
00166 std::cerr << "Copy constructor for ELfwkJobReport\n";
00167 #endif
00168
00169
00170 threshold = orig.threshold;
00171 traceThreshold = orig.traceThreshold;
00172 limits = orig.limits;
00173 preamble = orig.preamble;
00174 newline = orig.newline;
00175 indent = orig.indent;
00176 lineLength = orig.lineLength;
00177
00178 ignoreMostModules = orig.ignoreMostModules;
00179 respondToThese = orig.respondToThese;
00180 respondToMostModules = orig.respondToMostModules;
00181 ignoreThese = orig.ignoreThese;
00182
00183
00184 const_cast<ELfwkJobReport &>(orig).osIsOwned = false;
00185
00186 }
00187
00188
00189 ELfwkJobReport::~ELfwkJobReport() {
00190
00191 #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
00192 std::cerr << "Destructor for ELfwkJobReport\n";
00193 #endif
00194
00195 if ( osIsOwned ) {
00196 ((std::ofstream*)os)->close();
00197 delete os;
00198 }
00199
00200 }
00201
00202
00203
00204
00205
00206
00207 ELfwkJobReport *
00208 ELfwkJobReport::clone() const {
00209
00210 return new ELfwkJobReport( *this );
00211
00212 }
00213
00214
00215 bool ELfwkJobReport::log( const edm::ErrorObj & msg ) {
00216
00217 #ifdef ELfwkJobReportTRACE_LOG
00218 std::cerr << " =:=:=: Log to an ELfwkJobReport \n";
00219 #endif
00220
00221 xid = msg.xid();
00222
00223
00224 if (xid.id != "FwkJob") return false;
00225
00226
00227
00228
00229
00230 if ( msg.xid().severity < threshold ) return false;
00231
00232 if ( (xid.id == "BeginningJob") ||
00233 (xid.id == "postBeginJob") ||
00234 (xid.id == "preEventProcessing") ||
00235 (xid.id == "preModule") ||
00236 (xid.id == "postModule") ||
00237 (xid.id == "postEventProcessing") ||
00238 (xid.id == "postEndJob") ) return false;
00239 if ( thisShouldBeIgnored(xid.module) ) return false;
00240 if ( ! limits.add( msg.xid() ) ) return false;
00241
00242 #ifdef ELfwkJobReportTRACE_LOG
00243 std::cerr << " =:=:=: Limits table work done \n";
00244 #endif
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 #ifdef ELfwkJobReportTRACE_LOG
00260 std::cerr << " =:=:=: Prologue done \n";
00261 #endif
00262
00263
00264
00265 if ( wantText ) {
00266 ELlist_string::const_iterator it;
00267 for ( it = msg.items().begin(); it != msg.items().end(); ++it ) {
00268 #ifdef ELfwkJobReportTRACE_LOG
00269 std::cerr << " =:=:=: Item: " << *it << '\n';
00270 #endif
00271
00272 emit( *it);
00273 emit( "\n" );
00274
00275 }
00276 }
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287 #ifdef ELfwkJobReportTRACE_LOG
00288 std::cerr << " =:=:=: Module done \n";
00289 #endif
00290
00291
00292
00293
00294
00295 #ifdef ELfwkJobReportTRACE_LOG
00296 std::cerr << " =:=:=: log(msg) done: \n";
00297 #endif
00298
00299 return true;
00300
00301 }
00302
00303 void ELfwkJobReport::finish() {
00304
00305 (*os) << "</FrameworkJobReport>\n";
00306 }
00307
00308
00309
00310
00311
00312
00313
00314
00315 void ELfwkJobReport::emit( const ELstring & s, bool nl ) {
00316
00317 #ifdef ELfwkJobReport_EMIT_TRACE
00318 std::cerr << "[][][] in emit: charsOnLine is " << charsOnLine << '\n';
00319 std::cerr << "[][][] in emit: s.length() " << s.length() << '\n';
00320 std::cerr << "[][][] in emit: lineLength is " << lineLength << '\n';
00321 #endif
00322
00323 if (s.length() == 0) {
00324 return;
00325 }
00326
00327 #ifdef ELfwkJobReport_EMIT_TRACE
00328 std::cerr << "[][][] in emit: about to << s to *os: " << s << " \n";
00329 #endif
00330
00331 (*os) << s;
00332
00333 #ifdef ELfwkJobReport_EMIT_TRACE
00334 std::cerr << "[][][] in emit: completed \n";
00335 #endif
00336
00337 }
00338
00339
00340
00341
00342
00343
00344 void ELfwkJobReport::includeTime() { wantTimestamp = true; }
00345 void ELfwkJobReport::suppressTime() { wantTimestamp = false; }
00346
00347 void ELfwkJobReport::includeModule() { wantModule = true; }
00348 void ELfwkJobReport::suppressModule() { wantModule = false; }
00349
00350 void ELfwkJobReport::includeSubroutine() { wantSubroutine = true; }
00351 void ELfwkJobReport::suppressSubroutine() { wantSubroutine = false; }
00352
00353 void ELfwkJobReport::includeText() { wantText = true; }
00354 void ELfwkJobReport::suppressText() { wantText = false; }
00355
00356 void ELfwkJobReport::includeContext() { wantSomeContext = true; }
00357 void ELfwkJobReport::suppressContext() { wantSomeContext = false; }
00358
00359 void ELfwkJobReport::suppressSerial() { wantSerial = false; }
00360 void ELfwkJobReport::includeSerial() { wantSerial = true; }
00361
00362 void ELfwkJobReport::useFullContext() { wantFullContext = true; }
00363 void ELfwkJobReport::useContext() { wantFullContext = false; }
00364
00365 void ELfwkJobReport::separateTime() { wantTimeSeparate = true; }
00366 void ELfwkJobReport::attachTime() { wantTimeSeparate = false; }
00367
00368 void ELfwkJobReport::separateEpilogue() { wantEpilogueSeparate = true; }
00369 void ELfwkJobReport::attachEpilogue() { wantEpilogueSeparate = false; }
00370
00371
00372
00373
00374
00375
00376 void ELfwkJobReport::summarization(
00377 const ELstring & fullTitle
00378 , const ELstring & sumLines
00379 ) {
00380 const int titleMaxLength( 40 );
00381
00382
00383
00384 ELstring title( fullTitle, 0, titleMaxLength );
00385 int q = (lineLength - title.length() - 2) / 2;
00386 ELstring line(q, '=');
00387 emit( "", true );
00388 emit( line );
00389 emit( " " );
00390 emit( title );
00391 emit( " " );
00392 emit( line, true );
00393
00394
00395
00396 *os << sumLines;
00397
00398
00399
00400 emit( "", true );
00401 emit( ELstring(lineLength, '='), true );
00402
00403 }
00404
00405
00406
00407
00408
00409
00410 void ELfwkJobReport::changeFile (std::ostream & os_) {
00411 if ( osIsOwned ) {
00412 ((std::ofstream*)os)->close();
00413 delete os;
00414 }
00415 os = &os_;
00416 osIsOwned = false;
00417 emit( "\n=======================================================", true );
00418 emit( "\nError Log changed to this stream\n" );
00419 emit( "\n=======================================================\n", true );
00420 }
00421
00422 void ELfwkJobReport::changeFile (const ELstring & filename) {
00423 if ( osIsOwned ) {
00424 ((std::ofstream*)os)->close();
00425 delete os;
00426 }
00427 os = new std::ofstream( filename.c_str(), std::ios::app );
00428 osIsOwned = false;
00429 emit( "\n=======================================================", true );
00430 emit( "\nError Log changed to this file\n" );
00431 emit( "\n=======================================================\n", true );
00432 }
00433
00434 void ELfwkJobReport::flush() {
00435 os->flush();
00436 }
00437
00438
00439
00440
00441
00442 }
00443 }