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

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

256  : defaultDAQHeader_(l1ID,bxID,0,evtType),
257  defaultDAQTrailer_(0,0),
258  defaultTrackerSpecialHeader_(bufferFormat,readoutMode,headerType,dataType),
260  feUnitsEnabled_(feUnitsEnabled),
261  channelsEnabled_(channelsEnabled)
262  {
263  if (!defaultFEHeader_.get()) {
264  std::ostringstream ss;
265  ss << "Bad header format: " << headerType;
266  throw cms::Exception("FEDBufferGenerator") << ss.str();
267  }
268  }
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 385 of file SiStripFEDBufferGenerator.h.

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

Referenced by fillBuffer(), and generateBuffer().

387  {
388  //FE header + payload + tracker special header + daq header + daq trailer
389  return feHeader.lengthInBytes()+payload.lengthInBytes()+8+8+8;
390  }
virtual size_t lengthInBytes() const =0
FEDDAQHeader & sistrip::FEDBufferGenerator::daqHeader ( )
inline

Definition at line 365 of file SiStripFEDBufferGenerator.h.

References defaultDAQHeader_.

Referenced by generateBuffer().

366  {
367  return defaultDAQHeader_;
368  }
FEDDAQTrailer & sistrip::FEDBufferGenerator::daqTrailer ( )
inline

Definition at line 370 of file SiStripFEDBufferGenerator.h.

References defaultDAQTrailer_.

371  {
372  return defaultDAQTrailer_;
373  }
FEDFEHeader & sistrip::FEDBufferGenerator::feHeader ( )
inline

Definition at line 380 of file SiStripFEDBufferGenerator.h.

References defaultFEHeader_.

381  {
382  return *defaultFEHeader_;
383  }
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 379 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().

385  {
386  //set the length in the DAQ trailer
387  const size_t lengthInBytes = bufferSizeInBytes(feHeader,payload);
388  FEDDAQTrailer updatedDAQTrailer(daqTrailer);
389  updatedDAQTrailer.setEventLengthIn64BitWords(lengthInBytes/8);
390  //copy pieces into buffer in order
391  uint8_t* bufferPointer = pointerToStartOfBuffer;
392  memcpy(bufferPointer,daqHeader.data(),8);
393  bufferPointer += 8;
394  memcpy(bufferPointer,tkSpecialHeader.data(),8);
395  bufferPointer += 8;
396  memcpy(bufferPointer,feHeader.data(),feHeader.lengthInBytes());
397  bufferPointer += feHeader.lengthInBytes();
398  memcpy(bufferPointer,payload.data(),payload.lengthInBytes());
399  bufferPointer += payload.lengthInBytes();
400  memcpy(bufferPointer,updatedDAQTrailer.data(),8);
401  //update CRC
402  const uint16_t crc = calculateFEDBufferCRC(pointerToStartOfBuffer,lengthInBytes);
403  updatedDAQTrailer.setCRC(crc);
404  memcpy(bufferPointer,updatedDAQTrailer.data(),8);
405  //word swap if necessary
406  if (tkSpecialHeader.wasSwapped()) {
407  for (size_t i = 0; i < 8; i++) {
408  bufferPointer[i] = bufferPointer[i^4];
409  }
410  }
411  }
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 344 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_().

345  {
346  //deal with disabled FE units and channels properly (FE enables, status bits)
347  TrackerSpecialHeader tkSpecialHeader(defaultTrackerSpecialHeader_);
348  std::auto_ptr<FEDFEHeader> fedFeHeader(defaultFEHeader_->clone());
349  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
350  const bool enabled = feUnitsEnabled_[iFE];
351  tkSpecialHeader.setFEEnableForFEUnit(iFE,enabled);
352  if (!enabled) {
353  for (uint8_t iFEUnitChannel = 0; iFEUnitChannel < FEDCH_PER_FEUNIT; iFEUnitChannel++) {
354  fedFeHeader->setChannelStatus(iFE,iFEUnitChannel,FEDChannelStatus(0));
355  }
356  }
357  }
358  for (uint8_t iCh = 0; iCh < FEDCH_PER_FED; iCh++) {
359  if (!channelsEnabled_[iCh]) {
360  fedFeHeader->setChannelStatus(iCh,FEDChannelStatus(0));
361  }
362  }
363  //set the source ID
364  FEDDAQHeader daqHeader(defaultDAQHeader_);
365  daqHeader.setSourceID(sourceID);
366  //build payload
367  const FEDBufferPayloadCreator payloadPacker(feUnitsEnabled_,channelsEnabled_);
368  const FEDBufferPayload payload = payloadPacker(getReadoutMode(),data);
369  //fill FE lengths
370  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
371  fedFeHeader->setFEUnitLength(iFE,payload.getFELength(iFE));
372  }
373  //resize buffer
374  rawDataObject->resize(bufferSizeInBytes(*fedFeHeader,payload));
375  //fill buffer
376  fillBuffer(rawDataObject->data(),daqHeader,defaultDAQTrailer_,tkSpecialHeader,*fedFeHeader,payload);
377  }
static size_t bufferSizeInBytes(const FEDFEHeader &feHeader, const FEDBufferPayload &payload)
FEDReadoutMode getReadoutMode() const
void resize(size_t newsize)
Definition: FEDRawData.cc:33
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:29
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 293 of file SiStripFEDBufferGenerator.h.

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

294  {
295  return defaultDAQHeader_.bxID();
296  }
bool sistrip::FEDBufferGenerator::getChannelEnabled ( const uint8_t  internalFEDChannelNumber) const

Definition at line 281 of file SiStripFEDBufferGenerator.cc.

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

282  {
283  try {
284  return channelsEnabled_.at(internalFEDChannelNumber);
285  } catch (const std::out_of_range&) {
286 
287  std::ostringstream ss;
288  ss << "Invalid channel number " << internalFEDChannelNumber << ". "
289  << "Should be in internal numbering scheme (0-95)";
290  throw cms::Exception("FEDBufferGenerator") << ss.str();
291  }
292  }
FEDDAQEventType sistrip::FEDBufferGenerator::getDAQEventType ( ) const
inline

Definition at line 313 of file SiStripFEDBufferGenerator.h.

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

314  {
315  return defaultDAQHeader_.eventType();
316  }
FEDDAQEventType eventType() const
FEDDataType sistrip::FEDBufferGenerator::getFEDDataType ( ) const
inline
bool sistrip::FEDBufferGenerator::getFEUnitEnabled ( const uint8_t  internalFEUnitNumber) const

Definition at line 270 of file SiStripFEDBufferGenerator.cc.

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

271  {
272  try {
273  return feUnitsEnabled_.at(internalFEUnitNumber);
274  } catch (const std::out_of_range&) {
275  std::ostringstream ss;
276  ss << "Invalid FE unit number " << internalFEUnitNumber << ". Should be in internal numbering scheme (0-7)";
277  throw cms::Exception("FEDBufferGenerator") << ss.str();
278  }
279  }
FEDHeaderType sistrip::FEDBufferGenerator::getHeaderType ( ) const
inline
uint32_t sistrip::FEDBufferGenerator::getL1ID ( ) const
inline

Definition at line 288 of file SiStripFEDBufferGenerator.h.

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

289  {
290  return defaultDAQHeader_.l1ID();
291  }
FEDReadoutMode sistrip::FEDBufferGenerator::getReadoutMode ( ) const
inline
FEDBufferGenerator & sistrip::FEDBufferGenerator::setBufferFormat ( const FEDBufferFormat  newBufferFormat)
inline

Definition at line 347 of file SiStripFEDBufferGenerator.h.

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

348  {
350  return *this;
351  }
TrackerSpecialHeader & setBufferFormat(const FEDBufferFormat newBufferFormat)
TrackerSpecialHeader defaultTrackerSpecialHeader_
FEDBufferGenerator & sistrip::FEDBufferGenerator::setBXID ( const uint16_t  newBXID)
inline

Definition at line 329 of file SiStripFEDBufferGenerator.h.

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

330  {
331  defaultDAQHeader_.setBXID(newBXID);
332  return *this;
333  }
FEDDAQHeader & setBXID(const uint16_t bxID)
FEDBufferGenerator & sistrip::FEDBufferGenerator::setChannelEnable ( const uint8_t  internalFEDChannelNumber,
const bool  enabled 
)

Definition at line 307 of file SiStripFEDBufferGenerator.cc.

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

308  {
309  try {
310  channelsEnabled_.at(internalFEDChannelNumber) = enabled;
311  } catch (const std::out_of_range&) {
312  std::ostringstream ss;
313  ss << "Invalid channel number " << internalFEDChannelNumber << ". "
314  <<"Should be in internal numbering scheme (0-95)";
315  throw cms::Exception("FEDBufferGenerator") << ss.str();
316  }
317  return *this;
318  }
FEDBufferGenerator & sistrip::FEDBufferGenerator::setChannelEnables ( const std::vector< bool > &  channelsEnabled)

Definition at line 332 of file SiStripFEDBufferGenerator.cc.

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

333  {
334  if (channelEnables.size() != FEDCH_PER_FED) {
335  std::ostringstream ss;
336  ss << "Setting FED channel enable vector with vector which is the wrong size. Size is " << channelEnables.size()
337  << " it must be " << FEDCH_PER_FED << "." << std::endl;
338  throw cms::Exception("FEDBufferGenerator") << ss.str();
339  }
340  channelsEnabled_ = channelEnables;
341  return *this;
342  }
static const uint16_t FEDCH_PER_FED
FEDBufferGenerator & sistrip::FEDBufferGenerator::setDAQEventType ( const FEDDAQEventType  newDAQEventType)
inline

Definition at line 353 of file SiStripFEDBufferGenerator.h.

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

354  {
355  defaultDAQHeader_.setEventType(newDAQEventType);
356  return *this;
357  }
FEDDAQHeader & setEventType(const FEDDAQEventType evtType)
FEDBufferGenerator & sistrip::FEDBufferGenerator::setFEDDataType ( const FEDDataType  newFEDDataType)
inline

Definition at line 359 of file SiStripFEDBufferGenerator.h.

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

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

Definition at line 294 of file SiStripFEDBufferGenerator.cc.

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

295  {
296  try {
297  feUnitsEnabled_.at(internalFEUnitNumber) = enabled;
298  } catch (const std::out_of_range&) {
299  std::ostringstream ss;
300  ss << "Invalid FE unit number " << internalFEUnitNumber << ". "
301  << "Should be in internal numbering scheme (0-7)";
302  throw cms::Exception("FEDBufferGenerator") << ss.str();
303  }
304  return *this;
305  }
FEDBufferGenerator & sistrip::FEDBufferGenerator::setFEUnitEnables ( const std::vector< bool > &  feUnitsEnabled)

Definition at line 320 of file SiStripFEDBufferGenerator.cc.

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

321  {
322  if (feUnitEnables.size() != FEUNITS_PER_FED) {
323  std::ostringstream ss;
324  ss << "Setting FE enable vector with vector which is the wrong size. Size is " << feUnitEnables.size()
325  << " it must be " << FEUNITS_PER_FED << "." << std::endl;
326  throw cms::Exception("FEDBufferGenerator") << ss.str();
327  }
328  feUnitsEnabled_ = feUnitEnables;
329  return *this;
330  }
static const uint16_t FEUNITS_PER_FED
FEDBufferGenerator & sistrip::FEDBufferGenerator::setHeaderType ( const FEDHeaderType  newHeaderType)
inline

Definition at line 341 of file SiStripFEDBufferGenerator.h.

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

342  {
344  return *this;
345  }
TrackerSpecialHeader & setHeaderType(const FEDHeaderType headerType)
TrackerSpecialHeader defaultTrackerSpecialHeader_
FEDBufferGenerator & sistrip::FEDBufferGenerator::setL1ID ( const uint32_t  newL1ID)
inline

Definition at line 323 of file SiStripFEDBufferGenerator.h.

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

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

324  {
325  defaultDAQHeader_.setL1ID(newL1ID);
326  return *this;
327  }
FEDDAQHeader & setL1ID(const uint32_t l1ID)
FEDBufferGenerator & sistrip::FEDBufferGenerator::setReadoutMode ( const FEDReadoutMode  newReadoutMode)
inline

Definition at line 335 of file SiStripFEDBufferGenerator.h.

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

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

336  {
338  return *this;
339  }
TrackerSpecialHeader defaultTrackerSpecialHeader_
TrackerSpecialHeader & setReadoutMode(const FEDReadoutMode readoutMode)
TrackerSpecialHeader & sistrip::FEDBufferGenerator::trackerSpecialHeader ( )
inline

Definition at line 375 of file SiStripFEDBufferGenerator.h.

References defaultTrackerSpecialHeader_.

376  {
378  }
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 164 of file SiStripFEDBufferGenerator.h.

Referenced by daqTrailer(), and generateBuffer().

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

Definition at line 166 of file SiStripFEDBufferGenerator.h.

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

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