mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-06 18:10:40 +02:00
added function Reorder
This commit is contained in:
parent
63bb79d727
commit
a74fb2bcd1
@ -358,6 +358,10 @@ void DataProcessor::ProcessAnImage(sls_receiver_header &header, size_t &size,
|
|||||||
if (framePadding && nump < generalData->packetsPerFrame)
|
if (framePadding && nump < generalData->packetsPerFrame)
|
||||||
PadMissingPackets(header, data);
|
PadMissingPackets(header, data);
|
||||||
|
|
||||||
|
if (reorder && ctbDbitList.empty()) {
|
||||||
|
Reorder(size, data);
|
||||||
|
}
|
||||||
|
|
||||||
// rearrange ctb digital bits (if ctbDbitlist is not empty)
|
// rearrange ctb digital bits (if ctbDbitlist is not empty)
|
||||||
if (!ctbDbitList.empty()) {
|
if (!ctbDbitList.empty()) {
|
||||||
ArrangeDbitData(size, data);
|
ArrangeDbitData(size, data);
|
||||||
@ -532,6 +536,88 @@ void DataProcessor::PadMissingPackets(sls_receiver_header header, char *data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DataProcessor::Reorder(size_t &size, char *data) {
|
||||||
|
const size_t nAnalogDataBytes = generalData->GetNumberOfAnalogDatabytes();
|
||||||
|
const size_t nDigitalDataBytes = generalData->GetNumberOfDigitalDatabytes();
|
||||||
|
const size_t nTransceiverDataBytes =
|
||||||
|
generalData->GetNumberOfTransceiverDatabytes();
|
||||||
|
|
||||||
|
const size_t ctbDigitalDataBytes = nDigitalDataBytes - ctbDbitOffset;
|
||||||
|
|
||||||
|
// no digital data
|
||||||
|
if (ctbDigitalDataBytes == 0) {
|
||||||
|
LOG(logWARNING)
|
||||||
|
<< "No digital data for call back, yet reorder is set to 1.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto *source = (uint64_t *)(data + nAnalogDataBytes + ctbDbitOffset);
|
||||||
|
|
||||||
|
const size_t numDigitalSamples = (ctbDigitalDataBytes / sizeof(uint64_t));
|
||||||
|
|
||||||
|
size_t numBytesPerBit =
|
||||||
|
0; // number of bytes per bit in digital data after reordering
|
||||||
|
|
||||||
|
if ((numDigitalSamples % 8) == 0)
|
||||||
|
numBytesPerBit = numDigitalSamples / 8;
|
||||||
|
else
|
||||||
|
numBytesPerBit = numDigitalSamples / 8 + 1;
|
||||||
|
|
||||||
|
size_t totalNumBytes =
|
||||||
|
numBytesPerBit *
|
||||||
|
64; // number of bytes for digital data after reordering
|
||||||
|
|
||||||
|
LOG(logDEBUG1) << "totalNumBytes: " << totalNumBytes
|
||||||
|
<< " nAnalogDataBytes:" << nAnalogDataBytes
|
||||||
|
<< " nDigitalDataBytes: " << nDigitalDataBytes
|
||||||
|
<< " ctbDbitOffset:" << ctbDbitOffset
|
||||||
|
<< " nTransceiverDataBytes:" << nTransceiverDataBytes
|
||||||
|
<< " size:" << size << " numsamples:" << numDigitalSamples;
|
||||||
|
|
||||||
|
std::vector<uint8_t> result(totalNumBytes, 0);
|
||||||
|
uint8_t *dest = &result[0];
|
||||||
|
|
||||||
|
int bitoffset = 0;
|
||||||
|
// reorder
|
||||||
|
for (size_t bi = 0; bi < 64; ++bi) {
|
||||||
|
|
||||||
|
if (bitoffset != 0) {
|
||||||
|
bitoffset = 0;
|
||||||
|
++dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto *ptr = source; ptr < (source + numDigitalSamples); ++ptr) {
|
||||||
|
uint8_t bit = (*ptr >> bi) & 1;
|
||||||
|
*dest |= bit << bitoffset; // most significant bits will be padded
|
||||||
|
++bitoffset;
|
||||||
|
|
||||||
|
if (bitoffset == 8) {
|
||||||
|
bitoffset = 0;
|
||||||
|
++dest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// move transceiver data to not overwrite and avoid gap in memory
|
||||||
|
if (totalNumBytes != nDigitalDataBytes)
|
||||||
|
memmove(data + nAnalogDataBytes + totalNumBytes * sizeof(uint8_t),
|
||||||
|
data + nAnalogDataBytes + nDigitalDataBytes,
|
||||||
|
nTransceiverDataBytes);
|
||||||
|
|
||||||
|
// copy back to memory and update size
|
||||||
|
size = totalNumBytes * sizeof(uint8_t) + nAnalogDataBytes +
|
||||||
|
nTransceiverDataBytes;
|
||||||
|
|
||||||
|
memcpy(data + nAnalogDataBytes, result.data(),
|
||||||
|
totalNumBytes * sizeof(uint8_t));
|
||||||
|
|
||||||
|
LOG(logDEBUG1) << "totalNumBytes: " << totalNumBytes
|
||||||
|
<< " nAnalogDataBytes:" << nAnalogDataBytes
|
||||||
|
<< " ctbDbitOffset:" << ctbDbitOffset
|
||||||
|
<< " nTransceiverDataBytes:" << nTransceiverDataBytes
|
||||||
|
<< " size:" << size;
|
||||||
|
}
|
||||||
|
|
||||||
/** ctb specific */
|
/** ctb specific */
|
||||||
void DataProcessor::ArrangeDbitData(size_t &size, char *data) {
|
void DataProcessor::ArrangeDbitData(size_t &size, char *data) {
|
||||||
size_t nAnalogDataBytes = generalData->GetNumberOfAnalogDatabytes();
|
size_t nAnalogDataBytes = generalData->GetNumberOfAnalogDatabytes();
|
||||||
@ -589,7 +675,7 @@ void DataProcessor::ArrangeDbitData(size_t &size, char *data) {
|
|||||||
for (auto *ptr = source; ptr < (source + numDigitalSamples);) {
|
for (auto *ptr = source; ptr < (source + numDigitalSamples);) {
|
||||||
// get selected bit from each 8 bit
|
// get selected bit from each 8 bit
|
||||||
uint8_t bit = (*ptr++ >> bi) & 1;
|
uint8_t bit = (*ptr++ >> bi) & 1;
|
||||||
*dest |= bit << bitoffset;
|
*dest |= bit << bitoffset; // stored as least significant
|
||||||
++bitoffset;
|
++bitoffset;
|
||||||
// extract destination in 8 bit batches
|
// extract destination in 8 bit batches
|
||||||
if (bitoffset == 8) {
|
if (bitoffset == 8) {
|
||||||
|
@ -101,6 +101,12 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
|
|||||||
*/
|
*/
|
||||||
void ArrangeDbitData(size_t &size, char *data);
|
void ArrangeDbitData(size_t &size, char *data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* reorder datastream such that individual digital bits from all samples are
|
||||||
|
* stored consecutively in memory
|
||||||
|
*/
|
||||||
|
void Reorder(size_t &size, char *data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void RecordFirstIndex(uint64_t fnum);
|
void RecordFirstIndex(uint64_t fnum);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user