CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/FWCore/MessageService/src/ELfwkJobReport.cc

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------
00002 //
00003 // ELfwkJobReport.cc
00004 //
00005 //
00006 // 1/10/06      mf, de  Created
00007 //
00008 // Changes:
00009 //
00010 //   1 - 3/22/06  mf  - in configure_dest()     
00011 //      Repaired the fact that destination limits for categories
00012 //      were not being effective:
00013 //      a) use values from the destination specific default PSet
00014 //         rather than the overall default PSet to set these
00015 //      b) when an explicit value has been set - either by overall default or 
00016 //         by a destination specific default PSet - set that limit or
00017 //         timespan for that dest_ctrl via a "*" msgId.
00018 //
00019 // ----------------------------------------------------------------------
00020 
00021 
00022 #include "FWCore/MessageService/interface/ELfwkJobReport.h"
00023 #include "FWCore/MessageLogger/interface/ErrorObj.h"
00024 #include "FWCore/Utilities/interface/do_nothing_deleter.h"
00025 
00026 // Possible Traces:
00027 // #define ELfwkJobReportCONSTRUCTOR_TRACE
00028 // #define ELfwkJobReportTRACE_LOG
00029 // #define ELfwkJobReport_EMIT_TRACE
00030 
00031 #include <iostream>
00032 #include <fstream>
00033 
00034 namespace edm {
00035 namespace service {
00036 
00037 // ----------------------------------------------------------------------
00038 // Constructors:
00039 // ----------------------------------------------------------------------
00040 
00041 ELfwkJobReport::ELfwkJobReport()
00042 : ELdestination       (            )
00043 , os                  ( &std::cerr, do_nothing_deleter() )
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   // Opening xml tag
00062   emitToken( "<FrameworkJobReport>\n", true );
00063 
00064 }  // ELfwkJobReport()
00065 
00066 
00067 ELfwkJobReport::ELfwkJobReport( std::ostream & os_ , bool /*emitAtStart*/ )
00068 : ELdestination       (       )
00069 , os                  ( &os_, do_nothing_deleter() )
00070 , charsOnLine         ( 0     )
00071 , xid                 (       )
00072 , wantTimestamp       ( true  )
00073 , wantModule          ( true  )
00074 , wantSubroutine      ( true  )
00075 , wantText            ( true  )
00076 , wantSomeContext     ( true  )
00077 , wantSerial          ( false )
00078 , wantFullContext     ( false )
00079 , wantTimeSeparate    ( false )
00080 , wantEpilogueSeparate( false )
00081 {
00082 
00083   #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
00084     std::cerr << "Constructor for ELfwkJobReport( os )\n";
00085   #endif
00086 
00087   // Opening xml tag
00088   emitToken( "<FrameworkJobReport>\n\n", true );
00089 
00090 }  // ELfwkJobReport()
00091 
00092 
00093 ELfwkJobReport::ELfwkJobReport( const ELstring & fileName, bool /*emitAtStart*/ )
00094 : ELdestination       (       )
00095 , os                  ( new std::ofstream( fileName.c_str() , std::ios/*_base*/::app), close_and_delete())
00096 , charsOnLine         ( 0     )
00097 , xid                 (       )
00098 , wantTimestamp       ( true  )
00099 , wantModule          ( true  )
00100 , wantSubroutine      ( true  )
00101 , wantText            ( true  )
00102 , wantSomeContext     ( true  )
00103 , wantSerial          ( false )
00104 , wantFullContext     ( false )
00105 , wantTimeSeparate    ( false )
00106 , wantEpilogueSeparate( false )
00107 {
00108 
00109   #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
00110     std::cerr << "Constructor for ELfwkJobReport( " << fileName << " )\n";
00111   #endif
00112 
00113   if ( os && *os )  {
00114     #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
00115       std::cerr << "          Testing if os is owned\n";
00116     #endif
00117     #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
00118       std::cerr << "          About to do first emit\n";
00119     #endif
00120     // Opening xml tag
00121     emitToken( "<FrameworkJobReport>\n");
00122   } else  {
00123     #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
00124       std::cerr << "          Deleting os\n";
00125     #endif
00126     os.reset(&std::cerr, do_nothing_deleter());
00127     #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
00128       std::cerr << "          about to emit to cerr\n";
00129     #endif
00130     // Opening xml tag
00131     emitToken( "<FrameworkJobReport>\n\n" );
00132   }
00133 
00134   #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
00135     std::cerr << "Constructor for ELfwkJobReport completed.\n";
00136   #endif
00137 
00138 }  // ELfwkJobReport()
00139 
00140 
00141 ELfwkJobReport::ELfwkJobReport( const ELfwkJobReport & orig )
00142 : ELdestination       (                           )
00143 , os                  ( orig.os                   )
00144 , charsOnLine         ( orig.charsOnLine          )
00145 , xid                 ( orig.xid                  )
00146 , wantTimestamp       ( orig.wantTimestamp        )
00147 , wantModule          ( orig.wantModule           )
00148 , wantSubroutine      ( orig.wantSubroutine       )
00149 , wantText            ( orig.wantText             )
00150 , wantSomeContext     ( orig.wantSomeContext      )
00151 , wantSerial          ( orig.wantSerial           )
00152 , wantFullContext     ( orig.wantFullContext      )
00153 , wantTimeSeparate    ( orig.wantTimeSeparate     )
00154 , wantEpilogueSeparate( orig.wantEpilogueSeparate )
00155 {
00156 
00157   #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
00158     std::cerr << "Copy constructor for ELfwkJobReport\n";
00159   #endif
00160 
00161   // mf 6/15/01 fix of Bug 005
00162   threshold             = orig.threshold;
00163   traceThreshold        = orig.traceThreshold;
00164   limits                = orig.limits;
00165   preamble              = orig.preamble;
00166   newline               = orig.newline;
00167   indent                = orig.indent;
00168   lineLength            = orig.lineLength;
00169 
00170   ignoreMostModules     = orig.ignoreMostModules;
00171   respondToThese        = orig.respondToThese;
00172   respondToMostModules  = orig.respondToMostModules;
00173   ignoreThese           = orig.ignoreThese;
00174 
00175 }  // ELfwkJobReport()
00176 
00177 
00178 ELfwkJobReport::~ELfwkJobReport()  {
00179 
00180   #ifdef ELfwkJobReportCONSTRUCTOR_TRACE
00181     std::cerr << "Destructor for ELfwkJobReport\n";
00182   #endif
00183 }  // ~ELfwkJobReport()
00184 
00185 
00186 // ----------------------------------------------------------------------
00187 // Methods invoked by the ELadministrator:
00188 // ----------------------------------------------------------------------
00189 
00190 ELfwkJobReport *
00191 ELfwkJobReport::clone() const  {
00192 
00193   return new ELfwkJobReport( *this );
00194 
00195 } // clone()
00196 
00197 
00198 bool ELfwkJobReport::log( const edm::ErrorObj & msg )  {
00199 
00200   #ifdef ELfwkJobReportTRACE_LOG
00201     std::cerr << "    =:=:=: Log to an ELfwkJobReport \n";
00202   #endif
00203 
00204   xid = msg.xid();      // Save the xid.
00205 
00206   // Change log 1:  React ONLY to category FwkJob
00207   if (xid.id != "FwkJob") return false;
00208   
00209   // See if this message is to be acted upon
00210   // (this is redundant if we are reacting only to FwkJob)
00211   // and add it to limits table if it was not already present:
00212   //
00213   if ( msg.xid().severity < threshold  )  return false;
00214   
00215   if ( (xid.id == "BeginningJob")        ||
00216        (xid.id == "postBeginJob")        ||
00217        (xid.id == "preEventProcessing")  ||
00218        (xid.id == "preModule")           ||
00219        (xid.id == "postModule")          ||
00220        (xid.id == "postEventProcessing") ||
00221        (xid.id == "postEndJob")             ) return false; 
00222   if ( thisShouldBeIgnored(xid.module) )  return false;
00223   if ( ! limits.add( msg.xid() )       )  return false;
00224 
00225   #ifdef ELfwkJobReportTRACE_LOG
00226     std::cerr << "    =:=:=: Limits table work done \n";
00227   #endif
00228 
00229   // Output the prologue:
00230   //
00231   //emitToken( "  <Report>\n" );
00232   //emitToken( "    <Severity> " );
00233   //emitToken(xid.severity.getSymbol());
00234   //emitToken(" </Severity>\n");
00235   //emitToken( "    <Category> ");
00236   //emitToken(xid.id);
00237   //emitToken( " </Category>\n");
00238   //emitToken( "    <Message> \n");
00239   
00240  //  emitToken( msg.idOverflow() ); this is how to get the rest of the category
00241 
00242   #ifdef ELfwkJobReportTRACE_LOG
00243     std::cerr << "    =:=:=: Prologue done \n";
00244   #endif
00245 
00246   // Output each item in the message:
00247   //
00248   if ( wantText )  {
00249     ELlist_string::const_iterator it;
00250     for ( it = msg.items().begin();  it != msg.items().end();  ++it )  {
00251     #ifdef ELfwkJobReportTRACE_LOG
00252       std::cerr << "      =:=:=: Item:  " << *it << '\n';
00253     #endif
00254       //  emitToken( "      <Item> " );
00255       emitToken( *it);
00256       emitToken( "\n" );
00257       //emitToken( " </Item>\n" );
00258     }
00259   }
00260 
00261   // Close the body of the message
00262   //emitToken("    </Message>\n");
00263   
00264   // Provide further identification: Module
00265   //
00266   //emitToken("    <Module> ");
00267   //emitToken( xid.module );
00268   //emitToken(" </Module>\n");    
00269 
00270   #ifdef ELfwkJobReportTRACE_LOG
00271     std::cerr << "    =:=:=: Module done \n";
00272   #endif
00273 
00274   // close report
00275   //
00276   //emitToken("  </Report>\n\n");
00277 
00278   #ifdef ELfwkJobReportTRACE_LOG
00279     std::cerr << "  =:=:=: log(msg) done: \n";
00280   #endif
00281 
00282   return true;
00283 
00284 }  // log()
00285 
00286 void ELfwkJobReport::finish()   {
00287   // closing xml tag
00288   (*os) << "</FrameworkJobReport>\n";
00289 }
00290 
00291 // Remainder are from base class.
00292 
00293 
00294 // ----------------------------------------------------------------------
00295 // Output methods:
00296 // ----------------------------------------------------------------------
00297 
00298 void ELfwkJobReport::emitToken( const ELstring & s, bool /*nl*/ )  {
00299 
00300   #ifdef ELfwkJobReport_EMIT_TRACE
00301     std::cerr << "[][][] in emit:  charsOnLine is " << charsOnLine << '\n';
00302     std::cerr << "[][][] in emit:  s.length() " << s.length() << '\n';
00303     std::cerr << "[][][] in emit:  lineLength is " << lineLength << '\n';
00304   #endif
00305 
00306   if (s.length() == 0)  {
00307     return;
00308   }
00309 
00310   #ifdef ELfwkJobReport_EMIT_TRACE
00311     std::cerr << "[][][] in emit: about to << s to *os: " << s << " \n";
00312   #endif
00313 
00314   (*os) << s;
00315 
00316   #ifdef ELfwkJobReport_EMIT_TRACE
00317     std::cerr << "[][][] in emit: completed \n";
00318   #endif
00319 
00320 }  // emitToken()
00321 
00322 
00323 // ----------------------------------------------------------------------
00324 // Methods controlling message formatting:
00325 // ----------------------------------------------------------------------
00326 
00327 void ELfwkJobReport::includeTime()   { wantTimestamp = true;  }
00328 void ELfwkJobReport::suppressTime()  { wantTimestamp = false; }
00329 
00330 void ELfwkJobReport::includeModule()   { wantModule = true;  }
00331 void ELfwkJobReport::suppressModule()  { wantModule = false; }
00332 
00333 void ELfwkJobReport::includeSubroutine()   { wantSubroutine = true;  }
00334 void ELfwkJobReport::suppressSubroutine()  { wantSubroutine = false; }
00335 
00336 void ELfwkJobReport::includeText()   { wantText = true;  }
00337 void ELfwkJobReport::suppressText()  { wantText = false; }
00338 
00339 void ELfwkJobReport::includeContext()   { wantSomeContext = true;  }
00340 void ELfwkJobReport::suppressContext()  { wantSomeContext = false; }
00341 
00342 void ELfwkJobReport::suppressSerial()  { wantSerial = false; }
00343 void ELfwkJobReport::includeSerial()   { wantSerial = true;  }
00344 
00345 void ELfwkJobReport::useFullContext()  { wantFullContext = true;  }
00346 void ELfwkJobReport::useContext()      { wantFullContext = false; }
00347 
00348 void ELfwkJobReport::separateTime()  { wantTimeSeparate = true;  }
00349 void ELfwkJobReport::attachTime()    { wantTimeSeparate = false; }
00350 
00351 void ELfwkJobReport::separateEpilogue()  { wantEpilogueSeparate = true;  }
00352 void ELfwkJobReport::attachEpilogue()    { wantEpilogueSeparate = false; }
00353 
00354 
00355 // ----------------------------------------------------------------------
00356 // Summary output:
00357 // ----------------------------------------------------------------------
00358 
00359 void ELfwkJobReport::summarization(
00360   const ELstring & fullTitle
00361 , const ELstring & sumLines
00362 )  {
00363   const int titleMaxLength( 40 );
00364 
00365   // title:
00366   //
00367   ELstring title( fullTitle, 0, titleMaxLength );
00368   int q = (lineLength - title.length() - 2) / 2;
00369   ELstring line(q, '=');
00370   emitToken( "", true );
00371   emitToken( line );
00372   emitToken( " " );
00373   emitToken( title );
00374   emitToken( " " );
00375   emitToken( line, true );
00376 
00377   // body:
00378   //
00379   *os << sumLines;
00380 
00381   // finish:
00382   //
00383   emitToken( "", true );
00384   emitToken( ELstring(lineLength, '='), true );
00385 
00386 }  // summarization()
00387 
00388 
00389 // ----------------------------------------------------------------------
00390 // Changing ostream:
00391 // ----------------------------------------------------------------------
00392 
00393 void ELfwkJobReport::changeFile (std::ostream & os_) {
00394   os.reset(&os_, do_nothing_deleter());
00395   emitToken( "\n=======================================================", true );
00396   emitToken( "\nError Log changed to this stream\n" );
00397   emitToken( "\n=======================================================\n", true );
00398 }
00399 
00400 void ELfwkJobReport::changeFile (const ELstring & filename) {
00401   os.reset(new std::ofstream( filename.c_str(), std::ios/*_base*/::app ), close_and_delete());
00402   emitToken( "\n=======================================================", true );
00403   emitToken( "\nError Log changed to this file\n" );
00404   emitToken( "\n=======================================================\n", true );
00405 }
00406 
00407 void ELfwkJobReport::flush()  {
00408   os->flush();
00409 }
00410 
00411 
00412 // ----------------------------------------------------------------------
00413 
00414 
00415 } // end of namespace service  
00416 } // end of namespace edm