CMS 3D CMS Logo

SiStripFEDSpyBuffer.h
Go to the documentation of this file.
1 #ifndef DQM_SiStripMonitorHardware_SiStripFEDSpyBuffer_H
2 #define DQM_SiStripMonitorHardware_SiStripFEDSpyBuffer_H
3 
4 #include <string>
5 #include <ostream>
7 #include <cstdint>
8 
9 namespace sistrip {
10 
11  //
12  // Constants
13  //
14 
15  static const uint16_t FEDCH_PER_DELAY_CHIP = 4;
17  static const uint16_t SPY_DELAY_CHIP_PAYLOAD_SIZE_IN_BYTES = 376 * 4; // 376 32bit words
18  static const uint16_t SPY_DELAY_CHIP_BUFFER_SIZE_IN_BYTES =
19  SPY_DELAY_CHIP_PAYLOAD_SIZE_IN_BYTES + 8; // Extra 8 bytes for counters
20  static const uint16_t SPY_DELAYCHIP_DATA_OFFSET_IN_BITS = 44; // Offset to start of data
21  //static const uint16_t SPY_SAMPLES_PER_CHANNEL = ( (SPY_DELAY_CHIP_BUFFER_SIZE_IN_BYTES * 8) - SPY_DELAYCHIP_DATA_OFFSET_IN_BITS ) / 10 / FEDCH_PER_DELAY_CHIP;
22  // TW Dirty hack to lose the 3 samples from the end that screw things up...
23  static const uint16_t SPY_SAMPLES_PER_CHANNEL = 298;
24  static const uint16_t SPY_BUFFER_SIZE_IN_BYTES = SPY_DELAY_CHIP_BUFFER_SIZE_IN_BYTES * DELAY_CHIPS_PER_FED + 40;
25  // Delaychip data + 8 bytes header for counters + 8 bytes for word with delay chip enable bits
26  // + 16 bytes for DAQ header and trailer
27 
28  //
29  // Class definitions
30  //
31 
32  //class representing spy channel buffers
33  class FEDSpyBuffer : public FEDBufferBase {
34  public:
35  //construct from buffer
36  FEDSpyBuffer(const uint8_t* fedBuffer, const size_t fedBufferSize);
37  ~FEDSpyBuffer() override;
38  void print(std::ostream& os) const override;
39 
40  //get the run number from the corresponding global run
41  uint32_t globalRunNumber() const;
42  //get the L1 ID stored in the spy header
43  uint32_t spyHeaderL1ID() const;
44  //get the total frame count stored in the spy header
45  uint32_t spyHeaderTotalEventCount() const;
46  //get the L1 ID after reading a given delay chip
47  uint32_t delayChipL1ID(const uint8_t delayChip) const;
48  //get the total event count after reading a given delay chip
49  uint32_t delayChipTotalEventCount(const uint8_t delayChip) const;
50 
51  //checks that a delay chip is complete i.e. that it all came from the same event
52  bool delayChipGood(const uint8_t delayChip) const;
53  //checks that a channel is usable (i.e. that the delay chip it is on is good)
54  bool channelGood(const uint8_t internalFEDannelNum) const override;
55 
56  private:
57  //mapping of channel index to position in data
59 
60  //setup the channel objects
61  void findChannels();
62 
63  const uint8_t* payloadPointer_;
64  uint16_t payloadLength_;
65  uint8_t versionId_;
66  };
67 
69  public:
70  explicit FEDSpyChannelUnpacker(const FEDChannel& channel);
71  uint16_t sampleNumber() const;
72  uint16_t adc() const;
73  bool hasData() const;
74  FEDSpyChannelUnpacker& operator++();
75  FEDSpyChannelUnpacker& operator++(int);
76 
77  private:
78  const uint32_t* data_;
80  uint16_t currentSample_;
81  uint16_t valuesLeft_;
82  };
83 
84  //
85  // Inline function definitions
86  //
87 
88  //FEDSpyChannelUnpacker
89 
91  : data_(reinterpret_cast<const uint32_t*>(channel.data())),
92  currentOffset_(channel.offset()),
93  currentSample_(0),
94  valuesLeft_(channel.length()) {}
95 
96  inline uint16_t FEDSpyChannelUnpacker::sampleNumber() const { return currentSample_; }
97 
98  inline bool FEDSpyChannelUnpacker::hasData() const { return (valuesLeft_ != 0); }
99 
101  currentOffset_ += FEDCH_PER_DELAY_CHIP * 10;
102  currentSample_++;
103  valuesLeft_--;
104  return (*this);
105  }
106 
108  ++(*this);
109  return *this;
110  }
111 
112 } // namespace sistrip
113 
114 #endif //ndef DQM_SiStripMonitorHardware_SiStripFEDSpyBuffer_H
FEDSpyChannelUnpacker(const FEDChannel &channel)
void print(std::ostream &os) const override
static const uint16_t SPY_BUFFER_SIZE_IN_BYTES
static const uint16_t SPY_SAMPLES_PER_CHANNEL
sistrip classes
uint32_t globalRunNumber() const
static const uint16_t DELAY_CHIPS_PER_FED
static const uint16_t SPY_DELAY_CHIP_PAYLOAD_SIZE_IN_BYTES
uint32_t delayChipTotalEventCount(const uint8_t delayChip) const
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
uint32_t spyHeaderL1ID() const
const FEDChannel & channel(const uint8_t internalFEDChannelNum) const
static const uint16_t FEDCH_PER_DELAY_CHIP
static const uint16_t SPY_DELAY_CHIP_BUFFER_SIZE_IN_BYTES
const uint8_t * payloadPointer_
bool channelGood(const uint8_t internalFEDannelNum) const override
static const uint8_t channelPositionsInData_[FEDCH_PER_DELAY_CHIP]
FEDSpyBuffer(const uint8_t *fedBuffer, const size_t fedBufferSize)
uint32_t spyHeaderTotalEventCount() const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
uint32_t delayChipL1ID(const uint8_t delayChip) const
static const uint16_t FEDCH_PER_FED
bool delayChipGood(const uint8_t delayChip) const
static const uint16_t SPY_DELAYCHIP_DATA_OFFSET_IN_BITS
FEDSpyChannelUnpacker & operator++()