#ifndef RunMonitor_HH
#define RunMonitor_HH

#include <cassert>

#include "RunCount.hh"
#include "ShmObject.hh"


class RunMonitor : public RcdUserRO {

public:
  RunMonitor() : _shmRunCount(RunCount::shmKey) {

    // Connect to run count shared memory
    _runCount=_shmRunCount.payload();
    assert(_runCount!=0);
  }

  bool record(const RcdRecord &r) {
    if(doPrint(r.recordType())) {
      std::cout << "RunMonitor::record()" << std::endl;
      r.RcdHeader::print(std::cout," ") << std::endl;
    }

    _runCount->increment(r);

    return true;
  }

private:
  ShmObject<RunCount> _shmRunCount;
  RunCount *_runCount;
};

#endif
