CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/FWCore/MessageService/src/ELlimitsTable.cc

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------
00002 //
00003 // ELlimitsTable.cc
00004 //
00005 // History:
00006 //   7/6/98     mf      Created
00007 //   6/10/99    jvr     Corrected initialization for severityLimits and
00008 //                      timespans to -1 instead of 0.
00009 //   6/17/99    jvr     setLimit(id,n) works w/ setTimespan(sev||"*",n)
00010 //                      and setTimespan(id,n) w/ setLimit(sev||"*",n)
00011 //   6/15/00    web     using -> USING
00012 //  11/01/01    web     Fixed mixed-type comparisons
00013 //   5/18/06    mf      setInterval
00014 //  11/2/07     mf      add:  Changed ivl = wildcardLimit to wildcardInterval.
00015 //                      Probably moot and never reached, but a clear correction.
00016 //  9/29/10     mf,ql   Fix savanah bug 65284 where two messages of same
00017 //                      category but different severity, if limits were not
00018 //                      take from category, first severity sets the limit
00019 //                      for both of those xid's.
00020 //
00021 // ----------------------------------------------------------------------
00022 
00023 
00024 #include "FWCore/MessageService/interface/ELlimitsTable.h"
00025 
00026 // Posible traces
00027 //#include <iostream>
00028 //using std::cerr;
00029 //#define ELlimitsTableCONSTRUCTOR_TRACE
00030 //#define ELlimitsTableATRACE
00031 
00032 
00033 namespace edm {
00034 namespace service {
00035 
00036 // ----------------------------------------------------------------------
00037 // Constructor, destructor:
00038 // ----------------------------------------------------------------------
00039 
00040 
00041 ELlimitsTable::ELlimitsTable()
00042 : wildcardLimit   ( -1 )
00043 , wildcardInterval( -1 )
00044 , wildcardTimespan( -1 )
00045 , tableLimit      ( -1 )
00046 , limits          (    )
00047 , counts          (    )
00048 {
00049 
00050 #ifdef ELlimitsTableCONSTRUCTOR_TRACE
00051   std::cerr << "Constructor for ELlimitsTable\n";
00052 #endif
00053 
00054   for ( int k = 0;  k < ELseverityLevel::nLevels;  ++k )  {
00055     severityLimits[k]    = -1;                // JvR 99-06-10
00056     severityIntervals[k]    = -1;             
00057     severityTimespans[k] = -1;
00058   }
00059 
00060 }  // ELlimitsTable()
00061 
00062 
00063 ELlimitsTable::~ELlimitsTable()  {
00064 
00065 #ifdef ELlimitsTableCONSTRUCTOR_TRACE
00066   std::cerr << "Destructor for ELlimitsTable\n";
00067 #endif
00068 
00069 }  // ~ELlimitsTable()
00070 
00071 
00072 // ----------------------------------------------------------------------
00073 // Methods invoked by the logger:
00074 // ----------------------------------------------------------------------
00075 
00076 void ELlimitsTable::setTableLimit( int n )  { tableLimit = n; }
00077 
00078 
00079 bool ELlimitsTable::add( const ELextendedID & xid )  {
00080 
00081 #ifdef ELlimitsTableATRACE
00082   std::cerr << "&&&--- adding to limits table: " << xid.id << '\n';
00083 #endif
00084 
00085   ELmap_counts::iterator c = counts.find( xid );
00086 
00087   if ( c == counts.end() )  {  // no such entry yet
00088 
00089     #ifdef ELlimitsTableATRACE
00090     std::cerr << "&&&    no such entry yet in counts \n";
00091     #endif
00092 
00093     // if the counts table is "full", then this will never be rejected
00094     // and info will not be kept so why go through significant work: 
00095     if ( tableLimit > 0  && static_cast<int>(counts.size()) >= tableLimit ) {
00096       return true;
00097     }
00098     int lim;
00099     int ivl;
00100     int ts;
00101     ELmap_limits::iterator l = limits.find( xid.id );
00102 
00103     if ( l != limits.end() )  { // use limits previously established for this id
00104       lim = (*l).second.limit;
00105       ivl = (*l).second.interval;
00106       ts  = (*l).second.timespan;
00107       if ( lim < 0 )  {                                    // jvr 6/17/99
00108         lim = severityLimits[xid.severity.getLevel()];
00109         if ( lim < 0 )  {
00110           lim = wildcardLimit;
00111         }
00112       }
00113       if ( ivl < 0 )  {                                    
00114         ivl = severityIntervals[xid.severity.getLevel()];
00115         if ( ivl < 0 )  {
00116           ivl = wildcardInterval;                       // mf 11/02/07
00117         }
00118       }
00119       if ( ts < 0 )  {
00120         ts = severityTimespans[xid.severity.getLevel()];
00121         if (ts < 0 )  {
00122           ts = wildcardTimespan;
00123         }
00124         limits[xid.id] = LimitAndTimespan( lim, ts );
00125       }
00126       #ifdef ELlimitsTableATRACE
00127       std::cerr << "&&&    Entry found in limits: limit = " << lim
00128            << " interval = " << ivl
00129            << " timespan = " << ts << '\n';
00130       #endif
00131       // change log 9/29/10:  Do not put this into limits table
00132    } else  {   // establish and use limits new to this id
00133       lim = severityLimits   [xid.severity.getLevel()];
00134       ivl = severityIntervals[xid.severity.getLevel()];
00135       ts  = severityTimespans[xid.severity.getLevel()];
00136       #ifdef ELlimitsTableATRACE
00137       std::cerr << "&&&    Limit taken from severityLimits: " << lim << '\n'
00138            << "&&&    Interval taken from severityLimits: " << ivl << '\n';
00139       #endif
00140       if ( lim < 0 )  {
00141         lim = wildcardLimit;
00142         #ifdef ELlimitsTableATRACE
00143         std::cerr << "&&&    Limit reset to wildcard limit: " << lim << '\n';
00144         #endif
00145       }
00146       if ( ivl < 0 )  {
00147         ivl = wildcardInterval;
00148         #ifdef ELlimitsTableATRACE
00149         std::cerr << "&&&    Interval reset to wildcard interval: " << ivl << '\n';
00150         #endif
00151       }
00152       #ifdef ELlimitsTableATRACE
00153       std::cerr << "&&&    Timespan taken from severityTimespans: " << ts << '\n';
00154       #endif
00155       if ( ts < 0 )  {
00156         ts = wildcardTimespan;
00157         #ifdef ELlimitsTableATRACE
00158         std::cerr << "&&&    timespan reset to wildcard timespan: " << ts << '\n';
00159         #endif
00160       }
00161 
00162       // change log 9/29/10 DO not save id's future limits:
00163     }
00164 
00165     // save, if possible, this xid's initial entry:
00166     if ( tableLimit < 0  || static_cast<int>(counts.size()) < tableLimit )
00167       counts[xid] = CountAndLimit( lim, ts, ivl );
00168     c = counts.find( xid );
00169   }
00170 
00171   return  ( c == counts.end() )
00172         ? true               // no limit filtering can be applied
00173         : (*c).second.add()  // apply limit filtering
00174         ;
00175 
00176 }  // add()
00177 
00178 
00179 // ----------------------------------------------------------------------
00180 // Control methods invoked by the framework:
00181 // ----------------------------------------------------------------------
00182 
00183 void ELlimitsTable::wipe()  {
00184   // This clears everything -- counts and aggregate counts for severity levels
00185   // and for individual ID's, as well as any limits established, the limit
00186   // for "*" all messages, and the collection of severity defaults.  wipe()
00187   // does not not affect thresholds.
00188 
00189   limits.erase( limits.begin(), limits.end() );
00190   ELmap_counts::iterator i;
00191   for ( i = counts.begin();  i != counts.end();  ++i )  {
00192     (*i).second.limit = -1;
00193     (*i).second.n = (*i).second.aggregateN = 0;
00194   }
00195 
00196   wildcardLimit    = -1;
00197   wildcardTimespan = -1;
00198   for ( int lev = 0;  lev < ELseverityLevel::nLevels;  ++lev )  {
00199     severityLimits   [lev] = -1;
00200     severityIntervals[lev] = -1;
00201     severityTimespans[lev] = -1;
00202   }
00203 
00204 }
00205 
00206 
00207 void ELlimitsTable::zero()  {
00208   // This clears counts but not aggregate counts for severity levels
00209   // and for individual ID's.
00210 
00211   ELmap_counts::iterator i;
00212   for ( i = counts.begin();  i != counts.end();  ++i )
00213     (*i).second.n = 0;
00214 }
00215 
00216 
00217 void ELlimitsTable::setLimit( const ELstring & id, int n )  {
00218   if ( id[0] == '*' )  wildcardLimit    = n;
00219   else                 limits[id].limit = n;
00220 }
00221 
00222 
00223 void ELlimitsTable::setLimit( const ELseverityLevel & sev, int n )  {
00224   severityLimits[sev.getLevel()] = n;
00225 }
00226 
00227 void ELlimitsTable::setInterval( const ELstring & id, int interval )  {
00228   if ( id[0] == '*' )  wildcardInterval    = interval;
00229   else                 limits[id].interval = interval;
00230 }
00231 
00232 
00233 void ELlimitsTable::setInterval( const ELseverityLevel & sev, int interval )  {
00234   severityIntervals[sev.getLevel()] = interval;
00235 }
00236 
00237 
00238 void ELlimitsTable::setTimespan( const ELstring & id, int n )  {
00239   if ( id[0] == '*' )  wildcardTimespan    = n;
00240   else                 limits[id].timespan = n;
00241 }
00242 
00243 
00244 void ELlimitsTable::setTimespan( const ELseverityLevel & sev, int n )  {
00245   severityTimespans[sev.getLevel()] = n;
00246 }
00247 
00248 
00249 // ----------------------------------------------------------------------
00250 // Support for internal operations:
00251 // ----------------------------------------------------------------------
00252 
00253 ELlimitsTable & ELlimitsTable::operator=( const ELlimitsTable & t )  {
00254 
00255   if(this == &t) {
00256     return  *this; // self assignment
00257   }
00258   limits = t.limits;  // The non-trivial operator= for a map!
00259 
00260   for ( int lev = 0;  lev < ELseverityLevel::nLevels;  ++lev )  {
00261     severityTimespans[lev] = t.severityTimespans[lev];
00262     severityTimespans[lev] = t.severityTimespans[lev];
00263   }
00264 
00265   wildcardLimit    = t.wildcardLimit;
00266   wildcardTimespan = t.wildcardTimespan;
00267 
00268   return  *this;
00269 
00270 }  // operator=()
00271 
00272 
00273 // ----------------------------------------------------------------------
00274 
00275 
00276 } // end of namespace service  
00277 } // end of namespace edm