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 std::ostringstream ss;
134 ss <<
"Invalid readout mode " <<
mode;
141 const uint8_t packetCode,
143 const bool channelEnabled,
144 const bool reorderData)
const
146 const uint16_t nSamples = data.
size();
148 const uint16_t channelLength = nSamples*2 + 3;
149 channelBuffer->reserve(channelLength);
151 channelBuffer->push_back( channelLength & 0xFF );
152 channelBuffer->push_back( (channelLength & 0xF00) >> 8 );
154 channelBuffer->push_back(packetCode);
156 for (uint16_t sampleNumber = 0; sampleNumber < nSamples; sampleNumber++) {
158 const uint16_t sampleValue = (channelEnabled ? data.
getSample(sampleIndex) : 0);
159 channelBuffer->push_back(sampleValue & 0xFF);
160 channelBuffer->push_back((sampleValue & 0x300) >> 8);
166 const bool channelEnabled)
const
168 channelBuffer->reserve(50);
170 if (!channelEnabled) {
172 channelBuffer->push_back(7);
173 channelBuffer->push_back(0);
177 channelBuffer->insert(channelBuffer->end(),4,0);
182 channelBuffer->push_back(0xFF); channelBuffer->push_back(0xFF);
186 const std::pair<uint16_t,uint16_t> medians = data.
getMedians();
187 channelBuffer->push_back(medians.first & 0xFF);
188 channelBuffer->push_back((medians.first & 0x300) >> 8);
189 channelBuffer->push_back(medians.second & 0xFF);
190 channelBuffer->push_back((medians.second & 0x300) >> 8);
192 fillClusterData(channelBuffer,data);
194 const uint16_t length = channelBuffer->size();
195 (*channelBuffer)[0] = (length & 0xFF);
196 (*channelBuffer)[1] = ((length & 0x300) >> 8);
201 const bool channelEnabled)
const
203 channelBuffer->reserve(50);
205 if (!channelEnabled) {
207 channelBuffer->push_back(2);
208 channelBuffer->push_back(0);
213 channelBuffer->push_back(0xFF); channelBuffer->push_back(0xFF);
215 fillClusterData(channelBuffer,data);
217 const uint16_t length = channelBuffer->size();
218 (*channelBuffer)[0] = (length & 0xFF);
219 (*channelBuffer)[1] = ((length & 0x300) >> 8);
224 uint16_t clusterSize = 0;
225 const uint16_t nSamples = data.
size();
226 for( uint16_t strip = 0; strip < nSamples; ++strip) {
232 *(channelBuffer->end() - clusterSize - 1) = clusterSize ;
235 channelBuffer->push_back(strip);
236 channelBuffer->push_back(0);
238 channelBuffer->push_back(adc);
242 else if(clusterSize) {
243 *(channelBuffer->end() - clusterSize - 1) = clusterSize ;
247 if(clusterSize) *(channelBuffer->end() - clusterSize - 1) = clusterSize ;
253 const std::vector<bool>& feUnitsEnabled,
const std::vector<bool>& channelsEnabled,
256 : defaultDAQHeader_(l1ID,bxID,0,evtType),
257 defaultDAQTrailer_(0,0),
258 defaultTrackerSpecialHeader_(bufferFormat,readoutMode,headerType,dataType),
259 defaultFEHeader_(
FEDFEHeader::newFEHeader(headerType)),
260 feUnitsEnabled_(feUnitsEnabled),
261 channelsEnabled_(channelsEnabled)
264 std::ostringstream ss;
265 ss <<
"Bad header format: " << headerType;
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)";
285 }
catch (
const std::out_of_range&) {
287 std::ostringstream ss;
288 ss <<
"Invalid channel number " << internalFEDChannelNumber <<
". "
289 <<
"Should be in internal numbering scheme (0-95)";
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)";
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)";
323 std::ostringstream ss;
324 ss <<
"Setting FE enable vector with vector which is the wrong size. Size is " << feUnitEnables.size()
335 std::ostringstream ss;
336 ss <<
"Setting FED channel enable vector with vector which is the wrong size. Size is " << channelEnables.size()
353 for (uint8_t iFEUnitChannel = 0; iFEUnitChannel <
FEDCH_PER_FEUNIT; iFEUnitChannel++) {
371 fedFeHeader->setFEUnitLength(iFE,payload.
getFELength(iFE));
391 uint8_t* bufferPointer = pointerToStartOfBuffer;
392 memcpy(bufferPointer,daqHeader.
data(),8);
394 memcpy(bufferPointer,tkSpecialHeader.
data(),8);
400 memcpy(bufferPointer,updatedDAQTrailer.
data(),8);
403 updatedDAQTrailer.
setCRC(crc);
404 memcpy(bufferPointer,updatedDAQTrailer.
data(),8);
407 for (
size_t i = 0;
i < 8;
i++) {
408 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)
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
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_
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