CMS 3D CMS Logo

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