File indexing completed on 2024-04-06 12:12:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include "FWCore/MessageLogger/interface/ELmap.h"
0020
0021 #include <ctime>
0022
0023
0024
0025
0026
0027
0028 namespace edm {
0029
0030
0031
0032
0033
0034 LimitAndTimespan::LimitAndTimespan(int lim, int ts, int ivl) : limit(lim), timespan(ts), interval(ivl) {}
0035
0036
0037
0038
0039
0040 CountAndLimit::CountAndLimit(int lim, int ts, int ivl)
0041 : n(0),
0042 aggregateN(0),
0043 lastTime(time(nullptr)),
0044 limit(lim),
0045 timespan(ts),
0046 interval(ivl),
0047 skipped(ivl - 1)
0048 {}
0049
0050 bool CountAndLimit::add() {
0051 time_t now = time(nullptr);
0052
0053 #ifdef ELcountTRACE
0054 std::cerr << "&&&--- CountAndLimit::add \n";
0055 std::cerr << "&&& Time now is " << now << "\n";
0056 std::cerr << "&&& Last time is " << lastTime << "\n";
0057 std::cerr << "&&& timespan is " << timespan << "\n";
0058 std::cerr << "&&& difftime is " << difftime(now, lastTime) << "\n" << std::flush;
0059 #endif
0060
0061
0062 if ((timespan >= 0) && (difftime(now, lastTime) >= timespan)) {
0063 n = 0;
0064 if (interval > 0) {
0065 skipped = interval - 1;
0066 } else {
0067 skipped = 0;
0068 }
0069 }
0070
0071 lastTime = now;
0072
0073 ++n;
0074 ++aggregateN;
0075 ++skipped;
0076
0077 #ifdef ELcountTRACE
0078 std::cerr << "&&& n is " << n << "-- limit is " << limit << "\n";
0079 std::cerr << "&&& skipped is " << skipped << "-- interval is " << interval << "\n";
0080 #endif
0081
0082 if (skipped < interval)
0083 return false;
0084
0085 if (limit == 0)
0086 return false;
0087 if ((limit < 0) || (n <= limit)) {
0088 skipped = 0;
0089 return true;
0090 }
0091
0092
0093 long diff = n - limit;
0094 long r = diff / limit;
0095 if (r * limit != diff) {
0096 return false;
0097 }
0098 if (r == 1) {
0099 skipped = 0;
0100 return true;
0101 }
0102
0103 while (r > 1) {
0104 if ((r & 1) != 0)
0105 return false;
0106 r >>= 1;
0107 }
0108
0109
0110 skipped = 0;
0111 return true;
0112
0113 }
0114
0115
0116
0117
0118
0119 StatsCount::StatsCount() : n(0), aggregateN(0), ignoredFlag(false), context1(""), context2(""), contextLast("") {}
0120
0121 void StatsCount::add(std::string_view context, bool reactedTo) {
0122 ++n;
0123 ++aggregateN;
0124
0125 ((1 == n) ? context1 : (2 == n) ? context2 : contextLast) = std::string(context, 0, 16);
0126
0127 if (!reactedTo)
0128 ignoredFlag = true;
0129
0130 }
0131
0132 }