Throttle.hh 653 Bytes
Newer Older
dauncey's avatar
dauncey committed
1 2 3 4 5 6 7 8 9 10 11 12 13
#ifndef Throttle_HH
#define Throttle_HH

class Throttle {
public:
  Throttle(uint64_t b) :  fDelay(60), fRaisedBx(b), fEndedBx(-1) {
  }

  void endThrottle(uint64_t bx) {
    if(fEndedBx==-1) fEndedBx=bx;
  }
  
  bool allowL1Accept(uint64_t bx) {
dauncey's avatar
dauncey committed
14
    if(fEndedBx==-1) return bx<(fRaisedBx+fDelay);
dauncey's avatar
dauncey committed
15 16
    return bx<(fRaisedBx+fDelay) || bx>=(fEndedBx+fDelay);
  }
dauncey's avatar
dauncey committed
17 18 19 20 21 22 23

  void print() const {
    std::cout << "Throttle::print()  Raised, ended BXs = "
	      << fRaisedBx << ", " << fEndedBx
	      << ", duration = " << fEndedBx - fRaisedBx 
	      << std::endl;
  }
dauncey's avatar
dauncey committed
24 25 26 27 28 29 30 31
  
private:
  const uint64_t fDelay;
  uint64_t fRaisedBx;
  uint64_t fEndedBx;
};

#endif