Commit 5528e7e9 authored by legoc's avatar legoc

Corrected reading of the 1724 board (30bits of timestamp with 2 bits of

zero)
parent fc5e0200
......@@ -108,6 +108,8 @@ bool readEvent(Event & event, int32_t * buffer) {
BoardType boardType = event.boardType();
int numberOfBitsOfTimestamp = 32;
if (boardType == CFD_BOARD_TYPE) {
event.timestamp = (uint32_t)(*(buffer + 1) & 0xFFFFFFFF);
event.energy = (uint16_t)(*(buffer + 2) & 0xFFF);
......@@ -123,18 +125,28 @@ bool readEvent(Event & event, int32_t * buffer) {
// Extra data
event.data = (uint16_t)((*(buffer + 2)) & 0x7FFF);
} else if ((boardType == V1724_BOARD_TYPE) || (boardType == V1730_BOARD_TYPE)) {
} else if (boardType == V1724_BOARD_TYPE) {
// The timestamp is on 30bits
numberOfBitsOfTimestamp = 30;
event.timestamp = (uint32_t)(*(buffer + 1) & 0x3FFFFFFF);
event.energy = (uint16_t)(*(buffer + 2) & 0x7FFF);
} else if (boardType == V1730_BOARD_TYPE) {
event.timestamp = (uint32_t)(*(buffer + 1) & 0xFFFFFFFF);
event.energy = (uint16_t)(*(buffer + 2) & 0x7FFF);
}
// Use printBinary(buffer) to debug if necessary.
// Calculate the absolute time.
time_type absoluteTime = (((int64_t)event.rollover << numberOfBitsOfTimestamp) | event.timestamp);
// In version == 1, the event time in the file is relative so that the time resolution is used to convert to absolute time.
// In version >= 2, the event time in the file is already absolute.
if (listModeContext.version == 1) {
// Set the absolute time. Here the event is still in relative time.
time_type absoluteTime = event.time() * event.timeResolution();
absoluteTime = absoluteTime * event.timeResolution();
// We can set the absolute time that changes the rollover and timestamp.
event.setTime(absoluteTime);
......@@ -143,6 +155,10 @@ bool readEvent(Event & event, int32_t * buffer) {
cerr << "Problem while converting relative time to absolute time" << endl;
}
}
else {
// We can set the absolute time that changes the rollover and timestamp.
event.setTime(absoluteTime);
}
return true;
}
......@@ -165,22 +181,42 @@ void writeEvent(Event const & event, int32_t * buffer) {
*buffer |= ((relativeTimeEvent.crate & 0xF) << 28);
*buffer |= ((relativeTimeEvent.board & 0x3F) << 22);
*buffer |= ((relativeTimeEvent.channel & 0x3F) << 16);
*buffer |= (relativeTimeEvent.rollover & 0xFFFF);
BoardType boardType = relativeTimeEvent.boardType();
if (boardType == CFD_BOARD_TYPE) {
*buffer |= (relativeTimeEvent.rollover & 0xFFFF);
*(buffer + 1) = relativeTimeEvent.timestamp;
*(buffer + 2) = (relativeTimeEvent.energy & 0xFFF);
memcpy(buffer + 3, reinterpret_cast<const void *>(&relativeTimeEvent.data), 4);
} else if (boardType == V1751_BOARD_TYPE) {
*buffer |= (relativeTimeEvent.rollover & 0xFFFF);
// There is one bit that is not used: first bit of data (the buffer written may be different from the buffer read).
*(buffer + 1) = relativeTimeEvent.timestamp;
*(buffer + 2) = ((relativeTimeEvent.energy << 16)) | (event.data & 0x7FFF);
*(buffer + 3) = 0;
} else if ((boardType == V1724_BOARD_TYPE) || (boardType == V1730_BOARD_TYPE)) {
} else if (boardType == V1724_BOARD_TYPE) {
// The card timestamp is on 30bits with 2 bits of zero.
// The rollover is calculated by taking the 2 bits of the actual timestamp (>> 30 for 32 bits = 2 bits).
int32_t rollover = ((relativeTimeEvent.rollover << 2) | (relativeTimeEvent.timestamp >> 30));
*buffer |= (rollover & 0xFFFF);
// Taking the 30 bits and setting 0 to the 2 first bits.
*(buffer + 1) = (relativeTimeEvent.timestamp & 0x3FFFFFFF);
*(buffer + 2) = (relativeTimeEvent.energy & 0x7FFF);
*(buffer + 3) = 0;
} else if (boardType == V1730_BOARD_TYPE) {
*buffer |= (relativeTimeEvent.rollover & 0xFFFF);
*(buffer + 1) = (relativeTimeEvent.timestamp & 0xFFFFFFFF);
*(buffer + 2) = (relativeTimeEvent.energy & 0x7FFF);
*(buffer + 3) = 0;
......
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