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

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

Member Function Documentation

bool edm::CountAndLimit::add ( )

Definition at line 48 of file ELmap.cc.

References aggregateN, MessageLogger_cfi::cerr, diffTreeTool::diff, interval, lastTime, limit, n, cmsPerfSuiteHarvest::now, alignCSCRings::r, skipped, ntuplemaker::time, and timespan.

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

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

Member Data Documentation

int edm::CountAndLimit::aggregateN

Definition at line 56 of file ELmap.h.

Referenced by add().

int edm::CountAndLimit::interval

Definition at line 60 of file ELmap.h.

Referenced by add().

time_t edm::CountAndLimit::lastTime

Definition at line 57 of file ELmap.h.

Referenced by add().

int edm::CountAndLimit::limit

Definition at line 58 of file ELmap.h.

Referenced by add().

int edm::CountAndLimit::n

Definition at line 55 of file ELmap.h.

Referenced by add().

int edm::CountAndLimit::skipped

Definition at line 61 of file ELmap.h.

Referenced by add().

int edm::CountAndLimit::timespan

Definition at line 59 of file ELmap.h.

Referenced by add().