1 #ifndef EventFilter_SiStripRawToDigi_SiStripFEDBufferComponents_H
2 #define EventFilter_SiStripRawToDigi_SiStripFEDBufferComponents_H
161 uint8_t
internalFEDChannelNum(
const uint8_t internalFEUnitNum,
const uint8_t internalFEUnitChannelNum);
162 void printHex(
const void* pointer,
const size_t length, std::ostream& os);
206 uint32_t
l1ID()
const;
207 uint16_t
bxID()
const;
213 void print(std::ostream& os)
const;
215 const uint8_t*
data()
const;
238 uint16_t
crc()
const;
254 void print(std::ostream& os)
const;
256 const uint8_t*
data()
const;
265 const uint16_t
crc = 0,
268 const bool badFEDID =
false,
290 void print(std::ostream& os)
const;
292 operator uint16_t()
const;
300 const bool trackerHeaderMonitorDataReadyFlagSet =
false,
301 const bool slinkFullFlagSet =
false);
305 void setBit(
const uint8_t num,
const bool bitSet);
331 bool feEnabled(
const uint8_t internalFEUnitNum)
const;
333 bool feOverflow(
const uint8_t internalFEUnitNum)
const;
336 void print(std::ostream& os)
const;
339 const uint8_t*
data()
const;
355 const uint8_t address = 0x00,
356 const uint8_t addressErrorRegister = 0x00,
357 const uint8_t feEnableRegister = 0xFF,
358 const uint8_t feOverflowRegister = 0x00,
410 void print(std::ostream& os)
const;
412 operator uint32_t()
const;
434 const bool backpressure =
false,
435 const bool slinkFull =
false,
436 const bool slinkDown =
false,
437 const bool internalFreeze =
false,
438 const bool trackerHeaderMonitorDataReady =
false,
439 const bool ttcReady =
true);
443 void setBit(
const uint8_t num,
const bool bitSet);
479 bool checkChannelStatusBits(
const uint8_t internalFEUnitNum,
const uint8_t internalFEUnitChannelNum)
const;
483 const uint8_t internalFEUnitChannelNum,
484 const uint8_t apvNum)
const;
485 virtual bool checkStatusBits(
const uint8_t internalFEDChannelNum,
const uint8_t apvNum)
const = 0;
486 virtual void print(std::ostream& os)
const = 0;
489 virtual const uint8_t*
data()
const = 0;
496 virtual void setFEUnitLength(
const uint8_t internalFEUnitNum,
const uint16_t length) = 0;
498 const uint8_t internalFEUnitChannelNum,
508 bool checkStatusBits(
const uint8_t internalFEDChannelNum,
const uint8_t apvNum)
const override;
509 void print(std::ostream& os)
const override;
512 const uint8_t*
data()
const override;
515 const uint8_t internalFEUnitChannelNum,
516 const uint8_t apvNum,
527 void setFEUnitLength(
const uint8_t internalFEUnitNum,
const uint16_t length)
override;
541 bool checkStatusBits(
const uint8_t internalFEDChannelNum,
const uint8_t apvNum)
const override;
542 void print(std::ostream& os)
const override;
549 uint16_t
feUnitLength(
const uint8_t internalFEUnitNum)
const;
550 bool fePresent(
const uint8_t internalFEUnitNum)
const;
558 bool unlocked(
const uint8_t internalFEDChannelNum)
const;
559 bool unlocked(
const uint8_t internalFEUnitNum,
const uint8_t internalFEUnitChannelNum)
const;
561 bool outOfSync(
const uint8_t internalFEDChannelNum)
const;
562 bool outOfSync(
const uint8_t internalFEUnitNum,
const uint8_t internalFEUnitChannelNum)
const;
564 bool apvError(
const uint8_t internalFEDChannelNum,
const uint8_t apvNum)
const;
565 bool apvError(
const uint8_t internalFEUnitNum,
const uint8_t internalFEUnitChannelNum,
const uint8_t apvNum)
const;
567 bool apvAddressError(
const uint8_t internalFEDChannelNum,
const uint8_t apvNum)
const;
569 const uint8_t internalFEUnitChannelNum,
570 const uint8_t apvNum)
const;
573 const uint8_t*
data()
const override;
580 void setFEUnitLength(
const uint8_t internalFEUnitNum,
const uint16_t length)
override;
582 uint8_t*
feWord(
const uint8_t internalFEUnitNum);
583 const uint8_t*
feWord(
const uint8_t internalFEUnitNum)
const;
585 const std::vector<uint8_t>& feMajorityAddresses = std::vector<uint8_t>(
FEUNITS_PER_FED, 0),
586 const std::vector<FEDChannelStatus>& channelStatus =
589 const uint32_t daqRegister = 0,
590 const uint32_t daqRegister2 = 0);
593 bool getBit(
const uint8_t internalFEDChannelNum,
const uint8_t bit)
const;
595 void setBit(
const uint8_t internalFEDChannelNum,
const uint8_t bit,
const bool value);
602 bool apvErrorFromBit(
const uint8_t internalFEDChannelNum,
const uint8_t apvNum)
const;
606 void setUnlocked(
const uint8_t internalFEDChannelNum,
const bool value);
607 void setOutOfSync(
const uint8_t internalFEDChannelNum,
const bool value);
608 void setAPVAddressError(
const uint8_t internalFEDChannelNum,
const uint8_t apvNum,
const bool value);
609 void setAPVError(
const uint8_t internalFEDChannelNum,
const uint8_t apvNum,
const bool value);
620 FEDChannel(
const uint8_t*
const data,
const uint32_t offset);
622 const uint8_t*
data()
const;
631 uint16_t
cmMedian(
const uint8_t apvIndex)
const;
656 void dump(std::ostream& os)
const;
659 virtual void print(std::ostream& os)
const;
687 bool feEnabled(
const uint8_t internalFEUnitNum)
const;
689 bool feOverflow(
const uint8_t internalFEUnitNum)
const;
694 bool channelGood(
const uint8_t internalFEUnitNum,
const uint8_t internalChannelNum)
const;
697 const FEDChannel&
channel(
const uint8_t internalFEUnitNum,
const uint8_t internalChannelNum)
const;
758 bool checkRecognizedFormat =
true) {
759 if (!fedBuffer.
data())
762 static const size_t MIN_BUFFER_SIZE = 8 + 8 + 8;
764 if (fedBuffer.
size() < MIN_BUFFER_SIZE) {
765 LogDebug(
"FEDBuffer") <<
"Buffer is too small. Min size is " << MIN_BUFFER_SIZE <<
". Buffer size is "
766 << fedBuffer.
size() <<
". ";
769 if (checkRecognizedFormat) {
771 LogDebug(
"FEDBuffer") <<
"Buffer format not recognized. Tracker special header: "
819 (physicalOrderStripIndexInChannel / 128));
823 return ((32 * (readout_order % 4)) + (8 * static_cast<uint16_t>(static_cast<float>(readout_order) / 4.0)) -
824 (31 * static_cast<uint16_t>(static_cast<float>(readout_order) / 16.0)));
828 return (4 * ((static_cast<uint16_t>((static_cast<float>(physical_order) / 8.0))) % 4) +
829 static_cast<uint16_t>(static_cast<float>(physical_order) / 32.0) + 16 * (physical_order % 8));
862 const uint8_t
mode = (nibble & 0xF);
908 return statusRegister;
980 return getBit(8 + internalFEUnitNum);
1009 const bool trackerHeaderMonitorDataReadyFlagSet,
1010 const bool slinkFullFlagSet)
1021 : data_(backendStatusRegister) {}
1137 const uint8_t* headerBuffer) {
1138 switch (headerType) {
1144 return std::unique_ptr<FEDFEHeader>();
1149 switch (headerType) {
1155 return std::unique_ptr<FEDFEHeader>();
1160 switch (headerType) {
1166 return std::unique_ptr<FEDFEHeader>();
1171 const uint8_t internalFEUnitChannelNum)
const {
1176 const uint8_t internalFEUnitChannelNum,
1177 const uint8_t apvNum)
const {
1182 const uint8_t internalFEUnitChannelNum,
1192 const uint8_t internalFEUnitChannelNum,
1193 const uint8_t apvNum,
1194 const bool apvGood) {
1203 return feWord(internalFEUnitNum)[9];
1215 return ((
feWord(internalFEUnitNum)[15] << 8) | (
feWord(internalFEUnitNum)[14]));
1227 const uint8_t internalFEUnitChannelNum)
const {
1236 const uint8_t internalFEUnitChannelNum)
const {
1246 const uint8_t internalFEUnitChannelNum,
1247 const uint8_t apvNum)
const {
1257 const uint8_t internalFEUnitChannelNum,
1258 const uint8_t apvNum)
const {
1263 const uint8_t internalFEUnitChannelNum)
const {
1268 return !
getBit(internalFEDChannelNum, 5);
1272 return !
getBit(internalFEDChannelNum, 4);
1282 return !
getBit(internalFEDChannelNum, 0 + 2 * (1 - apvNum));
1286 const uint8_t apvNum)
const {
1287 return !
getBit(internalFEDChannelNum, 1 + 2 * apvNum);
1293 return (pFEWord[bitInFeWord / 8] & (0x1 << (bitInFeWord % 8)));
1297 return (startOfWord[0] | (startOfWord[1] << 8) | (startOfWord[2] << 16) | (startOfWord[3] << 24));
1301 memcpy(startOfWord, &value, 4);
1305 return header_ + internalFEUnitNum * 2 * 8;
1310 return const_cast<uint8_t*
>(std::as_const(*this).feWord(internalFEUnitNum));
1314 setBit(internalFEDChannelNum, 5, !value);
1318 setBit(internalFEDChannelNum, 4, !value);
1322 const uint8_t apvNum,
1324 setBit(internalFEDChannelNum, 1 + 2 * apvNum, !value);
1328 const uint8_t apvNum,
1336 setBit(internalFEDChannelNum, 0 + 2 * (1 - apvNum), !value);
1511 const uint8_t internalChannelNum)
const {
1563 : data_(data), offset_(offset), length_(length) {}
1573 result |= (((
data_[(
offset_ + 4 + 2 * apvIndex) ^ 7]) << 8) & 0x300);
1582 #endif //ndef EventFilter_SiStripRawToDigi_FEDBufferComponents_H
static uint8_t physicalOrderForStripInChannel(const uint8_t readoutOrderStripIndexInChannel)
bool checkNoUnexpectedSourceID() const
FEDBackendStatusRegister & setFEFPGABufferState(const FEDBufferState state)
FEDBackendStatusRegister & setQDRMemoryState(const FEDBufferState state)
FEDBackendStatusRegister & setL1ABXFIFOState(const FEDBufferState state)
uint16_t sourceID() const
bool checkNoExtraHeadersOrTrailers() const
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED8_BOTBOT
bool feDataMissingFlag(const uint8_t internalFEUnitNum) const
bool qdrMemoryPartialFullFlag() const
bool checkSourceIDs() const
void printFlags(std::ostream &os) const
void setBit(const uint8_t num, const bool bitSet)
uint8_t nFEUnitsEnabled() const
bool ttcReadyFlag() const
bool checkReadoutMode() const
bool getBit(const uint8_t num) const
void setQDRMemoryEmptyFlag(const bool bitSet)
uint32_t daqEventLengthIn64bitWords() const
virtual std::string checkSummary() const
uint8_t apveAddress() const
FEDStatusRegister & setTrackerHeaderMonitorDataReadyFlag(const bool bitSet)
FEDBackendStatusRegister & setFrameAddressFIFOState(const FEDBufferState state)
uint32_t daqEventLengthInBytes() const
const uint8_t * getPointerToByteAfterEndOfPayload() const
FEDDAQTrailer daqTrailer() const
static const uint8_t PACKET_CODE_SCOPE
FEDBackendStatusRegister & setTrackerHeaderFIFOState(const FEDBufferState state)
bool slinkDownFlag() const
FEDChannel(const uint8_t *const data, const uint32_t offset, const uint16_t length)
bool l1aBxFIFOPartialFullFlag() const
void print(std::ostream &os) const
static const uint8_t PACKET_CODE_PROC_RAW10
bool checkHeaderType() const
bool doDAQHeaderAndTrailerChecks() const
uint8_t eoeNibble() const
FEDDAQTrailer & setSLinkCRCErrorBit(const bool bitSet)
FEDDAQTrailer & setTTSBits(const FEDTTSBits ttsBits)
bool trackerHeaderMonitorDataReadyFlag() const
FEDReadoutMode readoutMode() const
bool getBit(const uint8_t num) const
FEDStatusRegister(const uint16_t fedStatusRegister)
FEDStatusRegister & setSLinkFullFlag(const bool bitSet)
uint8_t internalFEDChannelNum(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum)
void print(std::ostream &os) const
bool checkNoFEOverflows() const
const uint8_t * getPointerToDataAfterTrackerSpecialHeader() const
FEDDAQTrailer & setSLinkTransmissionErrorBit(const bool bitSet)
FEDHeaderType fedHeaderTypeFromString(const std::string &headerTypeString)
void printFlags(std::ostream &os) const
uint32_t eventLengthIn64BitWords() const
uint16_t calculateFEDBufferCRC(const uint8_t *buffer, const size_t lengthInBytes)
bool backpressureFlag() const
uint8_t packetCodeFromString(const std::string &packetCodeString, FEDReadoutMode mode)
std::ostream & operator<<(std::ostream &os, const FEDBufferFormat &value)
bool slinkCRCError() const
FEDBufferFormat fedBufferFormatFromString(const std::string &bufferFormatString)
size_t size() const
Lenght of the data buffer in bytes.
void setBit(const uint8_t num, const bool bitSet)
FEDDAQEventType daqEventType() const
const uint8_t * orderedBuffer_
void dumpOriginalBuffer(std::ostream &os) const
FEDTTSBits daqTTSState() const
bool checkNoSlinkCRCError() const
bool checkNoSLinkTransmissionError() const
FEDReadoutMode fedReadoutModeFromString(const std::string &readoutModeString)
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED8_TOPBOT
FEDBufferState qdrMemoryState() const
static uint8_t readoutOrderForStripInChannel(const uint8_t physicalOrderStripIndexInChannel)
FEDBufferState frameAddressFIFOState() const
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED10
FEDBackendStatusRegister(const uint32_t backendStatusRegister)
uint16_t cmMedian(const uint8_t apvIndex) const
FEDDAQTrailer daqTrailer_
static const uint8_t PACKET_CODE_VIRGIN_RAW10
bool slinkFullFlag() const
const uint8_t * data() const
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED
uint8_t ttsNibble() const
FEDBackendStatusRegister & setTotalLengthFIFOState(const FEDBufferState state)
bool qdrMemoryEmptyFlag() const
FEDDAQTrailer & setEventLengthIn64BitWords(const uint32_t eventLengthIn64BitWords)
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
void print(std::ostream &os) const
FEDLegacyReadoutMode legacyReadoutMode() const
void setQDRMemoryFullFlag(const bool bitSet)
bool feEnabled(const uint8_t internalFEUnitNum) const
FEDBufferState trackerHeaderFIFOState() const
void dump(std::ostream &os) const
void setL1ABXFIFOFullFlag(const bool bitSet)
static const uint8_t BUFFER_FORMAT_CODE_NEW
bool qdrMemoryFullFlag() const
bool internalFreezeFlag() const
FEDHeaderType headerType() const
const uint8_t * originalBuffer_
bool checkAPVEAddressValid() const
void printFlagsForBuffer(const FEDBufferState bufferState, const std::string name, std::ostream &os) const
static const uint8_t APV_MAX_ADDRESS
uint8_t packetCode(bool legacy=false, const uint8_t internalFEDChannelNum=0) const
void setL1ABXFIFOPartialFullFlag(const bool bitSet)
FEDBufferState l1aBxFIFOState() const
bool slinkTransmissionError() const
FEDTTSBits ttsBits() const
static const uint8_t INVALID
const FEDChannel & channel(const uint8_t internalFEDChannelNum) const
static const uint8_t PACKET_CODE_VIRGIN_RAW8_TOPBOT
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
FEDBufferBase(const FEDRawData &fedBuffer)
bool l1aBxFIFOEmptyFlag() const
static const uint8_t PACKET_CODE_PROC_RAW
static const uint16_t APVS_PER_FED
static const uint8_t PACKET_CODE_VIRGIN_RAW8_BOTBOT
void printHex(const void *pointer, const size_t length, std::ostream &os)
bool checkBufferFormat() const
static uint8_t physicalOrderForStripInAPV(const uint8_t readoutOrderStripIndexInAPV)
static const uint16_t FEDCH_PER_FEUNIT
Constants and enumerated types for FED/FEC systems.
bool trackerHeaderMonitorDataReadyFlag() const
FEDBackendStatusRegister & setTrackerHeaderMonitorDataReadyFlag(const bool bitSet)
const uint8_t * data() const
TrackerSpecialHeader trackerSpecialHeader() const
size_t bufferSize() const
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)
FEDBufferState l1aBxFIFOState() const
TrackerSpecialHeader specialHeader_
virtual void print(std::ostream &os) const
char data[epos_bytes_allocation]
bool doTrackerSpecialHeaderChecks() const
static const uint16_t FEDCH_PER_FED
static const uint16_t STRIPS_PER_APV
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
FEDBufferState totalLengthFIFOState() const
bool checkLengthFromTrailer() const
virtual bool channelGood(const uint8_t internalFEDChannelNum) const
bool slinkFullFlag() const
FEDBackendStatusRegister & setFEEventLengthFIFOState(const FEDBufferState state)
static const uint8_t PACKET_CODE_PROC_RAW8_BOTBOT
static const uint8_t BUFFER_FORMAT_CODE_OLD
FEDBufferStatusCode preconstructCheckFEDBufferBase(const FEDRawData &fedBuffer, bool checkRecognizedFormat=true)
uint8_t eventStatusNibble() const
static const uint16_t SCOPE_MODE_MAX_SCOPE_LENGTH
static uint8_t readoutOrderForStripInAPV(const uint8_t physicalOrderStripIndexInAPV)
uint16_t daqSourceID() const
FEDStatusRegister & setQDRMemoryBufferState(const FEDBufferState state)
FEDBackendStatusRegister & setInternalFreezeFlag(const bool bitSet)
static const uint8_t PACKET_CODE_PROC_RAW8_TOPBOT
void setL1ABXFIFOEmptyFlag(const bool bitSet)
FEDDAQHeader daqHeader() const
FEDBackendStatusRegister & setBackpressureFlag(const bool bitSet)
bool checkMajorityAddresses() const
static const uint8_t PACKET_CODE_VIRGIN_RAW
bool feOverflow(const uint8_t internalFEUnitNum) const
uint32_t eventLengthInBytes() const
FEDBufferState feEventLengthFIFOState() const
FEDStatusRegister fedStatusRegister() const
void setQDRMemoryPartialFullFlag(const bool bitSet)
FEDBackendStatusRegister & setSLinkDownFlag(const bool bitSet)
FEDBufferFormat bufferFormat() const