/* * ReadoutBuffer.hh * * Class to represented the entire buffer from the DMA that * gets readout once. The purpose to keep this type of objects in * a circular buffer of objects of this type and let the DAQ thread * keep reading out the VME board using DMA without delays. * * Created on: Dec 11, 2017 * Author: Hovanes Egiyan */ #ifndef READOUTBUFFER_HH_ #define READOUTBUFFER_HH_ #include #include #include #include #include #include #include #include #include #include #include using namespace std; namespace VETROC { template class ReadoutBuffer { protected: TYPE dataPointer[SIZE]; public: ReadoutBuffer() { // std::cout << "Called Default Constructor for ReadoutBuffer" << std::endl; } ReadoutBuffer( const TYPE& val ) { // cout << "Building ReadoutBuffer of length " << SIZE << " with the same value " << (val & 0xFF) << endl; memset( dataPointer, val & 0xFF, this->getBufferSizeInBytes() ); } ReadoutBuffer( const void* pointer ) { // cout << "Building ReadoutBuffer of length " << SIZE << " from pointer " << hex << showbase << pointer << endl; memcpy( dataPointer, pointer, this->getBufferSizeInBytes() ); } ReadoutBuffer( const ReadoutBuffer& b ) { // cout << "Copy-constructing ReadoutBuffer of length " << getBufferSizeInBytes() << " bytes " << " from another object " << &b << endl; memcpy( dataPointer, b.dataPointer, getBufferSizeInBytes() ); } template ReadoutBuffer& operator=( const VETROC::ReadoutBuffer& buf ) { cout << "Copying ReadoutBuffer of length " << buf.getBufferSizeInBytes() << " bytes" << endl; if ( this->getBufferSize() != buf.getBufferSize() ) { cout << "The length of this buffer " << this->getBufferSize() << " does not match the length of the source buffer " << buf.getBufferSize() << " , not assigning " << endl; return *this; } if ( typeid(TYPE) != typeid(OTHER_TYPE) ) { cout << "The type of this ReadoutBuffer does not match the type of the source buffer, not assigning" << endl; return *this; } if ( this != &buf ) { memcpy( this->dataPointer, buf.dataPointer, getBufferSizeInBytes() ); } return *this; } ~ReadoutBuffer() { // cout << "Destructing ReadoutBuffer at " << this << endl; } friend std::ostream& operator<<( std::ostream& out, const ReadoutBuffer& b ) { // out << "Number of elements in ReadoutBuffer is " << dec << b.getBufferSize() // << " size is " << sizeof(b) << "(" << b.getBufferSizeInBytes() << "bytes )" // << endl; for ( unsigned i = 0; i < b.getBufferSize(); i++ ) { // out << " point " << i << " - > value " << std::hex << std::showbase << b.dataPointer[i] << dec << " , "; out << std::hex << std::showbase << b.dataPointer[i] << " "; } out << endl; return out; } TYPE& operator[]( int index ) { return dataPointer[index]; } unsigned long getBufferSizeInBytes() const { return getBufferSize() * sizeof(TYPE); } unsigned long getBufferSize() const { return SIZE; } TYPE* getDataPointer() { return dataPointer; } }; } /* namespace VETROC */ #endif /* READOUTBUFFER_HH_ */