CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 61 of file ELmap.h.

Constructor & Destructor Documentation

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

Definition at line 47 of file ELmap.cc.

48 : n ( 0 )
49 , aggregateN( 0 )
50 , lastTime ( time(0) )
51 , limit ( lim )
52 , timespan ( ts )
53 , interval ( ivl )
54 , skipped ( ivl-1 ) // So that the FIRST of the prescaled messages emerges
55 { }
time_t lastTime
Definition: ELmap.h:67

Member Function Documentation

bool edm::CountAndLimit::add ( )

Definition at line 58 of file ELmap.cc.

References aggregateN, dtNoiseDBValidation_cfg::cerr, diffTreeTool::diff, interval, lastTime, limit, n, fileCollector::now, alignCSCRings::r, skipped, cond::rpcobgas::time, and timespan.

Referenced by counter.Counter::register().

58  {
59 
60  time_t now = time(0);
61 
62 #ifdef ELcountTRACE
63  std::cerr << "&&&--- CountAndLimit::add \n";
64  std::cerr << "&&& Time now is " << now << "\n";
65  std::cerr << "&&& Last time is " << lastTime << "\n";
66  std::cerr << "&&& timespan is " << timespan << "\n";
67  std::cerr << "&&& difftime is " << difftime( now, lastTime ) << "\n"
68  << std::flush;
69 #endif
70 
71  // Has it been so long that we should restart counting toward the limit?
72  if ( (timespan >= 0)
73  &&
74  (difftime(now, lastTime) >= timespan) ) {
75  n = 0;
76  if ( interval > 0 ) {
77  skipped = interval - 1; // So this message will be reacted to
78  } else {
79  skipped = 0;
80  }
81  }
82 
83  lastTime = now;
84 
85  ++n;
86  ++aggregateN;
87  ++skipped;
88 
89 #ifdef ELcountTRACE
90  std::cerr << "&&& n is " << n << "-- limit is " << limit << "\n";
91  std::cerr << "&&& skipped is " << skipped
92  << "-- interval is " << interval << "\n";
93 #endif
94 
95  if (skipped < interval) return false;
96 
97  if ( limit == 0 ) return false; // Zero limit - never react to this
98  if ( (limit < 0) || ( n <= limit )) {
99  skipped = 0;
100  return true;
101  }
102 
103  // Now we are over the limit - have we exceeded limit by 2^N * limit?
104  long diff = n - limit;
105  long r = diff/limit;
106  if ( r*limit != diff ) { // Not a multiple of limit - don't react
107  return false;
108  }
109  if ( r == 1 ) { // Exactly twice limit - react
110  skipped = 0;
111  return true;
112  }
113 
114  while ( r > 1 ) {
115  if ( (r & 1) != 0 ) return false; // Not 2**n times limit - don't react
116  r >>= 1;
117  }
118  // If you never get an odd number till one, r is 2**n so react
119 
120  skipped = 0;
121  return true;
122 
123 } // add()
time_t lastTime
Definition: ELmap.h:67

Member Data Documentation

int edm::CountAndLimit::aggregateN

Definition at line 66 of file ELmap.h.

Referenced by add().

int edm::CountAndLimit::interval

Definition at line 70 of file ELmap.h.

Referenced by add().

time_t edm::CountAndLimit::lastTime

Definition at line 67 of file ELmap.h.

Referenced by add().

int edm::CountAndLimit::limit

Definition at line 68 of file ELmap.h.

Referenced by add().

int edm::CountAndLimit::n

Definition at line 65 of file ELmap.h.

Referenced by add().

int edm::CountAndLimit::skipped

Definition at line 71 of file ELmap.h.

Referenced by add().

int edm::CountAndLimit::timespan

Definition at line 69 of file ELmap.h.

Referenced by add().