Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // ----------------------------------------------------------------------
0002 //
0003 // ELlimitsTable.cc
0004 //
0005 // History:
0006 //   7/6/98     mf      Created
0007 //   6/10/99    jvr     Corrected initialization for severityLimits and
0008 //                      timespans to -1 instead of 0.
0009 //   6/17/99    jvr     setLimit(id,n) works w/ setTimespan(sev||"*",n)
0010 //                      and setTimespan(id,n) w/ setLimit(sev||"*",n)
0011 //   6/15/00    web     using -> USING
0012 //  11/01/01    web     Fixed mixed-type comparisons
0013 //   5/18/06    mf  setInterval
0014 //  11/2/07 mf  add:  Changed ivl = wildcardLimit to wildcardInterval.
0015 //          Probably moot and never reached, but a clear correction.
0016 //  9/29/10 mf,ql   Fix savanah bug 65284 where two messages of same
0017 //          category but different severity, if limits were not
0018 //          take from category, first severity sets the limit
0019 //          for both of those xid's.
0020 //
0021 // ----------------------------------------------------------------------
0022 
0023 #include "FWCore/MessageService/src/ELlimitsTable.h"
0024 
0025 // Posible traces
0026 //#include <iostream>
0027 //using std::cerr;
0028 //#define ELlimitsTableCONSTRUCTOR_TRACE
0029 //#define ELlimitsTableATRACE
0030 
0031 namespace edm {
0032   namespace service {
0033 
0034     // ----------------------------------------------------------------------
0035     // Constructor, destructor:
0036     // ----------------------------------------------------------------------
0037 
0038     ELlimitsTable::ELlimitsTable()
0039         : wildcardLimit(-1), wildcardInterval(-1), wildcardTimespan(-1), tableLimit(-1), limits(), counts() {
0040 #ifdef ELlimitsTableCONSTRUCTOR_TRACE
0041       std::cerr << "Constructor for ELlimitsTable\n";
0042 #endif
0043 
0044       for (int k = 0; k < messagelogger::ELseverityLevel::nLevels; ++k) {
0045         severityLimits[k] = -1;  // JvR 99-06-10
0046         severityIntervals[k] = -1;
0047         severityTimespans[k] = -1;
0048       }
0049 
0050     }  // ELlimitsTable()
0051 
0052     ELlimitsTable::~ELlimitsTable() {
0053 #ifdef ELlimitsTableCONSTRUCTOR_TRACE
0054       std::cerr << "Destructor for ELlimitsTable\n";
0055 #endif
0056 
0057     }  // ~ELlimitsTable()
0058 
0059     // ----------------------------------------------------------------------
0060     // Methods invoked by the logger:
0061     // ----------------------------------------------------------------------
0062 
0063     void ELlimitsTable::setTableLimit(int n) { tableLimit = n; }
0064 
0065     bool ELlimitsTable::add(const ELextendedID& xid) {
0066 #ifdef ELlimitsTableATRACE
0067       std::cerr << "&&&--- adding to limits table: " << xid.id << '\n';
0068 #endif
0069 
0070       ELmap_counts::iterator c = counts.find(xid);
0071 
0072       if (c == counts.end()) {  // no such entry yet
0073 
0074 #ifdef ELlimitsTableATRACE
0075         std::cerr << "&&&    no such entry yet in counts \n";
0076 #endif
0077 
0078         // if the counts table is "full", then this will never be rejected
0079         // and info will not be kept so why go through significant work:
0080         if (tableLimit > 0 && static_cast<int>(counts.size()) >= tableLimit) {
0081           return true;
0082         }
0083         int lim;
0084         int ivl;
0085         int ts;
0086         ELmap_limits::iterator l = limits.find(xid.id);
0087 
0088         if (l != limits.end()) {  // use limits previously established for this id
0089           lim = (*l).second.limit;
0090           ivl = (*l).second.interval;
0091           ts = (*l).second.timespan;
0092           if (lim < 0) {  // jvr 6/17/99
0093             lim = severityLimits[xid.severity.getLevel()];
0094             if (lim < 0) {
0095               lim = wildcardLimit;
0096             }
0097           }
0098           if (ivl < 0) {
0099             ivl = severityIntervals[xid.severity.getLevel()];
0100             if (ivl < 0) {
0101               ivl = wildcardInterval;  // mf 11/02/07
0102             }
0103           }
0104           if (ts < 0) {
0105             ts = severityTimespans[xid.severity.getLevel()];
0106             if (ts < 0) {
0107               ts = wildcardTimespan;
0108             }
0109             limits[xid.id] = LimitAndTimespan(lim, ts);
0110           }
0111 #ifdef ELlimitsTableATRACE
0112           std::cerr << "&&&    Entry found in limits: limit = " << lim << " interval = " << ivl << " timespan = " << ts
0113                     << '\n';
0114 #endif
0115           // change log 9/29/10:  Do not put this into limits table
0116         } else {  // establish and use limits new to this id
0117           lim = severityLimits[xid.severity.getLevel()];
0118           ivl = severityIntervals[xid.severity.getLevel()];
0119           ts = severityTimespans[xid.severity.getLevel()];
0120 #ifdef ELlimitsTableATRACE
0121           std::cerr << "&&&    Limit taken from severityLimits: " << lim << '\n'
0122                     << "&&&    Interval taken from severityLimits: " << ivl << '\n';
0123 #endif
0124           if (lim < 0) {
0125             lim = wildcardLimit;
0126 #ifdef ELlimitsTableATRACE
0127             std::cerr << "&&&    Limit reset to wildcard limit: " << lim << '\n';
0128 #endif
0129           }
0130           if (ivl < 0) {
0131             ivl = wildcardInterval;
0132 #ifdef ELlimitsTableATRACE
0133             std::cerr << "&&&    Interval reset to wildcard interval: " << ivl << '\n';
0134 #endif
0135           }
0136 #ifdef ELlimitsTableATRACE
0137           std::cerr << "&&&    Timespan taken from severityTimespans: " << ts << '\n';
0138 #endif
0139           if (ts < 0) {
0140             ts = wildcardTimespan;
0141 #ifdef ELlimitsTableATRACE
0142             std::cerr << "&&&    timespan reset to wildcard timespan: " << ts << '\n';
0143 #endif
0144           }
0145 
0146           // change log 9/29/10 DO not save id's future limits:
0147         }
0148 
0149         // save, if possible, this xid's initial entry:
0150         if (tableLimit < 0 || static_cast<int>(counts.size()) < tableLimit)
0151           counts[xid] = CountAndLimit(lim, ts, ivl);
0152         c = counts.find(xid);
0153       }
0154 
0155       return (c == counts.end()) ? true               // no limit filtering can be applied
0156                                  : (*c).second.add()  // apply limit filtering
0157           ;
0158 
0159     }  // add()
0160 
0161     // ----------------------------------------------------------------------
0162     // Control methods invoked by the framework:
0163     // ----------------------------------------------------------------------
0164 
0165     void ELlimitsTable::wipe() {
0166       // This clears everything -- counts and aggregate counts for severity levels
0167       // and for individual ID's, as well as any limits established, the limit
0168       // for "*" all messages, and the collection of severity defaults.  wipe()
0169       // does not not affect thresholds.
0170 
0171       limits.erase(limits.begin(), limits.end());
0172       ELmap_counts::iterator i;
0173       for (i = counts.begin(); i != counts.end(); ++i) {
0174         (*i).second.limit = -1;
0175         (*i).second.n = (*i).second.aggregateN = 0;
0176       }
0177 
0178       wildcardLimit = -1;
0179       wildcardTimespan = -1;
0180       for (int lev = 0; lev < messagelogger::ELseverityLevel::nLevels; ++lev) {
0181         severityLimits[lev] = -1;
0182         severityIntervals[lev] = -1;
0183         severityTimespans[lev] = -1;
0184       }
0185     }
0186 
0187     void ELlimitsTable::zero() {
0188       // This clears counts but not aggregate counts for severity levels
0189       // and for individual ID's.
0190 
0191       ELmap_counts::iterator i;
0192       for (i = counts.begin(); i != counts.end(); ++i)
0193         (*i).second.n = 0;
0194     }
0195 
0196     void ELlimitsTable::setLimit(const std::string& id, int n) {
0197       if (id[0] == '*')
0198         wildcardLimit = n;
0199       else
0200         limits[id].limit = n;
0201     }
0202 
0203     void ELlimitsTable::setLimit(const messagelogger::ELseverityLevel& sev, int n) {
0204       severityLimits[sev.getLevel()] = n;
0205     }
0206 
0207     void ELlimitsTable::setInterval(const std::string& id, int interval) {
0208       if (id[0] == '*')
0209         wildcardInterval = interval;
0210       else
0211         limits[id].interval = interval;
0212     }
0213 
0214     void ELlimitsTable::setInterval(const messagelogger::ELseverityLevel& sev, int interval) {
0215       severityIntervals[sev.getLevel()] = interval;
0216     }
0217 
0218     void ELlimitsTable::setTimespan(const std::string& id, int n) {
0219       if (id[0] == '*')
0220         wildcardTimespan = n;
0221       else
0222         limits[id].timespan = n;
0223     }
0224 
0225     void ELlimitsTable::setTimespan(const messagelogger::ELseverityLevel& sev, int n) {
0226       severityTimespans[sev.getLevel()] = n;
0227     }
0228 
0229     // ----------------------------------------------------------------------
0230     // Support for internal operations:
0231     // ----------------------------------------------------------------------
0232 
0233     ELlimitsTable& ELlimitsTable::operator=(const ELlimitsTable& t) {
0234       if (this == &t) {
0235         return *this;  // self assignment
0236       }
0237       limits = t.limits;  // The non-trivial operator= for a map!
0238 
0239       for (int lev = 0; lev < messagelogger::ELseverityLevel::nLevels; ++lev) {
0240         severityTimespans[lev] = t.severityTimespans[lev];
0241         severityTimespans[lev] = t.severityTimespans[lev];
0242       }
0243 
0244       wildcardLimit = t.wildcardLimit;
0245       wildcardTimespan = t.wildcardTimespan;
0246 
0247       return *this;
0248 
0249     }  // operator=()
0250 
0251     // ----------------------------------------------------------------------
0252 
0253   }  // end of namespace service
0254 }  // end of namespace edm