Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:11:58

0001 #include "DQM/SiStripMonitorHardware/interface/SiStripFEDSpyBuffer.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 
0004 namespace sistrip {
0005 
0006   const uint8_t FEDSpyBuffer::channelPositionsInData_[FEDCH_PER_DELAY_CHIP] = {0, 3, 2, 1};
0007 
0008   FEDSpyBuffer::FEDSpyBuffer(const FEDRawData& fedBuffer)
0009       : FEDBufferBase(fedBuffer),
0010         payloadPointer_(getPointerToDataAfterTrackerSpecialHeader() + 16),
0011         payloadLength_(getPointerToByteAfterEndOfPayload() - payloadPointer_),
0012         versionId_(*(getPointerToDataAfterTrackerSpecialHeader() + 3)) {
0013     //Check the buffer format version ID and take action for any exceptions
0014     if (versionId_ == 0x00) {
0015       payloadPointer_ = payloadPointer_ - 8;
0016     }
0017     //find the channel start positions
0018     findChannels();
0019   }
0020 
0021   FEDSpyBuffer::~FEDSpyBuffer() {}
0022 
0023   void FEDSpyBuffer::findChannels() {
0024     size_t delayChipStartByteIndex = 0;
0025     //Loop over delay chips checking their data fits into buffer and setting up channel objects with correct offset
0026     for (uint8_t iDelayChip = 0; iDelayChip < DELAY_CHIPS_PER_FED; ++iDelayChip) {
0027       if (delayChipStartByteIndex + SPY_DELAY_CHIP_BUFFER_SIZE_IN_BYTES > payloadLength_) {
0028         throw cms::Exception("FEDSpyBuffer") << "Delay chip " << uint16_t(iDelayChip) << " does not fit into buffer. "
0029                                              << "Buffer size is " << bufferSize() << " delay chip data starts at "
0030                                              << delayChipStartByteIndex + 8 + 8 + 8 + 8 << ". ";
0031       }
0032       for (uint8_t i = 0; i < FEDCH_PER_DELAY_CHIP; i++) {
0033         const uint8_t chanelIndexInDataOrder = channelPositionsInData_[i];
0034         const uint8_t fedCh = iDelayChip * FEDCH_PER_DELAY_CHIP + i;
0035         const size_t channelOffsetInBits = SPY_DELAYCHIP_DATA_OFFSET_IN_BITS + 10 * chanelIndexInDataOrder;
0036         channels_[fedCh] =
0037             FEDChannel(payloadPointer_ + delayChipStartByteIndex, channelOffsetInBits, SPY_SAMPLES_PER_CHANNEL);
0038       }
0039       delayChipStartByteIndex += SPY_DELAY_CHIP_BUFFER_SIZE_IN_BYTES;
0040     }
0041   }
0042 
0043   uint32_t FEDSpyBuffer::globalRunNumber() const {
0044     if (versionId_ < 0x02) {
0045       return 0;
0046     }
0047     const uint8_t* runNumberPointer = getPointerToDataAfterTrackerSpecialHeader() + 4;
0048     uint32_t result = 0;
0049     result |= runNumberPointer[0];
0050     result |= (uint32_t(runNumberPointer[1]) << 8);
0051     result |= (uint32_t(runNumberPointer[2]) << 16);
0052     result |= (uint32_t(runNumberPointer[3]) << 24);
0053     return result;
0054   }
0055 
0056   uint32_t FEDSpyBuffer::spyHeaderL1ID() const {
0057     if (versionId_ == 0x00) {
0058       return delayChipL1ID(0);
0059     }
0060     uint32_t result = 0;
0061     const uint8_t* spyCounters = payloadPointer_ - 8;
0062     result |= spyCounters[4];
0063     result |= (uint32_t(spyCounters[5]) << 8);
0064     result |= (uint32_t(spyCounters[6]) << 16);
0065     result |= (uint32_t(spyCounters[7]) << 24);
0066     return result;
0067   }
0068 
0069   uint32_t FEDSpyBuffer::spyHeaderTotalEventCount() const {
0070     if (versionId_ == 0x00) {
0071       return delayChipTotalEventCount(0);
0072     }
0073     uint32_t result = 0;
0074     const uint8_t* spyCounters = payloadPointer_ - 8;
0075     result |= spyCounters[0];
0076     result |= (uint32_t(spyCounters[1]) << 8);
0077     result |= (uint32_t(spyCounters[2]) << 16);
0078     result |= (uint32_t(spyCounters[3]) << 24);
0079     return result;
0080   }
0081 
0082   uint32_t FEDSpyBuffer::delayChipL1ID(const uint8_t delayChip) const {
0083     const uint8_t* delayChipCounters = payloadPointer_ + ((SPY_DELAY_CHIP_BUFFER_SIZE_IN_BYTES) * (delayChip + 1) - 8);
0084     uint32_t result = 0;
0085     result |= delayChipCounters[4];
0086     result |= (uint32_t(delayChipCounters[5]) << 8);
0087     result |= (uint32_t(delayChipCounters[6]) << 16);
0088     result |= (uint32_t(delayChipCounters[7]) << 24);
0089     return result;
0090   }
0091 
0092   uint32_t FEDSpyBuffer::delayChipTotalEventCount(const uint8_t delayChip) const {
0093     const uint8_t* delayChipCounters = payloadPointer_ + ((SPY_DELAY_CHIP_BUFFER_SIZE_IN_BYTES) * (delayChip + 1) - 8);
0094     uint32_t result = 0;
0095     result |= delayChipCounters[0];
0096     result |= (uint32_t(delayChipCounters[1]) << 8);
0097     result |= (uint32_t(delayChipCounters[2]) << 16);
0098     result |= (uint32_t(delayChipCounters[3]) << 24);
0099     return result;
0100   }
0101 
0102   void FEDSpyBuffer::print(std::ostream& os) const {
0103     FEDBufferBase::print(os);
0104     //TODO
0105   }
0106 
0107   bool FEDSpyBuffer::delayChipGood(const uint8_t delayChip) const {
0108     if (versionId_ == 0x00) {
0109       if (delayChip == 0)
0110         return true;
0111     }
0112     uint32_t l1CountBefore = 0;
0113     uint32_t totalEventCountBefore = 0;
0114     if (delayChip == 0) {
0115       l1CountBefore = spyHeaderL1ID();
0116       totalEventCountBefore = spyHeaderTotalEventCount();
0117     } else {
0118       l1CountBefore = delayChipL1ID(delayChip - 1);
0119       totalEventCountBefore = delayChipTotalEventCount(delayChip - 1);
0120     }
0121     const uint32_t l1CountAfter = delayChipL1ID(delayChip);
0122     const uint32_t totalEventCountAfter = delayChipTotalEventCount(delayChip);
0123     const bool eventMatches = ((l1CountBefore == l1CountAfter) && (totalEventCountBefore == totalEventCountAfter));
0124     if (!eventMatches) {
0125       std::ostringstream ss;
0126       ss << "Delay chip data was overwritten on chip " << uint16_t(delayChip) << " L1A before: " << l1CountBefore
0127          << " after: " << l1CountAfter << " Total event count before: " << totalEventCountBefore
0128          << " after: " << totalEventCountAfter << std::endl;
0129       dump(ss);
0130       edm::LogInfo("FEDSpyBuffer") << ss.str();
0131     }
0132     return eventMatches;
0133   }
0134 
0135   bool FEDSpyBuffer::channelGood(const uint8_t internalFEDChannelNum) const {
0136     return delayChipGood(internalFEDChannelNum / FEDCH_PER_DELAY_CHIP);
0137   }
0138 
0139   uint16_t FEDSpyChannelUnpacker::adc() const {
0140     const size_t offsetWords = currentOffset_ / 32;
0141     const uint8_t offsetBits = currentOffset_ % 32;
0142     if (offsetBits < 23) {
0143       return ((data_[offsetWords] >> (32 - 10 - offsetBits)) & 0x3FF);
0144     } else {
0145       return (((data_[offsetWords] << (10 - 32 + offsetBits)) & 0x3FF) |
0146               ((data_[offsetWords + 1] & (0xFFC00000 << (32 - offsetBits))) >> (64 - 10 - offsetBits)));
0147     }
0148   }
0149 
0150 }  // namespace sistrip