CMS 3D CMS Logo

SiStripFEDSpyBuffer.cc
Go to the documentation of this file.
3 
4 namespace sistrip {
5 
7 
9  : FEDBufferBase(fedBuffer),
10  payloadPointer_(getPointerToDataAfterTrackerSpecialHeader() + 16),
11  payloadLength_(getPointerToByteAfterEndOfPayload() - payloadPointer_),
12  versionId_(*(getPointerToDataAfterTrackerSpecialHeader() + 3)) {
13  //Check the buffer format version ID and take action for any exceptions
14  if (versionId_ == 0x00) {
16  }
17  //find the channel start positions
18  findChannels();
19  }
20 
22 
24  size_t delayChipStartByteIndex = 0;
25  //Loop over delay chips checking their data fits into buffer and setting up channel objects with correct offset
26  for (uint8_t iDelayChip = 0; iDelayChip < DELAY_CHIPS_PER_FED; ++iDelayChip) {
27  if (delayChipStartByteIndex + SPY_DELAY_CHIP_BUFFER_SIZE_IN_BYTES > payloadLength_) {
28  throw cms::Exception("FEDSpyBuffer") << "Delay chip " << uint16_t(iDelayChip) << " does not fit into buffer. "
29  << "Buffer size is " << bufferSize() << " delay chip data starts at "
30  << delayChipStartByteIndex + 8 + 8 + 8 + 8 << ". ";
31  }
32  for (uint8_t i = 0; i < FEDCH_PER_DELAY_CHIP; i++) {
33  const uint8_t chanelIndexInDataOrder = channelPositionsInData_[i];
34  const uint8_t fedCh = iDelayChip * FEDCH_PER_DELAY_CHIP + i;
35  const size_t channelOffsetInBits = SPY_DELAYCHIP_DATA_OFFSET_IN_BITS + 10 * chanelIndexInDataOrder;
36  channels_[fedCh] =
37  FEDChannel(payloadPointer_ + delayChipStartByteIndex, channelOffsetInBits, SPY_SAMPLES_PER_CHANNEL);
38  }
39  delayChipStartByteIndex += SPY_DELAY_CHIP_BUFFER_SIZE_IN_BYTES;
40  }
41  }
42 
43  uint32_t FEDSpyBuffer::globalRunNumber() const {
44  if (versionId_ < 0x02) {
45  return 0;
46  }
47  const uint8_t* runNumberPointer = getPointerToDataAfterTrackerSpecialHeader() + 4;
48  uint32_t result = 0;
49  result |= runNumberPointer[0];
50  result |= (uint32_t(runNumberPointer[1]) << 8);
51  result |= (uint32_t(runNumberPointer[2]) << 16);
52  result |= (uint32_t(runNumberPointer[3]) << 24);
53  return result;
54  }
55 
56  uint32_t FEDSpyBuffer::spyHeaderL1ID() const {
57  if (versionId_ == 0x00) {
58  return delayChipL1ID(0);
59  }
60  uint32_t result = 0;
61  const uint8_t* spyCounters = payloadPointer_ - 8;
62  result |= spyCounters[4];
63  result |= (uint32_t(spyCounters[5]) << 8);
64  result |= (uint32_t(spyCounters[6]) << 16);
65  result |= (uint32_t(spyCounters[7]) << 24);
66  return result;
67  }
68 
70  if (versionId_ == 0x00) {
71  return delayChipTotalEventCount(0);
72  }
73  uint32_t result = 0;
74  const uint8_t* spyCounters = payloadPointer_ - 8;
75  result |= spyCounters[0];
76  result |= (uint32_t(spyCounters[1]) << 8);
77  result |= (uint32_t(spyCounters[2]) << 16);
78  result |= (uint32_t(spyCounters[3]) << 24);
79  return result;
80  }
81 
82  uint32_t FEDSpyBuffer::delayChipL1ID(const uint8_t delayChip) const {
83  const uint8_t* delayChipCounters = payloadPointer_ + ((SPY_DELAY_CHIP_BUFFER_SIZE_IN_BYTES) * (delayChip + 1) - 8);
84  uint32_t result = 0;
85  result |= delayChipCounters[4];
86  result |= (uint32_t(delayChipCounters[5]) << 8);
87  result |= (uint32_t(delayChipCounters[6]) << 16);
88  result |= (uint32_t(delayChipCounters[7]) << 24);
89  return result;
90  }
91 
92  uint32_t FEDSpyBuffer::delayChipTotalEventCount(const uint8_t delayChip) const {
93  const uint8_t* delayChipCounters = payloadPointer_ + ((SPY_DELAY_CHIP_BUFFER_SIZE_IN_BYTES) * (delayChip + 1) - 8);
94  uint32_t result = 0;
95  result |= delayChipCounters[0];
96  result |= (uint32_t(delayChipCounters[1]) << 8);
97  result |= (uint32_t(delayChipCounters[2]) << 16);
98  result |= (uint32_t(delayChipCounters[3]) << 24);
99  return result;
100  }
101 
102  void FEDSpyBuffer::print(std::ostream& os) const {
104  //TODO
105  }
106 
107  bool FEDSpyBuffer::delayChipGood(const uint8_t delayChip) const {
108  if (versionId_ == 0x00) {
109  if (delayChip == 0)
110  return true;
111  }
112  uint32_t l1CountBefore = 0;
113  uint32_t totalEventCountBefore = 0;
114  if (delayChip == 0) {
115  l1CountBefore = spyHeaderL1ID();
116  totalEventCountBefore = spyHeaderTotalEventCount();
117  } else {
118  l1CountBefore = delayChipL1ID(delayChip - 1);
119  totalEventCountBefore = delayChipTotalEventCount(delayChip - 1);
120  }
121  const uint32_t l1CountAfter = delayChipL1ID(delayChip);
122  const uint32_t totalEventCountAfter = delayChipTotalEventCount(delayChip);
123  const bool eventMatches = ((l1CountBefore == l1CountAfter) && (totalEventCountBefore == totalEventCountAfter));
124  if (!eventMatches) {
125  std::ostringstream ss;
126  ss << "Delay chip data was overwritten on chip " << uint16_t(delayChip) << " L1A before: " << l1CountBefore
127  << " after: " << l1CountAfter << " Total event count before: " << totalEventCountBefore
128  << " after: " << totalEventCountAfter << std::endl;
129  dump(ss);
130  edm::LogInfo("FEDSpyBuffer") << ss.str();
131  }
132  return eventMatches;
133  }
134 
137  }
138 
139  uint16_t FEDSpyChannelUnpacker::adc() const {
140  const size_t offsetWords = currentOffset_ / 32;
141  const uint8_t offsetBits = currentOffset_ % 32;
142  if (offsetBits < 23) {
143  return ((data_[offsetWords] >> (32 - 10 - offsetBits)) & 0x3FF);
144  } else {
145  return (((data_[offsetWords] << (10 - 32 + offsetBits)) & 0x3FF) |
146  ((data_[offsetWords + 1] & (0xFFC00000 << (32 - offsetBits))) >> (64 - 10 - offsetBits)));
147  }
148  }
149 
150 } // namespace sistrip
uint32_t spyHeaderL1ID() const
uint32_t delayChipL1ID(const uint8_t delayChip) const
uint8_t internalFEDChannelNum(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum)
static const uint16_t SPY_SAMPLES_PER_CHANNEL
const uint8_t * getPointerToDataAfterTrackerSpecialHeader() const
bool delayChipGood(const uint8_t delayChip) const
uint32_t delayChipTotalEventCount(const uint8_t delayChip) const
uint32_t spyHeaderTotalEventCount() const
sistrip classes
uint32_t globalRunNumber() const
static const uint16_t DELAY_CHIPS_PER_FED
void dump(std::ostream &os) const
std::vector< FEDChannel > channels_
static const uint16_t FEDCH_PER_DELAY_CHIP
static const uint16_t SPY_DELAY_CHIP_BUFFER_SIZE_IN_BYTES
Log< level::Info, false > LogInfo
const uint8_t * payloadPointer_
static const uint8_t channelPositionsInData_[FEDCH_PER_DELAY_CHIP]
void print(std::ostream &os) const override
bool channelGood(const uint8_t internalFEDannelNum) const override
FEDSpyBuffer(const FEDRawData &fedBuffer)
static const uint16_t SPY_DELAYCHIP_DATA_OFFSET_IN_BITS
virtual void print(std::ostream &os) const