CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
edm::CountAndLimit Class Reference

#include <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
 

Detailed Description

Definition at line 53 of file ELmap.h.

Constructor & Destructor Documentation

◆ CountAndLimit()

edm::CountAndLimit::CountAndLimit ( int  lim = -1,
int  ts = -1,
int  ivl = -1 
)

Definition at line 38 of file ELmap.cc.

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  {}

Member Function Documentation

◆ add()

bool edm::CountAndLimit::add ( )

Definition at line 48 of file ELmap.cc.

48  {
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()

References aggregateN, EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, change_name::diff, interval, lastTime, limit, n, submitPVValidationJobs::now, alignCSCRings::r, skipped, protons_cff::time, and timespan.

Referenced by counter.Counter::register(), SequenceTypes.Task::remove(), and SequenceTypes.Task::replace().

Member Data Documentation

◆ aggregateN

int edm::CountAndLimit::aggregateN

Definition at line 56 of file ELmap.h.

Referenced by add().

◆ interval

int edm::CountAndLimit::interval

Definition at line 60 of file ELmap.h.

Referenced by add().

◆ lastTime

time_t edm::CountAndLimit::lastTime

Definition at line 57 of file ELmap.h.

Referenced by add().

◆ limit

int edm::CountAndLimit::limit

Definition at line 58 of file ELmap.h.

Referenced by add().

◆ n

int edm::CountAndLimit::n

Definition at line 55 of file ELmap.h.

Referenced by add().

◆ skipped

int edm::CountAndLimit::skipped

Definition at line 61 of file ELmap.h.

Referenced by add().

◆ timespan

int edm::CountAndLimit::timespan

Definition at line 59 of file ELmap.h.

Referenced by add().

change_name.diff
diff
Definition: change_name.py:13
submitPVValidationJobs.now
now
Definition: submitPVValidationJobs.py:639
edm::CountAndLimit::interval
int interval
Definition: ELmap.h:60
protons_cff.time
time
Definition: protons_cff.py:35
edm::CountAndLimit::timespan
int timespan
Definition: ELmap.h:59
edm::CountAndLimit::skipped
int skipped
Definition: ELmap.h:61
edm::CountAndLimit::n
int n
Definition: ELmap.h:55
alignCSCRings.r
r
Definition: alignCSCRings.py:93
edm::CountAndLimit::limit
int limit
Definition: ELmap.h:58
edm::CountAndLimit::aggregateN
int aggregateN
Definition: ELmap.h:56
edm::CountAndLimit::lastTime
time_t lastTime
Definition: ELmap.h:57
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8