/* * BufferReader.hh * * Created on: Dec 14, 2017 * Author: hovanes */ #ifndef BUFFERREADER_HH_ #define BUFFERREADER_HH_ #include #include #include #include #include #include #include #include #include #include // for auto_cpu_timer #include "BufferSubscriber.hh" #include "VetrocBlockData.hh" namespace VETROC { template class BufferReader: public BufferSubscriber { private: BufferReader( const BufferReader& ); BufferReader& operator=( const BufferReader& ); protected: typename VETROC::BufferSubscriber::value_type m_item; std::vector m_vec; public: BufferReader( BUFFER* buffer, unsigned vecSize = 1 ) : BufferSubscriber( buffer ) , m_vec(vecSize) { this->setActiveSleepTime(0); } virtual ~BufferReader() { // TODO Auto-generated destructor stub } void operator()() { keepReadingBuffer(); } void keepReadingBuffer() { this->setAccessingRequested( true ); std::cout << "Will keep reading" << std::endl; while ( !this->isExitThreadFlagRaised() ) { std::cout << "Keep reading" << std::endl; if ( this->isAccessingRequested() ) { this->readBuffer(); } usleep( this->getPassiveSleepTime() ); } } void readBuffer() { std::cout << "In reading buffer" << std::endl; unsigned mult = 10; long unsigned nReadBuffers = 1; while ( this->isAccessingRequested() ) { std::cout << this->m_container->backElement() << std::endl; for ( unsigned iElm = 0; iElm < m_vec.size(); iElm++ ) { this->m_container->popBack( &m_vec[iElm] ); // std::cout << "Read element " << iElm << std::endl; // std::cout << std::endl << std::endl << "Read value " << m_vec[iElm] // << std::endl; // std::cout << "Buffer size is " << std::dec << m_vec[iElm].getBufferSize() << std::endl; if ( ( nReadBuffers % (mult*m_vec.size()) ) == 0 ) { for ( unsigned iWord = 0; iWord < m_vec[iElm].getBufferSize(); iWord++ ) { // std::cout << "Reader : " << std::dec << iWord; decodeData( LSWAP( m_vec[iElm][iWord] ) ); } } VetrocBlockData dataBlock( m_vec[iElm].getBufferSize(), m_vec[iElm].getDataPointer() ); std::cout << "Block " << dataBlock.getBlockNumber() << " contains " << dataBlock.getNumberOfEvents() << " events " << std::endl; for ( std::map::iterator it = dataBlock.getEventMap().begin(); it != dataBlock.getEventMap().end(); it++ ){ std::cout << "Event number is " << std::dec << it->first << " : " << it->second->getNumberOfWords() << std::endl; } nReadBuffers++; } // usleep( this->getActiveSleepTime() ); } } typename VETROC::BufferSubscriber::value_type getLastValue() { boost::mutex::scoped_lock lock( this->m_mutex ); return m_item; } }; } /* namespace VETROC */ #endif /* BUFFERREADER_HH_ */