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, const uint16_t sourceID) 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::auto_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 357 of file SiStripFEDBufferGenerator.cc.

References defaultFEHeader_, and Exception.

361  : defaultDAQHeader_(l1ID,bxID,0,evtType),
362  defaultDAQTrailer_(0,0),
363  defaultTrackerSpecialHeader_(bufferFormat,readoutMode,headerType),
365  feUnitsEnabled_(feUnitsEnabled),
366  channelsEnabled_(channelsEnabled)
367  {
368  if (!defaultFEHeader_.get()) {
369  std::ostringstream ss;
370  ss << "Bad header format: " << headerType;
371  throw cms::Exception("FEDBufferGenerator") << ss.str();
372  }
373  }
std::auto_ptr< FEDFEHeader > defaultFEHeader_
static std::auto_ptr< FEDFEHeader > newFEHeader(const FEDHeaderType headerType, const uint8_t *headerBuffer)
TrackerSpecialHeader defaultTrackerSpecialHeader_

Member Function Documentation

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

Definition at line 405 of file SiStripFEDBufferGenerator.h.

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

Referenced by fillBuffer(), and generateBuffer().

407  {
408  //FE header + payload + tracker special header + daq header + daq trailer
409  return feHeader.lengthInBytes()+payload.lengthInBytes()+8+8+8;
410  }
payload
payload postfix for testing
virtual size_t lengthInBytes() const =0
FEDDAQHeader & sistrip::FEDBufferGenerator::daqHeader ( )
inline

Definition at line 385 of file SiStripFEDBufferGenerator.h.

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

386  {
387  return defaultDAQHeader_;
388  }
FEDDAQTrailer & sistrip::FEDBufferGenerator::daqTrailer ( )
inline

Definition at line 390 of file SiStripFEDBufferGenerator.h.

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

391  {
392  return defaultDAQTrailer_;
393  }
FEDFEHeader & sistrip::FEDBufferGenerator::feHeader ( )
inline

Definition at line 400 of file SiStripFEDBufferGenerator.h.

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

401  {
402  return *defaultFEHeader_;
403  }
std::auto_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 484 of file SiStripFEDBufferGenerator.cc.

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

Referenced by generateBuffer().

490  {
491  //set the length in the DAQ trailer
492  const size_t lengthInBytes = bufferSizeInBytes(feHeader,payload);
493  FEDDAQTrailer updatedDAQTrailer(daqTrailer);
494  updatedDAQTrailer.setEventLengthIn64BitWords(lengthInBytes/8);
495  //copy pieces into buffer in order
496  uint8_t* bufferPointer = pointerToStartOfBuffer;
497  memcpy(bufferPointer,daqHeader.data(),8);
498  bufferPointer += 8;
499  memcpy(bufferPointer,tkSpecialHeader.data(),8);
500  bufferPointer += 8;
501  memcpy(bufferPointer,feHeader.data(),feHeader.lengthInBytes());
502  bufferPointer += feHeader.lengthInBytes();
503  memcpy(bufferPointer,payload.data(),payload.lengthInBytes());
504  bufferPointer += payload.lengthInBytes();
505  memcpy(bufferPointer,updatedDAQTrailer.data(),8);
506  //update CRC
507  const uint16_t crc = calculateFEDBufferCRC(pointerToStartOfBuffer,lengthInBytes);
508  updatedDAQTrailer.setCRC(crc);
509  memcpy(bufferPointer,updatedDAQTrailer.data(),8);
510  //word swap if necessary
511  if (tkSpecialHeader.wasSwapped()) {
512  for (size_t i = 0; i < 8; i++) {
513  bufferPointer[i] = bufferPointer[i^4];
514  }
515  }
516  }
int i
Definition: DBlmapReader.cc:9
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
payload
payload postfix for testing
virtual const uint8_t * data() const =0
virtual size_t lengthInBytes() const =0
void sistrip::FEDBufferGenerator::generateBuffer ( FEDRawData rawDataObject,
const FEDStripData data,
const uint16_t  sourceID 
) const

Definition at line 449 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(), jetCorrFactors_cfi::payload, FEDRawData::resize(), sistrip::TrackerSpecialHeader::setFEEnableForFEUnit(), and sistrip::FEDDAQHeader::setSourceID().

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

450  {
451  //deal with disabled FE units and channels properly (FE enables, status bits)
452  TrackerSpecialHeader tkSpecialHeader(defaultTrackerSpecialHeader_);
453  std::auto_ptr<FEDFEHeader> fedFeHeader(defaultFEHeader_->clone());
454  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
455  const bool enabled = feUnitsEnabled_[iFE];
456  tkSpecialHeader.setFEEnableForFEUnit(iFE,enabled);
457  if (!enabled) {
458  for (uint8_t iFEUnitChannel = 0; iFEUnitChannel < FEDCH_PER_FEUNIT; iFEUnitChannel++) {
459  fedFeHeader->setChannelStatus(iFE,iFEUnitChannel,FEDChannelStatus(0));
460  }
461  }
462  }
463  for (uint8_t iCh = 0; iCh < FEDCH_PER_FED; iCh++) {
464  if (!channelsEnabled_[iCh]) {
465  fedFeHeader->setChannelStatus(iCh,FEDChannelStatus(0));
466  }
467  }
468  //set the source ID
469  FEDDAQHeader daqHeader(defaultDAQHeader_);
470  daqHeader.setSourceID(sourceID);
471  //build payload
472  const FEDBufferPayloadCreator payloadPacker(feUnitsEnabled_,channelsEnabled_);
473  const FEDBufferPayload payload = payloadPacker(getReadoutMode(),data);
474  //fill FE lengths
475  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
476  fedFeHeader->setFEUnitLength(iFE,payload.getFELength(iFE));
477  }
478  //resize buffer
479  rawDataObject->resize(bufferSizeInBytes(*fedFeHeader,payload));
480  //fill buffer
481  fillBuffer(rawDataObject->data(),daqHeader,defaultDAQTrailer_,tkSpecialHeader,*fedFeHeader,payload);
482  }
static size_t bufferSizeInBytes(const FEDFEHeader &feHeader, const FEDBufferPayload &payload)
FEDReadoutMode getReadoutMode() const
payload
payload postfix for testing
void resize(size_t newsize)
Definition: FEDRawData.cc:32
static const uint16_t FEUNITS_PER_FED
static const uint16_t FEDCH_PER_FEUNIT
std::auto_ptr< FEDFEHeader > defaultFEHeader_
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 339 of file SiStripFEDBufferGenerator.h.

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

340  {
342  }
TrackerSpecialHeader defaultTrackerSpecialHeader_
uint16_t sistrip::FEDBufferGenerator::getBXID ( ) const
inline

Definition at line 324 of file SiStripFEDBufferGenerator.h.

325  {
326  return defaultDAQHeader_.bxID();
327  }
bool sistrip::FEDBufferGenerator::getChannelEnabled ( const uint8_t  internalFEDChannelNumber) const

Definition at line 386 of file SiStripFEDBufferGenerator.cc.

References channelsEnabled_, and Exception.

387  {
388  try {
389  return channelsEnabled_.at(internalFEDChannelNumber);
390  } catch (const std::out_of_range&) {
391 
392  std::ostringstream ss;
393  ss << "Invalid channel number " << internalFEDChannelNumber << ". "
394  << "Should be in internal numbering scheme (0-95)";
395  throw cms::Exception("FEDBufferGenerator") << ss.str();
396  }
397  }
FEDDAQEventType sistrip::FEDBufferGenerator::getDAQEventType ( ) const
inline

Definition at line 344 of file SiStripFEDBufferGenerator.h.

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

345  {
346  return defaultDAQHeader_.eventType();
347  }
FEDDAQEventType eventType() const
bool sistrip::FEDBufferGenerator::getFEUnitEnabled ( const uint8_t  internalFEUnitNumber) const

Definition at line 375 of file SiStripFEDBufferGenerator.cc.

References Exception, and feUnitsEnabled_.

376  {
377  try {
378  return feUnitsEnabled_.at(internalFEUnitNumber);
379  } catch (const std::out_of_range&) {
380  std::ostringstream ss;
381  ss << "Invalid FE unit number " << internalFEUnitNumber << ". Should be in internal numbering scheme (0-7)";
382  throw cms::Exception("FEDBufferGenerator") << ss.str();
383  }
384  }
FEDHeaderType sistrip::FEDBufferGenerator::getHeaderType ( ) const
inline

Definition at line 334 of file SiStripFEDBufferGenerator.h.

335  {
337  }
TrackerSpecialHeader defaultTrackerSpecialHeader_
uint32_t sistrip::FEDBufferGenerator::getL1ID ( ) const
inline

Definition at line 319 of file SiStripFEDBufferGenerator.h.

320  {
321  return defaultDAQHeader_.l1ID();
322  }
FEDReadoutMode sistrip::FEDBufferGenerator::getReadoutMode ( ) const
inline

Definition at line 329 of file SiStripFEDBufferGenerator.h.

Referenced by generateBuffer().

330  {
332  }
TrackerSpecialHeader defaultTrackerSpecialHeader_
FEDBufferGenerator & sistrip::FEDBufferGenerator::setBufferFormat ( const FEDBufferFormat  newBufferFormat)
inline

Definition at line 373 of file SiStripFEDBufferGenerator.h.

References setBufferFormat().

Referenced by setBufferFormat().

374  {
376  return *this;
377  }
TrackerSpecialHeader & setBufferFormat(const FEDBufferFormat newBufferFormat)
TrackerSpecialHeader defaultTrackerSpecialHeader_
FEDBufferGenerator & sistrip::FEDBufferGenerator::setBXID ( const uint16_t  newBXID)
inline

Definition at line 355 of file SiStripFEDBufferGenerator.h.

References setBXID().

Referenced by setBXID().

356  {
357  defaultDAQHeader_.setBXID(newBXID);
358  return *this;
359  }
FEDDAQHeader & setBXID(const uint16_t bxID)
FEDBufferGenerator & sistrip::FEDBufferGenerator::setChannelEnable ( const uint8_t  internalFEDChannelNumber,
const bool  enabled 
)

Definition at line 412 of file SiStripFEDBufferGenerator.cc.

References channelsEnabled_, patPFMETCorrections_cff::enabled, and Exception.

413  {
414  try {
415  channelsEnabled_.at(internalFEDChannelNumber) = enabled;
416  } catch (const std::out_of_range&) {
417  std::ostringstream ss;
418  ss << "Invalid channel number " << internalFEDChannelNumber << ". "
419  <<"Should be in internal numbering scheme (0-95)";
420  throw cms::Exception("FEDBufferGenerator") << ss.str();
421  }
422  return *this;
423  }
FEDBufferGenerator & sistrip::FEDBufferGenerator::setChannelEnables ( const std::vector< bool > &  channelsEnabled)

Definition at line 437 of file SiStripFEDBufferGenerator.cc.

References channelsEnabled_, Exception, and sistrip::FEDCH_PER_FED.

438  {
439  if (channelEnables.size() != FEDCH_PER_FED) {
440  std::ostringstream ss;
441  ss << "Setting FED channel enable vector with vector which is the wrong size. Size is " << channelEnables.size()
442  << " it must be " << FEDCH_PER_FED << "." << std::endl;
443  throw cms::Exception("FEDBufferGenerator") << ss.str();
444  }
445  channelsEnabled_ = channelEnables;
446  return *this;
447  }
static const uint16_t FEDCH_PER_FED
FEDBufferGenerator & sistrip::FEDBufferGenerator::setDAQEventType ( const FEDDAQEventType  newDAQEventType)
inline

Definition at line 379 of file SiStripFEDBufferGenerator.h.

380  {
381  defaultDAQHeader_.setEventType(newDAQEventType);
382  return *this;
383  }
FEDDAQHeader & setEventType(const FEDDAQEventType evtType)
FEDBufferGenerator & sistrip::FEDBufferGenerator::setFEUnitEnable ( const uint8_t  internalFEUnitNumber,
const bool  enabled 
)

Definition at line 399 of file SiStripFEDBufferGenerator.cc.

References patPFMETCorrections_cff::enabled, Exception, and feUnitsEnabled_.

400  {
401  try {
402  feUnitsEnabled_.at(internalFEUnitNumber) = enabled;
403  } catch (const std::out_of_range&) {
404  std::ostringstream ss;
405  ss << "Invalid FE unit number " << internalFEUnitNumber << ". "
406  << "Should be in internal numbering scheme (0-7)";
407  throw cms::Exception("FEDBufferGenerator") << ss.str();
408  }
409  return *this;
410  }
FEDBufferGenerator & sistrip::FEDBufferGenerator::setFEUnitEnables ( const std::vector< bool > &  feUnitsEnabled)

Definition at line 425 of file SiStripFEDBufferGenerator.cc.

References Exception, sistrip::FEUNITS_PER_FED, and feUnitsEnabled_.

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

426  {
427  if (feUnitEnables.size() != FEUNITS_PER_FED) {
428  std::ostringstream ss;
429  ss << "Setting FE enable vector with vector which is the wrong size. Size is " << feUnitEnables.size()
430  << " it must be " << FEUNITS_PER_FED << "." << std::endl;
431  throw cms::Exception("FEDBufferGenerator") << ss.str();
432  }
433  feUnitsEnabled_ = feUnitEnables;
434  return *this;
435  }
static const uint16_t FEUNITS_PER_FED
FEDBufferGenerator & sistrip::FEDBufferGenerator::setHeaderType ( const FEDHeaderType  newHeaderType)
inline

Definition at line 367 of file SiStripFEDBufferGenerator.h.

References setHeaderType().

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

368  {
370  return *this;
371  }
TrackerSpecialHeader & setHeaderType(const FEDHeaderType headerType)
TrackerSpecialHeader defaultTrackerSpecialHeader_
FEDBufferGenerator & sistrip::FEDBufferGenerator::setL1ID ( const uint32_t  newL1ID)
inline

Definition at line 349 of file SiStripFEDBufferGenerator.h.

References setL1ID().

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

350  {
351  defaultDAQHeader_.setL1ID(newL1ID);
352  return *this;
353  }
FEDDAQHeader & setL1ID(const uint32_t l1ID)
FEDBufferGenerator & sistrip::FEDBufferGenerator::setReadoutMode ( const FEDReadoutMode  newReadoutMode)
inline

Definition at line 361 of file SiStripFEDBufferGenerator.h.

References setReadoutMode().

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

362  {
364  return *this;
365  }
TrackerSpecialHeader defaultTrackerSpecialHeader_
TrackerSpecialHeader & setReadoutMode(const FEDReadoutMode readoutMode)
TrackerSpecialHeader & sistrip::FEDBufferGenerator::trackerSpecialHeader ( )
inline

Definition at line 395 of file SiStripFEDBufferGenerator.h.

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

396  {
398  }
TrackerSpecialHeader defaultTrackerSpecialHeader_

Member Data Documentation

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

Definition at line 163 of file SiStripFEDBufferGenerator.h.

Referenced by generateBuffer().

FEDDAQTrailer sistrip::FEDBufferGenerator::defaultDAQTrailer_
private

Definition at line 164 of file SiStripFEDBufferGenerator.h.

Referenced by generateBuffer().

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

Definition at line 166 of file SiStripFEDBufferGenerator.h.

Referenced by FEDBufferGenerator(), and generateBuffer().

TrackerSpecialHeader sistrip::FEDBufferGenerator::defaultTrackerSpecialHeader_
private

Definition at line 165 of file SiStripFEDBufferGenerator.h.

Referenced by generateBuffer().

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