11 const std::ios_base::fmtflags originalFormatFlags =
os.flags();
12 os << std::hex << std::setfill(
'0') << std::setw(2);
14 os.flags(originalFormatFlags);
17 void printHexWord(
const uint8_t* pointer,
const size_t lengthInBytes, std::ostream&
os) {
18 size_t i = lengthInBytes - 1;
26 void printHex(
const void* pointer,
const size_t lengthInBytes, std::ostream&
os) {
27 const uint8_t* bytePointer =
reinterpret_cast<const uint8_t*
>(pointer);
29 if (lengthInBytes <= 8) {
35 os <<
"word\tbyte\t \t\tbyte" << std::endl;
37 const size_t words = lengthInBytes / 8;
38 const size_t extraBytes = lengthInBytes - 8 * words;
40 for (
size_t w = 0;
w < words;
w++) {
41 const size_t startByte =
w * 8;
42 os <<
w <<
'\t' << startByte + 8 <<
'\t';
44 os <<
"\t\t" << startByte << std::endl;
48 const size_t startByte = words * 8;
49 os << words <<
'\t' << startByte + 8 <<
'\t';
52 while (
p-- > extraBytes) {
56 os <<
"\t\t" << startByte << std::endl;
63 uint16_t crc = 0xFFFF;
64 for (
size_t i = 0;
i < lengthInBytes - 8;
i++) {
67 for (
size_t i = lengthInBytes - 8;
i < lengthInBytes;
i++) {
70 if (
i == lengthInBytes - 4 ||
i == lengthInBytes - 3)
118 os <<
"Unrecognized";
130 os <<
"(L) Scope mode";
133 os <<
"(L) Virgin raw (real)";
136 os <<
"(L) Virgin raw (fake)";
139 os <<
"(L) Processed raw (real)";
142 os <<
"(L) Processed raw (fake)";
145 os <<
"(L) Zero suppressed (real)";
148 os <<
"(L) Zero suppressed (fake)";
151 os <<
"(L) Zero suppressed lite (real)";
154 os <<
"(L) Zero suppressed lite (fake)";
157 os <<
"(L) Spy channel";
160 os <<
"(L) PreMix raw";
166 os <<
"(L) Unrecognized";
184 os <<
"Processed raw";
187 os <<
"Zero suppressed";
190 os <<
"Zero suppressed (fake)";
193 os <<
"Zero suppressed lite";
202 os <<
"Zero suppressed lite CM Override";
205 os <<
"Zero suppressed lite (8 bit, top-stripped)";
208 os <<
"Zero suppressed lite CM Override (8 bit, top-stripped)";
211 os <<
"Zero suppressed lite (8 bit, bottom-stripped)";
214 os <<
"Zero suppressed lite CM Override (8 bit, bottom-stripped)";
217 os <<
"Zero suppressed lite (8 bit, top/bottom-stripped)";
220 os <<
"Zero suppressed lite CM Override (8 bit, top/bottom-stripped)";
229 os <<
"Unrecognized";
241 os <<
"Physics trigger";
244 os <<
"Calibration trigger";
247 os <<
"Test trigger";
250 os <<
"Technical trigger";
253 os <<
"Simulated event";
256 os <<
"Traced event";
265 os <<
"Unrecognized";
277 os <<
"Disconected 0";
280 os <<
"Warning overflow";
298 os <<
"Disconected 1";
301 os <<
"Unrecognized";
319 os <<
"Partial Full";
325 os <<
"Unrecognized";
338 os <<
"Out-of-sync ";
340 os <<
"APV 1 bad address ";
342 os <<
"APV 1 error ";
344 os <<
"APV 0 bad address ";
346 os <<
"APV 0 error ";
358 os <<
"Buffer pointer is NULL.";
361 os <<
"Buffer is too small. Min size is 24.";
364 os <<
"Buffer format not recognized. ";
367 os <<
"Unpacking of spy channel data with FEDBuffer is not supported";
370 os <<
"Buffer is not from spy channel";
373 os <<
"No or invalid header type";
377 os <<
"Channel does not fit into buffer";
380 os <<
"Channel is too short";
387 if ((bufferFormatString ==
"OLD_VME") || (bufferFormatString ==
"BUFFER_FORMAT_OLD_VME") ||
388 (bufferFormatString ==
"Old VME")) {
391 if ((bufferFormatString ==
"OLD_SLINK") || (bufferFormatString ==
"BUFFER_FORMAT_OLD_SLINK") ||
392 (bufferFormatString ==
"Old S-Link")) {
395 if ((bufferFormatString ==
"NEW") || (bufferFormatString ==
"BUFFER_FORMAT_NEW") || (bufferFormatString ==
"New")) {
403 if ((headerTypeString ==
"FULL_DEBUG") || (headerTypeString ==
"HEADER_TYPE_FULL_DEBUG") ||
404 (headerTypeString ==
"Full debug")) {
407 if ((headerTypeString ==
"APV_ERROR") || (headerTypeString ==
"HEADER_TYPE_APV_ERROR") ||
408 (headerTypeString ==
"APV error")) {
411 if ((headerTypeString ==
"None") || (headerTypeString ==
"none")) {
419 if ((readoutModeString ==
"READOUT_MODE_SCOPE") || (readoutModeString ==
"SCOPE") ||
420 (readoutModeString ==
"SCOPE_MODE") || (readoutModeString ==
"Scope mode")) {
423 if ((readoutModeString ==
"READOUT_MODE_VIRGIN_RAW") || (readoutModeString ==
"VIRGIN_RAW") ||
424 (readoutModeString ==
"Virgin raw")) {
427 if ((readoutModeString ==
"READOUT_MODE_PROC_RAW") || (readoutModeString ==
"PROC_RAW") ||
428 (readoutModeString ==
"PROCESSED_RAW") || (readoutModeString ==
"Processed raw")) {
431 if ((readoutModeString ==
"READOUT_MODE_ZERO_SUPPRESSED") || (readoutModeString ==
"ZERO_SUPPRESSED") ||
432 (readoutModeString ==
"Zero suppressed")) {
435 if ((readoutModeString ==
"READOUT_MODE_ZERO_SUPPRESSED_LITE8") || (readoutModeString ==
"ZERO_SUPPRESSED_LITE8") ||
436 (readoutModeString ==
"Zero suppressed lite8")) {
439 if ((readoutModeString ==
"READOUT_MODE_ZERO_SUPPRESSED_LITE8_TOPBOT") ||
440 (readoutModeString ==
"ZERO_SUPPRESSED_LITE8_TOPBOT") ||
441 (readoutModeString ==
"Zero suppressed lite8 TopBot")) {
444 if ((readoutModeString ==
"READOUT_MODE_ZERO_SUPPRESSED_LITE8_BOTBOT") ||
445 (readoutModeString ==
"ZERO_SUPPRESSED_LITE8_BOTBOT") ||
446 (readoutModeString ==
"Zero suppressed lite8 BotBot")) {
449 if ((readoutModeString ==
"READOUT_MODE_ZERO_SUPPRESSED_LITE10") ||
450 (readoutModeString ==
"ZERO_SUPPRESSED_LITE10") || (readoutModeString ==
"Zero suppressed lite10")) {
453 if ((readoutModeString ==
"READOUT_MODE_PREMIX_RAW") || (readoutModeString ==
"PREMIX_RAW") ||
454 (readoutModeString ==
"PreMix Raw")) {
457 if ((readoutModeString ==
"READOUT_MODE_SPY") || (readoutModeString ==
"SPY") ||
458 (readoutModeString ==
"Spy channel")) {
466 if (packetCode ==
"ZERO_SUPPRESSED" || packetCode ==
"Zero suppressed") {
468 }
else if (packetCode ==
"ZERO_SUPPRESSED10" || packetCode ==
"Zero suppressed 10") {
470 }
else if (packetCode ==
"ZERO_SUPPRESSED8_BOTBOT" || packetCode ==
"Zero suppressed 8 BOTBOT") {
472 }
else if (packetCode ==
"ZERO_SUPPRESSED8_TOPBOT" || packetCode ==
"Zero suppressed 8 TOPBOT") {
476 <<
"'" << packetCode <<
"' cannot be converted into a valid packet code for FEDReadoutMode ZERO_SUPPRESSED";
479 if (packetCode ==
"VIRGIN_RAW" || packetCode ==
"Virgin raw") {
481 }
else if (packetCode ==
"VIRGIN_RAW10" || packetCode ==
"Virgin raw 10") {
483 }
else if (packetCode ==
"VIRGIN_RAW8_BOTBOT" || packetCode ==
"Virgin raw 8 BOTBOT") {
485 }
else if (packetCode ==
"VIRGIN_RAW8_TOPBOT" || packetCode ==
"Virgin raw 8 TOPBOT") {
489 <<
"'" << packetCode <<
"' cannot be converted into a valid packet code for FEDReadoutMode VIRGIN_RAW";
492 if (packetCode ==
"PROC_RAW" || packetCode ==
"Processed raw") {
494 }
else if (packetCode ==
"PROC_RAW10" || packetCode ==
"Processed raw 10") {
496 }
else if (packetCode ==
"PROC_RAW8_BOTBOT" || packetCode ==
"Processed raw 8 BOTBOT") {
498 }
else if (packetCode ==
"PROC_RAW8_TOPBOT" || packetCode ==
"Processed raw 8 TOPBOT") {
502 <<
"'" << packetCode <<
"' cannot be converted into a valid packet code for FEDReadoutMode PROC_RAW";
505 if (packetCode ==
"SCOPE" || packetCode ==
"Scope" || packetCode.empty()) {
509 <<
"'" << packetCode <<
"' cannot be converted into a valid packet code for FEDReadoutMode SCOPE";
512 if (!packetCode.empty()) {
513 throw cms::Exception(
"FEDBuffer") <<
"Packet codes are only needed for zero-suppressed (non-lite), virgin raw, " 514 "processed raw and spy data. FEDReadoutMode=" 515 <<
mode <<
" and packetCode='" << packetCode <<
"'";
522 if ((daqEventTypeString ==
"PHYSICS") || (daqEventTypeString ==
"DAQ_EVENT_TYPE_PHYSICS") ||
523 (daqEventTypeString ==
"Physics trigger")) {
526 if ((daqEventTypeString ==
"CALIBRATION") || (daqEventTypeString ==
"DAQ_EVENT_TYPE_CALIBRATION") ||
527 (daqEventTypeString ==
"Calibration trigger")) {
530 if ((daqEventTypeString ==
"TEST") || (daqEventTypeString ==
"DAQ_EVENT_TYPE_TEST") ||
531 (daqEventTypeString ==
"Test trigger")) {
534 if ((daqEventTypeString ==
"TECHNICAL") || (daqEventTypeString ==
"DAQ_EVENT_TYPE_TECHNICAL") ||
535 (daqEventTypeString ==
"Technical trigger")) {
538 if ((daqEventTypeString ==
"SIMULATED") || (daqEventTypeString ==
"DAQ_EVENT_TYPE_SIMULATED") ||
539 (daqEventTypeString ==
"Simulated trigger")) {
542 if ((daqEventTypeString ==
"TRACED") || (daqEventTypeString ==
"DAQ_EVENT_TYPE_TRACED") ||
543 (daqEventTypeString ==
"Traced event")) {
546 if ((daqEventTypeString ==
"ERROR") || (daqEventTypeString ==
"DAQ_EVENT_TYPE_ERROR") ||
547 (daqEventTypeString ==
"Error")) {
558 os <<
"HEADER_MONITOR_READY ";
562 os <<
"QDR_PARTIAL_FULL ";
568 os <<
"L1A_PARTIAL_FULL ";
573 os <<
"FEUNIT" << uint16_t(iFE) <<
"MISSING ";
600 const uint16_t
mask = (0x0001 <<
num);
615 std::ostringstream
ss;
616 ss <<
"Invalid buffer state: ";
634 std::ostringstream
ss;
635 ss <<
"Invalid buffer state: ";
647 os <<
"INTERNAL_FREEZE ";
653 os <<
"BACKPRESSURE ";
657 os <<
"HEADER_MONITOR_READY ";
669 std::ostream&
os)
const {
673 os <<
name <<
"_PARTIAL_FULL ";
699 std::ostringstream
ss;
700 ss <<
"Invalid buffer state: ";
710 const uint32_t
mask = (0x00000001 <<
num);
724 const bool backpressure,
725 const bool slinkFull,
726 const bool slinkDown,
727 const bool internalFreeze,
728 const bool trackerHeaderMonitorDataReady,
753 if (validFormatByteWhenNotWordSwapped || (!validFormatByteWhenNotWordSwapped && !validFormatByteWhenWordSwapped)) {
777 const uint8_t
mode = (eventTypeNibble & 0xF);
805 switch (newBufferFormat) {
814 std::ostringstream
ss;
815 ss <<
"Invalid buffer format: ";
829 std::ostringstream
ss;
830 ss <<
"Invalid header type: ";
856 std::ostringstream
ss;
857 ss <<
"Invalid readout mode: ";
866 const uint8_t
mask = 0x1 << internalFEUnitNum;
874 const uint8_t
mask = 0x1 << internalFEUnitNum;
881 const bool overflow) {
882 const uint8_t
mask = 0x1 << internalFEUnitNum;
891 const uint8_t address,
892 const uint8_t addressErrorRegister,
893 const uint8_t feEnableRegister,
894 const uint8_t feOverflowRegister,
951 const uint16_t sourceID,
982 const bool slinkTransmissionError,
984 const bool slinkCRCError,
985 const uint8_t eventStatusNibble) {
1078 const uint8_t apvNum,
1079 const bool apvGood) {
1083 const uint8_t byteNumber =
bitNumber / 8;
1084 const uint8_t bitInByte =
bitNumber % 8;
1085 const uint8_t
mask = (0x01 << bitInByte);
1147 const uint8_t startByteInFEWord = (
FEDCH_PER_FEUNIT - 1 - feUnitChanNum) * 6 / 8;
1153 ((pFEWord[startByteInFEWord + 1] & 0x0F) << 2));
1156 ((pFEWord[startByteInFEWord + 1] & 0x03) << 4));
1188 const std::vector<uint8_t>& feMajorityAddresses,
1189 const std::vector<FEDChannelStatus>& channelStatus,
1191 const uint32_t daqRegister,
1192 const uint32_t daqRegister2) {
1216 feWord(internalFEUnitNum)[9] = address;
1235 feWord(internalFEUnitNum)[15] = ((length & 0xFF00) >> 8);
1236 feWord(internalFEUnitNum)[14] = (length & 0x00FF);
1242 const uint8_t
mask = (0x1 << bitInFeWord % 8);
1250 originalBuffer_(fedBuffer.
data()),
1251 bufferSize_(fedBuffer.size()) {
1256 : originalBuffer_(fedBuffer.
data()), bufferSize_(fedBuffer.size()) {
1258 if (fillChannelVector)
1271 const uint32_t* originalU32 =
reinterpret_cast<const uint32_t*
>(
originalBuffer_);
1273 uint32_t* newU32 =
reinterpret_cast<uint32_t*
>(newBuffer);
1276 for (
size_t i = 0;
i < sizeU32;
i += 2) {
1277 newU32[
i] = originalU32[
i + 1];
1278 newU32[
i + 1] = originalU32[
i];
1283 memcpy(newU32, originalU32, 8);
1285 memcpy(newU32 + sizeU32 - 2, originalU32 + sizeU32 - 2, 8);
1287 for (
size_t i = 2;
i < sizeU32 - 2;
i += 2) {
1288 newU32[
i] = originalU32[
i + 1];
1289 newU32[
i + 1] = originalU32[
i];
1312 os <<
"Buffer size: " <<
bufferSize() <<
" bytes" << std::endl;
1320 os <<
"BX ID: " <<
daqBXID() << std::endl;
1321 os <<
"FED status register flags: ";
1324 os <<
"APVe Address: " << uint16_t(
apveAddress()) << std::endl;
1364 summary <<
"FEs with majority address error: ";
1365 unsigned int badFEs = 0;
1370 summary << uint16_t(iFE) <<
" ";
1375 summary <<
"Number of FE Units with bad addresses: " << badFEs << std::endl;
1379 summary <<
"FEs which overflowed: ";
1380 unsigned int badFEs = 0;
1383 summary << uint16_t(iFE) <<
" ";
1388 summary <<
"Number of FE Units which overflowed: " << badFEs << std::endl;
1393 summary <<
"Check CRC: " << (
checkCRC() ?
"passed" :
"FAILED") << std::endl;
1397 summary <<
"Check there are no extra headers or trailers: " FEDBufferFormat bufferFormat() const
size_t bufferSize() const
FEDBackendStatusRegister & setFEFPGABufferState(const FEDBufferState state)
FEDBackendStatusRegister & setQDRMemoryState(const FEDBufferState state)
FEDReadoutMode readoutMode() const
FEDBackendStatusRegister & setL1ABXFIFOState(const FEDBufferState state)
void printFlags(std::ostream &os) const
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED8_BOTBOT
bool checkNoSLinkTransmissionError() const
bool feOverflow(const uint8_t internalFEUnitNum) const
void printHexValue(const uint8_t value, std::ostream &os)
void setBit(const uint8_t num, const bool bitSet)
FEDTTSBits daqTTSState() const
static const uint16_t FED_ID_MIN
bool trackerHeaderMonitorDataReadyFlag() const
void setQDRMemoryEmptyFlag(const bool bitSet)
bool l1aBxFIFOEmptyFlag() const
uint32_t eventLengthIn64BitWords() const
FEDBackendStatusRegister & setFrameAddressFIFOState(const FEDBufferState state)
static const uint8_t PACKET_CODE_SCOPE
FEDBackendStatusRegister & setTrackerHeaderFIFOState(const FEDBufferState state)
static const uint8_t PACKET_CODE_PROC_RAW10
FEDDAQTrailer & setSLinkCRCErrorBit(const bool bitSet)
FEDDAQTrailer & setTTSBits(const FEDTTSBits ttsBits)
bool l1aBxFIFOFullFlag() const
FEDBufferState qdrMemoryState() const
uint8_t internalFEDChannelNum(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum)
uint32_t daqEventLengthInBytes() const
bool slinkFullFlag() const
bool checkNoFEOverflows() const
bool checkReadoutMode() const
FEDDAQTrailer & setSLinkTransmissionErrorBit(const bool bitSet)
FEDHeaderType fedHeaderTypeFromString(const std::string &headerTypeString)
bool l1aBxFIFOPartialFullFlag() const
uint16_t calculateFEDBufferCRC(const uint8_t *buffer, const size_t lengthInBytes)
FEDHeaderType headerType() const
void printFlagsForBuffer(const FEDBufferState bufferState, const std::string name, std::ostream &os) const
bool ttcReadyFlag() const
uint8_t packetCodeFromString(const std::string &packetCodeString, FEDReadoutMode mode)
virtual std::string checkSummary() const
std::ostream & operator<<(std::ostream &os, const FEDBufferFormat &value)
FEDTTSBits ttsBits() const
bool slinkCRCError() const
bool getBit(const uint8_t num) const
FEDBufferFormat fedBufferFormatFromString(const std::string &bufferFormatString)
void setBit(const uint8_t num, const bool bitSet)
bool checkNoSlinkCRCError() const
bool majorityAddressErrorForFEUnit(const uint8_t internalFEUnitNum) const
const uint8_t * orderedBuffer_
bool qdrMemoryPartialFullFlag() const
FEDBufferState qdrMemoryState() const
bool feEnabled(const uint8_t internalFEUnitNum) const
bool feDataMissingFlag(const uint8_t internalFEUnitNum) const
FEDReadoutMode fedReadoutModeFromString(const std::string &readoutModeString)
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED8_TOPBOT
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED10
FEDBackendStatusRegister(const uint32_t backendStatusRegister)
FEDDAQTrailer daqTrailer_
static const uint8_t PACKET_CODE_VIRGIN_RAW10
FEDBufferState l1aBxFIFOState() const
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED
FEDBufferState l1aBxFIFOState() const
FEDBackendStatusRegister & setTotalLengthFIFOState(const FEDBufferState state)
FEDDAQTrailer & setEventLengthIn64BitWords(const uint32_t eventLengthIn64BitWords)
uint16_t daqSourceID() const
FEDDAQTrailer & setEventStatusNibble(const uint8_t eventStatusNibble)
FEDBackendStatusRegister & setTTCReadyFlag(const bool bitSet)
FEDDAQTrailer & setCRC(const uint16_t crc)
uint8_t nFEUnitsEnabled() const
FEDStatusRegister & setL1ABXFIFOBufferState(const FEDBufferState state)
static const uint16_t FEUNITS_PER_FED
bool checkNoExtraHeadersOrTrailers() const
bool checkLengthFromTrailer() const
bool slinkFullFlag() const
void setQDRMemoryFullFlag(const bool bitSet)
FEDDAQEventType daqEventType() const
FEDBufferState getBufferState(const uint8_t bufferPosition) const
void setL1ABXFIFOFullFlag(const bool bitSet)
static const uint8_t BUFFER_FORMAT_CODE_NEW
const uint8_t * originalBuffer_
FEDBufferState frameAddressFIFOState() const
void setL1ABXFIFOPartialFullFlag(const bool bitSet)
bool slinkTransmissionError() const
bool qdrMemoryFullFlag() const
FEDBufferState trackerHeaderFIFOState() const
FEDBufferState feFPGABufferState() const
static const uint8_t PACKET_CODE_VIRGIN_RAW8_TOPBOT
FEDDAQEventType fedDAQEventTypeFromString(const std::string &daqEventTypeString)
bool checkSourceIDs() const
std::vector< FEDChannel > channels_
bool checkMajorityAddresses() const
bool slinkDownFlag() const
FEDDAQTrailer & setBadSourceIDBit(const bool bitSet)
FEDBufferBase(const FEDRawData &fedBuffer)
uint32_t daqLvl1ID() const
static const uint8_t PACKET_CODE_PROC_RAW
static const uint8_t PACKET_CODE_VIRGIN_RAW8_BOTBOT
void printHex(const void *pointer, const size_t length, std::ostream &os)
bool internalFreezeFlag() const
static const uint16_t FEDCH_PER_FEUNIT
uint8_t ttsNibble() const
bool checkNoUnexpectedSourceID() const
FEDBackendStatusRegister & setTrackerHeaderMonitorDataReadyFlag(const bool bitSet)
bool backpressureFlag() const
uint8_t eventStatusNibble() const
FEDBufferState feEventLengthFIFOState() const
unsigned short compute_crc_8bit(unsigned short crc, unsigned char data)
FEDBackendStatusRegister & setSLinkFullFlag(const bool bitSet)
void setBufferSate(const uint8_t bufferPosition, const FEDBufferState state)
TrackerSpecialHeader specialHeader_
virtual bool channelGood(const uint8_t internalFEDChannelNum) const
FEDBufferState totalLengthFIFOState() const
char data[epos_bytes_allocation]
static const uint16_t FEDCH_PER_FED
void printFlags(std::ostream &os) const
FEDStatusRegister fedStatusRegister() const
bool qdrMemoryEmptyFlag() const
FEDBackendStatusRegister & setFEEventLengthFIFOState(const FEDBufferState state)
static const uint8_t PACKET_CODE_PROC_RAW8_BOTBOT
bool checkBufferFormat() const
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
FEDStatusRegister & setQDRMemoryBufferState(const FEDBufferState state)
bool checkHeaderType() const
bool trackerHeaderMonitorDataReadyFlag() const
FEDBackendStatusRegister & setInternalFreezeFlag(const bool bitSet)
static const uint8_t PACKET_CODE_PROC_RAW8_TOPBOT
void setL1ABXFIFOEmptyFlag(const bool bitSet)
FEDBackendStatusRegister & setBackpressureFlag(const bool bitSet)
static const uint8_t PACKET_CODE_VIRGIN_RAW
uint8_t apveAddress() const
void setQDRMemoryPartialFullFlag(const bool bitSet)
FEDBackendStatusRegister & setSLinkDownFlag(const bool bitSet)
virtual void print(std::ostream &os) const