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]);
127 fillZeroSuppressedChannelBuffer(channelBuffer,data,channelEnabled);
130 fillZeroSuppressedLiteChannelBuffer(channelBuffer,data,channelEnabled);
133 fillPreMixRawChannelBuffer(channelBuffer,data,channelEnabled);
136 std::ostringstream
ss;
137 ss <<
"Invalid readout mode " <<
mode;
144 const uint8_t packetCode,
146 const bool channelEnabled,
147 const bool reorderData)
const
149 const uint16_t nSamples = data.
size();
151 const uint16_t channelLength = nSamples*2 + 3;
152 channelBuffer->reserve(channelLength);
154 channelBuffer->push_back( channelLength & 0xFF );
155 channelBuffer->push_back( (channelLength & 0xF00) >> 8 );
157 channelBuffer->push_back(packetCode);
159 for (uint16_t sampleNumber = 0; sampleNumber < nSamples; sampleNumber++) {
161 const uint16_t sampleValue = (channelEnabled ? data.
getSample(sampleIndex) : 0);
162 channelBuffer->push_back(sampleValue & 0xFF);
163 channelBuffer->push_back((sampleValue & 0x300) >> 8);
169 const bool channelEnabled)
const
171 channelBuffer->reserve(50);
173 if (!channelEnabled) {
175 channelBuffer->push_back(7);
176 channelBuffer->push_back(0);
180 channelBuffer->insert(channelBuffer->end(),4,0);
185 channelBuffer->push_back(0xFF); channelBuffer->push_back(0xFF);
189 const std::pair<uint16_t,uint16_t> medians = data.
getMedians();
190 channelBuffer->push_back(medians.first & 0xFF);
191 channelBuffer->push_back((medians.first & 0x300) >> 8);
192 channelBuffer->push_back(medians.second & 0xFF);
193 channelBuffer->push_back((medians.second & 0x300) >> 8);
195 fillClusterData(channelBuffer,data);
197 const uint16_t length = channelBuffer->size();
198 (*channelBuffer)[0] = (length & 0xFF);
199 (*channelBuffer)[1] = ((length & 0x300) >> 8);
204 const bool channelEnabled)
const
206 channelBuffer->reserve(50);
208 if (!channelEnabled) {
210 channelBuffer->push_back(2);
211 channelBuffer->push_back(0);
216 channelBuffer->push_back(0xFF); channelBuffer->push_back(0xFF);
218 fillClusterData(channelBuffer,data);
220 const uint16_t length = channelBuffer->size();
221 (*channelBuffer)[0] = (length & 0xFF);
222 (*channelBuffer)[1] = ((length & 0x300) >> 8);
227 const bool channelEnabled)
const
229 channelBuffer->reserve(50);
231 if (!channelEnabled) {
233 channelBuffer->push_back(7);
234 channelBuffer->push_back(0);
238 channelBuffer->insert(channelBuffer->end(),4,0);
243 channelBuffer->push_back(0xFF); channelBuffer->push_back(0xFF);
247 const std::pair<uint16_t,uint16_t> medians = data.
getMedians();
248 channelBuffer->push_back(medians.first & 0xFF);
249 channelBuffer->push_back((medians.first & 0x300) >> 8);
250 channelBuffer->push_back(medians.second & 0xFF);
251 channelBuffer->push_back((medians.second & 0x300) >> 8);
253 fillClusterDataPreMixMode(channelBuffer,data);
255 const uint16_t length = channelBuffer->size();
256 (*channelBuffer)[0] = (length & 0xFF);
257 (*channelBuffer)[1] = ((length & 0x300) >> 8);
262 uint16_t clusterSize = 0;
263 const uint16_t nSamples = data.
size();
264 for( uint16_t strip = 0; strip < nSamples; ++strip) {
270 *(channelBuffer->end() - clusterSize - 1) = clusterSize ;
273 channelBuffer->push_back(strip);
274 channelBuffer->push_back(0);
276 channelBuffer->push_back(adc);
280 else if(clusterSize) {
281 *(channelBuffer->end() - clusterSize - 1) = clusterSize ;
285 if(clusterSize) *(channelBuffer->end() - clusterSize - 1) = clusterSize ;
290 uint16_t clusterSize = 0;
291 const uint16_t nSamples = data.
size();
292 for( uint16_t strip = 0; strip < nSamples; ++strip) {
298 *(channelBuffer->end() - 2*clusterSize - 1) = clusterSize ;
301 channelBuffer->push_back(strip);
302 channelBuffer->push_back(0);
304 channelBuffer->push_back(adc & 0xFF);
305 channelBuffer->push_back((adc & 0x0300) >> 8);
310 else if(clusterSize) {
311 *(channelBuffer->end() - 2*clusterSize - 1) = clusterSize ;
316 *(channelBuffer->end() - 2*clusterSize - 1) = clusterSize ;
323 const std::vector<bool>& feUnitsEnabled,
const std::vector<bool>& channelsEnabled,
326 : defaultDAQHeader_(l1ID,bxID,0,evtType),
327 defaultDAQTrailer_(0,0),
328 defaultTrackerSpecialHeader_(bufferFormat,readoutMode,headerType,dataType),
329 defaultFEHeader_(
FEDFEHeader::newFEHeader(headerType)),
330 feUnitsEnabled_(feUnitsEnabled),
331 channelsEnabled_(channelsEnabled)
334 std::ostringstream
ss;
335 ss <<
"Bad header format: " << headerType;
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)";
355 }
catch (
const std::out_of_range&) {
357 std::ostringstream
ss;
358 ss <<
"Invalid channel number " << internalFEDChannelNumber <<
". "
359 <<
"Should be in internal numbering scheme (0-95)";
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)";
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)";
393 std::ostringstream
ss;
394 ss <<
"Setting FE enable vector with vector which is the wrong size. Size is " << feUnitEnables.size()
405 std::ostringstream
ss;
406 ss <<
"Setting FED channel enable vector with vector which is the wrong size. Size is " << channelEnables.size()
423 for (uint8_t iFEUnitChannel = 0; iFEUnitChannel <
FEDCH_PER_FEUNIT; iFEUnitChannel++) {
441 fedFeHeader->setFEUnitLength(iFE,payload.
getFELength(iFE));
461 uint8_t* bufferPointer = pointerToStartOfBuffer;
462 memcpy(bufferPointer,daqHeader.
data(),8);
464 memcpy(bufferPointer,tkSpecialHeader.
data(),8);
470 memcpy(bufferPointer,updatedDAQTrailer.
data(),8);
473 updatedDAQTrailer.
setCRC(crc);
474 memcpy(bufferPointer,updatedDAQTrailer.
data(),8);
477 for (
size_t i = 0;
i < 8;
i++) {
478 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)
void fillClusterData(std::vector< uint8_t > *channelBuffer, const FEDStripData::ChannelData &data) const
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_
uint8_t get8BitSample(const uint16_t sampleNumber) const
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
const uint8_t * data() const
FEDDAQTrailer defaultDAQTrailer_
uint16_t getFELength(const uint8_t internalFEUnitNum) const
FEDBufferGenerator & setChannelEnable(const uint8_t internalFEDChannelNumber, const bool enabled)
void fillRawChannelBuffer(std::vector< uint8_t > *channelBuffer, const uint8_t packetCode, const FEDStripData::ChannelData &data, const bool channelEnabled, const bool reorderData) 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, const FEDDataType dataType=DATA_TYPE_FAKE)
FEDBufferPayload createPayload(const FEDReadoutMode mode, const FEDStripData &data) const
void fillZeroSuppressedLiteChannelBuffer(std::vector< uint8_t > *channelBuffer, const FEDStripData::ChannelData &data, const bool channelEnabled) const
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_
FEDDAQHeader & daqHeader()
static const uint8_t PACKET_CODE_VIRGIN_RAW