CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
sistrip::FEDBuffer Class Referencefinal

#include <SiStripFEDBuffer.h>

Inheritance diagram for sistrip::FEDBuffer:
sistrip::FEDBufferBase

Public Member Functions

virtual bool channelGood (const uint8_t internalFEDannelNum, const bool doAPVeCheck=true) const
 
bool checkAllChannelStatusBits () const
 
bool checkChannelLengths () const
 
bool checkChannelLengthsMatchBufferLength () const
 
bool checkChannelPacketCodes () const
 
bool checkFEPayloadsPresent () const
 
bool checkFEUnitAPVAddresses () const
 
bool checkFEUnitLengths () const
 
bool checkStatusBits (const uint8_t internalFEDChannelNum) const
 
bool checkStatusBits (const uint8_t internalFEUnitNum, const uint8_t internalChannelNum) const
 
std::string checkSummary () const override
 
virtual bool doChecks (bool doCRC=true) const
 
virtual bool doCorruptBufferChecks () const
 
 FEDBuffer (const uint8_t *fedBuffer, const uint16_t fedBufferSize, const bool allowBadBuffer=false)
 
bool feGood (const uint8_t internalFEUnitNum) const
 
bool feGoodWithoutAPVEmulatorCheck (const uint8_t internalFEUnitNum) const
 
const FEDFEHeaderfeHeader () const
 
bool fePresent (uint8_t internalFEUnitNum) const
 
void print (std::ostream &os) const override
 
void setLegacyMode (bool legacy)
 
 ~FEDBuffer () override
 
- Public Member Functions inherited from sistrip::FEDBufferBase
uint8_t apveAddress () const
 
FEDBufferFormat bufferFormat () const
 
size_t bufferSize () const
 
uint16_t calcCRC () const
 
const FEDChannelchannel (const uint8_t internalFEDChannelNum) const
 
const FEDChannelchannel (const uint8_t internalFEUnitNum, const uint8_t internalChannelNum) const
 
virtual bool channelGood (const uint8_t internalFEDChannelNum) const
 
bool channelGood (const uint8_t internalFEUnitNum, const uint8_t internalChannelNum) const
 
bool checkAPVEAddressValid () const
 
bool checkBufferFormat () const
 
bool checkCRC () const
 
bool checkHeaderType () const
 
bool checkLengthFromTrailer () const
 
bool checkMajorityAddresses () const
 
bool checkNoExtraHeadersOrTrailers () const
 
bool checkNoFEOverflows () const
 
bool checkNoSlinkCRCError () const
 
bool checkNoSLinkTransmissionError () const
 
bool checkNoUnexpectedSourceID () const
 
bool checkReadoutMode () const
 
bool checkSourceIDs () const
 
uint16_t daqBXID () const
 
uint16_t daqCRC () const
 
uint32_t daqEventLengthIn64bitWords () const
 
uint32_t daqEventLengthInBytes () const
 
FEDDAQEventType daqEventType () const
 
FEDDAQHeader daqHeader () const
 
uint32_t daqLvl1ID () const
 
uint16_t daqSourceID () const
 
FEDDAQTrailer daqTrailer () const
 
FEDTTSBits daqTTSState () const
 
virtual bool doChecks () const
 
bool doDAQHeaderAndTrailerChecks () const
 
bool doTrackerSpecialHeaderChecks () const
 
void dump (std::ostream &os) const
 
void dumpOriginalBuffer (std::ostream &os) const
 
 FEDBufferBase (const uint8_t *fedBuffer, const size_t fedBufferSize, const bool allowUnrecognizedFormat=false)
 
FEDStatusRegister fedStatusRegister () const
 
bool feEnabled (const uint8_t internalFEUnitNum) const
 
bool feOverflow (const uint8_t internalFEUnitNum) const
 
FEDHeaderType headerType () const
 
FEDLegacyReadoutMode legacyReadoutMode () const
 
bool majorityAddressErrorForFEUnit (const uint8_t internalFEUnitNum) const
 
uint8_t nFEUnitsEnabled () const
 
uint8_t packetCode (bool legacy=false, const uint8_t internalFEDChannelNum=0) const
 
FEDReadoutMode readoutMode () const
 
uint16_t sourceID () const
 
TrackerSpecialHeader trackerSpecialHeader () const
 
virtual ~FEDBufferBase ()
 

Private Member Functions

uint16_t calculateFEUnitLength (const uint8_t internalFEUnitNumber) const
 
void findChannels ()
 
uint8_t getCorrectPacketCode () const
 
uint8_t nFEUnitsPresent () const
 

Private Attributes

std::unique_ptr< FEDFEHeaderfeHeader_
 
bool fePresent_ [FEUNITS_PER_FED]
 
bool legacyUnpacker_ =false
 
uint16_t payloadLength_
 
const uint8_t * payloadPointer_
 
uint8_t validChannels_
 

Additional Inherited Members

- Protected Member Functions inherited from sistrip::FEDBufferBase
 FEDBufferBase (const uint8_t *fedBuffer, const size_t fedBufferSize, const bool allowUnrecognizedFormat, const bool fillChannelVector)
 
const uint8_t * getPointerToByteAfterEndOfPayload () const
 
const uint8_t * getPointerToDataAfterTrackerSpecialHeader () const
 
- Protected Attributes inherited from sistrip::FEDBufferBase
std::vector< FEDChannelchannels_
 

Detailed Description

Definition at line 23 of file SiStripFEDBuffer.h.

Constructor & Destructor Documentation

sistrip::FEDBuffer::FEDBuffer ( const uint8_t *  fedBuffer,
const uint16_t  fedBufferSize,
const bool  allowBadBuffer = false 
)

Definition at line 12 of file SiStripFEDBuffer.cc.

References sistrip::FEDBufferBase::channels_, MillePedeFileConverter_cfg::e, Exception, sistrip::FEDStatusRegister::feDataMissingFlag(), sistrip::FEDCH_PER_FED, sistrip::FEDBufferBase::fedStatusRegister(), feHeader_, sistrip::FEDFullDebugHeader::fePresent(), fePresent_, sistrip::FEUNITS_PER_FED, findChannels(), sistrip::FEDBufferBase::getPointerToByteAfterEndOfPayload(), sistrip::FEDBufferBase::getPointerToDataAfterTrackerSpecialHeader(), sistrip::HEADER_TYPE_INVALID, sistrip::HEADER_TYPE_NONE, sistrip::FEDBufferBase::headerType(), sistrip::TrackerSpecialHeader::headerTypeNibble(), sistrip::FEDFEHeader::newFEHeader(), payloadLength_, payloadPointer_, sistrip::printHex(), sistrip::READOUT_MODE_SPY, sistrip::FEDBufferBase::readoutMode(), sistrip::FEDBufferBase::trackerSpecialHeader(), and validChannels_.

13  : FEDBufferBase(fedBuffer,fedBufferSize,allowBadBuffer,false)
14  {
15  channels_.reserve(FEDCH_PER_FED);
16  //build the correct type of FE header object
20  } else {
21  feHeader_ = std::unique_ptr<FEDFEHeader>();
23  if (!allowBadBuffer) {
24  std::ostringstream ss;
25  ss << "Header type is invalid. "
26  << "Header type nibble is ";
27  uint8_t headerNibble = trackerSpecialHeader().headerTypeNibble();
28  printHex(&headerNibble,1,ss);
29  ss << ". ";
30  throw cms::Exception("FEDBuffer") << ss.str();
31  }
32  }
33  if (readoutMode() == READOUT_MODE_SPY) {
34  throw cms::Exception("FEDBuffer") << "Unpacking of spy channel data with FEDBuffer is not supported" << std::endl;
35  }
37  //check if FE units are present in data
38  //in Full Debug mode, use the lengths from the header
39  const FEDFullDebugHeader* fdHeader = dynamic_cast<FEDFullDebugHeader*>(feHeader_.get());
40  if (fdHeader) {
41  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
42  if (fdHeader->fePresent(iFE)) fePresent_[iFE] = true;
43  else fePresent_[iFE] = false;
44  }
45  }
46  //in APV error mode, use the FE present byte in the FED status register
47  // a value of '1' means a FE unit's data is missing (in old firmware versions it is always 0)
48  else {
49  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
50  if (fedStatusRegister().feDataMissingFlag(iFE)) fePresent_[iFE] = false;
51  else fePresent_[iFE] = true;
52  }
53  }
54  //try to find channels
55  validChannels_ = 0;
56  try {
57  findChannels();
58  } catch (const cms::Exception& e) {
59  //if there was a problem either rethrow the exception or just mark channel pointers NULL
60  if (!allowBadBuffer) throw;
61  else {
62  channels_.insert(channels_.end(),uint16_t(FEDCH_PER_FED-validChannels_),FEDChannel(payloadPointer_,0,0));
63  }
64  }
65  }
bool feDataMissingFlag(const uint8_t internalFEUnitNum) const
const uint8_t * getPointerToByteAfterEndOfPayload() const
static std::unique_ptr< FEDFEHeader > newFEHeader(const FEDHeaderType headerType, const uint8_t *headerBuffer)
FEDReadoutMode readoutMode() const
const uint8_t * getPointerToDataAfterTrackerSpecialHeader() const
bool fePresent_[FEUNITS_PER_FED]
const uint8_t * payloadPointer_
static const uint16_t FEUNITS_PER_FED
FEDBufferBase(const uint8_t *fedBuffer, const size_t fedBufferSize, const bool allowUnrecognizedFormat=false)
FEDHeaderType headerType() const
std::vector< FEDChannel > channels_
void printHex(const void *pointer, const size_t length, std::ostream &os)
std::unique_ptr< FEDFEHeader > feHeader_
TrackerSpecialHeader trackerSpecialHeader() const
static const uint16_t FEDCH_PER_FED
FEDStatusRegister fedStatusRegister() const
sistrip::FEDBuffer::~FEDBuffer ( )
override

Definition at line 67 of file SiStripFEDBuffer.cc.

68  {
69  }

Member Function Documentation

uint16_t sistrip::FEDBuffer::calculateFEUnitLength ( const uint8_t  internalFEUnitNumber) const
private

Definition at line 289 of file SiStripFEDBuffer.cc.

References sistrip::FEDBufferBase::channels_, sistrip::FEDCH_PER_FEUNIT, and sistrip::internalFEDChannelNum().

Referenced by checkFEUnitLengths(), checkSummary(), and getCorrectPacketCode().

290  {
291  //get length from channels
292  uint16_t lengthFromChannels = 0;
293  for (uint8_t iCh = 0; iCh < FEDCH_PER_FEUNIT; iCh++) {
294  lengthFromChannels += channels_[internalFEDChannelNum(internalFEUnitNumber,iCh)].length();
295  }
296  return lengthFromChannels;
297  }
uint8_t internalFEDChannelNum(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum)
std::vector< FEDChannel > channels_
static const uint16_t FEDCH_PER_FEUNIT
bool sistrip::FEDBuffer::channelGood ( const uint8_t  internalFEDannelNum,
const bool  doAPVeCheck = true 
) const
virtual

Definition at line 156 of file SiStripFEDBuffer.cc.

References checkStatusBits(), sistrip::FEDCH_PER_FEUNIT, feGood(), feGoodWithoutAPVEmulatorCheck(), sistrip::READOUT_MODE_SCOPE, sistrip::FEDBufferBase::readoutMode(), and validChannels_.

Referenced by checkChannelPacketCodes(), and SiStripClusterizerFromRaw::run().

157  {
158  return ( (internalFEDChannelNum < validChannels_) &&
159  ( (doAPVeCheck && feGood(internalFEDChannelNum/FEDCH_PER_FEUNIT)) ||
161  ) &&
163  }
bool checkStatusBits(const uint8_t internalFEDChannelNum) const
FEDReadoutMode readoutMode() const
uint8_t internalFEDChannelNum(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum)
bool feGoodWithoutAPVEmulatorCheck(const uint8_t internalFEUnitNum) const
static const uint16_t FEDCH_PER_FEUNIT
bool feGood(const uint8_t internalFEUnitNum) const
bool sistrip::FEDBuffer::checkAllChannelStatusBits ( ) const

Definition at line 186 of file SiStripFEDBuffer.cc.

References checkStatusBits(), sistrip::FEDCH_PER_FED, sistrip::FEDCH_PER_FEUNIT, and feGood().

Referenced by checkSummary(), and setLegacyMode().

187  {
188  for (uint8_t iCh = 0; iCh < FEDCH_PER_FED; iCh++) {
189  //if FE unit is disabled then skip all channels on it
190  if (!feGood(iCh/FEDCH_PER_FEUNIT)) {
191  iCh += FEDCH_PER_FEUNIT;
192  continue;
193  }
194  //channel is bad then return false
195  if (!checkStatusBits(iCh)) return false;
196  }
197  //if no bad channels have been found then they are all fine
198  return true;
199  }
bool checkStatusBits(const uint8_t internalFEDChannelNum) const
static const uint16_t FEDCH_PER_FEUNIT
static const uint16_t FEDCH_PER_FED
bool feGood(const uint8_t internalFEUnitNum) const
bool sistrip::FEDBuffer::checkChannelLengths ( ) const

Definition at line 201 of file SiStripFEDBuffer.cc.

References sistrip::FEDCH_PER_FED, and validChannels_.

Referenced by checkChannelLengthsMatchBufferLength(), and setLegacyMode().

202  {
203  return (validChannels_ == FEDCH_PER_FED);
204  }
static const uint16_t FEDCH_PER_FED
bool sistrip::FEDBuffer::checkChannelLengthsMatchBufferLength ( ) const

Definition at line 206 of file SiStripFEDBuffer.cc.

References sistrip::FEDBufferBase::channels_, checkChannelLengths(), sistrip::FEDCH_PER_FEUNIT, sistrip::FEDBufferBase::feEnabled(), fePresent(), sistrip::internalFEDChannelNum(), sistrip::FEDChannel::length(), sistrip::FEDChannel::offset(), and payloadLength_.

Referenced by checkSummary(), doCorruptBufferChecks(), and setLegacyMode().

207  {
208  //check they fit into buffer
209  if (!checkChannelLengths()) return false;
210 
211  //payload length from length of data buffer
212  const uint16_t payloadLengthInWords = payloadLength_/8;
213 
214  //find channel length
215  //find last enabled FE unit
216  uint8_t lastEnabledFeUnit = 7;
217  while ( !(fePresent(lastEnabledFeUnit) && feEnabled(lastEnabledFeUnit)) && lastEnabledFeUnit!=0 ) lastEnabledFeUnit--;
218  //last channel is last channel on last enabled FE unit
219  const FEDChannel& lastChannel = channels_[internalFEDChannelNum(lastEnabledFeUnit,FEDCH_PER_FEUNIT-1)];
220  const uint16_t offsetLastChannel = lastChannel.offset();
221  const uint16_t offsetEndOfChannelData = offsetLastChannel+lastChannel.length();
222  const uint16_t channelDataLength = offsetEndOfChannelData;
223  //channel length in words is length in bytes rounded up to nearest word
224  uint16_t channelDataLengthInWords = channelDataLength/8;
225  if (channelDataLength % 8) channelDataLengthInWords++;
226 
227  //check lengths match
228  if (channelDataLengthInWords == payloadLengthInWords) {
229  return true;
230  } else {
231  return false;
232  }
233  }
uint8_t internalFEDChannelNum(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum)
bool fePresent(uint8_t internalFEUnitNum) const
bool feEnabled(const uint8_t internalFEUnitNum) const
std::vector< FEDChannel > channels_
static const uint16_t FEDCH_PER_FEUNIT
bool checkChannelLengths() const
bool sistrip::FEDBuffer::checkChannelPacketCodes ( ) const

Definition at line 235 of file SiStripFEDBuffer.cc.

References channelGood(), sistrip::FEDBufferBase::channels_, sistrip::FEDCH_PER_FED, sistrip::FEDCH_PER_FEUNIT, feGood(), getCorrectPacketCode(), and sistrip::FEDBufferBase::packetCode().

Referenced by checkSummary(), doCorruptBufferChecks(), and setLegacyMode().

236  {
237  const uint8_t correctPacketCode = getCorrectPacketCode();
238  //if the readout mode if not one which has a packet code then this is set to zero. in this case return true
239  if (!correctPacketCode) return true;
240  for (uint8_t iCh = 0; iCh < FEDCH_PER_FED; iCh++) {
241  //if FE unit is disabled then skip all channels on it
242  if (!feGood(iCh/FEDCH_PER_FEUNIT)) {
243  iCh += FEDCH_PER_FEUNIT;
244  continue;
245  }
246  //only check enabled, working channels
247  if (FEDBuffer::channelGood(iCh, true)) {
248  //if a channel is bad then return false
249  if (channels_[iCh].packetCode() != correctPacketCode) return false;
250  }
251  }
252  //if no bad channels were found the they are all ok
253  return true;
254  }
virtual bool channelGood(const uint8_t internalFEDannelNum, const bool doAPVeCheck=true) const
uint8_t packetCode(bool legacy=false, const uint8_t internalFEDChannelNum=0) const
std::vector< FEDChannel > channels_
static const uint16_t FEDCH_PER_FEUNIT
uint8_t getCorrectPacketCode() const
static const uint16_t FEDCH_PER_FED
bool feGood(const uint8_t internalFEUnitNum) const
bool sistrip::FEDBuffer::checkFEPayloadsPresent ( ) const

Definition at line 299 of file SiStripFEDBuffer.cc.

References fePresent(), and sistrip::FEUNITS_PER_FED.

Referenced by checkSummary(), and setLegacyMode().

300  {
301  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
302  if (!fePresent(iFE)) return false;
303  }
304  return true;
305  }
bool fePresent(uint8_t internalFEUnitNum) const
static const uint16_t FEUNITS_PER_FED
bool sistrip::FEDBuffer::checkFEUnitAPVAddresses ( ) const

Definition at line 256 of file SiStripFEDBuffer.cc.

References sistrip::FEDBufferBase::apveAddress(), feGood(), feHeader_, sistrip::FEDFullDebugHeader::feUnitMajorityAddress(), and sistrip::FEUNITS_PER_FED.

Referenced by checkSummary(), and setLegacyMode().

257  {
258  //get golden address
259  const uint8_t goldenAddress = apveAddress();
260  //don't check if the address is 00 since APVe is probably not connected
261  if (goldenAddress == 0x00) return true;
262  //check can only be done for full debug headers
263  const FEDFullDebugHeader* fdHeader = dynamic_cast<FEDFullDebugHeader*>(feHeader_.get());
264  if (!fdHeader) return true;
265  //check all enabled FE units
266  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
267  if (!feGood(iFE)) continue;
268  //if address is bad then return false
269  if (fdHeader->feUnitMajorityAddress(iFE) != goldenAddress) return false;
270  }
271  //if no bad addresses were found then return true
272  return true;
273  }
static const uint16_t FEUNITS_PER_FED
std::unique_ptr< FEDFEHeader > feHeader_
bool feGood(const uint8_t internalFEUnitNum) const
bool sistrip::FEDBuffer::checkFEUnitLengths ( ) const

Definition at line 275 of file SiStripFEDBuffer.cc.

References calculateFEUnitLength(), feGood(), feHeader_, sistrip::FEDFullDebugHeader::feUnitLength(), and sistrip::FEUNITS_PER_FED.

Referenced by checkSummary(), doCorruptBufferChecks(), and setLegacyMode().

276  {
277  //check can only be done for full debug headers
278  const FEDFullDebugHeader* fdHeader = dynamic_cast<FEDFullDebugHeader*>(feHeader_.get());
279  if (!fdHeader) return true;
280  //check lengths for enabled FE units
281  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
282  if (!feGood(iFE)) continue;
283  if (calculateFEUnitLength(iFE) != fdHeader->feUnitLength(iFE)) return false;
284  }
285  //if no errors were encountered then return true
286  return true;
287  }
static const uint16_t FEUNITS_PER_FED
std::unique_ptr< FEDFEHeader > feHeader_
uint16_t calculateFEUnitLength(const uint8_t internalFEUnitNumber) const
bool feGood(const uint8_t internalFEUnitNum) const
bool sistrip::FEDBuffer::checkStatusBits ( const uint8_t  internalFEDChannelNum) const
inline

Definition at line 197 of file SiStripFEDBuffer.h.

References feHeader_.

Referenced by channelGood(), checkAllChannelStatusBits(), checkStatusBits(), checkSummary(), and setLegacyMode().

198  {
199  return feHeader_->checkChannelStatusBits(internalFEDChannelNum);
200  }
uint8_t internalFEDChannelNum(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum)
std::unique_ptr< FEDFEHeader > feHeader_
bool sistrip::FEDBuffer::checkStatusBits ( const uint8_t  internalFEUnitNum,
const uint8_t  internalChannelNum 
) const
inline

Definition at line 202 of file SiStripFEDBuffer.h.

References checkStatusBits(), and sistrip::internalFEDChannelNum().

203  {
204  return checkStatusBits(internalFEDChannelNum(internalFEUnitNum,internalChannelNum));
205  }
bool checkStatusBits(const uint8_t internalFEDChannelNum) const
uint8_t internalFEDChannelNum(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum)
std::string sistrip::FEDBuffer::checkSummary ( ) const
overridevirtual

Reimplemented from sistrip::FEDBufferBase.

Definition at line 307 of file SiStripFEDBuffer.cc.

References sistrip::FEDBufferBase::apveAddress(), calculateFEUnitLength(), sistrip::FEDBufferBase::channels_, checkAllChannelStatusBits(), checkChannelLengthsMatchBufferLength(), checkChannelPacketCodes(), checkFEPayloadsPresent(), checkFEUnitAPVAddresses(), checkFEUnitLengths(), checkStatusBits(), sistrip::FEDBufferBase::checkSummary(), sistrip::FEDCH_PER_FED, sistrip::FEDCH_PER_FEUNIT, feGood(), feHeader_, fePresent(), sistrip::FEDFullDebugHeader::feUnitLength(), sistrip::FEDFullDebugHeader::feUnitMajorityAddress(), sistrip::FEUNITS_PER_FED, sistrip::FEDFullDebugHeader::getChannelStatus(), getCorrectPacketCode(), sistrip::HEADER_TYPE_FULL_DEBUG, sistrip::FEDBufferBase::headerType(), sistrip::FEDBufferBase::packetCode(), and heppy_report::summary.

Referenced by setLegacyMode().

308  {
309  std::ostringstream summary;
310  summary << FEDBufferBase::checkSummary();
311  summary << "Check FE unit payloads are all present: " << (checkFEPayloadsPresent() ? "passed" : "FAILED" ) << std::endl;
312  if (!checkFEPayloadsPresent()) {
313  summary << "FE units missing payloads: ";
314  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
315  if (!fePresent(iFE)) summary << uint16_t(iFE) << " ";
316  }
317  summary << std::endl;
318  }
319  summary << "Check channel status bits: " << ( checkAllChannelStatusBits() ? "passed" : "FAILED" ) << std::endl;
320  if (!checkAllChannelStatusBits()) {
321  unsigned int badChannels = 0;
323  const FEDFullDebugHeader* fdHeader = dynamic_cast<FEDFullDebugHeader*>(feHeader_.get());
324  if (fdHeader) {
325  for (uint8_t iCh = 0; iCh < FEDCH_PER_FED; iCh++) {
326  if (!feGood(iCh/FEDCH_PER_FEUNIT)) continue;
327  if (!checkStatusBits(iCh)) {
328  summary << uint16_t(iCh) << ": " << fdHeader->getChannelStatus(iCh) << std::endl;
329  badChannels++;
330  }
331  }
332  }
333  } else {
334  summary << "Channels with errors: ";
335  for (uint8_t iCh = 0; iCh < FEDCH_PER_FED; iCh++) {
336  if (!feGood(iCh/FEDCH_PER_FEUNIT)) continue;
337  if (!checkStatusBits(iCh)) {
338  summary << uint16_t(iCh) << " ";
339  badChannels++;
340  }
341  }
342  summary << std::endl;
343  }
344  summary << "Number of channels with bad status bits: " << badChannels << std::endl;
345  }
346  summary << "Check channel lengths match buffer length: " << ( checkChannelLengthsMatchBufferLength() ? "passed" : "FAILED" ) << std::endl;
347  summary << "Check channel packet codes: " << ( checkChannelPacketCodes() ? "passed" : "FAILED" ) << std::endl;
348  if (!checkChannelPacketCodes()) {
349  summary << "Channels with bad packet codes: ";
350  for (uint8_t iCh = 0; iCh < FEDCH_PER_FED; iCh++) {
351  if (!feGood(iCh/FEDCH_PER_FEUNIT)) continue;
352  if (channels_[iCh].packetCode() != getCorrectPacketCode())
353  summary << uint16_t(iCh) << " ";
354  }
355  }
356  summary << "Check FE unit lengths: " << ( checkFEUnitLengths() ? "passed" : "FAILED" ) << std::endl;
357  if (!checkFEUnitLengths()) {
358  const FEDFullDebugHeader* fdHeader = dynamic_cast<FEDFullDebugHeader*>(feHeader_.get());
359  if (fdHeader) {
360  summary << "Bad FE units:" << std::endl;
361  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
362  if (!feGood(iFE)) continue;
363  uint16_t lengthFromChannels = calculateFEUnitLength(iFE);
364  uint16_t lengthFromHeader = fdHeader->feUnitLength(iFE);
365  if (lengthFromHeader != lengthFromChannels) {
366  summary << "FE unit: " << uint16_t(iFE)
367  << " length in header: " << lengthFromHeader
368  << " length from channel lengths: " << lengthFromChannels << std::endl;
369  }
370  }
371  }
372  }
373  summary << "Check FE unit APV addresses match APVe: " << ( checkFEUnitAPVAddresses() ? "passed" : "FAILED" ) << std::endl;
374  if (!checkFEUnitAPVAddresses()) {
375  const FEDFullDebugHeader* fdHeader = dynamic_cast<FEDFullDebugHeader*>(feHeader_.get());
376  if (fdHeader) {
377  const uint8_t goldenAddress = apveAddress();
378  summary << "Address from APVe:" << uint16_t(goldenAddress) << std::endl;
379  summary << "Bad FE units:" << std::endl;
380  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
381  if (!feGood(iFE)) continue;
382  if (fdHeader->feUnitMajorityAddress(iFE) != goldenAddress) {
383  summary << "FE unit: " << uint16_t(iFE)
384  << " majority address: " << uint16_t(fdHeader->feUnitMajorityAddress(iFE)) << std::endl;
385  }
386  }
387  }
388  }
389  return summary.str();
390  }
bool checkFEUnitLengths() const
bool checkStatusBits(const uint8_t internalFEDChannelNum) const
virtual std::string checkSummary() const
bool checkFEPayloadsPresent() const
bool fePresent(uint8_t internalFEUnitNum) const
static const uint16_t FEUNITS_PER_FED
FEDHeaderType headerType() const
uint8_t packetCode(bool legacy=false, const uint8_t internalFEDChannelNum=0) const
std::vector< FEDChannel > channels_
bool checkChannelPacketCodes() const
static const uint16_t FEDCH_PER_FEUNIT
std::unique_ptr< FEDFEHeader > feHeader_
bool checkFEUnitAPVAddresses() const
uint8_t getCorrectPacketCode() const
bool checkChannelLengthsMatchBufferLength() const
static const uint16_t FEDCH_PER_FED
bool checkAllChannelStatusBits() const
uint16_t calculateFEUnitLength(const uint8_t internalFEUnitNumber) const
bool feGood(const uint8_t internalFEUnitNum) const
bool sistrip::FEDBuffer::doChecks ( bool  doCRC = true) const
virtual

Definition at line 165 of file SiStripFEDBuffer.cc.

References sistrip::FEDBufferBase::checkCRC(), sistrip::FEDBufferBase::doChecks(), sistrip::FEDCH_PER_FED, and validChannels_.

166  {
167  //check that all channels were unpacked properly
168  if (validChannels_ != FEDCH_PER_FED) return false;
169  //do checks from base class
170  if (!FEDBufferBase::doChecks()) return false;
171  //check CRC
172  if (doCRC && !checkCRC()) return false;
173  return true;
174  }
static const uint16_t FEDCH_PER_FED
bool sistrip::FEDBuffer::doCorruptBufferChecks ( ) const
virtual

Definition at line 176 of file SiStripFEDBuffer.cc.

References checkChannelLengthsMatchBufferLength(), checkChannelPacketCodes(), sistrip::FEDBufferBase::checkCRC(), and checkFEUnitLengths().

Referenced by setLegacyMode().

177  {
178  return ( checkCRC() &&
181  //checkClusterLengths() &&
182  checkFEUnitLengths() );
183  //checkFEUnitAPVAddresses() );
184  }
bool checkFEUnitLengths() const
bool checkChannelPacketCodes() const
bool checkChannelLengthsMatchBufferLength() const
bool sistrip::FEDBuffer::feGood ( const uint8_t  internalFEUnitNum) const
inline

Definition at line 182 of file SiStripFEDBuffer.h.

References sistrip::FEDBufferBase::feOverflow(), fePresent(), and sistrip::FEDBufferBase::majorityAddressErrorForFEUnit().

Referenced by channelGood(), checkAllChannelStatusBits(), checkChannelPacketCodes(), checkFEUnitAPVAddresses(), checkFEUnitLengths(), and checkSummary().

183  {
184  return ( !majorityAddressErrorForFEUnit(internalFEUnitNum) && !feOverflow(internalFEUnitNum) && fePresent(internalFEUnitNum) );
185  }
bool fePresent(uint8_t internalFEUnitNum) const
bool majorityAddressErrorForFEUnit(const uint8_t internalFEUnitNum) const
bool feOverflow(const uint8_t internalFEUnitNum) const
bool sistrip::FEDBuffer::feGoodWithoutAPVEmulatorCheck ( const uint8_t  internalFEUnitNum) const
inline

Definition at line 187 of file SiStripFEDBuffer.h.

References sistrip::FEDBufferBase::feOverflow(), and fePresent().

Referenced by channelGood().

188  {
189  return ( !feOverflow(internalFEUnitNum) && fePresent(internalFEUnitNum) );
190  }
bool fePresent(uint8_t internalFEUnitNum) const
bool feOverflow(const uint8_t internalFEUnitNum) const
const FEDFEHeader * sistrip::FEDBuffer::feHeader ( ) const
inline

Definition at line 177 of file SiStripFEDBuffer.h.

References feHeader_.

Referenced by print(), and sistrip::RawToDigiUnpacker::updateEventSummary().

178  {
179  return feHeader_.get();
180  }
std::unique_ptr< FEDFEHeader > feHeader_
bool sistrip::FEDBuffer::fePresent ( uint8_t  internalFEUnitNum) const
inline

Definition at line 192 of file SiStripFEDBuffer.h.

References fePresent_.

Referenced by checkChannelLengthsMatchBufferLength(), checkFEPayloadsPresent(), checkSummary(), feGood(), feGoodWithoutAPVEmulatorCheck(), findChannels(), and nFEUnitsPresent().

193  {
194  return fePresent_[internalFEUnitNum];
195  }
bool fePresent_[FEUNITS_PER_FED]
void sistrip::FEDBuffer::findChannels ( )
private

Definition at line 71 of file SiStripFEDBuffer.cc.

References sistrip::FEDBufferBase::channels_, Exception, SiStripFedKey::feChan(), sistrip::FEDCH_PER_FED, sistrip::FEDCH_PER_FEUNIT, sistrip::FEDBufferBase::feEnabled(), fePresent(), SiStripFedKey::feUnit(), mps_fire::i, crabWrapper::key, payloadLength_, payloadPointer_, sistrip::READOUT_MODE_PREMIX_RAW, sistrip::READOUT_MODE_ZERO_SUPPRESSED, sistrip::READOUT_MODE_ZERO_SUPPRESSED_FAKE, sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE10, sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE10_CMOVERRIDE, sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE8, sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE8_BOTBOT, sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE8_BOTBOT_CMOVERRIDE, sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE8_CMOVERRIDE, sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE8_TOPBOT, sistrip::READOUT_MODE_ZERO_SUPPRESSED_LITE8_TOPBOT_CMOVERRIDE, sistrip::FEDBufferBase::readoutMode(), UNLIKELY, and validChannels_.

Referenced by FEDBuffer(), and setLegacyMode().

72  {
73  //set min length to 2 for ZSLite, 7 for ZS and 3 for raw
74  uint16_t minLength;
75  switch (readoutMode()) {
78  minLength = 7;
79  break;
81  minLength = 2;
82  break;
91  minLength = 2;
92  break;
93  default:
94  minLength = 3;
95  break;
96  }
97  uint16_t offsetBeginningOfChannel = 0;
98  for (uint16_t i = 0; i < FEDCH_PER_FED; i++) {
99  //if FE unit is not enabled then skip rest of FE unit adding NULL pointers
101  channels_.insert(channels_.end(),uint16_t(FEDCH_PER_FEUNIT),FEDChannel(payloadPointer_,0,0));
102  i += FEDCH_PER_FEUNIT-1;
104  continue;
105  }
106  //if FE unit is enabled
107  //check that channel length bytes fit into buffer
108  if UNLIKELY(offsetBeginningOfChannel+1 >= payloadLength_) {
109  std::ostringstream ss;
111  ss << "Channel " << uint16_t(i) << " (FE unit " << key.feUnit() << " channel " << key.feChan() << " according to external numbering scheme)"
112  << " does not fit into buffer. "
113  << "Channel starts at " << uint16_t(offsetBeginningOfChannel) << " in payload. "
114  << "Payload length is " << uint16_t(payloadLength_) << ". ";
115  throw cms::Exception("FEDBuffer") << ss.str();
116  }
117 
118  channels_.push_back(FEDChannel(payloadPointer_,offsetBeginningOfChannel));
119  //get length and check that whole channel fits into buffer
120  uint16_t channelLength = channels_.back().length();
121 
122  //check that the channel length is long enough to contain the header
123  if UNLIKELY(channelLength < minLength) {
125  std::ostringstream ss;
126  ss << "Channel " << uint16_t(i) << " (FE unit " << key.feUnit() << " channel " << key.feChan() << " according to external numbering scheme)"
127  << " is too short. "
128  << "Channel starts at " << uint16_t(offsetBeginningOfChannel) << " in payload. "
129  << "Channel length is " << uint16_t(channelLength) << ". "
130  << "Min length is " << uint16_t(minLength) << ". ";
131  throw cms::Exception("FEDBuffer") << ss.str();
132  }
133  if UNLIKELY(offsetBeginningOfChannel+channelLength > payloadLength_) {
135  std::ostringstream ss;
136  ss << "Channel " << uint16_t(i) << " (FE unit " << key.feUnit() << " channel " << key.feChan() << " according to external numbering scheme)"
137  << "Channel starts at " << uint16_t(offsetBeginningOfChannel) << " in payload. "
138  << "Channel length is " << uint16_t(channelLength) << ". "
139  << "Payload length is " << uint16_t(payloadLength_) << ". ";
140  throw cms::Exception("FEDBuffer") << ss.str();
141  }
142 
143  validChannels_++;
144  const uint16_t offsetEndOfChannel = offsetBeginningOfChannel+channelLength;
145  //add padding if necessary and calculate offset for begining of next channel
146  if (!( (i+1) % FEDCH_PER_FEUNIT )) {
147  uint8_t numPaddingBytes = 8 - (offsetEndOfChannel % 8);
148  if (numPaddingBytes == 8) numPaddingBytes = 0;
149  offsetBeginningOfChannel = offsetEndOfChannel + numPaddingBytes;
150  } else {
151  offsetBeginningOfChannel = offsetEndOfChannel;
152  }
153  }
154  }
A container class for generic run and event-related info, information required by the commissioning a...
Definition: SiStripFedKey.h:56
FEDReadoutMode readoutMode() const
const uint8_t * payloadPointer_
bool fePresent(uint8_t internalFEUnitNum) const
bool feEnabled(const uint8_t internalFEUnitNum) const
std::vector< FEDChannel > channels_
static const uint16_t FEDCH_PER_FEUNIT
static const uint16_t FEDCH_PER_FED
#define UNLIKELY(x)
Definition: Likely.h:21
uint8_t sistrip::FEDBuffer::getCorrectPacketCode ( ) const
inlineprivate

Definition at line 78 of file SiStripFEDBuffer.h.

References calculateFEUnitLength(), legacyUnpacker_, and sistrip::FEDBufferBase::packetCode().

Referenced by checkChannelPacketCodes(), and checkSummary().

78 { return packetCode(legacyUnpacker_); }
uint8_t packetCode(bool legacy=false, const uint8_t internalFEDChannelNum=0) const
uint8_t sistrip::FEDBuffer::nFEUnitsPresent ( ) const
private

Definition at line 392 of file SiStripFEDBuffer.cc.

References fePresent(), sistrip::FEUNITS_PER_FED, and mps_fire::result.

Referenced by print(), and setLegacyMode().

393  {
394  uint8_t result = 0;
395  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
396  if (fePresent(iFE)) result++;
397  }
398  return result;
399  }
bool fePresent(uint8_t internalFEUnitNum) const
static const uint16_t FEUNITS_PER_FED
void sistrip::FEDBuffer::print ( std::ostream &  os) const
overridevirtual

Reimplemented from sistrip::FEDBufferBase.

Definition at line 401 of file SiStripFEDBuffer.cc.

References feHeader(), sistrip::HEADER_TYPE_FULL_DEBUG, sistrip::FEDBufferBase::headerType(), nFEUnitsPresent(), and sistrip::FEDBufferBase::print().

402  {
405  os << "FE units with data: " << uint16_t(nFEUnitsPresent()) << std::endl;
406  os << "BE status register flags: ";
407  dynamic_cast<const FEDFullDebugHeader*>(feHeader())->beStatusRegister().printFlags(os);
408  os << std::endl;
409  }
410  }
const FEDFEHeader * feHeader() const
FEDHeaderType headerType() const
uint8_t nFEUnitsPresent() const
virtual void print(std::ostream &os) const
void sistrip::FEDBuffer::setLegacyMode ( bool  legacy)
inline

Member Data Documentation

std::unique_ptr<FEDFEHeader> sistrip::FEDBuffer::feHeader_
private
bool sistrip::FEDBuffer::fePresent_[FEUNITS_PER_FED]
private

Definition at line 84 of file SiStripFEDBuffer.h.

Referenced by FEDBuffer(), and fePresent().

bool sistrip::FEDBuffer::legacyUnpacker_ =false
private

Definition at line 85 of file SiStripFEDBuffer.h.

Referenced by getCorrectPacketCode(), and setLegacyMode().

uint16_t sistrip::FEDBuffer::payloadLength_
private
const uint8_t* sistrip::FEDBuffer::payloadPointer_
private

Definition at line 81 of file SiStripFEDBuffer.h.

Referenced by FEDBuffer(), and findChannels().

uint8_t sistrip::FEDBuffer::validChannels_
private