/** * @file SRawBuffer.h * @author Dan Saunders, on behalf of the SoLid collaboration. * @date 17 Aug 2016 */ #ifndef __SRawBuffer_H__ #define __SRawBuffer_H__ #include #include "stdint.h" #include // 64 MB buffer #define BUFF_SIZE 67108864 enum blocktype { waveformblock = 0x0, triggerblock = 0x1, }; /** * SRawBlock is either a trigger block or a waveform data block */ class SRawBlock { public: SRawBlock(uint32_t *, uint16_t); bool parse(); uint32_t * data; uint16_t len; blocktype type; uint64_t timestamp; }; enum input {inFile, inTCP, inIPC}; /** * SRawBuffer buffers raw data from the detector * * SRawBufffer collects data either from a binary file, tcp or unix domain * socket and makes it available for parsing. */ class SRawBuffer { public: SRawBuffer(); /** * nextblock returns next time-block of data to be parsed. * * If there is no data available to parse the returned SRawBlock * will have data = NULL and len == 0. More data may arrive at a * later time. */ void open(input, std::string); SRawBlock nextblock(); /** * Signal that there is no more input data to read and buffers have * been used up. */ bool end(); std::string msg; private: /** * Collect (up to) a buffer of data from input source. */ void read(); // Double buffer char * m_data0; int m_index; int m_size; // Capacity of current buffer int m_cap; bool m_inputend; uint32_t * m_block; input m_intype; std::ifstream m_file; }; #endif