00001 #include "EventCounter.h"
00002
00003 #include "GaudiKernel/MsgStream.h"
00004 #include "GaudiKernel/AlgFactory.h"
00005
00006 static const AlgFactory<EventCounter> Factory;
00007 const IAlgFactory& EventCounterFactory = Factory;
00008
00012 EventCounter::EventCounter(const std::string& name, ISvcLocator* pSvcLocator) :
00013 Algorithm(name, pSvcLocator),
00014 m_skip ( 0 ),
00015 m_total( 0 )
00016 {
00017 declareProperty( "Frequency", m_frequency=1 );
00018 m_frequency.verifier().setBounds( 0, 1000 );
00019 }
00020
00024 EventCounter::~EventCounter( )
00025 {
00026 }
00027
00028 StatusCode
00029 EventCounter::initialize()
00030 {
00031 MsgStream log(msgSvc(), name());
00032 log << MSG::INFO << name( ) << ":EventCounter::initialize - Frequency: " << m_frequency << endreq;
00033 return StatusCode::SUCCESS;
00034 }
00035
00036 StatusCode
00037 EventCounter::execute()
00038 {
00039 MsgStream log(msgSvc(), name());
00040 m_total++;
00041 int freq = m_frequency;
00042 if ( freq > 0 ) {
00043 m_skip++;
00044 if ( m_skip >= freq ) {
00045 log << MSG::INFO << name( ) << ":EventCounter::execute - seen events: " << m_total << endreq;
00046 m_skip = 0;
00047 }
00048 }
00049 return StatusCode::SUCCESS;
00050 }
00051
00052 StatusCode
00053 EventCounter::finalize()
00054 {
00055 MsgStream log(msgSvc(), name());
00056 log << MSG::INFO << name( ) << ":EventCounter::finalize - total events: " << m_total << endreq;
00057 return StatusCode::SUCCESS;
00058 }