File indexing completed on 2024-04-06 12:08:48
0001 #ifndef DQM_SiStripMonitorHardware_SiStripFEDSpyBuffer_H
0002 #define DQM_SiStripMonitorHardware_SiStripFEDSpyBuffer_H
0003
0004 #include <string>
0005 #include <ostream>
0006 #include "EventFilter/SiStripRawToDigi/interface/SiStripFEDBufferComponents.h"
0007 #include <cstdint>
0008
0009 namespace sistrip {
0010
0011
0012
0013
0014
0015 static const uint16_t FEDCH_PER_DELAY_CHIP = 4;
0016 static const uint16_t DELAY_CHIPS_PER_FED = FEDCH_PER_FED / FEDCH_PER_DELAY_CHIP;
0017 static const uint16_t SPY_DELAY_CHIP_PAYLOAD_SIZE_IN_BYTES = 376 * 4;
0018 static const uint16_t SPY_DELAY_CHIP_BUFFER_SIZE_IN_BYTES =
0019 SPY_DELAY_CHIP_PAYLOAD_SIZE_IN_BYTES + 8;
0020 static const uint16_t SPY_DELAYCHIP_DATA_OFFSET_IN_BITS = 44;
0021
0022
0023 static const uint16_t SPY_SAMPLES_PER_CHANNEL = 298;
0024 static const uint16_t SPY_BUFFER_SIZE_IN_BYTES = SPY_DELAY_CHIP_BUFFER_SIZE_IN_BYTES * DELAY_CHIPS_PER_FED + 40;
0025
0026
0027
0028
0029
0030
0031
0032
0033 class FEDSpyBuffer : public FEDBufferBase {
0034 public:
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 explicit FEDSpyBuffer(const FEDRawData& fedBuffer);
0045 ~FEDSpyBuffer() override;
0046 void print(std::ostream& os) const override;
0047
0048
0049 uint32_t globalRunNumber() const;
0050
0051 uint32_t spyHeaderL1ID() const;
0052
0053 uint32_t spyHeaderTotalEventCount() const;
0054
0055 uint32_t delayChipL1ID(const uint8_t delayChip) const;
0056
0057 uint32_t delayChipTotalEventCount(const uint8_t delayChip) const;
0058
0059
0060 bool delayChipGood(const uint8_t delayChip) const;
0061
0062 bool channelGood(const uint8_t internalFEDannelNum) const override;
0063
0064 private:
0065
0066 static const uint8_t channelPositionsInData_[FEDCH_PER_DELAY_CHIP];
0067
0068
0069 void findChannels();
0070
0071 const uint8_t* payloadPointer_;
0072 uint16_t payloadLength_;
0073 uint8_t versionId_;
0074 };
0075
0076 class FEDSpyChannelUnpacker {
0077 public:
0078 explicit FEDSpyChannelUnpacker(const FEDChannel& channel);
0079 uint16_t sampleNumber() const;
0080 uint16_t adc() const;
0081 bool hasData() const;
0082 FEDSpyChannelUnpacker& operator++();
0083 FEDSpyChannelUnpacker& operator++(int);
0084
0085 private:
0086 const uint32_t* data_;
0087 size_t currentOffset_;
0088 uint16_t currentSample_;
0089 uint16_t valuesLeft_;
0090 };
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108 inline FEDBufferStatusCode preconstructCheckFEDSpyBuffer(const FEDRawData& fedBuffer) {
0109 const auto st_base = preconstructCheckFEDBufferBase(fedBuffer, true);
0110 if (FEDBufferStatusCode::SUCCESS != st_base)
0111 return st_base;
0112 const TrackerSpecialHeader hdr{fedBuffer.data() + 8};
0113 if (READOUT_MODE_SPY != hdr.readoutMode())
0114 return FEDBufferStatusCode::EXPECT_SPY;
0115 return FEDBufferStatusCode::SUCCESS;
0116 }
0117
0118
0119
0120 inline FEDSpyChannelUnpacker::FEDSpyChannelUnpacker(const FEDChannel& channel)
0121 : data_(reinterpret_cast<const uint32_t*>(channel.data())),
0122 currentOffset_(channel.offset()),
0123 currentSample_(0),
0124 valuesLeft_(channel.length()) {}
0125
0126 inline uint16_t FEDSpyChannelUnpacker::sampleNumber() const { return currentSample_; }
0127
0128 inline bool FEDSpyChannelUnpacker::hasData() const { return (valuesLeft_ != 0); }
0129
0130 inline FEDSpyChannelUnpacker& FEDSpyChannelUnpacker::operator++() {
0131 currentOffset_ += FEDCH_PER_DELAY_CHIP * 10;
0132 currentSample_++;
0133 valuesLeft_--;
0134 return (*this);
0135 }
0136
0137 inline FEDSpyChannelUnpacker& FEDSpyChannelUnpacker::operator++(int) {
0138 ++(*this);
0139 return *this;
0140 }
0141
0142 }
0143
0144 #endif