Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:56

0001 #ifndef EventFilter_Phase2TrackerRawToDigi_Phase2TrackerPhase2TrackerFEDRawChannelUnpacker_H  // {
0002 #define EventFilter_Phase2TrackerRawToDigi_Phase2TrackerPhase2TrackerFEDRawChannelUnpacker_H
0003 
0004 #include "EventFilter/Phase2TrackerRawToDigi/interface/Phase2TrackerFEDDAQHeader.h"
0005 #include "EventFilter/Phase2TrackerRawToDigi/interface/Phase2TrackerFEDDAQTrailer.h"
0006 #include "EventFilter/Phase2TrackerRawToDigi/interface/Phase2TrackerFEDChannel.h"
0007 #include <cstdint>
0008 
0009 namespace Phase2Tracker {
0010 
0011   // unpacker for RAW CBC data
0012   // each bit of the channel is related to one strip
0013   class Phase2TrackerFEDRawChannelUnpacker {
0014   public:
0015     Phase2TrackerFEDRawChannelUnpacker(const Phase2TrackerFEDChannel& channel);
0016     uint8_t stripIndex() const { return currentStrip_; }
0017     bool stripOn() const { return bool((currentWord_ >> bitInWord_) & 0x1); }
0018     bool hasData() const { return valuesLeft_; }
0019     Phase2TrackerFEDRawChannelUnpacker& operator++();
0020     Phase2TrackerFEDRawChannelUnpacker& operator++(int);
0021 
0022   private:
0023     const uint8_t* data_;
0024     uint8_t currentOffset_;
0025     uint8_t currentStrip_;
0026     uint16_t valuesLeft_;
0027     uint8_t currentWord_;
0028     uint8_t bitInWord_;
0029   };  // end of Phase2TrackerFEDRawChannelUnpacker
0030 
0031   inline Phase2TrackerFEDRawChannelUnpacker::Phase2TrackerFEDRawChannelUnpacker(const Phase2TrackerFEDChannel& channel)
0032       : data_(channel.data()),
0033         currentOffset_(channel.offset()),
0034         currentStrip_(0),
0035         valuesLeft_((channel.length()) * 8 - STRIPS_PADDING),
0036         currentWord_(channel.data()[currentOffset_ ^ 7]),
0037         bitInWord_(0) {}
0038 
0039   inline Phase2TrackerFEDRawChannelUnpacker& Phase2TrackerFEDRawChannelUnpacker::operator++() {
0040     bitInWord_++;
0041     currentStrip_++;
0042     if (bitInWord_ > 7) {
0043       bitInWord_ = 0;
0044       currentOffset_++;
0045       currentWord_ = data_[currentOffset_ ^ 7];
0046     }
0047     valuesLeft_--;
0048     return (*this);
0049   }
0050 
0051   inline Phase2TrackerFEDRawChannelUnpacker& Phase2TrackerFEDRawChannelUnpacker::operator++(int) {
0052     ++(*this);
0053     return *this;
0054   }
0055 
0056 }  // namespace Phase2Tracker
0057 
0058 #endif  // } end def EventFilter_Phase2TrackerRawToDigi_Phase2TrackerPhase2TrackerFEDRawChannelUnpacker_H