Commit 75d4e430 authored by legoc's avatar legoc

Reimplemented LiveReader.

parent 3bb37c2b
......@@ -28,7 +28,11 @@ namespace lstdpp128 {
BaseReader::BaseReader() :
_size(0),
_sizeInBytes(0),
_buffer(0) {
_buffer(0),
_version(0),
_timeBase(0),
_totalNumberOfBoards(0),
_boardHeader(0) {
}
BaseReader::~BaseReader() {
......@@ -53,4 +57,17 @@ int32_t * BaseReader::buffer() const {
return _buffer;
}
uint32_t BaseReader::version() const {
return _version;
}
uint32_t BaseReader::timeBase() const {
return _timeBase;
}
uint32_t BaseReader::totalNumberOfBoards() const {
return _totalNumberOfBoards;
}
}
......@@ -47,6 +47,21 @@ public:
*/
int32_t * buffer() const;
/**
* Returns the version.
*/
uint32_t version() const;
/**
* Returns the time base.
*/
uint32_t timeBase() const;
/**
* Returns the total number of boards.
*/
uint32_t totalNumberOfBoards() const;
/**
* Opens the file. Returns false if problem opening the file.
*/
......@@ -71,6 +86,12 @@ protected:
int32_t * _buffer;
std::ifstream _dataFile;
FileSize _fileSize;
uint32_t _version;
uint32_t _timeBase;
uint32_t _totalNumberOfBoards;
int32_t * _boardHeader;
};
/**
......
......@@ -25,8 +25,9 @@ using namespace std;
namespace lstdpp128 {
LiveReader::LiveReader() :
LiveReader::LiveReader(int32_t size) :
_end(false) {
init(size);
}
LiveReader::~LiveReader() {
......@@ -41,26 +42,26 @@ bool LiveReader::open(std::string const & fileName) {
_dataFile.open(fileName.c_str(), ios::in | ios::binary);
if (_dataFile.is_open()) {
_dataFile.seekg(0, ios::end);
FileSize size = _dataFile.tellg();
_fileSize = _dataFile.tellg();
_dataFile.seekg(0, ios::beg);
if (size < 4 * sizeof(int32_t)) {
_dataFile.close();
} else {
_dataFile.seekg(0, ios::beg);
// Read the 4 fixed elements of the header.
uint32_t nbEvents = 0;
uint32_t nbBoards = 0;
// just reading 4 elements for the header
_dataFile.read((char *)_buffer, 4 * sizeof(int32_t));
_dataFile.read(reinterpret_cast<char *>(&_version), sizeof(int32_t));
_dataFile.read(reinterpret_cast<char *>(&_timeBase), sizeof(int32_t));
_dataFile.read(reinterpret_cast<char *>(&nbEvents), sizeof(int32_t));
_dataFile.read(reinterpret_cast<char *>(&nbBoards), sizeof(int32_t));
_nbAdc = _buffer[0];
_nbChannels = _buffer[1];
_listMode = _buffer[2];
_listModeSize = _buffer[3];
// Read the board structure.
_boardHeader = new int32_t[nbBoards];
_dataFile.read(reinterpret_cast<char *>(_boardHeader), nbBoards * sizeof(uint32_t));
if (_nbChannels <= 0 || _nbAdc <= 0) {
_dataFile.close();
}
}
// Read the list mode context.
_totalNumberOfBoards = readListModeContextFromBinary(listModeContext, _version, _timeBase, nbEvents, nbBoards, (uint32_t*)_boardHeader);
}
++counter;
......
......@@ -29,7 +29,7 @@ public:
/**
* Constructor.
*/
LiveReader();
LiveReader(int32_t size);
/**
* Destructor.
......
......@@ -9,6 +9,7 @@ liblstdpp128_la_SOURCES = \
CrateBoard.cpp \
BaseAlgorithm.cpp \
Reader.cpp \
LiveReader.cpp \
EventBlockArray.cpp \
Event.cpp \
EventData.cpp \
......
......@@ -24,7 +24,7 @@ using namespace std;
namespace lstdpp128 {
Reader::Reader(int32_t size) : _version(0), _timeBase(0), _totalNumberOfBoards(0), _boardHeader(0) {
Reader::Reader(int32_t size) {
init(size);
}
......@@ -68,18 +68,6 @@ bool Reader::open(std::string const & fileName) {
return true;
}
uint32_t Reader::version() const {
return _version;
}
uint32_t Reader::timeBase() const {
return _timeBase;
}
uint32_t Reader::totalNumberOfBoards() const {
return _totalNumberOfBoards;
}
int32_t Reader::read() {
// reading next block
......
......@@ -46,21 +46,6 @@ public:
*/
virtual bool open(std::string const & fileName);
/**
* Returns the version.
*/
uint32_t version() const;
/**
* Returns the time base.
*/
uint32_t timeBase() const;
/**
* Returns the total number of boards.
*/
uint32_t totalNumberOfBoards() const;
/**
* Returns the number of int32_t elements read.
*/
......@@ -68,12 +53,6 @@ public:
private:
int32_t getBlockSizeInBytes();
FileSize _fileSize;
uint32_t _version;
uint32_t _timeBase;
uint32_t _totalNumberOfBoards;
int32_t * _boardHeader;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment