CMS 3D CMS Logo

List of all members | Public Member Functions | Static Private Member Functions | Private Attributes
sistrip::FEDBufferGenerator Class Reference

#include <SiStripFEDBufferGenerator.h>

Public Member Functions

FEDDAQHeaderdaqHeader ()
 
FEDDAQTrailerdaqTrailer ()
 
 FEDBufferGenerator (const uint32_t l1ID=0, const uint16_t bxID=0, const std::vector< bool > &feUnitsEnabled=std::vector< bool >(FEUNITS_PER_FED, true), const std::vector< bool > &channelsEnabled=std::vector< bool >(FEDCH_PER_FED, true), const FEDReadoutMode readoutMode=READOUT_MODE_ZERO_SUPPRESSED, const FEDHeaderType headerType=HEADER_TYPE_FULL_DEBUG, const FEDBufferFormat bufferFormat=BUFFER_FORMAT_OLD_SLINK, const FEDDAQEventType evtType=DAQ_EVENT_TYPE_PHYSICS)
 
FEDFEHeaderfeHeader ()
 
void generateBuffer (FEDRawData *rawDataObject, const FEDStripData &data, uint16_t sourceID, uint8_t packetCode) const
 
FEDBufferFormat getBufferFormat () const
 
uint16_t getBXID () const
 
bool getChannelEnabled (const uint8_t internalFEDChannelNumber) const
 
FEDDAQEventType getDAQEventType () const
 
bool getFEUnitEnabled (const uint8_t internalFEUnitNumber) const
 
FEDHeaderType getHeaderType () const
 
uint32_t getL1ID () const
 
FEDReadoutMode getReadoutMode () const
 
FEDBufferGeneratorsetBufferFormat (const FEDBufferFormat newBufferFormat)
 
FEDBufferGeneratorsetBXID (const uint16_t newBXID)
 
FEDBufferGeneratorsetChannelEnable (const uint8_t internalFEDChannelNumber, const bool enabled)
 
FEDBufferGeneratorsetChannelEnables (const std::vector< bool > &channelsEnabled)
 
FEDBufferGeneratorsetDAQEventType (const FEDDAQEventType newDAQEventType)
 
FEDBufferGeneratorsetFEUnitEnable (const uint8_t internalFEUnitNumber, const bool enabled)
 
FEDBufferGeneratorsetFEUnitEnables (const std::vector< bool > &feUnitsEnabled)
 
FEDBufferGeneratorsetHeaderType (const FEDHeaderType newHeaderType)
 
FEDBufferGeneratorsetL1ID (const uint32_t newL1ID)
 
FEDBufferGeneratorsetReadoutMode (const FEDReadoutMode newReadoutMode)
 
TrackerSpecialHeadertrackerSpecialHeader ()
 

Static Private Member Functions

static size_t bufferSizeInBytes (const FEDFEHeader &feHeader, const FEDBufferPayload &payload)
 
static void fillBuffer (uint8_t *pointerToStartOfBuffer, const FEDDAQHeader &daqHeader, const FEDDAQTrailer &daqTrailer, const TrackerSpecialHeader &tkSpecialHeader, const FEDFEHeader &feHeader, const FEDBufferPayload &payload)
 

Private Attributes

std::vector< bool > channelsEnabled_
 
FEDDAQHeader defaultDAQHeader_
 
FEDDAQTrailer defaultDAQTrailer_
 
std::unique_ptr< FEDFEHeaderdefaultFEHeader_
 
TrackerSpecialHeader defaultTrackerSpecialHeader_
 
std::vector< bool > feUnitsEnabled_
 

Detailed Description

Definition at line 126 of file SiStripFEDBufferGenerator.h.

Constructor & Destructor Documentation

◆ FEDBufferGenerator()

sistrip::FEDBufferGenerator::FEDBufferGenerator ( const uint32_t  l1ID = 0,
const uint16_t  bxID = 0,
const std::vector< bool > &  feUnitsEnabled = std::vector<bool>(FEUNITS_PER_FED, true),
const std::vector< bool > &  channelsEnabled = std::vector<bool>(FEDCH_PER_FED, true),
const FEDReadoutMode  readoutMode = READOUT_MODE_ZERO_SUPPRESSED,
const FEDHeaderType  headerType = HEADER_TYPE_FULL_DEBUG,
const FEDBufferFormat  bufferFormat = BUFFER_FORMAT_OLD_SLINK,
const FEDDAQEventType  evtType = DAQ_EVENT_TYPE_PHYSICS 
)

Definition at line 438 of file SiStripFEDBufferGenerator.cc.

References defaultFEHeader_, Exception, and contentValuesCheck::ss.

446  : defaultDAQHeader_(l1ID, bxID, 0, evtType),
447  defaultDAQTrailer_(0, 0),
448  defaultTrackerSpecialHeader_(bufferFormat, readoutMode, headerType),
450  feUnitsEnabled_(feUnitsEnabled),
451  channelsEnabled_(channelsEnabled) {
452  if (!defaultFEHeader_.get()) {
453  std::ostringstream ss;
454  ss << "Bad header format: " << headerType;
455  throw cms::Exception("FEDBufferGenerator") << ss.str();
456  }
457  }
static std::unique_ptr< FEDFEHeader > newFEHeader(const FEDHeaderType headerType, const uint8_t *headerBuffer)
std::unique_ptr< FEDFEHeader > defaultFEHeader_
TrackerSpecialHeader defaultTrackerSpecialHeader_

Member Function Documentation

◆ bufferSizeInBytes()

size_t sistrip::FEDBufferGenerator::bufferSizeInBytes ( const FEDFEHeader feHeader,
const FEDBufferPayload payload 
)
inlinestaticprivate

Definition at line 356 of file SiStripFEDBufferGenerator.h.

References feHeader(), sistrip::FEDFEHeader::lengthInBytes(), and jetsAK4_Puppi_cff::payload.

Referenced by fillBuffer(), and generateBuffer().

356  {
357  //FE header + payload + tracker special header + daq header + daq trailer
358  return feHeader.lengthInBytes() + payload.lengthInBytes() + 8 + 8 + 8;
359  }
virtual size_t lengthInBytes() const =0

◆ daqHeader()

FEDDAQHeader & sistrip::FEDBufferGenerator::daqHeader ( )
inline

◆ daqTrailer()

FEDDAQTrailer & sistrip::FEDBufferGenerator::daqTrailer ( )
inline

◆ feHeader()

FEDFEHeader & sistrip::FEDBufferGenerator::feHeader ( )
inline

Definition at line 354 of file SiStripFEDBufferGenerator.h.

References defaultFEHeader_.

Referenced by bufferSizeInBytes(), sistrip::DigiToRaw::createFedBuffers_(), and fillBuffer().

354 { return *defaultFEHeader_; }
std::unique_ptr< FEDFEHeader > defaultFEHeader_

◆ fillBuffer()

void sistrip::FEDBufferGenerator::fillBuffer ( uint8_t *  pointerToStartOfBuffer,
const FEDDAQHeader daqHeader,
const FEDDAQTrailer daqTrailer,
const TrackerSpecialHeader tkSpecialHeader,
const FEDFEHeader feHeader,
const FEDBufferPayload payload 
)
staticprivate

Definition at line 563 of file SiStripFEDBufferGenerator.cc.

References bufferSizeInBytes(), sistrip::calculateFEDBufferCRC(), daqHeader(), daqTrailer(), sistrip::FEDDAQHeader::data(), sistrip::FEDDAQTrailer::data(), sistrip::TrackerSpecialHeader::data(), sistrip::FEDFEHeader::data(), feHeader(), mps_fire::i, sistrip::FEDFEHeader::lengthInBytes(), jetsAK4_Puppi_cff::payload, sistrip::FEDDAQTrailer::setCRC(), sistrip::FEDDAQTrailer::setEventLengthIn64BitWords(), and sistrip::TrackerSpecialHeader::wasSwapped().

Referenced by generateBuffer().

568  {
569  //set the length in the DAQ trailer
570  const size_t lengthInBytes = bufferSizeInBytes(feHeader, payload);
571  FEDDAQTrailer updatedDAQTrailer(daqTrailer);
572  updatedDAQTrailer.setEventLengthIn64BitWords(lengthInBytes / 8);
573  //copy pieces into buffer in order
574  uint8_t* bufferPointer = pointerToStartOfBuffer;
575  memcpy(bufferPointer, daqHeader.data(), 8);
576  bufferPointer += 8;
577  memcpy(bufferPointer, tkSpecialHeader.data(), 8);
578  bufferPointer += 8;
579  memcpy(bufferPointer, feHeader.data(), feHeader.lengthInBytes());
580  bufferPointer += feHeader.lengthInBytes();
581  memcpy(bufferPointer, payload.data(), payload.lengthInBytes());
582  bufferPointer += payload.lengthInBytes();
583  memcpy(bufferPointer, updatedDAQTrailer.data(), 8);
584  //update CRC
585  const uint16_t crc = calculateFEDBufferCRC(pointerToStartOfBuffer, lengthInBytes);
586  updatedDAQTrailer.setCRC(crc);
587  memcpy(bufferPointer, updatedDAQTrailer.data(), 8);
588  //word swap if necessary
589  if (tkSpecialHeader.wasSwapped()) {
590  for (size_t i = 0; i < 8; i++) {
591  bufferPointer[i] = bufferPointer[i ^ 4];
592  }
593  }
594  }
virtual size_t lengthInBytes() const =0
static size_t bufferSizeInBytes(const FEDFEHeader &feHeader, const FEDBufferPayload &payload)
uint16_t calculateFEDBufferCRC(const uint8_t *buffer, const size_t lengthInBytes)
virtual const uint8_t * data() const =0
const uint8_t * data() const

◆ generateBuffer()

void sistrip::FEDBufferGenerator::generateBuffer ( FEDRawData rawDataObject,
const FEDStripData data,
uint16_t  sourceID,
uint8_t  packetCode 
) const

Definition at line 526 of file SiStripFEDBufferGenerator.cc.

References bufferSizeInBytes(), channelsEnabled_, daqHeader(), FEDRawData::data(), data, defaultDAQHeader_, defaultDAQTrailer_, defaultFEHeader_, defaultTrackerSpecialHeader_, pixel_dqm_sourceclient-live_cfg::enabled, sistrip::FEDCH_PER_FED, sistrip::FEDCH_PER_FEUNIT, sistrip::FEUNITS_PER_FED, feUnitsEnabled_, fillBuffer(), getReadoutMode(), jetsAK4_Puppi_cff::payload, FEDRawData::resize(), sistrip::TrackerSpecialHeader::setFEEnableForFEUnit(), and sistrip::FEDDAQHeader::setSourceID().

Referenced by sistrip::DigiToRaw::createFedBuffers_().

529  {
530  //deal with disabled FE units and channels properly (FE enables, status bits)
531  TrackerSpecialHeader tkSpecialHeader(defaultTrackerSpecialHeader_);
532  std::unique_ptr<FEDFEHeader> fedFeHeader(defaultFEHeader_->clone());
533  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
534  const bool enabled = feUnitsEnabled_[iFE];
535  tkSpecialHeader.setFEEnableForFEUnit(iFE, enabled);
536  if (!enabled) {
537  for (uint8_t iFEUnitChannel = 0; iFEUnitChannel < FEDCH_PER_FEUNIT; iFEUnitChannel++) {
538  fedFeHeader->setChannelStatus(iFE, iFEUnitChannel, FEDChannelStatus(0));
539  }
540  }
541  }
542  for (uint8_t iCh = 0; iCh < FEDCH_PER_FED; iCh++) {
543  if (!channelsEnabled_[iCh]) {
544  fedFeHeader->setChannelStatus(iCh, FEDChannelStatus(0));
545  }
546  }
547  //set the source ID
548  FEDDAQHeader daqHeader(defaultDAQHeader_);
549  daqHeader.setSourceID(sourceID);
550  //build payload
551  const FEDBufferPayloadCreator payloadPacker(feUnitsEnabled_, channelsEnabled_);
552  const FEDBufferPayload payload = payloadPacker(getReadoutMode(), packetCode, data);
553  //fill FE lengths
554  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
555  fedFeHeader->setFEUnitLength(iFE, payload.getFELength(iFE));
556  }
557  //resize buffer
558  rawDataObject->resize(bufferSizeInBytes(*fedFeHeader, payload));
559  //fill buffer
560  fillBuffer(rawDataObject->data(), daqHeader, defaultDAQTrailer_, tkSpecialHeader, *fedFeHeader, payload);
561  }
static size_t bufferSizeInBytes(const FEDFEHeader &feHeader, const FEDBufferPayload &payload)
std::unique_ptr< FEDFEHeader > defaultFEHeader_
void resize(size_t newsize)
Definition: FEDRawData.cc:28
static const uint16_t FEUNITS_PER_FED
static const uint16_t FEDCH_PER_FEUNIT
FEDDAQHeader & setSourceID(const uint16_t sourceID)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
static const uint16_t FEDCH_PER_FED
static void fillBuffer(uint8_t *pointerToStartOfBuffer, const FEDDAQHeader &daqHeader, const FEDDAQTrailer &daqTrailer, const TrackerSpecialHeader &tkSpecialHeader, const FEDFEHeader &feHeader, const FEDBufferPayload &payload)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
TrackerSpecialHeader defaultTrackerSpecialHeader_

◆ getBufferFormat()

FEDBufferFormat sistrip::FEDBufferGenerator::getBufferFormat ( ) const
inline

◆ getBXID()

uint16_t sistrip::FEDBufferGenerator::getBXID ( ) const
inline

◆ getChannelEnabled()

bool sistrip::FEDBufferGenerator::getChannelEnabled ( const uint8_t  internalFEDChannelNumber) const

Definition at line 469 of file SiStripFEDBufferGenerator.cc.

References channelsEnabled_, Exception, and contentValuesCheck::ss.

469  {
470  try {
471  return channelsEnabled_.at(internalFEDChannelNumber);
472  } catch (const std::out_of_range&) {
473  std::ostringstream ss;
474  ss << "Invalid channel number " << internalFEDChannelNumber << ". "
475  << "Should be in internal numbering scheme (0-95)";
476  throw cms::Exception("FEDBufferGenerator") << ss.str();
477  }
478  }

◆ getDAQEventType()

FEDDAQEventType sistrip::FEDBufferGenerator::getDAQEventType ( ) const
inline

◆ getFEUnitEnabled()

bool sistrip::FEDBufferGenerator::getFEUnitEnabled ( const uint8_t  internalFEUnitNumber) const

Definition at line 459 of file SiStripFEDBufferGenerator.cc.

References Exception, feUnitsEnabled_, and contentValuesCheck::ss.

459  {
460  try {
461  return feUnitsEnabled_.at(internalFEUnitNumber);
462  } catch (const std::out_of_range&) {
463  std::ostringstream ss;
464  ss << "Invalid FE unit number " << internalFEUnitNumber << ". Should be in internal numbering scheme (0-7)";
465  throw cms::Exception("FEDBufferGenerator") << ss.str();
466  }
467  }

◆ getHeaderType()

FEDHeaderType sistrip::FEDBufferGenerator::getHeaderType ( ) const
inline

◆ getL1ID()

uint32_t sistrip::FEDBufferGenerator::getL1ID ( ) const
inline

◆ getReadoutMode()

FEDReadoutMode sistrip::FEDBufferGenerator::getReadoutMode ( ) const
inline

◆ setBufferFormat()

FEDBufferGenerator & sistrip::FEDBufferGenerator::setBufferFormat ( const FEDBufferFormat  newBufferFormat)
inline

Definition at line 338 of file SiStripFEDBufferGenerator.h.

References defaultTrackerSpecialHeader_, and sistrip::TrackerSpecialHeader::setBufferFormat().

338  {
340  return *this;
341  }
TrackerSpecialHeader & setBufferFormat(const FEDBufferFormat newBufferFormat)
TrackerSpecialHeader defaultTrackerSpecialHeader_

◆ setBXID()

FEDBufferGenerator & sistrip::FEDBufferGenerator::setBXID ( const uint16_t  newBXID)
inline

Definition at line 323 of file SiStripFEDBufferGenerator.h.

References defaultDAQHeader_, and sistrip::FEDDAQHeader::setBXID().

323  {
324  defaultDAQHeader_.setBXID(newBXID);
325  return *this;
326  }
FEDDAQHeader & setBXID(const uint16_t bxID)

◆ setChannelEnable()

FEDBufferGenerator & sistrip::FEDBufferGenerator::setChannelEnable ( const uint8_t  internalFEDChannelNumber,
const bool  enabled 
)

Definition at line 492 of file SiStripFEDBufferGenerator.cc.

References channelsEnabled_, pixel_dqm_sourceclient-live_cfg::enabled, Exception, and contentValuesCheck::ss.

492  {
493  try {
494  channelsEnabled_.at(internalFEDChannelNumber) = enabled;
495  } catch (const std::out_of_range&) {
496  std::ostringstream ss;
497  ss << "Invalid channel number " << internalFEDChannelNumber << ". "
498  << "Should be in internal numbering scheme (0-95)";
499  throw cms::Exception("FEDBufferGenerator") << ss.str();
500  }
501  return *this;
502  }

◆ setChannelEnables()

FEDBufferGenerator & sistrip::FEDBufferGenerator::setChannelEnables ( const std::vector< bool > &  channelsEnabled)

Definition at line 515 of file SiStripFEDBufferGenerator.cc.

References channelsEnabled_, Exception, sistrip::FEDCH_PER_FED, and contentValuesCheck::ss.

515  {
516  if (channelEnables.size() != FEDCH_PER_FED) {
517  std::ostringstream ss;
518  ss << "Setting FED channel enable vector with vector which is the wrong size. Size is " << channelEnables.size()
519  << " it must be " << FEDCH_PER_FED << "." << std::endl;
520  throw cms::Exception("FEDBufferGenerator") << ss.str();
521  }
522  channelsEnabled_ = channelEnables;
523  return *this;
524  }
static const uint16_t FEDCH_PER_FED

◆ setDAQEventType()

FEDBufferGenerator & sistrip::FEDBufferGenerator::setDAQEventType ( const FEDDAQEventType  newDAQEventType)
inline

Definition at line 343 of file SiStripFEDBufferGenerator.h.

References defaultDAQHeader_, and sistrip::FEDDAQHeader::setEventType().

343  {
344  defaultDAQHeader_.setEventType(newDAQEventType);
345  return *this;
346  }
FEDDAQHeader & setEventType(const FEDDAQEventType evtType)

◆ setFEUnitEnable()

FEDBufferGenerator & sistrip::FEDBufferGenerator::setFEUnitEnable ( const uint8_t  internalFEUnitNumber,
const bool  enabled 
)

Definition at line 480 of file SiStripFEDBufferGenerator.cc.

References pixel_dqm_sourceclient-live_cfg::enabled, Exception, feUnitsEnabled_, and contentValuesCheck::ss.

480  {
481  try {
482  feUnitsEnabled_.at(internalFEUnitNumber) = enabled;
483  } catch (const std::out_of_range&) {
484  std::ostringstream ss;
485  ss << "Invalid FE unit number " << internalFEUnitNumber << ". "
486  << "Should be in internal numbering scheme (0-7)";
487  throw cms::Exception("FEDBufferGenerator") << ss.str();
488  }
489  return *this;
490  }

◆ setFEUnitEnables()

FEDBufferGenerator & sistrip::FEDBufferGenerator::setFEUnitEnables ( const std::vector< bool > &  feUnitsEnabled)

Definition at line 504 of file SiStripFEDBufferGenerator.cc.

References Exception, sistrip::FEUNITS_PER_FED, feUnitsEnabled_, and contentValuesCheck::ss.

Referenced by sistrip::DigiToRaw::createFedBuffers_().

504  {
505  if (feUnitEnables.size() != FEUNITS_PER_FED) {
506  std::ostringstream ss;
507  ss << "Setting FE enable vector with vector which is the wrong size. Size is " << feUnitEnables.size()
508  << " it must be " << FEUNITS_PER_FED << "." << std::endl;
509  throw cms::Exception("FEDBufferGenerator") << ss.str();
510  }
511  feUnitsEnabled_ = feUnitEnables;
512  return *this;
513  }
static const uint16_t FEUNITS_PER_FED

◆ setHeaderType()

FEDBufferGenerator & sistrip::FEDBufferGenerator::setHeaderType ( const FEDHeaderType  newHeaderType)
inline

Definition at line 333 of file SiStripFEDBufferGenerator.h.

References defaultTrackerSpecialHeader_, and sistrip::TrackerSpecialHeader::setHeaderType().

Referenced by sistrip::DigiToRaw::createFedBuffers_().

333  {
335  return *this;
336  }
TrackerSpecialHeader & setHeaderType(const FEDHeaderType headerType)
TrackerSpecialHeader defaultTrackerSpecialHeader_

◆ setL1ID()

FEDBufferGenerator & sistrip::FEDBufferGenerator::setL1ID ( const uint32_t  newL1ID)
inline

Definition at line 318 of file SiStripFEDBufferGenerator.h.

References defaultDAQHeader_, and sistrip::FEDDAQHeader::setL1ID().

Referenced by sistrip::DigiToRaw::createFedBuffers_().

318  {
319  defaultDAQHeader_.setL1ID(newL1ID);
320  return *this;
321  }
FEDDAQHeader & setL1ID(const uint32_t l1ID)

◆ setReadoutMode()

FEDBufferGenerator & sistrip::FEDBufferGenerator::setReadoutMode ( const FEDReadoutMode  newReadoutMode)
inline

Definition at line 328 of file SiStripFEDBufferGenerator.h.

References defaultTrackerSpecialHeader_, and sistrip::TrackerSpecialHeader::setReadoutMode().

Referenced by sistrip::DigiToRaw::createFedBuffers_(), and sistrip::DigiToRaw::DigiToRaw().

328  {
330  return *this;
331  }
TrackerSpecialHeader defaultTrackerSpecialHeader_
TrackerSpecialHeader & setReadoutMode(const FEDReadoutMode readoutMode)

◆ trackerSpecialHeader()

TrackerSpecialHeader & sistrip::FEDBufferGenerator::trackerSpecialHeader ( )
inline

Member Data Documentation

◆ channelsEnabled_

std::vector<bool> sistrip::FEDBufferGenerator::channelsEnabled_
private

◆ defaultDAQHeader_

FEDDAQHeader sistrip::FEDBufferGenerator::defaultDAQHeader_
private

◆ defaultDAQTrailer_

FEDDAQTrailer sistrip::FEDBufferGenerator::defaultDAQTrailer_
private

Definition at line 185 of file SiStripFEDBufferGenerator.h.

Referenced by daqTrailer(), and generateBuffer().

◆ defaultFEHeader_

std::unique_ptr<FEDFEHeader> sistrip::FEDBufferGenerator::defaultFEHeader_
private

Definition at line 187 of file SiStripFEDBufferGenerator.h.

Referenced by FEDBufferGenerator(), feHeader(), and generateBuffer().

◆ defaultTrackerSpecialHeader_

TrackerSpecialHeader sistrip::FEDBufferGenerator::defaultTrackerSpecialHeader_
private

◆ feUnitsEnabled_

std::vector<bool> sistrip::FEDBufferGenerator::feUnitsEnabled_
private