CMS 3D CMS Logo

Public Member Functions | Public Attributes

edm::CountAndLimit Class Reference

#include <ELmap.h>

List of all members.

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.

: n         ( 0 )
, aggregateN( 0 )
, lastTime  ( time(0) )
, limit     ( lim )
, timespan  ( ts  )
, interval  ( ivl )
, skipped   ( ivl-1 )  // So that the FIRST of the prescaled messages emerges
{ }

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, cmsPerfSuiteHarvest::now, alignCSCRings::r, skipped, cond::rpcobgas::time, and timespan.

                          {

  time_t  now = time(0);

#ifdef ELcountTRACE
  std::cerr << "&&&--- CountAndLimit::add \n";
  std::cerr << "&&&    Time now  is " << now << "\n";
  std::cerr << "&&&    Last time is " << lastTime << "\n";
  std::cerr << "&&&    timespan  is " << timespan << "\n";
  std::cerr << "&&&    difftime  is " << difftime( now, lastTime ) << "\n"
                                << std::flush;
#endif

  // Has it been so long that we should restart counting toward the limit?
  if ( (timespan >= 0)
            &&
        (difftime(now, lastTime) >= timespan) )  {
     n = 0;
     if ( interval > 0 ) {
       skipped = interval - 1; // So this message will be reacted to
     } else {
       skipped = 0;
     }
  }

  lastTime = now;

  ++n;  
  ++aggregateN;
  ++skipped;  

#ifdef ELcountTRACE
  std::cerr << "&&&       n is " << n << "-- limit is    " << limit    << "\n";
  std::cerr << "&&& skipped is " << skipped 
                                      << "-- interval is " << interval << "\n";
#endif
  
  if (skipped < interval) return false;

  if ( limit == 0 ) return false;        // Zero limit - never react to this
  if ( (limit < 0)  || ( n <= limit )) {
    skipped = 0;
    return true;
  }
  
  // Now we are over the limit - have we exceeded limit by 2^N * limit?
  long  diff = n - limit;
  long  r = diff/limit;
  if ( r*limit != diff ) { // Not a multiple of limit - don't react
    return false;
  }  
  if ( r == 1 )   {     // Exactly twice limit - react
    skipped = 0;
    return true;
  }

  while ( r > 1 )  {
    if ( (r & 1) != 0 )  return false;  // Not 2**n times limit - don't react
    r >>= 1;
  }
  // If you never get an odd number till one, r is 2**n so react
  
  skipped = 0;
  return true;

}  // add()

Member Data Documentation

Definition at line 66 of file ELmap.h.

Referenced by add().

Definition at line 70 of file ELmap.h.

Referenced by add().

Definition at line 67 of file ELmap.h.

Referenced by add().

Definition at line 68 of file ELmap.h.

Referenced by add().

Definition at line 65 of file ELmap.h.

Referenced by add().

Definition at line 71 of file ELmap.h.

Referenced by add().

Definition at line 69 of file ELmap.h.

Referenced by add().