Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:41

0001 // ----------------------------------------------------------------------
0002 //
0003 // ELadministrator.cc
0004 //
0005 // Methods of ELadministrator.
0006 //
0007 // History:
0008 //
0009 // 7/2/98  mf   Created
0010 // 7/6/98  mf   Added ELadministratorX knowledge
0011 // 6/16/99 jvr  Attaches a destination when an error is logged and
0012 //              no destinations are attached          $$ JV:1
0013 // 6/18/99 jvr/mf       Constructor for ELadministratorX uses explcitly
0014 //              constructed ELseverityLevels in its init list, rather
0015 //              than objectslike ELabort, which may not yet have
0016 //              been fully constructed.  Repairs a problem with ELcout.
0017 // 6/23/99  mf  Made emptyContextSUpplier static to this comp unit.
0018 // 12/20/99 mf  Added virtual destructor to ELemptyContextSupplier.
0019 // 2/29/00  mf  swapContextSupplier.
0020 // 4/05/00  mf  swapProcess.
0021 // 5/03/00  mf  When aborting, changed exit() to abort() so that dump
0022 //              will reflect true condition without unwinding things.
0023 // 6/6/00  web  Consolidated ELadministrator/X.
0024 // 6/7/00  web  Reflect consolidation of ELdestination/X.
0025 // 6/12/00 web  Attach cerr, rather than cout, in case of no previously-
0026 //              attached destination; using -> USING.
0027 // 3/6/00  mf   Attach taking name to id the destination, getELdestControl()
0028 // 3/14/01 mf   exitThreshold
0029 // 1/10/06 mf   finish()
0030 //
0031 // ---- CMS version
0032 //
0033 // 12/12/05 mf  change exit() to throw edm::exception
0034 //
0035 //-----------------------------------------------------------------------
0036 
0037 // Directory of methods:
0038 //----------------------
0039 
0040 // ELadministrator::setProcess( const ELstring & process )
0041 // ELadministrator::swapProcess( const ELstring & process )
0042 // ELadministrator::attach( const ELdestination & sink )
0043 // ELadministrator::attach( const ELdestination & sink, const ELstring & name )
0044 // ELadministrator::checkSeverity()
0045 // ELadministrator::severityCount( const messagelogger::ELseverityLevel & sev ) const
0046 // ELadministrator::severityCount( const messagelogger::ELseverityLevel & from,
0047 //                                  const messagelogger::ELseverityLevel & to    ) const
0048 // ELadministrator::resetSeverityCount( const messagelogger::ELseverityLevel & sev )
0049 // ELadministrator::resetSeverityCount( const messagelogger::ELseverityLevel & from,
0050 //                                      const messagelogger::ELseverityLevel & to    )
0051 // ELadministrator::resetSeverityCount()
0052 // ELadministrator::setThresholds( const messagelogger::ELseverityLevel & sev )
0053 // ELadministrator::setLimits( const ELstring & id, int limit )
0054 // ELadministrator::setLimits( const messagelogger::ELseverityLevel & sev, int limit )
0055 // ELadministrator::setIntervals( const ELstring & id, int interval )
0056 // ELadministrator::setIntervals( const messagelogger::ELseverityLevel & sev, int interval )
0057 // ELadministrator::setTimespans( const ELstring & id, int seconds )
0058 // ELadministrator::setTimespans( const messagelogger::ELseverityLevel & sev, int seconds )
0059 // ELadministrator::wipe()
0060 // ELadministrator::finish()
0061 //
0062 // ELadministrator::process() const
0063 // ELadministrator::context() const
0064 // ELadministrator::abortThreshold() const
0065 // ELadministrator::exitThreshold() const
0066 // ELadministrator::sinks_
0067 // ELadministrator::highSeverity() const
0068 // ELadministrator::severityCounts( const int lev ) const
0069 // ELadministrator::finishMsg()
0070 // ELadministrator::clearMsg()
0071 //
0072 //
0073 // ----------------------------------------------------------------------
0074 
0075 #include "FWCore/MessageService/src/ELadministrator.h"
0076 #include "FWCore/MessageService/src/ELdestination.h"
0077 #include "FWCore/MessageService/src/ELoutput.h"
0078 
0079 #include "FWCore/Utilities/interface/EDMException.h"
0080 
0081 #include <iostream>
0082 #include <sstream>
0083 #include <list>
0084 using std::cerr;
0085 using namespace edm::messagelogger;
0086 
0087 namespace edm {
0088   namespace service {
0089 
0090     // Possible Traces:
0091     // #define ELadministratorCONSTRUCTOR_TRACE
0092     // #define ELadTRACE_FINISH
0093 
0094     void ELadministrator::log(edm::ErrorObj& msg) {
0095       // severity level statistics keeping:                 // $$ mf 6/7/01
0096       int lev = msg.xid().severity.getLevel();
0097       ++severityCounts_[lev];
0098       if (lev > highSeverity_.getLevel())
0099         highSeverity_ = msg.xid().severity;
0100 
0101       // -----  send the message to each destination:
0102       //
0103       if (sinks_.begin() == sinks_.end()) {
0104         std::cerr << "\nERROR LOGGED WITHOUT DESTINATION!\n";
0105         std::cerr << "Attaching destination \"cerr\" to ELadministrator by default\n" << std::endl;
0106         attach(std::make_shared<ELoutput>(std::cerr));
0107       }
0108       for (auto& sink : sinks_)
0109         if (sink->log(msg))
0110           msg.setReactedTo(true);
0111 
0112       return;
0113     }
0114 
0115     // ----------------------------------------------------------------------
0116     // ELadministrator functionality:
0117     // ----------------------------------------------------------------------
0118 
0119     std::shared_ptr<ELdestination> ELadministrator::attach(std::shared_ptr<ELdestination> sink) {
0120       sinks_.push_back(sink);
0121       return sink;
0122 
0123     }  // attach()
0124 
0125     ELseverityLevel ELadministrator::checkSeverity() {
0126       const ELseverityLevel retval(highSeverity_);
0127       highSeverity_ = ELzeroSeverity;
0128       return retval;
0129 
0130     }  // checkSeverity()
0131 
0132     int ELadministrator::severityCount(const ELseverityLevel& sev) const {
0133       return severityCounts_[sev.getLevel()];
0134 
0135     }  // severityCount()
0136 
0137     int ELadministrator::severityCount(const ELseverityLevel& from, const ELseverityLevel& to) const {
0138       int k = from.getLevel();
0139       int sum = severityCounts_[k];
0140 
0141       while (++k != to.getLevel())
0142         sum += severityCounts_[k];
0143 
0144       return sum;
0145 
0146     }  // severityCount()
0147 
0148     void ELadministrator::resetSeverityCount(const ELseverityLevel& sev) {
0149       severityCounts_[sev.getLevel()] = 0;
0150 
0151     }  // resetSeverityCount()
0152 
0153     void ELadministrator::resetSeverityCount(const ELseverityLevel& from, const ELseverityLevel& to) {
0154       for (int k = from.getLevel(); k <= to.getLevel(); ++k)
0155         severityCounts_[k] = 0;
0156 
0157     }  // resetSeverityCount()
0158 
0159     void ELadministrator::resetSeverityCount() {
0160       resetSeverityCount(ELzeroSeverity, ELhighestSeverity);
0161 
0162     }  // resetSeverityCount()
0163 
0164     // ----------------------------------------------------------------------
0165     // Accessors:
0166     // ----------------------------------------------------------------------
0167 
0168     const ELseverityLevel& ELadministrator::highSeverity() const { return highSeverity_; }
0169 
0170     int ELadministrator::severityCounts(const int lev) const { return severityCounts_[lev]; }
0171 
0172     // ----------------------------------------------------------------------
0173     // Message handling:
0174     // ----------------------------------------------------------------------
0175 
0176     // ----------------------------------------------------------------------
0177     // The following do the indicated action to all attached destinations:
0178     // ----------------------------------------------------------------------
0179 
0180     void ELadministrator::setThresholds(const ELseverityLevel& sev) {
0181       for (auto& sink : sinks_)
0182         sink->threshold = sev;
0183 
0184     }  // setThresholds()
0185 
0186     void ELadministrator::setLimits(const std::string& id, int limit) {
0187       for (auto& sink : sinks_)
0188         sink->limits.setLimit(id, limit);
0189 
0190     }  // setLimits()
0191 
0192     void ELadministrator::setIntervals(const ELseverityLevel& sev, int interval) {
0193       for (auto& sink : sinks_)
0194         sink->limits.setInterval(sev, interval);
0195 
0196     }  // setIntervals()
0197 
0198     void ELadministrator::setIntervals(const std::string& id, int interval) {
0199       for (auto& sink : sinks_)
0200         sink->limits.setInterval(id, interval);
0201 
0202     }  // setIntervals()
0203 
0204     void ELadministrator::setLimits(const ELseverityLevel& sev, int limit) {
0205       for (auto& sink : sinks_)
0206         sink->limits.setLimit(sev, limit);
0207 
0208     }  // setLimits()
0209 
0210     void ELadministrator::setTimespans(const std::string& id, int seconds) {
0211       for (auto& sink : sinks_)
0212         sink->limits.setTimespan(id, seconds);
0213 
0214     }  // setTimespans()
0215 
0216     void ELadministrator::setTimespans(const ELseverityLevel& sev, int seconds) {
0217       for (auto& sink : sinks_)
0218         sink->limits.setTimespan(sev, seconds);
0219 
0220     }  // setTimespans()
0221 
0222     void ELadministrator::wipe() {
0223       for (auto& sink : sinks_)
0224         sink->limits.wipe();
0225 
0226     }  // wipe()
0227 
0228     void ELadministrator::finish() {
0229       for (auto& sink : sinks_)
0230         sink->finish();
0231 
0232     }  // wipe()
0233 
0234     ELadministrator::ELadministrator() : sinks_(), highSeverity_(ELseverityLevel(ELseverityLevel::ELsev_zeroSeverity)) {
0235 #ifdef ELadministratorCONSTRUCTOR_TRACE
0236       std::cerr << "ELadminstrator constructor\n";
0237 #endif
0238 
0239       for (int lev = 0; lev < ELseverityLevel::nLevels; ++lev)
0240         severityCounts_[lev] = 0;
0241     }
0242     //-*****************************
0243     // The ELadminstrator destructor
0244     //-*****************************
0245 
0246     ELadministrator::~ELadministrator() {
0247 #ifdef ELadministratorCONSTRUCTOR_TRACE
0248       std::cerr << "ELadministrator Destructor\n";
0249 #endif
0250 
0251       sinks_.clear();
0252 
0253     }  // ~ELadministrator()
0254 
0255     // ----------------------------------------------------------------------
0256 
0257   }  // end of namespace service
0258 }  // end of namespace edm