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 // Possible traces
22 //#include <iostream>
23 //#define ELcountTRACE
24 // #define ELmapDumpTRACE
25 
26 namespace edm {
27 
28  // ----------------------------------------------------------------------
29  // LimitAndTimespan:
30  // ----------------------------------------------------------------------
31 
32  LimitAndTimespan::LimitAndTimespan(int lim, int ts, int ivl) : limit(lim), timespan(ts), interval(ivl) {}
33 
34  // ----------------------------------------------------------------------
35  // CountAndLimit:
36  // ----------------------------------------------------------------------
37 
38  CountAndLimit::CountAndLimit(int lim, int ts, int ivl)
39  : n(0),
40  aggregateN(0),
41  lastTime(time(nullptr)),
42  limit(lim),
43  timespan(ts),
44  interval(ivl),
45  skipped(ivl - 1) // So that the FIRST of the prescaled messages emerges
46  {}
47 
49  time_t now = time(nullptr);
50 
51 #ifdef ELcountTRACE
52  std::cerr << "&&&--- CountAndLimit::add \n";
53  std::cerr << "&&& Time now is " << now << "\n";
54  std::cerr << "&&& Last time is " << lastTime << "\n";
55  std::cerr << "&&& timespan is " << timespan << "\n";
56  std::cerr << "&&& difftime is " << difftime(now, lastTime) << "\n" << std::flush;
57 #endif
58 
59  // Has it been so long that we should restart counting toward the limit?
60  if ((timespan >= 0) && (difftime(now, lastTime) >= timespan)) {
61  n = 0;
62  if (interval > 0) {
63  skipped = interval - 1; // So this message will be reacted to
64  } else {
65  skipped = 0;
66  }
67  }
68 
69  lastTime = now;
70 
71  ++n;
72  ++aggregateN;
73  ++skipped;
74 
75 #ifdef ELcountTRACE
76  std::cerr << "&&& n is " << n << "-- limit is " << limit << "\n";
77  std::cerr << "&&& skipped is " << skipped << "-- interval is " << interval << "\n";
78 #endif
79 
80  if (skipped < interval)
81  return false;
82 
83  if (limit == 0)
84  return false; // Zero limit - never react to this
85  if ((limit < 0) || (n <= limit)) {
86  skipped = 0;
87  return true;
88  }
89 
90  // Now we are over the limit - have we exceeded limit by 2^N * limit?
91  long diff = n - limit;
92  long r = diff / limit;
93  if (r * limit != diff) { // Not a multiple of limit - don't react
94  return false;
95  }
96  if (r == 1) { // Exactly twice limit - react
97  skipped = 0;
98  return true;
99  }
100 
101  while (r > 1) {
102  if ((r & 1) != 0)
103  return false; // Not 2**n times limit - don't react
104  r >>= 1;
105  }
106  // If you never get an odd number till one, r is 2**n so react
107 
108  skipped = 0;
109  return true;
110 
111  } // add()
112 
113  // ----------------------------------------------------------------------
114  // StatsCount:
115  // ----------------------------------------------------------------------
116 
117  StatsCount::StatsCount() : n(0), aggregateN(0), ignoredFlag(false), context1(""), context2(""), contextLast("") {}
118 
119  void StatsCount::add(std::string_view context, bool reactedTo) {
120  ++n;
121  ++aggregateN;
122 
123  ((1 == n) ? context1 : (2 == n) ? context2 : contextLast) = std::string(context, 0, 16);
124 
125  if (!reactedTo)
126  ignoredFlag = true;
127 
128  } // add()
129 
130 } // end of namespace edm */
edm::LimitAndTimespan::LimitAndTimespan
LimitAndTimespan(int lim=-1, int ts=-1, int ivl=-1)
Definition: ELmap.cc:32
change_name.diff
diff
Definition: change_name.py:13
edm::CountAndLimit::CountAndLimit
CountAndLimit(int lim=-1, int ts=-1, int ivl=-1)
Definition: ELmap.cc:38
funct::false
false
Definition: Factorize.h:29
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
submitPVValidationJobs.now
now
Definition: submitPVValidationJobs.py:639
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::CountAndLimit::interval
int interval
Definition: ELmap.h:60
edm::StatsCount::context2
std::string context2
Definition: ELmap.h:74
edm::CountAndLimit::timespan
int timespan
Definition: ELmap.h:59
edm::StatsCount::n
int n
Definition: ELmap.h:70
edm::StatsCount::aggregateN
int aggregateN
Definition: ELmap.h:71
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ELmap.h
edm::CountAndLimit::add
bool add()
Definition: ELmap.cc:48
edm::CountAndLimit::skipped
int skipped
Definition: ELmap.h:61
readEcalDQMStatus.interval
interval
Definition: readEcalDQMStatus.py:18
edm::CountAndLimit::n
int n
Definition: ELmap.h:55
alignCSCRings.r
r
Definition: alignCSCRings.py:93
edm::StatsCount::contextLast
std::string contextLast
Definition: ELmap.h:75
edm::CountAndLimit::limit
int limit
Definition: ELmap.h:58
remoteMonitoring_LED_IterMethod_cfg.limit
limit
Definition: remoteMonitoring_LED_IterMethod_cfg.py:427
edm::CountAndLimit::aggregateN
int aggregateN
Definition: ELmap.h:56
edm::StatsCount::StatsCount
StatsCount()
Definition: ELmap.cc:117
edm::StatsCount::context1
std::string context1
Definition: ELmap.h:73
edm::StatsCount::add
void add(std::string_view context, bool reactedTo)
Definition: ELmap.cc:119
edm::StatsCount::ignoredFlag
bool ignoredFlag
Definition: ELmap.h:72
edm::CountAndLimit::lastTime
time_t lastTime
Definition: ELmap.h:57
runEdmFileComparison.skipped
skipped
Definition: runEdmFileComparison.py:225
ntuplemaker.time
time
Definition: ntuplemaker.py:310
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8