forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ELmap.cc
130 lines (104 loc) · 3.95 KB
/
ELmap.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// ----------------------------------------------------------------------
//
// ELmap.cc
//
// Change History:
// 99-06-10 mf correction in sense of comparison between timespan
// and diff (now, lastTime)
// mf ELcountTRACE made available
// 99-06-11 mf Corrected logic for suppressing output when n > limit
// but not but a factor of 2**K
// 06-05-16 mf Added code to establish interval and to use skipped
// and interval when determinine in add() whehter to react
// 06-05-19 wmtan Bug fix. skipped = 0, not skipped == 0.
// and interval when determinine in add() whehter to react
// 09-04-15 wmtan Use smart pointers with new, not bare pointers
//
// ----------------------------------------------------------------------
#include "FWCore/MessageLogger/interface/ELmap.h"
// Possible traces
//#include <iostream>
//#define ELcountTRACE
// #define ELmapDumpTRACE
namespace edm {
// ----------------------------------------------------------------------
// LimitAndTimespan:
// ----------------------------------------------------------------------
LimitAndTimespan::LimitAndTimespan(int lim, int ts, int ivl) : limit(lim), timespan(ts), interval(ivl) {}
// ----------------------------------------------------------------------
// CountAndLimit:
// ----------------------------------------------------------------------
CountAndLimit::CountAndLimit(int lim, int ts, int ivl)
: n(0),
aggregateN(0),
lastTime(time(nullptr)),
limit(lim),
timespan(ts),
interval(ivl),
skipped(ivl - 1) // So that the FIRST of the prescaled messages emerges
{}
bool CountAndLimit::add() {
time_t now = time(nullptr);
#ifdef ELcountTRACE
std::cerr << "&&&--- CountAndLimit::add \n";
std::cerr << "&&& Time now is " << now << "\n";
std::cerr << "&&& Last time is " << lastTime << "\n";
std::cerr << "&&& timespan is " << timespan << "\n";
std::cerr << "&&& difftime is " << difftime(now, lastTime) << "\n" << std::flush;
#endif
// Has it been so long that we should restart counting toward the limit?
if ((timespan >= 0) && (difftime(now, lastTime) >= timespan)) {
n = 0;
if (interval > 0) {
skipped = interval - 1; // So this message will be reacted to
} else {
skipped = 0;
}
}
lastTime = now;
++n;
++aggregateN;
++skipped;
#ifdef ELcountTRACE
std::cerr << "&&& n is " << n << "-- limit is " << limit << "\n";
std::cerr << "&&& skipped is " << skipped << "-- interval is " << interval << "\n";
#endif
if (skipped < interval)
return false;
if (limit == 0)
return false; // Zero limit - never react to this
if ((limit < 0) || (n <= limit)) {
skipped = 0;
return true;
}
// Now we are over the limit - have we exceeded limit by 2^N * limit?
long diff = n - limit;
long r = diff / limit;
if (r * limit != diff) { // Not a multiple of limit - don't react
return false;
}
if (r == 1) { // Exactly twice limit - react
skipped = 0;
return true;
}
while (r > 1) {
if ((r & 1) != 0)
return false; // Not 2**n times limit - don't react
r >>= 1;
}
// If you never get an odd number till one, r is 2**n so react
skipped = 0;
return true;
} // add()
// ----------------------------------------------------------------------
// StatsCount:
// ----------------------------------------------------------------------
StatsCount::StatsCount() : n(0), aggregateN(0), ignoredFlag(false), context1(""), context2(""), contextLast("") {}
void StatsCount::add(std::string_view context, bool reactedTo) {
++n;
++aggregateN;
((1 == n) ? context1 : (2 == n) ? context2 : contextLast) = std::string(context, 0, 16);
if (!reactedTo)
ignoredFlag = true;
} // add()
} // end of namespace edm */