#include <FWCore/MessageLogger/interface/ELmap.h>
Public Member Functions | |
bool | add () |
CountAndLimit (int lim=-1, int ts=-1, int ivl=-1) | |
Public Attributes | |
int | aggregateN |
int | interval |
time_t | lastTime |
int | limit |
int | n |
int | skipped |
int | timespan |
Definition at line 61 of file ELmap.h.
bool edm::CountAndLimit::add | ( | ) |
Definition at line 55 of file ELmap.cc.
References aggregateN, TestMuL1L2Filter_cff::cerr, diff, flush(), interval, lastTime, limit, n, r, skipped, and timespan.
00055 { 00056 00057 time_t now = time(0); 00058 00059 #ifdef ELcountTRACE 00060 std::cerr << "&&&--- CountAndLimit::add \n"; 00061 std::cerr << "&&& Time now is " << now << "\n"; 00062 std::cerr << "&&& Last time is " << lastTime << "\n"; 00063 std::cerr << "&&& timespan is " << timespan << "\n"; 00064 std::cerr << "&&& difftime is " << difftime( now, lastTime ) << "\n" 00065 << std::flush; 00066 #endif 00067 00068 // Has it been so long that we should restart counting toward the limit? 00069 if ( (timespan >= 0) 00070 && 00071 (difftime(now, lastTime) >= timespan) ) { 00072 n = 0; 00073 if ( interval > 0 ) { 00074 skipped = interval - 1; // So this message will be reacted to 00075 } else { 00076 skipped = 0; 00077 } 00078 } 00079 00080 lastTime = now; 00081 00082 ++n; 00083 ++aggregateN; 00084 ++skipped; 00085 00086 #ifdef ELcountTRACE 00087 std::cerr << "&&& n is " << n << "-- limit is " << limit << "\n"; 00088 std::cerr << "&&& skipped is " << skipped 00089 << "-- interval is " << interval << "\n"; 00090 #endif 00091 00092 if (skipped < interval) return false; 00093 00094 if ( limit == 0 ) return false; // Zero limit - never react to this 00095 if ( (limit < 0) || ( n <= limit )) { 00096 skipped = 0; 00097 return true; 00098 } 00099 00100 // Now we are over the limit - have we exceeded limit by 2^N * limit? 00101 long diff = n - limit; 00102 long r = diff/limit; 00103 if ( r*limit != diff ) { // Not a multiple of limit - don't react 00104 return false; 00105 } 00106 if ( r == 1 ) { // Exactly twice limit - react 00107 skipped = 0; 00108 return true; 00109 } 00110 00111 while ( r > 1 ) { 00112 if ( (r & 1) != 0 ) return false; // Not 2**n times limit - don't react 00113 r >>= 1; 00114 } 00115 // If you never get an odd number till one, r is 2**n so react 00116 00117 skipped = 0; 00118 return true; 00119 00120 } // add()
time_t edm::CountAndLimit::lastTime |