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 40 of file ELmap.cc.

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  {}
time_t lastTime
Definition: ELmap.h:57

Member Function Documentation

◆ add()

bool edm::CountAndLimit::add ( )

Definition at line 50 of file ELmap.cc.

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

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

50  {
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()
time_t lastTime
Definition: ELmap.h:57

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().