CMS 3D CMS Logo

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