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";
158 os <<
"Unrecognized";
177 os <<
"Unrecognized";
190 os <<
"Physics trigger";
193 os <<
"Calibration trigger";
196 os <<
"Test trigger";
199 os <<
"Technical trigger";
202 os <<
"Simulated event";
205 os <<
"Traced event";
214 os <<
"Unrecognized";
227 os <<
"Disconected 0";
230 os <<
"Warning overflow";
248 os <<
"Disconected 1";
251 os <<
"Unrecognized";
270 os <<
"Partial Full";
276 os <<
"Unrecognized";
299 if ( (bufferFormatString ==
"OLD_VME") ||
300 (bufferFormatString ==
"BUFFER_FORMAT_OLD_VME") ||
301 (bufferFormatString ==
"Old VME") ) {
304 if ( (bufferFormatString ==
"OLD_SLINK") ||
305 (bufferFormatString ==
"BUFFER_FORMAT_OLD_SLINK") ||
306 (bufferFormatString ==
"Old S-Link") ) {
309 if ( (bufferFormatString ==
"NEW") ||
310 (bufferFormatString ==
"BUFFER_FORMAT_NEW") ||
311 (bufferFormatString ==
"New") ) {
320 if ( (headerTypeString ==
"FULL_DEBUG") ||
321 (headerTypeString ==
"HEADER_TYPE_FULL_DEBUG") ||
322 (headerTypeString ==
"Full debug") ) {
325 if ( (headerTypeString ==
"APV_ERROR") ||
326 (headerTypeString ==
"HEADER_TYPE_APV_ERROR") ||
327 (headerTypeString ==
"APV error") ) {
330 if ( (headerTypeString ==
"None") ||
331 (headerTypeString ==
"none") ) {
340 if ( (readoutModeString ==
"READOUT_MODE_SCOPE") ||
341 (readoutModeString ==
"SCOPE") ||
342 (readoutModeString ==
"SCOPE_MODE") ||
343 (readoutModeString ==
"Scope mode") ) {
346 if ( (readoutModeString ==
"READOUT_MODE_VIRGIN_RAW") ||
347 (readoutModeString ==
"VIRGIN_RAW") ||
348 (readoutModeString ==
"Virgin raw") ) {
351 if ( (readoutModeString ==
"READOUT_MODE_PROC_RAW") ||
352 (readoutModeString ==
"PROC_RAW") ||
353 (readoutModeString ==
"PROCESSED_RAW") ||
354 (readoutModeString ==
"Processed raw") ) {
357 if ( (readoutModeString ==
"READOUT_MODE_ZERO_SUPPRESSED") ||
358 (readoutModeString ==
"ZERO_SUPPRESSED") ||
359 (readoutModeString ==
"Zero suppressed") ) {
362 if ( (readoutModeString ==
"READOUT_MODE_ZERO_SUPPRESSED_LITE") ||
363 (readoutModeString ==
"ZERO_SUPPRESSED_LITE") ||
364 (readoutModeString ==
"Zero suppressed lite") ) {
367 if ( (readoutModeString ==
"READOUT_MODE_SPY") ||
368 (readoutModeString ==
"SPY") ||
369 (readoutModeString ==
"Spy channel") ) {
378 if ( (dataTypeString ==
"REAL") ||
379 (dataTypeString ==
"DATA_TYPE_REAL") ||
380 (dataTypeString ==
"Real data") ) {
383 if ( (dataTypeString ==
"FAKE") ||
384 (dataTypeString ==
"DATA_TYPE_FAKE") ||
385 (dataTypeString ==
"Fake data") ) {
389 std::ostringstream
ss;
390 ss <<
"Trying to convert to a FEDDataType from an invalid string: " << dataTypeString;
396 if ( (daqEventTypeString ==
"PHYSICS") ||
397 (daqEventTypeString ==
"DAQ_EVENT_TYPE_PHYSICS") ||
398 (daqEventTypeString ==
"Physics trigger") ) {
401 if ( (daqEventTypeString ==
"CALIBRATION") ||
402 (daqEventTypeString ==
"DAQ_EVENT_TYPE_CALIBRATION") ||
403 (daqEventTypeString ==
"Calibration trigger") ) {
406 if ( (daqEventTypeString ==
"TEST") ||
407 (daqEventTypeString ==
"DAQ_EVENT_TYPE_TEST") ||
408 (daqEventTypeString ==
"Test trigger") ) {
411 if ( (daqEventTypeString ==
"TECHNICAL") ||
412 (daqEventTypeString ==
"DAQ_EVENT_TYPE_TECHNICAL") ||
413 (daqEventTypeString ==
"Technical trigger") ) {
416 if ( (daqEventTypeString ==
"SIMULATED") ||
417 (daqEventTypeString ==
"DAQ_EVENT_TYPE_SIMULATED") ||
418 (daqEventTypeString ==
"Simulated trigger") ) {
421 if ( (daqEventTypeString ==
"TRACED") ||
422 (daqEventTypeString ==
"DAQ_EVENT_TYPE_TRACED") ||
423 (daqEventTypeString ==
"Traced event") ) {
426 if ( (daqEventTypeString ==
"ERROR") ||
427 (daqEventTypeString ==
"DAQ_EVENT_TYPE_ERROR") ||
428 (daqEventTypeString ==
"Error") ) {
473 const uint16_t mask = (0x0001 <<
num);
474 if (bitSet)
data_ |= mask;
475 else data_ &= (~mask);
487 std::ostringstream
ss;
488 ss <<
"Invalid buffer state: ";
507 std::ostringstream
ss;
508 ss <<
"Invalid buffer state: ";
564 std::ostringstream
ss;
565 ss <<
"Invalid buffer state: ";
576 const uint32_t mask = (0x00000001 <<
num);
577 if (bitSet)
data_ |= mask;
578 else data_ &= (~mask);
588 const bool backpressure,
const bool slinkFull,
589 const bool slinkDown,
const bool internalFreeze,
590 const bool trackerHeaderMonitorDataReady,
const bool ttcReady)
619 if (validFormatByteWhenNotWordSwapped || (!validFormatByteWhenNotWordSwapped && !validFormatByteWhenWordSwapped) ) {
655 const uint8_t
mode = (eventTypeNibble & 0xE);
692 switch (newBufferFormat) {
701 std::ostringstream
ss;
702 ss <<
"Invalid buffer format: ";
717 std::ostringstream
ss;
718 ss <<
"Invalid header type: ";
726 switch(readoutMode) {
739 std::ostringstream
ss;
740 ss <<
"Invalid readout mode: ";
757 std::ostringstream
ss;
758 ss <<
"Invalid data type: ";
766 const uint8_t mask = 0x1 << internalFEUnitNum;
774 const uint8_t mask = 0x1 << internalFEUnitNum;
782 const uint8_t mask = 0x1 << internalFEUnitNum;
790 const uint8_t address,
const uint8_t addressErrorRegister,
791 const uint8_t feEnableRegister,
const uint8_t feOverflowRegister,
836 header_[4] = (l1ID & 0x000000FF);
837 header_[5] = ( (l1ID & 0x0000FF00) >> 8);
838 header_[6] = ( (l1ID & 0x00FF0000) >> 16);
844 header_[3] = ( (bxID & 0x0FF0) >> 4);
851 header_[2] = ( (
header_[2] & 0xF0) | ( (sourceID & 0x0F00) >> 8) );
852 header_[1] = (sourceID & 0x00FF);
889 const bool slinkTransmissionError,
const bool badFEDID,
const bool slinkCRCError,
890 const uint8_t eventStatusNibble)
908 trailer_[4] = (eventLengthIn64BitWords & 0x000000FF);
909 trailer_[5] = ( (eventLengthIn64BitWords & 0x0000FF00) >> 8);
910 trailer_[6] = ( (eventLengthIn64BitWords & 0x00FF0000) >> 16);
917 trailer_[3] = ( (crc >> 8) & 0x00FF );
981 return (
header_[bitNumber/8] & (0x01<<(bitNumber%8)) );
1007 const uint8_t byteNumber = bitNumber/8;
1008 const uint8_t bitInByte = bitNumber%8;
1009 const uint8_t mask = (0x01 << bitInByte);
1010 header_[byteNumber] = ( (
header_[byteNumber] & (~mask)) | (apvGood?mask:0x00) );
1074 !
apvError(internalFEDChannelNum,apvNum) &&
1093 const uint8_t startByteInFEWord = (
FEDCH_PER_FEUNIT-1 - feUnitChanNum) * 6 / 8;
1098 return FEDChannelStatus( ((pFEWord[startByteInFEWord] & 0xC0) >> 6) | ((pFEWord[startByteInFEWord+1] & 0x0F) << 2) );
1100 return FEDChannelStatus( ((pFEWord[startByteInFEWord] & 0xF0) >> 4) | ((pFEWord[startByteInFEWord+1] & 0x03) << 4) );
1136 const uint32_t daqRegister,
const uint32_t daqRegister2)
1163 feWord(internalFEUnitNum)[9] = address;
1183 feWord(internalFEUnitNum)[15] = ( (length & 0xFF00) >> 8);
1184 feWord(internalFEUnitNum)[14] = (length & 0x00FF);
1191 const uint8_t mask = (0x1 << bitInFeWord%8);
1192 byte = ( (byte & (~mask)) | (value?mask:0x0) );
1204 originalBuffer_(fedBuffer),
1205 bufferSize_(fedBufferSize)
1207 init(fedBuffer,fedBufferSize,allowUnrecognizedFormat);
1211 : originalBuffer_(fedBuffer),
1212 bufferSize_(fedBufferSize)
1214 init(fedBuffer,fedBufferSize,allowUnrecognizedFormat);
1218 void FEDBufferBase::init(
const uint8_t* fedBuffer,
const size_t fedBufferSize,
const bool allowUnrecognizedFormat)
1221 static const size_t MIN_BUFFER_SIZE = 8+8+8;
1225 std::ostringstream
ss;
1226 ss <<
"Buffer is too small. "
1227 <<
"Min size is " << MIN_BUFFER_SIZE <<
". "
1238 std::ostringstream
ss;
1239 ss <<
"Buffer format not recognized. "
1246 const uint32_t* originalU32 =
reinterpret_cast<const uint32_t*
>(
originalBuffer_);
1248 uint32_t* newU32 =
reinterpret_cast<uint32_t*
>(newBuffer);
1251 for (
size_t i = 0;
i < sizeU32;
i+=2) {
1252 newU32[
i] = originalU32[
i+1];
1253 newU32[
i+1] = originalU32[
i];
1258 memcpy(newU32,originalU32,8);
1260 memcpy(newU32+sizeU32-2,originalU32+sizeU32-2,8);
1262 for (
size_t i = 2;
i < sizeU32-2;
i+=2) {
1263 newU32[
i] = originalU32[
i+1];
1264 newU32[
i+1] = originalU32[
i];
1287 os <<
"buffer format: " <<
bufferFormat() << std::endl;
1288 os <<
"Buffer size: " <<
bufferSize() <<
" bytes" << std::endl;
1290 os <<
"Source ID: " <<
daqSourceID() << std::endl;
1291 os <<
"Header type: " <<
headerType() << std::endl;
1292 os <<
"Readout mode: " <<
readoutMode() << std::endl;
1293 os <<
"Data type: " <<
dataType() << std::endl;
1294 os <<
"DAQ event type: " <<
daqEventType() << std::endl;
1295 os <<
"TTS state: " <<
daqTTSState() << std::endl;
1296 os <<
"L1 ID: " <<
daqLvl1ID() << std::endl;
1297 os <<
"BX ID: " <<
daqBXID() << std::endl;
1299 os <<
"APVe Address: " << uint16_t(
apveAddress()) << std::endl;
1300 os <<
"Enabled FE units: " << uint16_t(
nFEUnitsEnabled()) << std::endl;
1341 summary <<
"Check buffer type valid: " << (
checkBufferFormat() ?
"passed" :
"FAILED" ) << std::endl;
1342 summary <<
"Check header format valid: " << (
checkHeaderType() ?
"passed" :
"FAILED" ) << std::endl;
1343 summary <<
"Check readout mode valid: " << (
checkReadoutMode() ?
"passed" :
"FAILED" ) << std::endl;
1345 summary <<
"Check FE unit majority addresses: " << (
checkMajorityAddresses() ?
"passed" :
"FAILED" ) << std::endl;
1347 summary <<
"FEs with majority address error: ";
1348 unsigned int badFEs = 0;
1352 summary << uint16_t(iFE) <<
" ";
1356 summary << std::endl;
1357 summary <<
"Number of FE Units with bad addresses: " << badFEs << std::endl;
1359 summary <<
"Check for FE unit buffer overflows: " << (
checkNoFEOverflows() ?
"passed" :
"FAILED" ) << std::endl;
1361 summary <<
"FEs which overflowed: ";
1362 unsigned int badFEs = 0;
1365 summary << uint16_t(iFE) <<
" ";
1369 summary << std::endl;
1370 summary <<
"Number of FE Units which overflowed: " << badFEs << std::endl;
1372 summary <<
"Check for S-Link CRC errors: " << (
checkNoSlinkCRCError() ?
"passed" :
"FAILED" ) << std::endl;
1374 summary <<
"Check CRC: " << (
checkCRC() ?
"passed" :
"FAILED" ) << std::endl;
1375 summary <<
"Check source ID is FED ID: " << (
checkSourceIDs() ?
"passed" :
"FAILED" ) << std::endl;
1376 summary <<
"Check for unexpected source ID at FRL: " << (
checkNoUnexpectedSourceID() ?
"passed" :
"FAILED" ) << std::endl;
1378 summary <<
"Check length from trailer: " << (
checkLengthFromTrailer() ?
"passed" :
"FAILED" ) << std::endl;
1379 return summary.str();
1388 std::ostringstream
ss;
1389 ss <<
"Request for CM median from channel with non-ZS packet code. "
1390 <<
"Packet code is " << uint16_t(
packetCode()) <<
"."
1395 std::ostringstream
ss;
1396 ss <<
"Channel APV index out of range when requesting CM median for APV. "
1397 <<
"Channel APV index is " << uint16_t(apvIndex) <<
"."
1404 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