CMS 3D CMS Logo

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 //
00017 // ----------------------------------------------------------------------
00018 
00019 
00020 #include "FWCore/MessageService/interface/ELlimitsTable.h"
00021 
00022 //#include <iostream>
00023 //using std::cerr;
00024 
00025 // Posible traces
00026 // #define ELlimitsTableCONSTRUCTOR_TRACE
00027 // #define ELlimitsTableATRACE
00028 
00029 
00030 namespace edm {
00031 namespace service {
00032 
00033 // ----------------------------------------------------------------------
00034 // Constructor, destructor:
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;                // JvR 99-06-10
00053     severityIntervals[k]    = -1;             
00054     severityTimespans[k] = -1;
00055   }
00056 
00057 }  // ELlimitsTable()
00058 
00059 
00060 ELlimitsTable::~ELlimitsTable()  {
00061 
00062 #ifdef ELlimitsTableCONSTRUCTOR_TRACE
00063   std::cerr << "Destructor for ELlimitsTable\n";
00064 #endif
00065 
00066 }  // ~ELlimitsTable()
00067 
00068 
00069 // ----------------------------------------------------------------------
00070 // Methods invoked by the logger:
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() )  {  // no such entry yet
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() )  { // use limits previously established for this id
00095       lim = (*l).second.limit;
00096       ivl = (*l).second.interval;
00097       ts  = (*l).second.timespan;
00098       if ( lim < 0 )  {                                    // jvr 6/17/99
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;                       // mf 11/02/07
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  {   // establish and use limits new to this id
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       // save, if possible, id's future limits:
00154       if ( tableLimit < 0  || static_cast<int>(limits.size()) < tableLimit )
00155         limits[xid.id] = LimitAndTimespan( lim, ts, ivl );
00156     }
00157 
00158     // save, if possible, this xid's initial entry:
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               // no limit filtering can be applied
00166         : (*c).second.add()  // apply limit filtering
00167         ;
00168 
00169 }  // add()
00170 
00171 
00172 // ----------------------------------------------------------------------
00173 // Control methods invoked by the framework:
00174 // ----------------------------------------------------------------------
00175 
00176 void ELlimitsTable::wipe()  {
00177   // This clears everything -- counts and aggregate counts for severity levels
00178   // and for individual ID's, as well as any limits established, the limit
00179   // for "*" all messages, and the collection of severity defaults.  wipe()
00180   // does not not affect thresholds.
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   // This clears counts but not aggregate counts for severity levels
00202   // and for individual ID's.
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 // Support for internal operations:
00244 // ----------------------------------------------------------------------
00245 
00246 ELlimitsTable & ELlimitsTable::operator=( const ELlimitsTable & t )  {
00247 
00248   limits = t.limits;  // The non-trivial operator= for a map!
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 }  // operator=()
00261 
00262 
00263 // ----------------------------------------------------------------------
00264 
00265 
00266 } // end of namespace service  
00267 } // end of namespace edm  

Generated on Tue Jun 9 17:36:18 2009 for CMSSW by  doxygen 1.5.4