00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "FWCore/MessageService/interface/ELlimitsTable.h"
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 namespace edm {
00031 namespace service {
00032
00033
00034
00035
00036
00037
00038 ELlimitsTable::ELlimitsTable()
00039 : wildcardLimit ( -1 )
00040 , wildcardInterval( -1 )
00041 , wildcardTimespan( -1 )
00042 , tableLimit ( -1 )
00043 , limits ( )
00044 , counts ( )
00045 {
00046
00047 #ifdef ELlimitsTableCONSTRUCTOR_TRACE
00048 std::cerr << "Constructor for ELlimitsTable\n";
00049 #endif
00050
00051 for ( int k = 0; k < ELseverityLevel::nLevels; ++k ) {
00052 severityLimits[k] = -1;
00053 severityIntervals[k] = -1;
00054 severityTimespans[k] = -1;
00055 }
00056
00057 }
00058
00059
00060 ELlimitsTable::~ELlimitsTable() {
00061
00062 #ifdef ELlimitsTableCONSTRUCTOR_TRACE
00063 std::cerr << "Destructor for ELlimitsTable\n";
00064 #endif
00065
00066 }
00067
00068
00069
00070
00071
00072
00073 void ELlimitsTable::setTableLimit( int n ) { tableLimit = n; }
00074
00075
00076 bool ELlimitsTable::add( const ELextendedID & xid ) {
00077
00078 #ifdef ELlimitsTableATRACE
00079 std::cerr << "&&&--- adding to limits table: " << xid.id << '\n';
00080 #endif
00081
00082 ELmap_counts::iterator c = counts.find( xid );
00083
00084 if ( c == counts.end() ) {
00085
00086 #ifdef ELlimitsTableATRACE
00087 std::cerr << "&&& no such entry yet in counts \n";
00088 #endif
00089 int lim;
00090 int ivl;
00091 int ts;
00092 ELmap_limits::iterator l = limits.find( xid.id );
00093
00094 if ( l != limits.end() ) {
00095 lim = (*l).second.limit;
00096 ivl = (*l).second.interval;
00097 ts = (*l).second.timespan;
00098 if ( lim < 0 ) {
00099 lim = severityLimits[xid.severity.getLevel()];
00100 if ( lim < 0 ) {
00101 lim = wildcardLimit;
00102 }
00103 }
00104 if ( ivl < 0 ) {
00105 ivl = severityIntervals[xid.severity.getLevel()];
00106 if ( ivl < 0 ) {
00107 ivl = wildcardInterval;
00108 }
00109 }
00110 if ( ts < 0 ) {
00111 ts = severityTimespans[xid.severity.getLevel()];
00112 if (ts < 0 ) {
00113 ts = wildcardTimespan;
00114 }
00115 limits[xid.id] = LimitAndTimespan( lim, ts );
00116 }
00117 #ifdef ELlimitsTableATRACE
00118 std::cerr << "&&& Entry found in limits: limit = " << lim
00119 << " interval = " << ivl
00120 << " timespan = " << ts << '\n';
00121 #endif
00122 limits[xid.id] = LimitAndTimespan( lim, ts, ivl );
00123 } else {
00124 lim = severityLimits [xid.severity.getLevel()];
00125 ivl = severityIntervals[xid.severity.getLevel()];
00126 ts = severityTimespans[xid.severity.getLevel()];
00127 #ifdef ELlimitsTableATRACE
00128 std::cerr << "&&& Limit taken from severityLimits: " << lim << '\n'
00129 << "&&& Interval taken from severityLimits: " << ivl << '\n';
00130 #endif
00131 if ( lim < 0 ) {
00132 lim = wildcardLimit;
00133 #ifdef ELlimitsTableATRACE
00134 std::cerr << "&&& Limit reset to wildcard limit: " << lim << '\n';
00135 #endif
00136 }
00137 if ( ivl < 0 ) {
00138 ivl = wildcardInterval;
00139 #ifdef ELlimitsTableATRACE
00140 std::cerr << "&&& Interval reset to wildcard interval: " << ivl << '\n';
00141 #endif
00142 }
00143 #ifdef ELlimitsTableATRACE
00144 std::cerr << "&&& Timespan taken from severityTimespans: " << ts << '\n';
00145 #endif
00146 if ( ts < 0 ) {
00147 ts = wildcardTimespan;
00148 #ifdef ELlimitsTableATRACE
00149 std::cerr << "&&& timespan reset to wildcard timespan: " << ts << '\n';
00150 #endif
00151 }
00152
00153
00154 if ( tableLimit < 0 || static_cast<int>(limits.size()) < tableLimit )
00155 limits[xid.id] = LimitAndTimespan( lim, ts, ivl );
00156 }
00157
00158
00159 if ( tableLimit < 0 || static_cast<int>(counts.size()) < tableLimit )
00160 counts[xid] = CountAndLimit( lim, ts, ivl );
00161 c = counts.find( xid );
00162 }
00163
00164 return ( c == counts.end() )
00165 ? true
00166 : (*c).second.add()
00167 ;
00168
00169 }
00170
00171
00172
00173
00174
00175
00176 void ELlimitsTable::wipe() {
00177
00178
00179
00180
00181
00182 limits.erase( limits.begin(), limits.end() );
00183 ELmap_counts::iterator i;
00184 for ( i = counts.begin(); i != counts.end(); ++i ) {
00185 (*i).second.limit = -1;
00186 (*i).second.n = (*i).second.aggregateN = 0;
00187 }
00188
00189 wildcardLimit = -1;
00190 wildcardTimespan = -1;
00191 for ( int lev = 0; lev < ELseverityLevel::nLevels; ++lev ) {
00192 severityLimits [lev] = -1;
00193 severityIntervals[lev] = -1;
00194 severityTimespans[lev] = -1;
00195 }
00196
00197 }
00198
00199
00200 void ELlimitsTable::zero() {
00201
00202
00203
00204 ELmap_counts::iterator i;
00205 for ( i = counts.begin(); i != counts.end(); ++i )
00206 (*i).second.n = 0;
00207 }
00208
00209
00210 void ELlimitsTable::setLimit( const ELstring & id, int n ) {
00211 if ( id[0] == '*' ) wildcardLimit = n;
00212 else limits[id].limit = n;
00213 }
00214
00215
00216 void ELlimitsTable::setLimit( const ELseverityLevel & sev, int n ) {
00217 severityLimits[sev.getLevel()] = n;
00218 }
00219
00220 void ELlimitsTable::setInterval( const ELstring & id, int interval ) {
00221 if ( id[0] == '*' ) wildcardInterval = interval;
00222 else limits[id].interval = interval;
00223 }
00224
00225
00226 void ELlimitsTable::setInterval( const ELseverityLevel & sev, int interval ) {
00227 severityIntervals[sev.getLevel()] = interval;
00228 }
00229
00230
00231 void ELlimitsTable::setTimespan( const ELstring & id, int n ) {
00232 if ( id[0] == '*' ) wildcardTimespan = n;
00233 else limits[id].timespan = n;
00234 }
00235
00236
00237 void ELlimitsTable::setTimespan( const ELseverityLevel & sev, int n ) {
00238 severityTimespans[sev.getLevel()] = n;
00239 }
00240
00241
00242
00243
00244
00245
00246 ELlimitsTable & ELlimitsTable::operator=( const ELlimitsTable & t ) {
00247
00248 limits = t.limits;
00249
00250 for ( int lev = 0; lev < ELseverityLevel::nLevels; ++lev ) {
00251 severityTimespans[lev] = t.severityTimespans[lev];
00252 severityTimespans[lev] = t.severityTimespans[lev];
00253 }
00254
00255 wildcardLimit = t.wildcardLimit;
00256 wildcardTimespan = t.wildcardTimespan;
00257
00258 return *this;
00259
00260 }
00261
00262
00263
00264
00265
00266 }
00267 }