CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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, const FEDDataType dataType=DATA_TYPE_FAKE)
 
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
 
FEDDataType getFEDDataType () 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)
 
FEDBufferGeneratorsetFEDDataType (const FEDDataType newFEDDataType)
 
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,
const FEDDataType  dataType = DATA_TYPE_FAKE 
)

Definition at line 322 of file SiStripFEDBufferGenerator.cc.

References defaultFEHeader_, edm::hlt::Exception, and contentValuesCheck::ss.

326  : defaultDAQHeader_(l1ID,bxID,0,evtType),
327  defaultDAQTrailer_(0,0),
328  defaultTrackerSpecialHeader_(bufferFormat,readoutMode,headerType,dataType),
330  feUnitsEnabled_(feUnitsEnabled),
331  channelsEnabled_(channelsEnabled)
332  {
333  if (!defaultFEHeader_.get()) {
334  std::ostringstream ss;
335  ss << "Bad header format: " << headerType;
336  throw cms::Exception("FEDBufferGenerator") << ss.str();
337  }
338  }
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 400 of file SiStripFEDBufferGenerator.h.

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

Referenced by fillBuffer(), and generateBuffer().

402  {
403  //FE header + payload + tracker special header + daq header + daq trailer
404  return feHeader.lengthInBytes()+payload.lengthInBytes()+8+8+8;
405  }
virtual size_t lengthInBytes() const =0
FEDDAQHeader & sistrip::FEDBufferGenerator::daqHeader ( )
inline

Definition at line 380 of file SiStripFEDBufferGenerator.h.

References defaultDAQHeader_.

Referenced by generateBuffer().

381  {
382  return defaultDAQHeader_;
383  }
FEDDAQTrailer & sistrip::FEDBufferGenerator::daqTrailer ( )
inline

Definition at line 385 of file SiStripFEDBufferGenerator.h.

References defaultDAQTrailer_.

386  {
387  return defaultDAQTrailer_;
388  }
FEDFEHeader & sistrip::FEDBufferGenerator::feHeader ( )
inline

Definition at line 395 of file SiStripFEDBufferGenerator.h.

References defaultFEHeader_.

396  {
397  return *defaultFEHeader_;
398  }
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 449 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().

455  {
456  //set the length in the DAQ trailer
457  const size_t lengthInBytes = bufferSizeInBytes(feHeader,payload);
458  FEDDAQTrailer updatedDAQTrailer(daqTrailer);
459  updatedDAQTrailer.setEventLengthIn64BitWords(lengthInBytes/8);
460  //copy pieces into buffer in order
461  uint8_t* bufferPointer = pointerToStartOfBuffer;
462  memcpy(bufferPointer,daqHeader.data(),8);
463  bufferPointer += 8;
464  memcpy(bufferPointer,tkSpecialHeader.data(),8);
465  bufferPointer += 8;
466  memcpy(bufferPointer,feHeader.data(),feHeader.lengthInBytes());
467  bufferPointer += feHeader.lengthInBytes();
468  memcpy(bufferPointer,payload.data(),payload.lengthInBytes());
469  bufferPointer += payload.lengthInBytes();
470  memcpy(bufferPointer,updatedDAQTrailer.data(),8);
471  //update CRC
472  const uint16_t crc = calculateFEDBufferCRC(pointerToStartOfBuffer,lengthInBytes);
473  updatedDAQTrailer.setCRC(crc);
474  memcpy(bufferPointer,updatedDAQTrailer.data(),8);
475  //word swap if necessary
476  if (tkSpecialHeader.wasSwapped()) {
477  for (size_t i = 0; i < 8; i++) {
478  bufferPointer[i] = bufferPointer[i^4];
479  }
480  }
481  }
virtual size_t lengthInBytes() const =0
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
virtual const uint8_t * data() const =0
void sistrip::FEDBufferGenerator::generateBuffer ( FEDRawData rawDataObject,
const FEDStripData data,
const uint16_t  sourceID 
) const

Definition at line 414 of file SiStripFEDBufferGenerator.cc.

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

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

415  {
416  //deal with disabled FE units and channels properly (FE enables, status bits)
417  TrackerSpecialHeader tkSpecialHeader(defaultTrackerSpecialHeader_);
418  std::auto_ptr<FEDFEHeader> fedFeHeader(defaultFEHeader_->clone());
419  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
420  const bool enabled = feUnitsEnabled_[iFE];
421  tkSpecialHeader.setFEEnableForFEUnit(iFE,enabled);
422  if (!enabled) {
423  for (uint8_t iFEUnitChannel = 0; iFEUnitChannel < FEDCH_PER_FEUNIT; iFEUnitChannel++) {
424  fedFeHeader->setChannelStatus(iFE,iFEUnitChannel,FEDChannelStatus(0));
425  }
426  }
427  }
428  for (uint8_t iCh = 0; iCh < FEDCH_PER_FED; iCh++) {
429  if (!channelsEnabled_[iCh]) {
430  fedFeHeader->setChannelStatus(iCh,FEDChannelStatus(0));
431  }
432  }
433  //set the source ID
434  FEDDAQHeader daqHeader(defaultDAQHeader_);
435  daqHeader.setSourceID(sourceID);
436  //build payload
437  const FEDBufferPayloadCreator payloadPacker(feUnitsEnabled_,channelsEnabled_);
438  const FEDBufferPayload payload = payloadPacker(getReadoutMode(),data);
439  //fill FE lengths
440  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
441  fedFeHeader->setFEUnitLength(iFE,payload.getFELength(iFE));
442  }
443  //resize buffer
444  rawDataObject->resize(bufferSizeInBytes(*fedFeHeader,payload));
445  //fill buffer
446  fillBuffer(rawDataObject->data(),daqHeader,defaultDAQTrailer_,tkSpecialHeader,*fedFeHeader,payload);
447  }
static size_t bufferSizeInBytes(const FEDFEHeader &feHeader, const FEDBufferPayload &payload)
FEDReadoutMode getReadoutMode() const
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
uint16_t sistrip::FEDBufferGenerator::getBXID ( ) const
inline

Definition at line 308 of file SiStripFEDBufferGenerator.h.

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

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

Definition at line 351 of file SiStripFEDBufferGenerator.cc.

References channelsEnabled_, edm::hlt::Exception, and contentValuesCheck::ss.

352  {
353  try {
354  return channelsEnabled_.at(internalFEDChannelNumber);
355  } catch (const std::out_of_range&) {
356 
357  std::ostringstream ss;
358  ss << "Invalid channel number " << internalFEDChannelNumber << ". "
359  << "Should be in internal numbering scheme (0-95)";
360  throw cms::Exception("FEDBufferGenerator") << ss.str();
361  }
362  }
FEDDAQEventType sistrip::FEDBufferGenerator::getDAQEventType ( ) const
inline

Definition at line 328 of file SiStripFEDBufferGenerator.h.

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

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

Definition at line 340 of file SiStripFEDBufferGenerator.cc.

References edm::hlt::Exception, feUnitsEnabled_, and contentValuesCheck::ss.

341  {
342  try {
343  return feUnitsEnabled_.at(internalFEUnitNumber);
344  } catch (const std::out_of_range&) {
345  std::ostringstream ss;
346  ss << "Invalid FE unit number " << internalFEUnitNumber << ". Should be in internal numbering scheme (0-7)";
347  throw cms::Exception("FEDBufferGenerator") << ss.str();
348  }
349  }
FEDHeaderType sistrip::FEDBufferGenerator::getHeaderType ( ) const
inline
uint32_t sistrip::FEDBufferGenerator::getL1ID ( ) const
inline

Definition at line 303 of file SiStripFEDBufferGenerator.h.

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

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

Definition at line 362 of file SiStripFEDBufferGenerator.h.

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

363  {
365  return *this;
366  }
TrackerSpecialHeader & setBufferFormat(const FEDBufferFormat newBufferFormat)
TrackerSpecialHeader defaultTrackerSpecialHeader_
FEDBufferGenerator & sistrip::FEDBufferGenerator::setBXID ( const uint16_t  newBXID)
inline

Definition at line 344 of file SiStripFEDBufferGenerator.h.

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

345  {
346  defaultDAQHeader_.setBXID(newBXID);
347  return *this;
348  }
FEDDAQHeader & setBXID(const uint16_t bxID)
FEDBufferGenerator & sistrip::FEDBufferGenerator::setChannelEnable ( const uint8_t  internalFEDChannelNumber,
const bool  enabled 
)

Definition at line 377 of file SiStripFEDBufferGenerator.cc.

References channelsEnabled_, edm::hlt::Exception, and contentValuesCheck::ss.

378  {
379  try {
380  channelsEnabled_.at(internalFEDChannelNumber) = enabled;
381  } catch (const std::out_of_range&) {
382  std::ostringstream ss;
383  ss << "Invalid channel number " << internalFEDChannelNumber << ". "
384  <<"Should be in internal numbering scheme (0-95)";
385  throw cms::Exception("FEDBufferGenerator") << ss.str();
386  }
387  return *this;
388  }
FEDBufferGenerator & sistrip::FEDBufferGenerator::setChannelEnables ( const std::vector< bool > &  channelsEnabled)

Definition at line 402 of file SiStripFEDBufferGenerator.cc.

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

403  {
404  if (channelEnables.size() != FEDCH_PER_FED) {
405  std::ostringstream ss;
406  ss << "Setting FED channel enable vector with vector which is the wrong size. Size is " << channelEnables.size()
407  << " it must be " << FEDCH_PER_FED << "." << std::endl;
408  throw cms::Exception("FEDBufferGenerator") << ss.str();
409  }
410  channelsEnabled_ = channelEnables;
411  return *this;
412  }
static const uint16_t FEDCH_PER_FED
FEDBufferGenerator & sistrip::FEDBufferGenerator::setDAQEventType ( const FEDDAQEventType  newDAQEventType)
inline

Definition at line 368 of file SiStripFEDBufferGenerator.h.

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

369  {
370  defaultDAQHeader_.setEventType(newDAQEventType);
371  return *this;
372  }
FEDDAQHeader & setEventType(const FEDDAQEventType evtType)
FEDBufferGenerator & sistrip::FEDBufferGenerator::setFEDDataType ( const FEDDataType  newFEDDataType)
inline

Definition at line 374 of file SiStripFEDBufferGenerator.h.

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

375  {
377  return *this;
378  }
TrackerSpecialHeader & setDataType(const FEDDataType dataType)
TrackerSpecialHeader defaultTrackerSpecialHeader_
FEDBufferGenerator & sistrip::FEDBufferGenerator::setFEUnitEnable ( const uint8_t  internalFEUnitNumber,
const bool  enabled 
)

Definition at line 364 of file SiStripFEDBufferGenerator.cc.

References edm::hlt::Exception, feUnitsEnabled_, and contentValuesCheck::ss.

365  {
366  try {
367  feUnitsEnabled_.at(internalFEUnitNumber) = enabled;
368  } catch (const std::out_of_range&) {
369  std::ostringstream ss;
370  ss << "Invalid FE unit number " << internalFEUnitNumber << ". "
371  << "Should be in internal numbering scheme (0-7)";
372  throw cms::Exception("FEDBufferGenerator") << ss.str();
373  }
374  return *this;
375  }
FEDBufferGenerator & sistrip::FEDBufferGenerator::setFEUnitEnables ( const std::vector< bool > &  feUnitsEnabled)

Definition at line 390 of file SiStripFEDBufferGenerator.cc.

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

391  {
392  if (feUnitEnables.size() != FEUNITS_PER_FED) {
393  std::ostringstream ss;
394  ss << "Setting FE enable vector with vector which is the wrong size. Size is " << feUnitEnables.size()
395  << " it must be " << FEUNITS_PER_FED << "." << std::endl;
396  throw cms::Exception("FEDBufferGenerator") << ss.str();
397  }
398  feUnitsEnabled_ = feUnitEnables;
399  return *this;
400  }
static const uint16_t FEUNITS_PER_FED
FEDBufferGenerator & sistrip::FEDBufferGenerator::setHeaderType ( const FEDHeaderType  newHeaderType)
inline

Definition at line 356 of file SiStripFEDBufferGenerator.h.

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

357  {
359  return *this;
360  }
TrackerSpecialHeader & setHeaderType(const FEDHeaderType headerType)
TrackerSpecialHeader defaultTrackerSpecialHeader_
FEDBufferGenerator & sistrip::FEDBufferGenerator::setL1ID ( const uint32_t  newL1ID)
inline

Definition at line 338 of file SiStripFEDBufferGenerator.h.

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

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

339  {
340  defaultDAQHeader_.setL1ID(newL1ID);
341  return *this;
342  }
FEDDAQHeader & setL1ID(const uint32_t l1ID)
FEDBufferGenerator & sistrip::FEDBufferGenerator::setReadoutMode ( const FEDReadoutMode  newReadoutMode)
inline

Definition at line 350 of file SiStripFEDBufferGenerator.h.

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

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

351  {
353  return *this;
354  }
TrackerSpecialHeader defaultTrackerSpecialHeader_
TrackerSpecialHeader & setReadoutMode(const FEDReadoutMode readoutMode)
TrackerSpecialHeader & sistrip::FEDBufferGenerator::trackerSpecialHeader ( )
inline

Definition at line 390 of file SiStripFEDBufferGenerator.h.

References defaultTrackerSpecialHeader_.

391  {
393  }
TrackerSpecialHeader defaultTrackerSpecialHeader_

Member Data Documentation

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

Definition at line 167 of file SiStripFEDBufferGenerator.h.

Referenced by daqTrailer(), and generateBuffer().

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

Definition at line 169 of file SiStripFEDBufferGenerator.h.

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

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