12 const std::ios_base::fmtflags originalFormatFlags = os.flags();
13 os << std::hex << std::setfill(
'0') << std::setw(2);
14 os << uint16_t(value);
15 os.flags(originalFormatFlags);
18 void printHexWord(
const uint8_t* pointer,
const size_t lengthInBytes, std::ostream& os)
20 size_t i = lengthInBytes-1;
23 if (i != 0) os <<
" ";
27 void printHex(
const void* pointer,
const size_t lengthInBytes, std::ostream& os)
29 const uint8_t* bytePointer =
reinterpret_cast<const uint8_t*
>(pointer);
31 if (lengthInBytes <= 8) {
37 os <<
"word\tbyte\t \t\tbyte" << std::endl;;
38 const size_t words = lengthInBytes/8;
39 const size_t extraBytes = lengthInBytes - 8*words;
41 for (
size_t w = 0;
w < words;
w++) {
42 const size_t startByte =
w*8;
43 os <<
w <<
'\t' << startByte+8 <<
'\t';
45 os <<
"\t\t" << startByte << std::endl;
49 const size_t startByte = words*8;
50 os << words <<
'\t' << startByte+8 <<
'\t';
53 while (p-- > extraBytes) {
57 os <<
"\t\t" << startByte << std::endl;
66 uint16_t crc = 0xFFFF;
67 for (
size_t i = 0;
i < lengthInBytes-8;
i++) {
70 for (
size_t i=lengthInBytes-8;
i<lengthInBytes;
i++) {
73 if (
i==lengthInBytes-4 ||
i==lengthInBytes-3)
124 os <<
"Unrecognized";
143 os <<
"Processed raw";
146 os <<
"Zero suppressed";
149 os <<
"Zero suppressed lite";
161 os <<
"Unrecognized";
180 os <<
"Unrecognized";
193 os <<
"Physics trigger";
196 os <<
"Calibration trigger";
199 os <<
"Test trigger";
202 os <<
"Technical trigger";
205 os <<
"Simulated event";
208 os <<
"Traced event";
217 os <<
"Unrecognized";
230 os <<
"Disconected 0";
233 os <<
"Warning overflow";
251 os <<
"Disconected 1";
254 os <<
"Unrecognized";
273 os <<
"Partial Full";
279 os <<
"Unrecognized";
302 if ( (bufferFormatString ==
"OLD_VME") ||
303 (bufferFormatString ==
"BUFFER_FORMAT_OLD_VME") ||
304 (bufferFormatString ==
"Old VME") ) {
307 if ( (bufferFormatString ==
"OLD_SLINK") ||
308 (bufferFormatString ==
"BUFFER_FORMAT_OLD_SLINK") ||
309 (bufferFormatString ==
"Old S-Link") ) {
312 if ( (bufferFormatString ==
"NEW") ||
313 (bufferFormatString ==
"BUFFER_FORMAT_NEW") ||
314 (bufferFormatString ==
"New") ) {
323 if ( (headerTypeString ==
"FULL_DEBUG") ||
324 (headerTypeString ==
"HEADER_TYPE_FULL_DEBUG") ||
325 (headerTypeString ==
"Full debug") ) {
328 if ( (headerTypeString ==
"APV_ERROR") ||
329 (headerTypeString ==
"HEADER_TYPE_APV_ERROR") ||
330 (headerTypeString ==
"APV error") ) {
333 if ( (headerTypeString ==
"None") ||
334 (headerTypeString ==
"none") ) {
343 if ( (readoutModeString ==
"READOUT_MODE_SCOPE") ||
344 (readoutModeString ==
"SCOPE") ||
345 (readoutModeString ==
"SCOPE_MODE") ||
346 (readoutModeString ==
"Scope mode") ) {
349 if ( (readoutModeString ==
"READOUT_MODE_VIRGIN_RAW") ||
350 (readoutModeString ==
"VIRGIN_RAW") ||
351 (readoutModeString ==
"Virgin raw") ) {
354 if ( (readoutModeString ==
"READOUT_MODE_PROC_RAW") ||
355 (readoutModeString ==
"PROC_RAW") ||
356 (readoutModeString ==
"PROCESSED_RAW") ||
357 (readoutModeString ==
"Processed raw") ) {
360 if ( (readoutModeString ==
"READOUT_MODE_ZERO_SUPPRESSED") ||
361 (readoutModeString ==
"ZERO_SUPPRESSED") ||
362 (readoutModeString ==
"Zero suppressed") ) {
365 if ( (readoutModeString ==
"READOUT_MODE_ZERO_SUPPRESSED_LITE") ||
366 (readoutModeString ==
"ZERO_SUPPRESSED_LITE") ||
367 (readoutModeString ==
"Zero suppressed lite") ) {
370 if ( (readoutModeString ==
"READOUT_MODE_PREMIX_RAW") ||
371 (readoutModeString ==
"PREMIX_RAW") ||
372 (readoutModeString ==
"PreMix Raw") ) {
375 if ( (readoutModeString ==
"READOUT_MODE_SPY") ||
376 (readoutModeString ==
"SPY") ||
377 (readoutModeString ==
"Spy channel") ) {
386 if ( (dataTypeString ==
"REAL") ||
387 (dataTypeString ==
"DATA_TYPE_REAL") ||
388 (dataTypeString ==
"Real data") ) {
391 if ( (dataTypeString ==
"FAKE") ||
392 (dataTypeString ==
"DATA_TYPE_FAKE") ||
393 (dataTypeString ==
"Fake data") ) {
397 std::ostringstream
ss;
398 ss <<
"Trying to convert to a FEDDataType from an invalid string: " << dataTypeString;
404 if ( (daqEventTypeString ==
"PHYSICS") ||
405 (daqEventTypeString ==
"DAQ_EVENT_TYPE_PHYSICS") ||
406 (daqEventTypeString ==
"Physics trigger") ) {
409 if ( (daqEventTypeString ==
"CALIBRATION") ||
410 (daqEventTypeString ==
"DAQ_EVENT_TYPE_CALIBRATION") ||
411 (daqEventTypeString ==
"Calibration trigger") ) {
414 if ( (daqEventTypeString ==
"TEST") ||
415 (daqEventTypeString ==
"DAQ_EVENT_TYPE_TEST") ||
416 (daqEventTypeString ==
"Test trigger") ) {
419 if ( (daqEventTypeString ==
"TECHNICAL") ||
420 (daqEventTypeString ==
"DAQ_EVENT_TYPE_TECHNICAL") ||
421 (daqEventTypeString ==
"Technical trigger") ) {
424 if ( (daqEventTypeString ==
"SIMULATED") ||
425 (daqEventTypeString ==
"DAQ_EVENT_TYPE_SIMULATED") ||
426 (daqEventTypeString ==
"Simulated trigger") ) {
429 if ( (daqEventTypeString ==
"TRACED") ||
430 (daqEventTypeString ==
"DAQ_EVENT_TYPE_TRACED") ||
431 (daqEventTypeString ==
"Traced event") ) {
434 if ( (daqEventTypeString ==
"ERROR") ||
435 (daqEventTypeString ==
"DAQ_EVENT_TYPE_ERROR") ||
436 (daqEventTypeString ==
"Error") ) {
481 const uint16_t mask = (0x0001 <<
num);
482 if (bitSet)
data_ |= mask;
483 else data_ &= (~mask);
495 std::ostringstream
ss;
496 ss <<
"Invalid buffer state: ";
515 std::ostringstream
ss;
516 ss <<
"Invalid buffer state: ";
572 std::ostringstream
ss;
573 ss <<
"Invalid buffer state: ";
584 const uint32_t mask = (0x00000001 <<
num);
585 if (bitSet)
data_ |= mask;
586 else data_ &= (~mask);
596 const bool backpressure,
const bool slinkFull,
597 const bool slinkDown,
const bool internalFreeze,
598 const bool trackerHeaderMonitorDataReady,
const bool ttcReady)
627 if (validFormatByteWhenNotWordSwapped || (!validFormatByteWhenNotWordSwapped && !validFormatByteWhenWordSwapped) ) {
665 const uint8_t
mode = (eventTypeNibble & 0xE);
702 switch (newBufferFormat) {
711 std::ostringstream
ss;
712 ss <<
"Invalid buffer format: ";
727 std::ostringstream
ss;
728 ss <<
"Invalid header type: ";
736 switch(readoutMode) {
754 std::ostringstream
ss;
755 ss <<
"Invalid readout mode: ";
772 std::ostringstream
ss;
773 ss <<
"Invalid data type: ";
781 const uint8_t mask = 0x1 << internalFEUnitNum;
789 const uint8_t mask = 0x1 << internalFEUnitNum;
797 const uint8_t mask = 0x1 << internalFEUnitNum;
805 const uint8_t address,
const uint8_t addressErrorRegister,
806 const uint8_t feEnableRegister,
const uint8_t feOverflowRegister,
851 header_[4] = (l1ID & 0x000000FF);
852 header_[5] = ( (l1ID & 0x0000FF00) >> 8);
853 header_[6] = ( (l1ID & 0x00FF0000) >> 16);
859 header_[3] = ( (bxID & 0x0FF0) >> 4);
866 header_[2] = ( (
header_[2] & 0xF0) | ( (sourceID & 0x0F00) >> 8) );
867 header_[1] = (sourceID & 0x00FF);
904 const bool slinkTransmissionError,
const bool badFEDID,
const bool slinkCRCError,
905 const uint8_t eventStatusNibble)
923 trailer_[4] = (eventLengthIn64BitWords & 0x000000FF);
924 trailer_[5] = ( (eventLengthIn64BitWords & 0x0000FF00) >> 8);
925 trailer_[6] = ( (eventLengthIn64BitWords & 0x00FF0000) >> 16);
932 trailer_[3] = ( (crc >> 8) & 0x00FF );
996 return (
header_[bitNumber/8] & (0x01<<(bitNumber%8)) );
1022 const uint8_t byteNumber = bitNumber/8;
1023 const uint8_t bitInByte = bitNumber%8;
1024 const uint8_t mask = (0x01 << bitInByte);
1025 header_[byteNumber] = ( (
header_[byteNumber] & (~mask)) | (apvGood?mask:0x00) );
1089 !
apvError(internalFEDChannelNum,apvNum) &&
1108 const uint8_t startByteInFEWord = (
FEDCH_PER_FEUNIT-1 - feUnitChanNum) * 6 / 8;
1113 return FEDChannelStatus( ((pFEWord[startByteInFEWord] & 0xC0) >> 6) | ((pFEWord[startByteInFEWord+1] & 0x0F) << 2) );
1115 return FEDChannelStatus( ((pFEWord[startByteInFEWord] & 0xF0) >> 4) | ((pFEWord[startByteInFEWord+1] & 0x03) << 4) );
1151 const uint32_t daqRegister,
const uint32_t daqRegister2)
1178 feWord(internalFEUnitNum)[9] = address;
1198 feWord(internalFEUnitNum)[15] = ( (length & 0xFF00) >> 8);
1199 feWord(internalFEUnitNum)[14] = (length & 0x00FF);
1206 const uint8_t mask = (0x1 << bitInFeWord%8);
1207 byte = ( (byte & (~mask)) | (value?mask:0x0) );
1219 originalBuffer_(fedBuffer),
1220 bufferSize_(fedBufferSize)
1222 init(fedBuffer,fedBufferSize,allowUnrecognizedFormat);
1226 : originalBuffer_(fedBuffer),
1227 bufferSize_(fedBufferSize)
1229 init(fedBuffer,fedBufferSize,allowUnrecognizedFormat);
1233 void FEDBufferBase::init(
const uint8_t* fedBuffer,
const size_t fedBufferSize,
const bool allowUnrecognizedFormat)
1236 static const size_t MIN_BUFFER_SIZE = 8+8+8;
1240 std::ostringstream
ss;
1241 ss <<
"Buffer is too small. "
1242 <<
"Min size is " << MIN_BUFFER_SIZE <<
". "
1253 std::ostringstream
ss;
1254 ss <<
"Buffer format not recognized. "
1261 const uint32_t* originalU32 =
reinterpret_cast<const uint32_t*
>(
originalBuffer_);
1263 uint32_t* newU32 =
reinterpret_cast<uint32_t*
>(newBuffer);
1266 for (
size_t i = 0;
i < sizeU32;
i+=2) {
1267 newU32[
i] = originalU32[
i+1];
1268 newU32[
i+1] = originalU32[
i];
1273 memcpy(newU32,originalU32,8);
1275 memcpy(newU32+sizeU32-2,originalU32+sizeU32-2,8);
1277 for (
size_t i = 2;
i < sizeU32-2;
i+=2) {
1278 newU32[
i] = originalU32[
i+1];
1279 newU32[
i+1] = originalU32[
i];
1302 os <<
"buffer format: " <<
bufferFormat() << std::endl;
1303 os <<
"Buffer size: " <<
bufferSize() <<
" bytes" << std::endl;
1305 os <<
"Source ID: " <<
daqSourceID() << std::endl;
1306 os <<
"Header type: " <<
headerType() << std::endl;
1307 os <<
"Readout mode: " <<
readoutMode() << std::endl;
1308 os <<
"Data type: " <<
dataType() << std::endl;
1309 os <<
"DAQ event type: " <<
daqEventType() << std::endl;
1310 os <<
"TTS state: " <<
daqTTSState() << std::endl;
1311 os <<
"L1 ID: " <<
daqLvl1ID() << std::endl;
1312 os <<
"BX ID: " <<
daqBXID() << std::endl;
1314 os <<
"APVe Address: " << uint16_t(
apveAddress()) << std::endl;
1315 os <<
"Enabled FE units: " << uint16_t(
nFEUnitsEnabled()) << std::endl;
1356 summary <<
"Check buffer type valid: " << (
checkBufferFormat() ?
"passed" :
"FAILED" ) << std::endl;
1357 summary <<
"Check header format valid: " << (
checkHeaderType() ?
"passed" :
"FAILED" ) << std::endl;
1358 summary <<
"Check readout mode valid: " << (
checkReadoutMode() ?
"passed" :
"FAILED" ) << std::endl;
1360 summary <<
"Check FE unit majority addresses: " << (
checkMajorityAddresses() ?
"passed" :
"FAILED" ) << std::endl;
1362 summary <<
"FEs with majority address error: ";
1363 unsigned int badFEs = 0;
1367 summary << uint16_t(iFE) <<
" ";
1371 summary << std::endl;
1372 summary <<
"Number of FE Units with bad addresses: " << badFEs << std::endl;
1374 summary <<
"Check for FE unit buffer overflows: " << (
checkNoFEOverflows() ?
"passed" :
"FAILED" ) << std::endl;
1376 summary <<
"FEs which overflowed: ";
1377 unsigned int badFEs = 0;
1380 summary << uint16_t(iFE) <<
" ";
1384 summary << std::endl;
1385 summary <<
"Number of FE Units which overflowed: " << badFEs << std::endl;
1387 summary <<
"Check for S-Link CRC errors: " << (
checkNoSlinkCRCError() ?
"passed" :
"FAILED" ) << std::endl;
1389 summary <<
"Check CRC: " << (
checkCRC() ?
"passed" :
"FAILED" ) << std::endl;
1390 summary <<
"Check source ID is FED ID: " << (
checkSourceIDs() ?
"passed" :
"FAILED" ) << std::endl;
1391 summary <<
"Check for unexpected source ID at FRL: " << (
checkNoUnexpectedSourceID() ?
"passed" :
"FAILED" ) << std::endl;
1393 summary <<
"Check length from trailer: " << (
checkLengthFromTrailer() ?
"passed" :
"FAILED" ) << std::endl;
1394 return summary.str();
1403 std::ostringstream
ss;
1404 ss <<
"Request for CM median from channel with non-ZS packet code. "
1405 <<
"Packet code is " << uint16_t(
packetCode()) <<
"."
1410 std::ostringstream
ss;
1411 ss <<
"Channel APV index out of range when requesting CM median for APV. "
1412 <<
"Channel APV index is " << uint16_t(apvIndex) <<
"."
1419 result |= ( ((
data_[(
offset_+4+2*apvIndex)^7]) << 8) & 0x300 );
bool checkNoUnexpectedSourceID() const
FEDBackendStatusRegister & setFEFPGABufferState(const FEDBufferState state)
FEDBackendStatusRegister & setQDRMemoryState(const FEDBufferState state)
FEDBackendStatusRegister & setL1ABXFIFOState(const FEDBufferState state)
bool checkNoExtraHeadersOrTrailers() const
virtual bool doChecks() const
bool feDataMissingFlag(const uint8_t internalFEUnitNum) const
bool qdrMemoryPartialFullFlag() const
void printHexValue(const uint8_t value, std::ostream &os)
bool checkSourceIDs() const
void printFlags(std::ostream &os) const
void setBit(const uint8_t num, const bool bitSet)
static const uint16_t FED_ID_MIN
uint8_t nFEUnitsEnabled() const
bool ttcReadyFlag() const
bool checkReadoutMode() const
void setQDRMemoryEmptyFlag(const bool bitSet)
virtual std::string checkSummary() const
uint8_t apveAddress() const
FEDBackendStatusRegister & setFrameAddressFIFOState(const FEDBufferState state)
uint32_t daqEventLengthInBytes() const
FEDBackendStatusRegister & setTrackerHeaderFIFOState(const FEDBufferState state)
bool slinkDownFlag() const
bool l1aBxFIFOPartialFullFlag() const
bool checkHeaderType() const
bool doDAQHeaderAndTrailerChecks() const
FEDDAQTrailer & setSLinkCRCErrorBit(const bool bitSet)
FEDDAQTrailer & setTTSBits(const FEDTTSBits ttsBits)
bool trackerHeaderMonitorDataReadyFlag() const
FEDReadoutMode readoutMode() const
FEDDataType fedDataTypeFromString(const std::string &dataTypeString)
bool getBit(const uint8_t num) const
uint8_t internalFEDChannelNum(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum)
bool checkNoFEOverflows() const
FEDDAQTrailer & setSLinkTransmissionErrorBit(const bool bitSet)
FEDHeaderType fedHeaderTypeFromString(const std::string &headerTypeString)
void printFlags(std::ostream &os) const
uint16_t calculateFEDBufferCRC(const uint8_t *buffer, const size_t lengthInBytes)
bool backpressureFlag() const
std::ostream & operator<<(std::ostream &os, const FEDBufferFormat &value)
FEDBufferFormat fedBufferFormatFromString(const std::string &bufferFormatString)
void setBit(const uint8_t num, const bool bitSet)
FEDDAQEventType daqEventType() const
const uint8_t * orderedBuffer_
FEDTTSBits daqTTSState() const
bool checkNoSlinkCRCError() const
bool checkNoSLinkTransmissionError() const
FEDReadoutMode fedReadoutModeFromString(const std::string &readoutModeString)
FEDBufferState qdrMemoryState() const
FEDBufferState frameAddressFIFOState() const
FEDBackendStatusRegister(const uint32_t backendStatusRegister)
uint16_t cmMedian(const uint8_t apvIndex) const
FEDDAQTrailer daqTrailer_
bool slinkFullFlag() const
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED
uint8_t ttsNibble() const
FEDBackendStatusRegister & setTotalLengthFIFOState(const FEDBufferState state)
FEDDAQTrailer & setEventLengthIn64BitWords(const uint32_t eventLengthIn64BitWords)
bool qdrMemoryEmptyFlag() const
FEDDAQTrailer & setEventStatusNibble(const uint8_t eventStatusNibble)
bool majorityAddressErrorForFEUnit(const uint8_t internalFEUnitNum) const
FEDBackendStatusRegister & setTTCReadyFlag(const bool bitSet)
FEDDAQTrailer & setCRC(const uint16_t crc)
FEDStatusRegister & setL1ABXFIFOBufferState(const FEDBufferState state)
static const uint16_t FEUNITS_PER_FED
FEDBufferState qdrMemoryState() const
FEDDataType dataType() const
void setQDRMemoryFullFlag(const bool bitSet)
bool feEnabled(const uint8_t internalFEUnitNum) const
FEDBufferState trackerHeaderFIFOState() const
void setL1ABXFIFOFullFlag(const bool bitSet)
static const uint8_t BUFFER_FORMAT_CODE_NEW
FEDBufferBase(const uint8_t *fedBuffer, const size_t fedBufferSize, const bool allowUnrecognizedFormat=false)
bool qdrMemoryFullFlag() const
bool internalFreezeFlag() const
FEDHeaderType headerType() const
const uint8_t * originalBuffer_
void printFlagsForBuffer(const FEDBufferState bufferState, const std::string name, std::ostream &os) const
void setL1ABXFIFOPartialFullFlag(const bool bitSet)
FEDBufferState l1aBxFIFOState() const
FEDTTSBits ttsBits() const
FEDDAQEventType fedDAQEventTypeFromString(const std::string &daqEventTypeString)
std::vector< FEDChannel > channels_
FEDBufferState getBufferState(const uint8_t bufferPosition) const
FEDDAQTrailer & setBadSourceIDBit(const bool bitSet)
bool l1aBxFIFOFullFlag() const
bool l1aBxFIFOEmptyFlag() const
void printHex(const void *pointer, const size_t length, std::ostream &os)
bool checkBufferFormat() const
static const uint16_t FEDCH_PER_FEUNIT
bool trackerHeaderMonitorDataReadyFlag() const
FEDBackendStatusRegister & setTrackerHeaderMonitorDataReadyFlag(const bool bitSet)
size_t bufferSize() const
unsigned short compute_crc_8bit(unsigned short crc, unsigned char data)
FEDBackendStatusRegister & setSLinkFullFlag(const bool bitSet)
FEDBufferState feFPGABufferState() const
uint8_t packetCode() const
uint32_t daqLvl1ID() const
void setBufferSate(const uint8_t bufferPosition, const FEDBufferState state)
void init(const uint8_t *fedBuffer, const size_t fedBufferSize, const bool allowUnrecognizedFormat)
FEDBufferState l1aBxFIFOState() const
TrackerSpecialHeader specialHeader_
virtual void print(std::ostream &os) const
bool doTrackerSpecialHeaderChecks() const
static const uint16_t FEDCH_PER_FED
FEDBufferState totalLengthFIFOState() const
bool checkLengthFromTrailer() const
virtual bool channelGood(const uint8_t internalFEDChannelNum) const
bool slinkFullFlag() const
FEDBackendStatusRegister & setFEEventLengthFIFOState(const FEDBufferState state)
void printHexWord(const uint8_t *pointer, const size_t lengthInBytes, std::ostream &os)
static const uint16_t FED_ID_MAX
static const uint8_t BUFFER_FORMAT_CODE_OLD
uint16_t daqSourceID() const
FEDStatusRegister & setQDRMemoryBufferState(const FEDBufferState state)
FEDBackendStatusRegister & setInternalFreezeFlag(const bool bitSet)
void setL1ABXFIFOEmptyFlag(const bool bitSet)
FEDBackendStatusRegister & setBackpressureFlag(const bool bitSet)
bool checkMajorityAddresses() const
bool feOverflow(const uint8_t internalFEUnitNum) const
FEDBufferState feEventLengthFIFOState() const
FEDStatusRegister fedStatusRegister() const
void setQDRMemoryPartialFullFlag(const bool bitSet)
FEDBackendStatusRegister & setSLinkDownFlag(const bool bitSet)
FEDBufferFormat bufferFormat() const