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