Commit df9e4afc authored by ics's avatar ics
Browse files

Implemented lst version 2 for timestamps, data and flags

parent 54185eda
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# This configure.ac script is free software; the Free Software Foundation # This configure.ac script is free software; the Free Software Foundation
# gives unlimited permission to copy, distribute and modify it. # gives unlimited permission to copy, distribute and modify it.
AC_INIT([lstdataprocess128], [1.2.1-dev]) AC_INIT([lstdataprocess128], [1.3.0-dev])
LIBRARY_VERSION=1:2:1 LIBRARY_VERSION=1:2:1
......
...@@ -61,8 +61,8 @@ std::string writeListModeContextToBinary(const ListModeContext & listModeContext ...@@ -61,8 +61,8 @@ std::string writeListModeContextToBinary(const ListModeContext & listModeContext
// Allocate the data. // Allocate the data.
uint32_t buffer[4 + boardSize]; uint32_t buffer[4 + boardSize];
buffer[0] = FORMAT_VERSION; buffer[0] = listModeContext.version;
buffer[1] = TIME_BASE; buffer[1] = listModeContext.timeBase;
buffer[2] = listModeContext.nbEvents; buffer[2] = listModeContext.nbEvents;
buffer[3] = boardSize; buffer[3] = boardSize;
......
...@@ -36,8 +36,9 @@ static const int EVENT_SIZE_8 = 16; ...@@ -36,8 +36,9 @@ static const int EVENT_SIZE_8 = 16;
/** /**
* Version of the file. * Version of the file.
* Version 2 : unify boards to have the same timestamp format.
*/ */
static const int FORMAT_VERSION = 1; static const int FORMAT_VERSION = 2;
/** /**
* Time base. * Time base.
...@@ -50,24 +51,17 @@ static const int TIME_BASE = 9; ...@@ -50,24 +51,17 @@ static const int TIME_BASE = 9;
enum BoardType { enum BoardType {
CFD = 0, CFD = 0,
C1751_PSD = 1, C1751_PSD = 1,
C1724_PHA_RT = 2, C1724_PHA = 2,
C1730_PSD_RT = 3, C1730_PSD = 3,
C1730_PHA_RT = 4, C1730_PHA = 4,
C1740_QDC = 5, C1740_QDC = 5,
C1740_QDIV = 6, C1740_QDIV = 6,
C1725_PHA_RT = 7, C1725_PHA = 7,
C1725_PSD = 8,
GGPICKUP = 20, GGPICKUP = 20,
MCC = 21, MCC = 21,
CAMERA = 22, CAMERA = 22,
C1751_WAVEFORM = 31,
C1724_WAVEFORM_RT = 32,
C1730_WAVEFORM_RT = 33,
C1725_WAVEFORM_RT = 34,
C1740_WAVEFORM = 35,
C1740_QDIV_WAVEFORM = 36
}; };
/** /**
...@@ -76,35 +70,25 @@ enum BoardType { ...@@ -76,35 +70,25 @@ enum BoardType {
static const char* BoardTypeName[] = { static const char* BoardTypeName[] = {
"CFD", // 0 "CFD", // 0
"1751 PSD", // 1 "1751 PSD", // 1
"1724 PHA RT", // 2 "1724 PHA", // 2
"1730 PSD RT", // 3 "1730 PSD", // 3
"1730 PHA RT", // 4 "1730 PHA", // 4
"1740 QDC", // 5 "1740 QDC", // 5
"1740 QDIV", // 6 "1740 QDIV", // 6
"1725 PHA RT", // 7 "1725 PHA", // 7
"1725 PSD", // 8
// 8 ... 19 // 9 ... 19
"8?", "9?", "10?", "11?", "12?", "13?", "14?", "15?", "16?", "17?", "18?", "19?", "9?", "10?", "11?", "12?", "13?", "14?", "15?", "16?", "17?", "18?", "19?",
"GGPICKUP", // 20 "GGPICKUP", // 20
"MCC", // 21 "MCC", // 21
"CAMERA", // 22 "CAMERA" // 22
// 23 ... 30
"23?", "24?", "25?", "26?", "27?", "28?", "29?", "30?",
"1751 WAVEFORM", // 31
"1724 WAVEFORM RT", // 32
"1730 WAVEFORM RT", // 33
"1725 WAVEFORM RT", // 34
"1740 WAVEFORM", // 35
"1740 QDIV WAVEFORM" // 36
}; };
/** /**
* The time relativity of the boards. * The time relativity of the boards.
* Only used for lst v1 files.
*/ */
static int BoardRelativeTime[] = { static int BoardRelativeTime[] = {
0, // 0 0, // 0
...@@ -115,25 +99,14 @@ static int BoardRelativeTime[] = { ...@@ -115,25 +99,14 @@ static int BoardRelativeTime[] = {
0, // 5 0, // 5
0, // 6 0, // 6
1, // 7 1, // 7
0, // 8
// 8.. 19 // 9.. 19
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, // 20 0, // 20
0, // 21 0, // 21
0, // 22 0 // 22
// 23.. 30
0, 0, 0, 0, 0, 0, 0, 0,
0, // 31
1, // 32
1, // 33
1, // 34
0, // 35
0 // 36
}; };
/** /**
...@@ -148,25 +121,14 @@ static uint32_t BoardTimeResolution[] = { ...@@ -148,25 +121,14 @@ static uint32_t BoardTimeResolution[] = {
16, // 5 16, // 5
16, // 6 16, // 6
4, // 7 4, // 7
4, // 8
// 8.. 19 // 9.. 19
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
10, // 20 10, // 20
10, // 21 10, // 21
0, // 22 0 // 22
// 23.. 30
0, 0, 0, 0, 0, 0, 0, 0,
1, // 31
10, // 32
2, // 33
4, // 34
16, // 35
16 // 36
}; };
/** /**
......
...@@ -109,26 +109,7 @@ std::ostream& operator<< (std::ostream& os, EventBlock const & b) { ...@@ -109,26 +109,7 @@ std::ostream& operator<< (std::ostream& os, EventBlock const & b) {
return os << b.id << " : " << b.minTime() << " - " << b.maxTime() << " (" << b.events.size() << ")"; return os << b.id << " : " << b.minTime() << " - " << b.maxTime() << " (" << b.events.size() << ")";
} }
bool readEvent(Event & event, int32_t * buffer) { void readEventV1(Event & event, int32_t * buffer) {
// Read crate, board, channel.
uint8_t crate = (uint8_t)((*buffer >> 28) & 0xF);
uint8_t board = (uint8_t)((*buffer >> 22) & 0x3F);
if (crate >= listModeContext.crateBoard.nbCrates) {
// No output because the log file can be very large.
return false;
}
if (board >= listModeContext.crateBoard.crates[event.crate].nbBoards) {
// No output because the log file can be very large.
return false;
}
event.crate = crate;
event.board = board;
event.channel = (uint8_t)((*buffer >> 16) & 0x3F);
event.rollover = (uint16_t)(*buffer & 0xFFFF);
BoardType boardType = event.boardType(); BoardType boardType = event.boardType();
...@@ -136,11 +117,11 @@ bool readEvent(Event & event, int32_t * buffer) { ...@@ -136,11 +117,11 @@ bool readEvent(Event & event, int32_t * buffer) {
int numberOfBitsOfTimestamp = 32; int numberOfBitsOfTimestamp = 32;
// In case of 1724 PHA, the number of bits for timestamp is 30. // In case of 1724 PHA, the number of bits for timestamp is 30.
if (boardType == C1724_PHA_RT) { if (boardType == C1724_PHA) {
numberOfBitsOfTimestamp = 30; numberOfBitsOfTimestamp = 30;
event.timestamp = (uint32_t)(*(buffer + 1) & 0x3FFFFFFF); event.timestamp = (uint32_t)(*(buffer + 1) & 0x3FFFFFFF);
} }
else if (boardType == C1725_PHA_RT) { else if (boardType == C1725_PHA) {
numberOfBitsOfTimestamp = 31; numberOfBitsOfTimestamp = 31;
event.timestamp = (uint32_t)(*(buffer + 1) & 0x7FFFFFFF); event.timestamp = (uint32_t)(*(buffer + 1) & 0x7FFFFFFF);
} }
...@@ -172,11 +153,62 @@ bool readEvent(Event & event, int32_t * buffer) { ...@@ -172,11 +153,62 @@ bool readEvent(Event & event, int32_t * buffer) {
// We can set the absolute time that changes the rollover and timestamp. // We can set the absolute time that changes the rollover and timestamp.
event.setTime(absoluteTime); event.setTime(absoluteTime);
} }
}
void readEventV2(Event & event, int32_t * buffer) {
BoardType boardType = event.boardType();
// The number of bits for timestamp.
int numberOfBitsOfTimestamp = 32;
event.timestamp = (uint32_t)(*(buffer + 1) & 0xFFFFFFFF);
// Copy data.
memcpy(reinterpret_cast<void *>(event.data), reinterpret_cast<const void *>(buffer + 2), 8);
// Use printBinary(buffer) to debug if necessary.
// Calculate the absolute time.
time_type absoluteTime = (((int64_t)event.rollover << numberOfBitsOfTimestamp) | event.timestamp);
// We can set the absolute time that changes the rollover and timestamp.
event.setTime(absoluteTime);
}
bool readEvent(Event & event, int32_t * buffer) {
// Read crate, board, channel.
uint8_t crate = (uint8_t)((*buffer >> 28) & 0xF);
uint8_t board = (uint8_t)((*buffer >> 22) & 0x3F);
if (crate >= listModeContext.crateBoard.nbCrates) {
// No output because the log file can be very large.
return false;
}
if (board >= listModeContext.crateBoard.crates[event.crate].nbBoards) {
// No output because the log file can be very large.
return false;
}
event.crate = crate;
event.board = board;
event.channel = (uint8_t)((*buffer >> 16) & 0x3F);
event.rollover = (uint16_t)(*buffer & 0xFFFF);
// Check the lst version to read the event.
if (listModeContext.version == 1) {
readEventV1(event, buffer);
}
else {
readEventV2(event, buffer);
}
return true; return true;
} }
void writeEvent(Event const & event, int32_t * buffer) { void writeEventV1(Event const & event, int32_t * buffer) {
Event relativeTimeEvent(event); Event relativeTimeEvent(event);
...@@ -197,7 +229,7 @@ void writeEvent(Event const & event, int32_t * buffer) { ...@@ -197,7 +229,7 @@ void writeEvent(Event const & event, int32_t * buffer) {
BoardType boardType = relativeTimeEvent.boardType(); BoardType boardType = relativeTimeEvent.boardType();
if (boardType == C1724_PHA_RT) { if (boardType == C1724_PHA) {
// The card timestamp is on 30bits with 2 bits of zero. // 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). // The rollover is calculated by taking the 2 bits of the actual timestamp (>> 30 for 32 bits = 2 bits).
...@@ -209,7 +241,6 @@ void writeEvent(Event const & event, int32_t * buffer) { ...@@ -209,7 +241,6 @@ void writeEvent(Event const & event, int32_t * buffer) {
} }
else { else {
*buffer |= (relativeTimeEvent.rollover & 0xFFFF); *buffer |= (relativeTimeEvent.rollover & 0xFFFF);
*(buffer + 1) = relativeTimeEvent.timestamp; *(buffer + 1) = relativeTimeEvent.timestamp;
} }
...@@ -219,4 +250,35 @@ void writeEvent(Event const & event, int32_t * buffer) { ...@@ -219,4 +250,35 @@ void writeEvent(Event const & event, int32_t * buffer) {
// Use printBinary(buffer) to debug if necessary. // Use printBinary(buffer) to debug if necessary.
} }
void writeEventV2(Event const & event, int32_t * buffer) {
Event relativeTimeEvent(event);
*buffer = 0;
*buffer |= ((relativeTimeEvent.crate & 0xF) << 28);
*buffer |= ((relativeTimeEvent.board & 0x3F) << 22);
*buffer |= ((relativeTimeEvent.channel & 0x3F) << 16);
BoardType boardType = relativeTimeEvent.boardType();
*buffer |= (relativeTimeEvent.rollover & 0xFFFF);
*(buffer + 1) = relativeTimeEvent.timestamp;
// Copy data.
memcpy(buffer + 2, reinterpret_cast<const void *>(&relativeTimeEvent.data), 8);
// Use printBinary(buffer) to debug if necessary.
}
void writeEvent(Event const & event, int32_t * buffer) {
// Check the lst version to write the event.
if (listModeContext.version == 1) {
writeEventV1(event, buffer);
}
else {
writeEventV2(event, buffer);
}
}
} }
...@@ -42,10 +42,10 @@ uint32_t eventDataPlus(Event const & event) { ...@@ -42,10 +42,10 @@ uint32_t eventDataPlus(Event const & event) {
bool boardHasEnergy(BoardType type) { bool boardHasEnergy(BoardType type) {
if (type == CFD if (type == CFD
|| type == C1724_PHA_RT || type == C1724_PHA
|| type == C1730_PHA_RT || type == C1730_PHA
|| type == C1740_QDC || type == C1740_QDC
|| type == C1725_PHA_RT) { || type == C1725_PHA) {
return true; return true;
} }
return false; return false;
...@@ -61,16 +61,16 @@ uint16_t boardEnergyResolution(BoardType type) { ...@@ -61,16 +61,16 @@ uint16_t boardEnergyResolution(BoardType type) {
case CFD: case CFD:
return 12; return 12;
case C1724_PHA_RT: case C1724_PHA:
return 15; return 15;
case C1730_PHA_RT: case C1730_PHA:
return 15; return 15;
case C1740_QDC: case C1740_QDC:
return 16; return 16;
case C1725_PHA_RT: case C1725_PHA:
return 15; return 15;
} }
...@@ -86,16 +86,16 @@ uint16_t eventEnergy(Event const & event) { ...@@ -86,16 +86,16 @@ uint16_t eventEnergy(Event const & event) {
if (event.boardType() == CFD) { if (event.boardType() == CFD) {
return event.data[0] & 0xFFF; return event.data[0] & 0xFFF;
} }
else if (event.boardType() == C1724_PHA_RT) { else if (event.boardType() == C1724_PHA) {
return event.data[0] & 0x7FFF; return event.data[0] & 0x7FFF;
} }
else if (event.boardType() == C1730_PHA_RT) { else if (event.boardType() == C1730_PHA) {
return event.data[0] & 0x7FFF; return event.data[0] & 0x7FFF;
} }
else if (event.boardType() == C1740_QDC) { else if (event.boardType() == C1740_QDC) {
return event.data[0] & 0xFFFF; return event.data[0] & 0xFFFF;
} }
else if (event.boardType() == C1725_PHA_RT) { else if (event.boardType() == C1725_PHA) {
return event.data[0] & 0x7FFF; return event.data[0] & 0x7FFF;
} }
...@@ -108,7 +108,8 @@ uint16_t eventEnergy(Event const & event) { ...@@ -108,7 +108,8 @@ uint16_t eventEnergy(Event const & event) {
bool boardHasQ(BoardType type) { bool boardHasQ(BoardType type) {
if (type == C1751_PSD if (type == C1751_PSD
|| type == C1730_PSD_RT) { || type == C1730_PSD
|| type == C1725_PSD) {
return true; return true;
} }
return false; return false;
...@@ -121,7 +122,8 @@ bool eventHasQ(Event const & event) { ...@@ -121,7 +122,8 @@ bool eventHasQ(Event const & event) {
uint16_t boardQShortResolution(BoardType type) { uint16_t boardQShortResolution(BoardType type) {
if (type == C1751_PSD if (type == C1751_PSD
|| type == C1730_PSD_RT) { || type == C1730_PSD
|| type == C1725_PSD) {
return 15; return 15;
} }
return 0; return 0;
...@@ -134,7 +136,8 @@ uint16_t eventQShortResolution(Event const & event) { ...@@ -134,7 +136,8 @@ uint16_t eventQShortResolution(Event const & event) {
uint16_t boardQLongResolution(BoardType type) { uint16_t boardQLongResolution(BoardType type) {
if (type == C1751_PSD if (type == C1751_PSD
|| type == C1730_PSD_RT) { || type == C1730_PSD
|| type == C1725_PSD) {
return 16; return 16;
} }
return 0; return 0;
...@@ -171,7 +174,22 @@ float eventQRatio(Event const & event) { ...@@ -171,7 +174,22 @@ float eventQRatio(Event const & event) {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Position XY // Position XY
bool boardHasPositionXY(BoardType type) { bool boardHasPositionX(BoardType type) {
if (type == C1740_QDIV
|| type == C1740_QDC
|| type == MCC
|| type == CAMERA) {
return true;
}
return false;
}
bool eventHasPositionX(Event const & event) {
return boardHasPositionX(event.boardType());
}
bool boardHasPositionY(BoardType type) {
if (type == C1740_QDIV if (type == C1740_QDIV
|| type == MCC || type == MCC
...@@ -181,8 +199,8 @@ bool boardHasPositionXY(BoardType type) { ...@@ -181,8 +199,8 @@ bool boardHasPositionXY(BoardType type) {
return false; return false;
} }
bool eventHasPositionXY(Event const & event) { bool eventHasPositionY(Event const & event) {
return boardHasPositionXY(event.boardType()); return boardHasPositionY(event.boardType());
} }
uint16_t boardPositionXResolution(BoardType type) { uint16_t boardPositionXResolution(BoardType type) {
...@@ -191,6 +209,9 @@ uint16_t boardPositionXResolution(BoardType type) { ...@@ -191,6 +209,9 @@ uint16_t boardPositionXResolution(BoardType type) {
case C1740_QDIV: case C1740_QDIV:
return 5; return 5;
case C1740_QDC:
return 6;
case MCC: case MCC:
return 16; return 16;
...@@ -319,35 +340,6 @@ float eventZeroCrossing(Event const & event) { ...@@ -319,35 +340,6 @@ float eventZeroCrossing(Event const & event) {
return floatData(event, 1); return floatData(event, 1);
} }
///////////////////////////////////////////////////////////////////////////////
// Fine timestamp
bool boardHasFineTimestamp(BoardType type) {
if (type == C1725_PHA_RT) {
return true;
}
return false;
}
bool eventHasFineTimestamp(Event const & event) {
return boardHasFineTimestamp(event.boardType());
}
uint16_t boardFineTimestampResolution(BoardType type) {
if (type == C1725_PHA_RT) {
return 10;
}
return 0;
}
uint16_t eventFineTimestampResolution(Event const & event) {
return boardFineTimestampResolution(event.boardType());
}
uint16_t eventFineTimestamp(Event const & event) {
return event.data[1] & 0x3FF;
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Special unspecified data // Special unspecified data
...@@ -355,6 +347,15 @@ bool boardHasUnspecifiedData(BoardType type) { ...@@ -355,6 +347,15 @@ bool boardHasUnspecifiedData(BoardType type) {
if (type == GGPICKUP) { if (type == GGPICKUP) {
return true; return true;
}