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
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 #include "FWCore/MessageService/interface/ELadministrator.h"
00085 #include "FWCore/MessageService/interface/ELdestination.h"
00086 #include "FWCore/MessageService/interface/ELcontextSupplier.h"
00087 #include "FWCore/MessageService/interface/ELoutput.h"
00088
00089 #include "FWCore/Utilities/interface/EDMException.h"
00090
00091 #include <iostream>
00092 #include <sstream>
00093 #include <list>
00094 using std::cerr;
00095
00096
00097 namespace edm {
00098 namespace service {
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 void ELadministrator::setProcess( const ELstring & process ) {
00111
00112 process_ = process;
00113 #if 0
00114 std::cerr << "Administrator process set to \"" << process << "\"\n";
00115 #endif
00116
00117 }
00118
00119
00120 ELstring ELadministrator::swapProcess( const ELstring & process ) {
00121
00122 ELstring temp = process_;
00123 process_ = process;
00124 return temp;
00125
00126 }
00127
00128
00129 void ELadministrator::setContextSupplier( const ELcontextSupplier & supplier ) {
00130
00131 context_.reset(supplier.clone());
00132
00133 }
00134
00135
00136 const ELcontextSupplier & ELadministrator::getContextSupplier() const {
00137
00138 return *(context_);
00139
00140 }
00141
00142 ELcontextSupplier & ELadministrator::swapContextSupplier
00143 (ELcontextSupplier & cs) {
00144 ELcontextSupplier & save = *(context_);
00145 context_.reset(&cs);
00146 return save;
00147 }
00148
00149
00150 void ELadministrator::setAbortThreshold( const ELseverityLevel & sev ) {
00151
00152 abortThreshold_ = sev;
00153
00154 }
00155
00156 void ELadministrator::setExitThreshold( const ELseverityLevel & sev ) {
00157
00158 exitThreshold_ = sev;
00159
00160 }
00161
00162 ELdestControl ELadministrator::attach( const ELdestination & sink ) {
00163
00164 boost::shared_ptr<ELdestination> dest(sink.clone());
00165 sinks().push_back( dest );
00166 return ELdestControl( dest );
00167
00168 }
00169
00170 ELdestControl ELadministrator::attach( const ELdestination & sink,
00171 const ELstring & name ) {
00172 boost::shared_ptr<ELdestination> dest(sink.clone());
00173 attachedDestinations[name] = dest;
00174 sinks().push_back( dest );
00175 return ELdestControl( dest );
00176 }
00177
00178
00179 bool ELadministrator::getELdestControl ( const ELstring & name,
00180 ELdestControl & theDestControl ) {
00181
00182 if ( attachedDestinations.find(name) != attachedDestinations.end() ) {
00183 theDestControl = ELdestControl ( attachedDestinations[name] );
00184 return true;
00185 } else {
00186 return false;
00187 }
00188
00189 }
00190
00191 ELseverityLevel ELadministrator::checkSeverity() {
00192
00193 const ELseverityLevel retval( highSeverity_ );
00194 highSeverity_ = ELzeroSeverity;
00195 return retval;
00196
00197 }
00198
00199
00200 int ELadministrator::severityCount( const ELseverityLevel & sev ) const {
00201
00202 return severityCounts_[sev.getLevel()];
00203
00204 }
00205
00206
00207 int ELadministrator::severityCount(
00208 const ELseverityLevel & from,
00209 const ELseverityLevel & to
00210 ) const {
00211
00212 int k = from.getLevel();
00213 int sum = severityCounts_[k];
00214
00215 while ( ++k <= to.getLevel() )
00216 sum += severityCounts_[k];
00217
00218 return sum;
00219
00220 }
00221
00222
00223 void ELadministrator::resetSeverityCount( const ELseverityLevel & sev ) {
00224
00225 severityCounts_[sev.getLevel()] = 0;
00226
00227 }
00228
00229
00230 void ELadministrator::resetSeverityCount( const ELseverityLevel & from,
00231 const ELseverityLevel & to ) {
00232
00233 for ( int k = from.getLevel(); k <= to.getLevel(); ++k )
00234 severityCounts_[k] = 0;
00235
00236 }
00237
00238
00239 void ELadministrator::resetSeverityCount() {
00240
00241 resetSeverityCount( ELzeroSeverity, ELhighestSeverity );
00242
00243 }
00244
00245
00246
00247
00248
00249
00250 const ELstring & ELadministrator::process() const { return process_; }
00251
00252
00253 ELcontextSupplier & ELadministrator::context() const { return *context_; }
00254
00255
00256 const ELseverityLevel & ELadministrator::abortThreshold() const {
00257 return abortThreshold_;
00258 }
00259
00260 const ELseverityLevel & ELadministrator::exitThreshold() const {
00261 return exitThreshold_;
00262 }
00263
00264 std::list<boost::shared_ptr<ELdestination> > & ELadministrator::sinks() { return sinks_; }
00265
00266
00267 const ELseverityLevel & ELadministrator::highSeverity() const {
00268 return highSeverity_;
00269 }
00270
00271
00272 int ELadministrator::severityCounts( const int lev ) const {
00273 return severityCounts_[lev];
00274 }
00275
00276
00277
00278
00279
00280
00281 static inline void msgexit(int s) {
00282 std::ostringstream os;
00283 os << "msgexit - MessageLogger requested to exit with status " << s;
00284 edm::Exception e(edm::errors::LogicError, os.str());
00285 throw e;
00286 }
00287
00288 static inline void msgabort() {
00289 std::ostringstream os;
00290 os << "msgabort - MessageLogger requested to abort";
00291 edm::Exception e(edm::errors::LogicError, os.str());
00292 throw e;
00293 }
00294
00295 static inline void possiblyAbortOrExit (int s, int a, int e) {
00296 if (s < a && s < e) return;
00297 if (a < e) {
00298 if ( s < e ) msgabort();
00299 msgexit(s);
00300 } else {
00301 if ( s < a ) msgexit(s);
00302 msgabort();
00303 }
00304 }
00305
00306 void ELadministrator::finishMsg() {
00307
00308 if ( ! msgIsActive )
00309 return;
00310
00311 int lev = msg.xid().severity.getLevel();
00312 ++ severityCounts_[lev];
00313 if ( lev > highSeverity_.getLevel() )
00314 highSeverity_ = msg.xid().severity;
00315
00316 #ifdef ELadTRACE_FINISH
00317 std::cerr << "=:=:=: finshMsg() - lev = " << lev << "\n";
00318 #endif
00319
00320 context_->editErrorObj( msg );
00321
00322 #ifdef ELadTRACE_FINISH
00323 std::cerr << "=:=:=: finshMsg() returns from editErrorObj( msg ) \n";
00324 #endif
00325
00326 std::list<boost::shared_ptr<ELdestination> >::iterator d;
00327 bool mrt;
00328 #ifdef ELadTRACE_FINISH
00329 int destCounter = 0;
00330 #endif
00331 if ( sinks().begin() == sinks().end() ) {
00332 std::cerr << "\nERROR LOGGED WITHOUT DESTINATION!\n";
00333 std::cerr << "Attaching destination \"cerr\" to ELadministrator by default\n\n";
00334 boost::shared_ptr<ELdestination> dest(new ELoutput(cerr));
00335 this->sinks().push_back(dest);
00336 }
00337 for ( d = sinks().begin(); d != sinks().end(); ++d ) {
00338 #ifdef ELadTRACE_FINISH
00339 std::cerr << " =:=:=: log(msg) for a destination number "
00340 << ++destCounter << " called ... \n";
00341 #endif
00342 mrt = (*d)->log( msg );
00343 #ifdef ELadTRACE_FINISH
00344 std::cerr << " =:=:=: log(msg) for a destination returned " << mrt << "\n";
00345 #endif
00346 if ( mrt )
00347 msg.setReactedTo(true);
00348 }
00349
00350 msgIsActive = false;
00351
00352 possiblyAbortOrExit ( lev,
00353 abortThreshold().getLevel(),
00354 exitThreshold().getLevel() );
00355
00356 }
00357
00358
00359 void ELadministrator::clearMsg() {
00360
00361 msgIsActive = false;
00362 msg.clear();
00363
00364 }
00365
00366
00367
00368
00369
00370
00371 void ELadministrator::setThresholds( const ELseverityLevel & sev ) {
00372
00373 std::list<boost::shared_ptr<ELdestination> >::iterator d;
00374 for ( d = sinks().begin(); d != sinks().end(); ++d )
00375 (*d)->threshold = sev;
00376
00377 }
00378
00379
00380 void ELadministrator::setLimits( const ELstring & id, int limit ) {
00381
00382 std::list<boost::shared_ptr<ELdestination> >::iterator d;
00383 for ( d = sinks().begin(); d != sinks().end(); ++d )
00384 (*d)->limits.setLimit( id, limit );
00385
00386 }
00387
00388
00389 void ELadministrator::setIntervals
00390 ( const ELseverityLevel & sev, int interval ) {
00391
00392 std::list<boost::shared_ptr<ELdestination> >::iterator d;
00393 for ( d = sinks().begin(); d != sinks().end(); ++d )
00394 (*d)->limits.setInterval( sev, interval );
00395
00396 }
00397
00398 void ELadministrator::setIntervals( const ELstring & id, int interval ) {
00399
00400 std::list<boost::shared_ptr<ELdestination> >::iterator d;
00401 for ( d = sinks().begin(); d != sinks().end(); ++d )
00402 (*d)->limits.setInterval( id, interval );
00403
00404 }
00405
00406
00407 void ELadministrator::setLimits( const ELseverityLevel & sev, int limit ) {
00408
00409 std::list<boost::shared_ptr<ELdestination> >::iterator d;
00410 for ( d = sinks().begin(); d != sinks().end(); ++d )
00411 (*d)->limits.setLimit( sev, limit );
00412
00413 }
00414
00415
00416 void ELadministrator::setTimespans( const ELstring & id, int seconds ) {
00417
00418 std::list<boost::shared_ptr<ELdestination> >::iterator d;
00419 for ( d = sinks().begin(); d != sinks().end(); ++d )
00420 (*d)->limits.setTimespan( id, seconds );
00421
00422 }
00423
00424
00425 void ELadministrator::setTimespans( const ELseverityLevel & sev, int seconds ) {
00426
00427 std::list<boost::shared_ptr<ELdestination> >::iterator d;
00428 for ( d = sinks().begin(); d != sinks().end(); ++d )
00429 (*d)->limits.setTimespan( sev, seconds );
00430
00431 }
00432
00433
00434 void ELadministrator::wipe() {
00435
00436 std::list<boost::shared_ptr<ELdestination> >::iterator d;
00437 for ( d = sinks().begin(); d != sinks().end(); ++d )
00438 (*d)->limits.wipe();
00439
00440 }
00441
00442 void ELadministrator::finish() {
00443
00444 std::list<boost::shared_ptr<ELdestination> >::iterator d;
00445 for ( d = sinks().begin(); d != sinks().end(); ++d )
00446 (*d)->finish();
00447
00448 }
00449
00450
00451
00452
00453
00454
00455 class ELemptyContextSupplier : public ELcontextSupplier {
00456
00457 public:
00458
00459 virtual
00460 ELemptyContextSupplier *
00461 clone() const {
00462 return new ELemptyContextSupplier( *this );
00463 }
00464 virtual ELstring context() const { return ""; }
00465 virtual ELstring summaryContext() const { return ""; }
00466 virtual ELstring fullContext() const { return ""; }
00467
00468 virtual ~ELemptyContextSupplier() {}
00469
00470 };
00471
00472
00473 static ELemptyContextSupplier emptyContext;
00474
00475
00476
00477
00478
00479
00480
00481
00482 ELadministrator * ELadministrator::instance_ = 0;
00483
00484
00485 ELadministrator * ELadministrator::instance() {
00486
00487 static ELadminDestroyer destroyer_;
00488
00489
00490
00491
00492 if ( !instance_ ) {
00493 instance_ = new ELadministrator;
00494 destroyer_.setELadmin( instance_ );
00495 }
00496 return instance_;
00497
00498 }
00499
00500
00501 ELadministrator::ELadministrator()
00502 : process_ ( "" )
00503 , context_ ( emptyContext.clone() )
00504 , abortThreshold_( ELseverityLevel (ELseverityLevel::ELsev_abort) )
00505 , exitThreshold_ ( ELseverityLevel (ELseverityLevel::ELsev_highestSeverity ) )
00506 , sinks_ ( )
00507 , highSeverity_ ( ELseverityLevel (ELseverityLevel::ELsev_zeroSeverity) )
00508 , msg ( ELseverityLevel (ELseverityLevel::ELsev_unspecified), "" )
00509 , msgIsActive ( false )
00510 {
00511
00512 #ifdef ELadministratorCONSTRUCTOR_TRACE
00513 std::cerr << "ELadminstrator constructor\n";
00514 #endif
00515
00516 for ( int lev = 0; lev < ELseverityLevel::nLevels; ++lev )
00517 severityCounts_[lev] = 0;
00518
00519 }
00520
00521
00522 ELadminDestroyer::ELadminDestroyer( ELadministrator * ad ) : admin_( ad ) {}
00523
00524
00525 ELadminDestroyer::~ELadminDestroyer() {
00526
00527 #ifdef ELadministratorCONSTRUCTOR_TRACE
00528 std::cerr << "~ELadminDestroyer: Deleting admin_\n";
00529 #endif
00530
00531 delete admin_;
00532
00533 }
00534
00535
00536 void ELadminDestroyer::setELadmin( ELadministrator * ad ) { admin_ = ad; }
00537
00538
00539
00540
00541
00542
00543 ELadministrator::~ELadministrator() {
00544
00545 #ifdef ELadministratorCONSTRUCTOR_TRACE
00546 std::cerr << "ELadministrator Destructor\n";
00547 #endif
00548
00549 finishMsg();
00550
00551 sinks().clear();
00552
00553 }
00554
00555
00556
00557
00558
00559
00560 }
00561 }