/* * VetrocBlockData.hh * * Class to handle the data from the event received from VECTROC board. * It inherits from STL vector and copies the content of the * 32bit C-array to the vectors data location. * Created on: Nov 7, 2017 * Author: Hovanes Egiyan */ #ifndef VETROCAPP_SRC_VETROCBLOCKDATA_HH_ #define VETROCAPP_SRC_VETROCBLOCKDATA_HH_ #include #include #include #include #include #include #include #include #include "VetrocWord.hh" #include "VetrocEvent.hh" class VetrocBlockData: public std::vector { protected: static unsigned sizeIncrement; unsigned long blockNumber; std::map eventMap; unsigned nextInsertPosition; virtual unsigned addWord( VetrocWordBase* word ) { if ( nextInsertPosition >= this->size() ) { this->resize( nextInsertPosition + sizeIncrement ); } (*this)[nextInsertPosition] = word; nextInsertPosition++; return nextInsertPosition; } public: VetrocBlockData( unsigned long nElem, const uint32_t* dataPointer ); virtual ~VetrocBlockData() { // Loop over the map elements and delete the event objects for ( std::map::iterator itEvent = eventMap.begin(); itEvent != eventMap.end(); itEvent++ ) { VetrocEvent* eventPointer = itEvent->second; if ( eventPointer != 0 ) { delete eventPointer; } } // Loop over the elements of this vector and delete the words in it. for( unsigned iWord = 0; iWord < this->size(); iWord++ ) { if( (*this)[iWord] != 0 ) { delete (*this)[iWord]; } } } virtual unsigned getNumberOfWords() { return nextInsertPosition; } std::vector::iterator getLastInsertionIterator() { if( nextInsertPosition > 0 ) { return ( this->begin() + nextInsertPosition - 1 ); } else { std::cerr << "getLastInsertionIterator() : Last entry never been made" << std::endl; return this->begin(); } } unsigned getLastInsertionPosition() { return ( nextInsertPosition -1 ); } std::map& getEventMap() { return eventMap; } unsigned long getNumberOfEvents() const { return eventMap.size(); } unsigned long getBlockNumber() const { return blockNumber; } unsigned long setBlockNumber( unsigned long blockNumber ) { return (this->blockNumber = blockNumber); } unsigned getNextInsertPosition() const { return nextInsertPosition; } static unsigned getSizeIncrement() { return sizeIncrement; } static unsigned setSizeIncrement( unsigned si ) { return ( sizeIncrement = si); } }; #endif /* VETROCAPP_SRC_VETROCBLOCKDATA_HH_ */