14 std::ostringstream
ss;
15 ss <<
"Scope length " << samplesPerChannel <<
" is too long. "
24 return data_.at(internalFEDChannelNum);
25 }
catch (
const std::out_of_range&) {
26 std::ostringstream
ss;
27 ss <<
"Channel index out of range. (" << uint16_t(internalFEDChannelNum) <<
") "
28 <<
"Index should be in internal numbering scheme (0-95). ";
36 std::ostringstream
ss;
37 ss <<
"Sample value (" << value <<
") is too large. Maximum allowed is 1023. ";
42 }
catch (
const std::out_of_range&) {
43 std::ostringstream
ss;
44 ss <<
"Sample index out of range. "
45 <<
"Requesting sample " << sampleNumber
46 <<
" when channel has only " <<
data_.size() <<
" samples.";
56 uint32_t totalSize = 0;
59 totalSize += channelBuffers[iFE*FEDCH_PER_FEUNIT+iCh].size();
63 totalSize = ((totalSize/8) + 1)*8;
66 data_.resize(totalSize);
67 size_t indexInBuffer = 0;
68 feLengths_.reserve(FEUNITS_PER_FED);
71 const size_t lengthAtStartOfFEUnit = indexInBuffer;
74 appendToBuffer(&indexInBuffer,channelBuffers[iFE*FEDCH_PER_FEUNIT+iCh].
begin(),channelBuffers[iFE*FEDCH_PER_FEUNIT+iCh].
end());
77 feLengths_.push_back(indexInBuffer-lengthAtStartOfFEUnit);
79 while (indexInBuffer % 8) appendToBuffer(&indexInBuffer,0);
86 if (lengthInBytes())
return &
data_[0];
94 return feLengths_.at(internalFEUnitNum);
95 }
catch (
const std::out_of_range&) {
96 std::ostringstream
ss;
97 ss <<
"Invalid FE unit number " << internalFEUnitNum <<
". "
98 <<
"Number should be in internal numbering scheme (0-7). ";
105 std::vector< std::vector<uint8_t> > channelBuffers(
FEDCH_PER_FED,std::vector<uint8_t>());
108 fillChannelBuffer(&channelBuffers[iCh],mode,data.
channel(iCh),channelsEnabled_[iCh]);
128 fillZeroSuppressedChannelBuffer(channelBuffer,data,channelEnabled);
138 fillZeroSuppressedLiteChannelBuffer(channelBuffer,data,channelEnabled,mode);
141 fillPreMixRawChannelBuffer(channelBuffer,data,channelEnabled);
144 std::ostringstream
ss;
145 ss <<
"Invalid readout mode " <<
mode;
152 const uint8_t packetCode,
154 const bool channelEnabled,
155 const bool reorderData)
const
159 const uint16_t channelLength = nSamples*2 + 3;
160 channelBuffer->reserve(channelLength);
162 channelBuffer->push_back( channelLength & 0xFF );
163 channelBuffer->push_back( (channelLength & 0xF00) >> 8 );
165 channelBuffer->push_back(packetCode);
167 for (uint16_t sampleNumber = 0; sampleNumber <
nSamples; sampleNumber++) {
169 const uint16_t sampleValue = (channelEnabled ? data.
getSample(sampleIndex) : 0);
170 channelBuffer->push_back(sampleValue & 0xFF);
171 channelBuffer->push_back((sampleValue & 0x300) >> 8);
177 const bool channelEnabled)
const
179 channelBuffer->reserve(50);
181 if (!channelEnabled) {
183 channelBuffer->push_back(7);
184 channelBuffer->push_back(0);
188 channelBuffer->insert(channelBuffer->end(),4,0);
193 channelBuffer->push_back(0xFF);
194 channelBuffer->push_back(0xFF);
198 const std::pair<uint16_t,uint16_t> medians = data.
getMedians();
199 channelBuffer->push_back(medians.first & 0xFF);
200 channelBuffer->push_back((medians.first & 0x300) >> 8);
201 channelBuffer->push_back(medians.second & 0xFF);
202 channelBuffer->push_back((medians.second & 0x300) >> 8);
206 const uint16_t length = channelBuffer->size();
207 (*channelBuffer)[0] = (length & 0xFF);
208 (*channelBuffer)[1] = ((length & 0x300) >> 8);
213 const bool channelEnabled,
216 channelBuffer->reserve(50);
218 if (!channelEnabled) {
220 channelBuffer->push_back(2);
221 channelBuffer->push_back(0);
226 channelBuffer->push_back(0xFF);
227 channelBuffer->push_back(0xFF);
229 fillClusterData(channelBuffer,data,mode);
231 const uint16_t length = channelBuffer->size();
232 (*channelBuffer)[0] = (length & 0xFF);
233 (*channelBuffer)[1] = ((length & 0x300) >> 8);
238 const bool channelEnabled)
const
240 channelBuffer->reserve(50);
242 if (!channelEnabled) {
244 channelBuffer->push_back(7);
245 channelBuffer->push_back(0);
249 channelBuffer->insert(channelBuffer->end(),4,0);
254 channelBuffer->push_back(0xFF); channelBuffer->push_back(0xFF);
258 const std::pair<uint16_t,uint16_t> medians = data.
getMedians();
259 channelBuffer->push_back(medians.first & 0xFF);
260 channelBuffer->push_back((medians.first & 0x300) >> 8);
261 channelBuffer->push_back(medians.second & 0xFF);
262 channelBuffer->push_back((medians.second & 0x300) >> 8);
264 fillClusterDataPreMixMode(channelBuffer,data);
266 const uint16_t length = channelBuffer->size();
267 (*channelBuffer)[0] = (length & 0xFF);
268 (*channelBuffer)[1] = ((length & 0x300) >> 8);
273 uint16_t clusterSize = 0;
283 for( uint16_t strip = 0; strip <
nSamples; ++strip) {
296 *(channelBuffer->end() - size*clusterSize - 1) = clusterSize ;
299 channelBuffer->push_back(strip);
300 channelBuffer->push_back(0);
305 channelBuffer->push_back(adc & 0xFF);
306 channelBuffer->push_back((adc & 0x0300) >> 8);
309 channelBuffer->push_back(adc & 0xFF);
315 else if(clusterSize) {
316 *(channelBuffer->end() - size*clusterSize - 1) = clusterSize ;
320 if(clusterSize) *(channelBuffer->end() - size*clusterSize - 1) = clusterSize ;
325 uint16_t clusterSize = 0;
327 for( uint16_t strip = 0; strip <
nSamples; ++strip) {
333 *(channelBuffer->end() - 2*clusterSize - 1) = clusterSize ;
336 channelBuffer->push_back(strip);
337 channelBuffer->push_back(0);
339 channelBuffer->push_back(adc & 0xFF);
340 channelBuffer->push_back((adc & 0x0300) >> 8);
345 else if(clusterSize) {
346 *(channelBuffer->end() - 2*clusterSize - 1) = clusterSize ;
351 *(channelBuffer->end() - 2*clusterSize - 1) = clusterSize ;
358 const std::vector<bool>& feUnitsEnabled,
const std::vector<bool>& channelsEnabled,
361 : defaultDAQHeader_(l1ID,bxID,0,evtType),
362 defaultDAQTrailer_(0,0),
363 defaultTrackerSpecialHeader_(bufferFormat,readoutMode,headerType),
364 defaultFEHeader_(
FEDFEHeader::newFEHeader(headerType)),
365 feUnitsEnabled_(feUnitsEnabled),
366 channelsEnabled_(channelsEnabled)
369 std::ostringstream
ss;
370 ss <<
"Bad header format: " << headerType;
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)";
390 }
catch (
const std::out_of_range&) {
392 std::ostringstream
ss;
393 ss <<
"Invalid channel number " << internalFEDChannelNumber <<
". "
394 <<
"Should be in internal numbering scheme (0-95)";
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)";
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)";
428 std::ostringstream
ss;
429 ss <<
"Setting FE enable vector with vector which is the wrong size. Size is " << feUnitEnables.size()
440 std::ostringstream
ss;
441 ss <<
"Setting FED channel enable vector with vector which is the wrong size. Size is " << channelEnables.size()
458 for (uint8_t iFEUnitChannel = 0; iFEUnitChannel <
FEDCH_PER_FEUNIT; iFEUnitChannel++) {
476 fedFeHeader->setFEUnitLength(iFE,payload.
getFELength(iFE));
496 uint8_t* bufferPointer = pointerToStartOfBuffer;
497 memcpy(bufferPointer,daqHeader.
data(),8);
499 memcpy(bufferPointer,tkSpecialHeader.
data(),8);
505 memcpy(bufferPointer,updatedDAQTrailer.
data(),8);
508 updatedDAQTrailer.
setCRC(crc);
509 memcpy(bufferPointer,updatedDAQTrailer.
data(),8);
512 for (
size_t i = 0;
i < 8;
i++) {
513 bufferPointer[
i] = bufferPointer[
i^4];
int adc(sample_type sample)
get the ADC sample (12 bits)
static uint8_t physicalOrderForStripInChannel(const uint8_t readoutOrderStripIndexInChannel)
FEDBufferGenerator & setChannelEnables(const std::vector< bool > &channelsEnabled)
void fillClusterDataPreMixMode(std::vector< uint8_t > *channelBuffer, const FEDStripData::ChannelData &data) const
FEDDAQHeader defaultDAQHeader_
void fillZeroSuppressedChannelBuffer(std::vector< uint8_t > *channelBuffer, const FEDStripData::ChannelData &data, const bool channelEnabled) const
void setSample(const uint16_t sampleNumber, const uint16_t adcValue)
void generateBuffer(FEDRawData *rawDataObject, const FEDStripData &data, const uint16_t sourceID) const
static const uint8_t PACKET_CODE_SCOPE
FEDBufferPayload(const std::vector< std::vector< uint8_t > > &channelBuffers)
static size_t bufferSizeInBytes(const FEDFEHeader &feHeader, const FEDBufferPayload &payload)
FEDStripData(const std::vector< ChannelData > &data)
uint8_t internalFEDChannelNum(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum)
uint16_t calculateFEDBufferCRC(const uint8_t *buffer, const size_t lengthInBytes)
FEDReadoutMode getReadoutMode() const
uint16_t get10BitSample(const uint16_t sampleNumber) const
std::vector< bool > channelsEnabled_
const uint8_t * data() const
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED
FEDDAQTrailer & setEventLengthIn64BitWords(const uint32_t eventLengthIn64BitWords)
FEDBufferGenerator & setFEUnitEnables(const std::vector< bool > &feUnitsEnabled)
std::vector< uint16_t > data_
FEDDAQTrailer & setCRC(const uint16_t crc)
void resize(size_t newsize)
std::pair< uint16_t, uint16_t > getMedians() const
static const uint16_t FEUNITS_PER_FED
void fillZeroSuppressedLiteChannelBuffer(std::vector< uint8_t > *channelBuffer, const FEDStripData::ChannelData &data, const bool channelEnabled, const FEDReadoutMode mode) const
const uint8_t * data() const
FEDDAQTrailer defaultDAQTrailer_
uint16_t getFELength(const uint8_t internalFEUnitNum) const
FEDBufferGenerator & setChannelEnable(const uint8_t internalFEDChannelNumber, const bool enabled)
constexpr size_t nSamples
void fillRawChannelBuffer(std::vector< uint8_t > *channelBuffer, const uint8_t packetCode, const FEDStripData::ChannelData &data, const bool channelEnabled, const bool reorderData) const
void fillClusterData(std::vector< uint8_t > *channelBuffer, const FEDStripData::ChannelData &data, const FEDReadoutMode mode) const
FEDBufferPayload createPayload(const FEDReadoutMode mode, const FEDStripData &data) const
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)
static const uint8_t PACKET_CODE_PROC_RAW
ChannelData & channel(const uint8_t internalFEDChannelNum)
static const uint16_t FEDCH_PER_FEUNIT
uint16_t getSample(const uint16_t sampleNumber) const
std::auto_ptr< FEDFEHeader > defaultFEHeader_
void fillPreMixRawChannelBuffer(std::vector< uint8_t > *channelBuffer, const FEDStripData::ChannelData &data, const bool channelEnabled) const
FEDBufferGenerator & setFEUnitEnable(const uint8_t internalFEUnitNumber, const bool enabled)
bool getFEUnitEnabled(const uint8_t internalFEUnitNumber) const
char data[epos_bytes_allocation]
std::vector< bool > feUnitsEnabled_
static const uint16_t FEDCH_PER_FED
static const uint16_t STRIPS_PER_APV
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
static void fillBuffer(uint8_t *pointerToStartOfBuffer, const FEDDAQHeader &daqHeader, const FEDDAQTrailer &daqTrailer, const TrackerSpecialHeader &tkSpecialHeader, const FEDFEHeader &feHeader, const FEDBufferPayload &payload)
std::vector< ChannelData > data_
void fillChannelBuffer(std::vector< uint8_t > *channelBuffer, const FEDReadoutMode mode, const FEDStripData::ChannelData &data, const bool channelEnabled) const
size_t lengthInBytes() const
bool getChannelEnabled(const uint8_t internalFEDChannelNumber) const
static const uint16_t SCOPE_MODE_MAX_SCOPE_LENGTH
TrackerSpecialHeader defaultTrackerSpecialHeader_
uint8_t get8BitSample(const uint16_t sampleNumber, const FEDReadoutMode mode) const
FEDDAQHeader & daqHeader()
tuple size
Write out results.
static const uint8_t PACKET_CODE_VIRGIN_RAW