CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

sistrip::FEDBufferPayload Class Reference

#include <SiStripFEDBufferGenerator.h>

List of all members.

Public Member Functions

const uint8_t * data () const
 FEDBufferPayload (const std::vector< std::vector< uint8_t > > &channelBuffers)
uint16_t getFELength (const uint8_t internalFEUnitNum) const
size_t lengthInBytes () const

Private Member Functions

void appendToBuffer (size_t *pIndexInBuffer, const uint8_t value)
void appendToBuffer (size_t *pIndexInBuffer, std::vector< uint8_t >::const_iterator start, std::vector< uint8_t >::const_iterator finish)

Private Attributes

std::vector< uint8_t > data_
std::vector< uint16_t > feLengths_

Detailed Description

Definition at line 59 of file SiStripFEDBufferGenerator.h.


Constructor & Destructor Documentation

sistrip::FEDBufferPayload::FEDBufferPayload ( const std::vector< std::vector< uint8_t > > &  channelBuffers)

Definition at line 53 of file SiStripFEDBufferGenerator.cc.

References begin, sistrip::FEDStripData::data_, end, sistrip::FEDCH_PER_FEUNIT, and sistrip::FEUNITS_PER_FED.

  {
    //calculate size of buffer and allocate enough memory
    uint32_t totalSize = 0;
    for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
      for (uint8_t iCh = 0; iCh < FEDCH_PER_FEUNIT; iCh++) {
        totalSize += channelBuffers[iFE*FEDCH_PER_FEUNIT+iCh].size();
      }
      //if it does not finish on a 64Bit word boundary then take into account padding
      if (totalSize%8) {
        totalSize = ((totalSize/8) + 1)*8;
      }
    }
    data_.resize(totalSize);
    size_t indexInBuffer = 0;
    feLengths_.reserve(FEUNITS_PER_FED);
    //copy channel data into buffer with padding and update lengths
    for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
      const size_t lengthAtStartOfFEUnit = indexInBuffer;
      //insert data for FE unit
      for (uint8_t iCh = 0; iCh < FEDCH_PER_FEUNIT; iCh++) {
        appendToBuffer(&indexInBuffer,channelBuffers[iFE*FEDCH_PER_FEUNIT+iCh].begin(),channelBuffers[iFE*FEDCH_PER_FEUNIT+iCh].end());
      }
      //store length
      feLengths_.push_back(indexInBuffer-lengthAtStartOfFEUnit);
      //add padding
      while (indexInBuffer % 8) appendToBuffer(&indexInBuffer,0);
    }
  }

Member Function Documentation

void sistrip::FEDBufferPayload::appendToBuffer ( size_t *  pIndexInBuffer,
const uint8_t  value 
) [inline, private]

Definition at line 262 of file SiStripFEDBufferGenerator.h.

References sistrip::FEDStripData::data_.

    {
      data_[((*pIndexInBuffer)++)^7] = value;
    }
void sistrip::FEDBufferPayload::appendToBuffer ( size_t *  pIndexInBuffer,
std::vector< uint8_t >::const_iterator  start,
std::vector< uint8_t >::const_iterator  finish 
) [inline, private]

Definition at line 267 of file SiStripFEDBufferGenerator.h.

    {
      for (std::vector<uint8_t>::const_iterator iVal = start; iVal != finish; iVal++) {
        appendToBuffer(pIndexInBuffer,*iVal);
      }
    }
const uint8_t * sistrip::FEDBufferPayload::data ( ) const

Definition at line 83 of file SiStripFEDBufferGenerator.cc.

References sistrip::FEDStripData::data_, and NULL.

Referenced by sistrip::FEDBufferGenerator::fillBuffer().

  {
    //vectors are guarenteed to be contiguous
    if (lengthInBytes()) return &data_[0];
    //return NULL if there is no data yet
    else return NULL;
  }
uint16_t sistrip::FEDBufferPayload::getFELength ( const uint8_t  internalFEUnitNum) const

Definition at line 91 of file SiStripFEDBufferGenerator.cc.

References Exception.

Referenced by sistrip::FEDBufferGenerator::generateBuffer().

  {
    try{
      return feLengths_.at(internalFEUnitNum);
    } catch (const std::out_of_range&) {
      std::ostringstream ss;
      ss << "Invalid FE unit number " << internalFEUnitNum << ". "
         << "Number should be in internal numbering scheme (0-7). ";
      throw cms::Exception("FEDBufferGenerator") << ss.str();
    }
  }
size_t sistrip::FEDBufferPayload::lengthInBytes ( ) const [inline]

Member Data Documentation

std::vector<uint8_t> sistrip::FEDBufferPayload::data_ [private]

Definition at line 72 of file SiStripFEDBufferGenerator.h.

std::vector<uint16_t> sistrip::FEDBufferPayload::feLengths_ [private]

Definition at line 73 of file SiStripFEDBufferGenerator.h.