Commit e60d3d97 authored by legoc's avatar legoc
Browse files

corrected header members

parent 7b558dff
Pipeline #305 skipped
......@@ -31,8 +31,10 @@ ListModeContext listModeContext;
std::ostream& operator<< (std::ostream& os, ListModeContext const & header) {
os << "#events = " << header.nbEvents << endl;
os << "#crates = " << header.crateBoard.nbCrates << endl << endl;
os << "version = " << header.version << endl;
os << "time base = " << header.timeBase << endl;
os << "#events = " << header.nbEvents << endl;
os << "#crates = " << header.crateBoard.nbCrates << endl << endl;
for (int c = 0; c < header.crateBoard.nbCrates; c++) {
os << "crate " << c << endl;
......@@ -50,8 +52,10 @@ std::ostream& operator<< (std::ostream& os, ListModeContext const & header) {
return os;
}
uint32_t readListModeContextFromBinary(ListModeContext & listModeContext, uint32_t nbEvents, uint32_t nbBoards, uint32_t* data) {
uint32_t readListModeContextFromBinary(ListModeContext & listModeContext, uint32_t version, uint32_t timeBase, uint32_t nbEvents, uint32_t nbBoards, uint32_t* data) {
listModeContext.version = version;
listModeContext.timeBase = timeBase;
listModeContext.nbEvents = nbEvents;
listModeContext.crateBoard.nbCrates = 0;
......
......@@ -93,10 +93,12 @@ struct CrateBoard {
* The list mode header.
*/
struct ListModeContext {
uint32_t version;
uint32_t timeBase;
uint32_t nbEvents;
CrateBoard crateBoard;
ListModeContext() : nbEvents(0) {}
ListModeContext() : version(0), timeBase(0), nbEvents(0) {}
};
/**
......@@ -119,7 +121,7 @@ std::ostream& operator<< (std::ostream& os, ListModeContext const & header);
/**
* Reads the list mode header.
*/
uint32_t readListModeContextFromBinary(ListModeContext & listModeContext, uint32_t nbEvents, uint32_t nbBoards, uint32_t* data);
uint32_t readListModeContextFromBinary(ListModeContext & listModeContext, uint32_t version, uint32_t timeBase, uint32_t nbEvents, uint32_t nbBoards, uint32_t* data);
/**
* Writes the list mode context to JSON.
......
......@@ -24,7 +24,7 @@ using namespace std;
namespace lstdpp128 {
Reader::Reader(int32_t size) : _totalNumberOfBoards(0), _boardHeader(0) {
Reader::Reader(int32_t size) : _version(0), _timeBase(0), _totalNumberOfBoards(0), _boardHeader(0) {
init(size);
}
......@@ -49,20 +49,33 @@ bool Reader::open(std::string const & fileName) {
_fileSize = _dataFile.tellg();
_dataFile.seekg(0, ios::beg);
// Read the 4 fixed elements of the header.
uint32_t nbEvents = 0;
_dataFile.read(reinterpret_cast<char *>(&nbEvents), sizeof(int32_t));
uint32_t nbBoards = 0;
_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));
// Read the board structure.
_boardHeader = new int32_t[nbBoards];
_dataFile.read(reinterpret_cast<char *>(_boardHeader), nbBoards * sizeof(uint32_t));
_totalNumberOfBoards = readListModeContextFromBinary(listModeContext, nbEvents, nbBoards, (uint32_t*)_boardHeader);
// Read the list mode context.
_totalNumberOfBoards = readListModeContextFromBinary(listModeContext, _version, _timeBase, nbEvents, nbBoards, (uint32_t*)_boardHeader);
return true;
}
uint32_t Reader::version() const {
return _version;
}
uint32_t Reader::timeBase() const {
return _timeBase;
}
uint32_t Reader::totalNumberOfBoards() const {
return _totalNumberOfBoards;
}
......
......@@ -46,6 +46,16 @@ 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.
*/
......@@ -58,7 +68,10 @@ public:
private:
int32_t getBlockSizeInBytes();
FileSize _fileSize;
uint32_t _version;
uint32_t _timeBase;
uint32_t _totalNumberOfBoards;
int32_t * _boardHeader;
};
......
......@@ -32,7 +32,7 @@ Sort::Sort() :
_eventId(0) {
}
void Sort::init(int32_t* headerMemoryBlock, uint32_t numberOfBoards, int32_t maxBlockSize, std::string const & outFileName) {
void Sort::init(int32_t* headerMemoryBlock, uint32_t version, uint32_t timeBase, uint32_t numberOfBoards, int32_t maxBlockSize, std::string const & outFileName) {
_maxNumberOfChannels = (1 << MAX_BITS);
......@@ -47,8 +47,13 @@ void Sort::init(int32_t* headerMemoryBlock, uint32_t numberOfBoards, int32_t max
_numberOfEventsNotInserted = 0;
uint32_t nbEvents = 0;
// Write the header.
_outDataFile.write((char *)&version, sizeof(uint32_t));
_outDataFile.write((char *)&timeBase, sizeof(uint32_t));
_outDataFile.write((char *)&nbEvents, sizeof(uint32_t));
_outDataFile.write((char *)&numberOfBoards, sizeof(uint32_t));
_outDataFile.write((char *)headerMemoryBlock, numberOfBoards * sizeof(uint32_t));
_maxBlockSize = maxBlockSize;
......@@ -117,8 +122,9 @@ void Sort::processEventNotInserted(Event const & event) {
void Sort::finish() {
// writing the number of events
_outDataFile.seekp(0, ios::beg);
// Write the number of events.
// The pointer is 2 uint32 after the beginning of the file.
_outDataFile.seekp(2 * sizeof(uint32_t), ios::beg);
_outDataFile.write((char *)&_numberOfGoodEvents, sizeof(uint32_t));
_outDataFile.close();
......
......@@ -36,7 +36,7 @@ public:
Sort();
~Sort();
void init(int32_t* headerMemoryBlock, uint32_t numberOfBoards, int32_t maxBlockSize, std::string const & outFileName);
void init(int32_t* headerMemoryBlock, uint32_t version, uint32_t timeBase, uint32_t numberOfBoards, int32_t maxBlockSize, std::string const & outFileName);
int32_t numberOfGoodEvents() const;
int32_t numberOfBadEvents() const;
......
......@@ -57,7 +57,7 @@ Coincidence::Coincidence() :
_numberOfTruncatedCoincidences(0) {
}
void Coincidence::init(int32_t* headerMemoryBlock, uint32_t numberOfBoards, int16_t coincidenceMatrixResolution, const std::vector<int16_t>& detectorADCs, time_type coincidenceDT, time_type cleanDT, int32_t maxBlockSize, std::string const & outFileName) {
void Coincidence::init(int32_t* headerMemoryBlock, uint32_t version, uint32_t timeBase, uint32_t numberOfBoards, int16_t coincidenceMatrixResolution, const std::vector<int16_t>& detectorADCs, time_type coincidenceDT, time_type cleanDT, int32_t maxBlockSize, std::string const & outFileName) {
_coincidenceDT = coincidenceDT;
_cleanDT = cleanDT;
......@@ -139,8 +139,13 @@ void Coincidence::init(int32_t* headerMemoryBlock, uint32_t numberOfBoards, int1
_outDataFile.open(tempOutFileName.c_str());
uint32_t nbEvents = 0;
// Write the header.
_outDataFile.write((char *)&version, sizeof(uint32_t));
_outDataFile.write((char *)&timeBase, sizeof(uint32_t));
_outDataFile.write((char *)&nbEvents, sizeof(uint32_t));
_outDataFile.write((char *)&numberOfBoards, sizeof(uint32_t));
_outDataFile.write((char *)headerMemoryBlock, numberOfBoards * sizeof(uint32_t));
}
......@@ -360,8 +365,10 @@ void Coincidence::updateRates() {
void Coincidence::finish() {
if (_outFileName != "") {
// writing the number of events
_outDataFile.seekp(0, ios::beg);
// Write the number of events.
// The pointer is 2 uint32 after the beginning of the file.
_outDataFile.seekp(2 * sizeof(uint32_t), ios::beg);
_outDataFile.write((char *)&_numberOfGoodEvents, sizeof(uint32_t));
_outDataFile.close();
......
......@@ -37,7 +37,7 @@ public:
Coincidence();
~Coincidence();
void init(int32_t* headerMemoryBlock, uint32_t numberOfBoards, int16_t coincidenceMatrixResolution, const std::vector<int16_t>& detectorADCs, time_type coincidenceDT, time_type cleanDT, int32_t maxBlockSize, std::string const & outFileName);
void init(int32_t* headerMemoryBlock, uint32_t version, uint32_t timeBase, uint32_t numberOfBoards, int16_t coincidenceMatrixResolution, const std::vector<int16_t>& detectorADCs, time_type coincidenceDT, time_type cleanDT, int32_t maxBlockSize, std::string const & outFileName);
int32_t numberOfGoodEvents() const;
int32_t numberOfBadEvents() const;
......
......@@ -44,7 +44,7 @@ Histogram::Histogram() :
_numberOfEventsInConflict(0) {
}
void Histogram::init(int32_t* headerMemoryBlock, uint32_t numberOfBoards, uint8_t triggerCrate, uint8_t triggerBoard, uint16_t triggerChannel, time_type delay, time_type dT, int32_t maxBlockSize, std::string const & outFileName) {
void Histogram::init(int32_t* headerMemoryBlock, uint32_t version, uint32_t timeBase, uint32_t numberOfBoards, uint8_t triggerCrate, uint8_t triggerBoard, uint16_t triggerChannel, time_type delay, time_type dT, int32_t maxBlockSize, std::string const & outFileName) {
_triggerCrate = triggerCrate;
_triggerBoard = triggerBoard;
......@@ -108,8 +108,13 @@ void Histogram::init(int32_t* headerMemoryBlock, uint32_t numberOfBoards, uint8_
_outDataFile.open(tempOutFileName.c_str());
uint32_t nbEvents = 0;
// Write the header.
_outDataFile.write((char *)&version, sizeof(uint32_t));
_outDataFile.write((char *)&timeBase, sizeof(uint32_t));
_outDataFile.write((char *)&nbEvents, sizeof(uint32_t));
_outDataFile.write((char *)&numberOfBoards, sizeof(uint32_t));
_outDataFile.write((char *)headerMemoryBlock, numberOfBoards * sizeof(uint32_t));
}
......@@ -319,8 +324,10 @@ void Histogram::processEventNotInserted(Event const & event) {
void Histogram::finish() {
if (_outFileName != "") {
// writing the number of events
_outDataFile.seekp(0, ios::beg);
// Write the number of events.
// The pointer is 2 uint32 after the beginning of the file.
_outDataFile.seekp(2 * sizeof(uint32_t), ios::beg);
_outDataFile.write((char *)&_numberOfGoodEvents, sizeof(uint32_t));
_outDataFile.close();
......
......@@ -37,7 +37,7 @@ public:
Histogram();
~Histogram();
void init(int32_t* headerMemoryBlock, uint32_t numberOfBoards, uint8_t triggerCrate, uint8_t triggerBoard, uint16_t triggerChannel, time_type delay, time_type dT, int32_t maxBlockSize, std::string const & outFileName);
void init(int32_t* headerMemoryBlock, uint32_t version, uint32_t timeBase, uint32_t numberOfBoards, uint8_t triggerCrate, uint8_t triggerBoard, uint16_t triggerChannel, time_type delay, time_type dT, int32_t maxBlockSize, std::string const & outFileName);
int32_t numberOfGoodEvents() const;
int32_t numberOfBadEvents() const;
......
......@@ -124,7 +124,7 @@ int main(int argc, char * argv[]) {
// algorithm
EventBlockArrayAlgorithm<Coincidence> algorithm;
algorithm.processor().init(0, 0, matrixResolution, detectorADCList, dT, cleanDT, MAX_BLOCK_SIZE, "");
algorithm.processor().init(0, 0, 0, 0, matrixResolution, detectorADCList, dT, cleanDT, MAX_BLOCK_SIZE, "");
// creating the events
EventBlockArray blocks(MAX_BLOCK_SIZE, maxBlocks);
......
......@@ -108,7 +108,7 @@ int main(int argc, char * argv[]) {
// algorithm
EventBlockArrayAlgorithm<Histogram> algorithm;
algorithm.processor().init(0, 0, crate, board, channel, delay, dT, MAX_BLOCK_SIZE, "");
algorithm.processor().init(0, 0, 0, 0, crate, board, channel, delay, dT, MAX_BLOCK_SIZE, "");
// creating the events
EventBlockArray blocks(MAX_BLOCK_SIZE, maxBlocks);
......
......@@ -78,7 +78,7 @@ int main(int argc, char * argv[]) {
// algorithm
EventBlockArrayAlgorithm<Sort> algorithm;
algorithm.processor().init(reader.boardHeader(), reader.totalNumberOfBoards(), MAX_BLOCK_SIZE, outFileName);
algorithm.processor().init(reader.boardHeader(), reader.version(), reader.timeBase(), reader.totalNumberOfBoards(), MAX_BLOCK_SIZE, outFileName);
// creating the events
EventBlockArray blocks(MAX_BLOCK_SIZE, maxBlocks);
......
......@@ -70,7 +70,7 @@ int main(int argc, char * argv[]) {
EventArrayAlgorithm<Sort> algorithm;
// The header size is the total number of boards + 2 for the number of events and the number of boards
algorithm.processor().init(reader.boardHeader(), reader.totalNumberOfBoards(), blockSize, outFileName);
algorithm.processor().init(reader.boardHeader(), reader.version(), reader.timeBase(), reader.totalNumberOfBoards(), blockSize, outFileName);
// creating the events
EventArray events(blockSize);
......
......@@ -95,7 +95,7 @@ int main(int argc, char * argv[]) {
// algorithm
EventBlockArrayAlgorithm<Histogram> algorithm;
algorithm.processor().init(reader.boardHeader(), reader.totalNumberOfBoards(), crate, board, channel, delay, dT, MAX_BLOCK_SIZE, outFileName);
algorithm.processor().init(reader.boardHeader(), reader.version(), reader.timeBase(), reader.totalNumberOfBoards(), crate, board, channel, delay, dT, MAX_BLOCK_SIZE, outFileName);
// creating the events
EventBlockArray blocks(MAX_BLOCK_SIZE, maxBlocks);
......
......@@ -87,7 +87,7 @@ int main(int argc, char * argv[]) {
// algorithm
EventArrayAlgorithm<Coincidence> algorithm;
algorithm.processor().init(reader.boardHeader(), reader.totalNumberOfBoards(), coincidenceMatrixResolution, detectorADCList, coincidenceDT, cleanDT, blockSize, outFileName);
algorithm.processor().init(reader.boardHeader(), reader.version(), reader.timeBase(), reader.totalNumberOfBoards(), coincidenceMatrixResolution, detectorADCList, coincidenceDT, cleanDT, blockSize, outFileName);
// creating the events
EventArray events(blockSize);
......
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