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 105 of file SiStripFEDBufferGenerator.h.

Constructor & Destructor Documentation

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 432 of file SiStripFEDBufferGenerator.cc.

References defaultFEHeader_, and Exception.

436  : defaultDAQHeader_(l1ID,bxID,0,evtType),
437  defaultDAQTrailer_(0,0),
438  defaultTrackerSpecialHeader_(bufferFormat,readoutMode,headerType),
440  feUnitsEnabled_(feUnitsEnabled),
441  channelsEnabled_(channelsEnabled)
442  {
443  if (!defaultFEHeader_.get()) {
444  std::ostringstream ss;
445  ss << "Bad header format: " << headerType;
446  throw cms::Exception("FEDBufferGenerator") << ss.str();
447  }
448  }
static std::unique_ptr< FEDFEHeader > newFEHeader(const FEDHeaderType headerType, const uint8_t *headerBuffer)
std::unique_ptr< FEDFEHeader > defaultFEHeader_
TrackerSpecialHeader defaultTrackerSpecialHeader_

Member Function Documentation

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

Definition at line 389 of file SiStripFEDBufferGenerator.h.

References sistrip::FEDBufferPayload::lengthInBytes(), and sistrip::FEDFEHeader::lengthInBytes().

Referenced by fillBuffer(), and generateBuffer().

391  {
392  //FE header + payload + tracker special header + daq header + daq trailer
393  return feHeader.lengthInBytes()+payload.lengthInBytes()+8+8+8;
394  }
virtual size_t lengthInBytes() const =0
FEDDAQHeader & sistrip::FEDBufferGenerator::daqHeader ( )
inline

Definition at line 369 of file SiStripFEDBufferGenerator.h.

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

370  {
371  return defaultDAQHeader_;
372  }
FEDDAQTrailer & sistrip::FEDBufferGenerator::daqTrailer ( )
inline

Definition at line 374 of file SiStripFEDBufferGenerator.h.

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

375  {
376  return defaultDAQTrailer_;
377  }
FEDFEHeader & sistrip::FEDBufferGenerator::feHeader ( )
inline

Definition at line 384 of file SiStripFEDBufferGenerator.h.

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

385  {
386  return *defaultFEHeader_;
387  }
std::unique_ptr< FEDFEHeader > defaultFEHeader_
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 559 of file SiStripFEDBufferGenerator.cc.

References bufferSizeInBytes(), sistrip::calculateFEDBufferCRC(), sistrip::FEDBufferPayload::data(), sistrip::FEDDAQHeader::data(), sistrip::FEDDAQTrailer::data(), sistrip::TrackerSpecialHeader::data(), sistrip::FEDFEHeader::data(), mps_fire::i, sistrip::FEDBufferPayload::lengthInBytes(), sistrip::FEDFEHeader::lengthInBytes(), sistrip::FEDDAQTrailer::setCRC(), sistrip::FEDDAQTrailer::setEventLengthIn64BitWords(), and sistrip::TrackerSpecialHeader::wasSwapped().

Referenced by generateBuffer().

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

Definition at line 524 of file SiStripFEDBufferGenerator.cc.

References bufferSizeInBytes(), channelsEnabled_, daqHeader(), FEDRawData::data(), defaultDAQHeader_, defaultDAQTrailer_, defaultFEHeader_, defaultTrackerSpecialHeader_, patPFMETCorrections_cff::enabled, sistrip::FEDCH_PER_FED, sistrip::FEDCH_PER_FEUNIT, sistrip::FEUNITS_PER_FED, feUnitsEnabled_, fillBuffer(), sistrip::FEDBufferPayload::getFELength(), getReadoutMode(), jets_cff::payload, FEDRawData::resize(), sistrip::TrackerSpecialHeader::setFEEnableForFEUnit(), and sistrip::FEDDAQHeader::setSourceID().

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

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

Definition at line 323 of file SiStripFEDBufferGenerator.h.

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

324  {
326  }
TrackerSpecialHeader defaultTrackerSpecialHeader_
uint16_t sistrip::FEDBufferGenerator::getBXID ( ) const
inline

Definition at line 308 of file SiStripFEDBufferGenerator.h.

309  {
310  return defaultDAQHeader_.bxID();
311  }
bool sistrip::FEDBufferGenerator::getChannelEnabled ( const uint8_t  internalFEDChannelNumber) const

Definition at line 461 of file SiStripFEDBufferGenerator.cc.

References channelsEnabled_, and Exception.

462  {
463  try {
464  return channelsEnabled_.at(internalFEDChannelNumber);
465  } catch (const std::out_of_range&) {
466 
467  std::ostringstream ss;
468  ss << "Invalid channel number " << internalFEDChannelNumber << ". "
469  << "Should be in internal numbering scheme (0-95)";
470  throw cms::Exception("FEDBufferGenerator") << ss.str();
471  }
472  }
FEDDAQEventType sistrip::FEDBufferGenerator::getDAQEventType ( ) const
inline

Definition at line 328 of file SiStripFEDBufferGenerator.h.

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

329  {
330  return defaultDAQHeader_.eventType();
331  }
FEDDAQEventType eventType() const
bool sistrip::FEDBufferGenerator::getFEUnitEnabled ( const uint8_t  internalFEUnitNumber) const

Definition at line 450 of file SiStripFEDBufferGenerator.cc.

References Exception, and feUnitsEnabled_.

451  {
452  try {
453  return feUnitsEnabled_.at(internalFEUnitNumber);
454  } catch (const std::out_of_range&) {
455  std::ostringstream ss;
456  ss << "Invalid FE unit number " << internalFEUnitNumber << ". Should be in internal numbering scheme (0-7)";
457  throw cms::Exception("FEDBufferGenerator") << ss.str();
458  }
459  }
FEDHeaderType sistrip::FEDBufferGenerator::getHeaderType ( ) const
inline

Definition at line 318 of file SiStripFEDBufferGenerator.h.

319  {
321  }
TrackerSpecialHeader defaultTrackerSpecialHeader_
uint32_t sistrip::FEDBufferGenerator::getL1ID ( ) const
inline

Definition at line 303 of file SiStripFEDBufferGenerator.h.

304  {
305  return defaultDAQHeader_.l1ID();
306  }
FEDReadoutMode sistrip::FEDBufferGenerator::getReadoutMode ( ) const
inline

Definition at line 313 of file SiStripFEDBufferGenerator.h.

Referenced by generateBuffer().

314  {
316  }
TrackerSpecialHeader defaultTrackerSpecialHeader_
FEDBufferGenerator & sistrip::FEDBufferGenerator::setBufferFormat ( const FEDBufferFormat  newBufferFormat)
inline

Definition at line 357 of file SiStripFEDBufferGenerator.h.

References setBufferFormat().

Referenced by setBufferFormat().

358  {
360  return *this;
361  }
TrackerSpecialHeader & setBufferFormat(const FEDBufferFormat newBufferFormat)
TrackerSpecialHeader defaultTrackerSpecialHeader_
FEDBufferGenerator & sistrip::FEDBufferGenerator::setBXID ( const uint16_t  newBXID)
inline

Definition at line 339 of file SiStripFEDBufferGenerator.h.

References setBXID().

Referenced by setBXID().

340  {
341  defaultDAQHeader_.setBXID(newBXID);
342  return *this;
343  }
FEDDAQHeader & setBXID(const uint16_t bxID)
FEDBufferGenerator & sistrip::FEDBufferGenerator::setChannelEnable ( const uint8_t  internalFEDChannelNumber,
const bool  enabled 
)

Definition at line 487 of file SiStripFEDBufferGenerator.cc.

References channelsEnabled_, patPFMETCorrections_cff::enabled, and Exception.

488  {
489  try {
490  channelsEnabled_.at(internalFEDChannelNumber) = enabled;
491  } catch (const std::out_of_range&) {
492  std::ostringstream ss;
493  ss << "Invalid channel number " << internalFEDChannelNumber << ". "
494  <<"Should be in internal numbering scheme (0-95)";
495  throw cms::Exception("FEDBufferGenerator") << ss.str();
496  }
497  return *this;
498  }
FEDBufferGenerator & sistrip::FEDBufferGenerator::setChannelEnables ( const std::vector< bool > &  channelsEnabled)

Definition at line 512 of file SiStripFEDBufferGenerator.cc.

References channelsEnabled_, Exception, and sistrip::FEDCH_PER_FED.

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

Definition at line 363 of file SiStripFEDBufferGenerator.h.

364  {
365  defaultDAQHeader_.setEventType(newDAQEventType);
366  return *this;
367  }
FEDDAQHeader & setEventType(const FEDDAQEventType evtType)
FEDBufferGenerator & sistrip::FEDBufferGenerator::setFEUnitEnable ( const uint8_t  internalFEUnitNumber,
const bool  enabled 
)

Definition at line 474 of file SiStripFEDBufferGenerator.cc.

References patPFMETCorrections_cff::enabled, Exception, and feUnitsEnabled_.

475  {
476  try {
477  feUnitsEnabled_.at(internalFEUnitNumber) = enabled;
478  } catch (const std::out_of_range&) {
479  std::ostringstream ss;
480  ss << "Invalid FE unit number " << internalFEUnitNumber << ". "
481  << "Should be in internal numbering scheme (0-7)";
482  throw cms::Exception("FEDBufferGenerator") << ss.str();
483  }
484  return *this;
485  }
FEDBufferGenerator & sistrip::FEDBufferGenerator::setFEUnitEnables ( const std::vector< bool > &  feUnitsEnabled)

Definition at line 500 of file SiStripFEDBufferGenerator.cc.

References Exception, sistrip::FEUNITS_PER_FED, and feUnitsEnabled_.

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

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

Definition at line 351 of file SiStripFEDBufferGenerator.h.

References setHeaderType().

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

352  {
354  return *this;
355  }
TrackerSpecialHeader & setHeaderType(const FEDHeaderType headerType)
TrackerSpecialHeader defaultTrackerSpecialHeader_
FEDBufferGenerator & sistrip::FEDBufferGenerator::setL1ID ( const uint32_t  newL1ID)
inline

Definition at line 333 of file SiStripFEDBufferGenerator.h.

References setL1ID().

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

334  {
335  defaultDAQHeader_.setL1ID(newL1ID);
336  return *this;
337  }
FEDDAQHeader & setL1ID(const uint32_t l1ID)
FEDBufferGenerator & sistrip::FEDBufferGenerator::setReadoutMode ( const FEDReadoutMode  newReadoutMode)
inline

Definition at line 345 of file SiStripFEDBufferGenerator.h.

References setReadoutMode().

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

346  {
348  return *this;
349  }
TrackerSpecialHeader defaultTrackerSpecialHeader_
TrackerSpecialHeader & setReadoutMode(const FEDReadoutMode readoutMode)
TrackerSpecialHeader & sistrip::FEDBufferGenerator::trackerSpecialHeader ( )
inline

Definition at line 379 of file SiStripFEDBufferGenerator.h.

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

380  {
382  }
TrackerSpecialHeader defaultTrackerSpecialHeader_

Member Data Documentation

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

Definition at line 164 of file SiStripFEDBufferGenerator.h.

Referenced by generateBuffer().

FEDDAQTrailer sistrip::FEDBufferGenerator::defaultDAQTrailer_
private

Definition at line 165 of file SiStripFEDBufferGenerator.h.

Referenced by generateBuffer().

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

Definition at line 167 of file SiStripFEDBufferGenerator.h.

Referenced by FEDBufferGenerator(), and generateBuffer().

TrackerSpecialHeader sistrip::FEDBufferGenerator::defaultTrackerSpecialHeader_
private

Definition at line 166 of file SiStripFEDBufferGenerator.h.

Referenced by generateBuffer().

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