diff --git a/slsReceiverSoftware/CMakeLists.txt b/slsReceiverSoftware/CMakeLists.txt index 9e6ad75c3..543ff7467 100755 --- a/slsReceiverSoftware/CMakeLists.txt +++ b/slsReceiverSoftware/CMakeLists.txt @@ -17,7 +17,6 @@ set(SOURCES set(PUBLICHEADERS include/sls/Receiver.h - include/sls/utils.h ) # HDF5 file writing diff --git a/slsReceiverSoftware/include/sls/utils.h b/slsReceiverSoftware/include/sls/utils.h deleted file mode 100644 index 3aa76456c..000000000 --- a/slsReceiverSoftware/include/sls/utils.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @file utils.cpp - * @short utility objects for Receiver - */ - -#include -#include - -namespace sls { - -/* - * AlignedData - * Aligns data to a given type T with proper alignment - * @param data: pointer to data - * @param size: size of data to align in bytes - */ -template struct AlignedData { - T *aligned_ptr; // aligned data pointer - - AlignedData(char *data, size_t size) { - if (reinterpret_cast(data) % alignof(uint64_t) == 0) { - // If aligned directly cast to pointer - aligned_ptr = reinterpret_cast(data); - - } else { - - auto alignedbuffer = std::aligned_alloc(alignof(T), size); - std::memcpy(alignedbuffer, data, size); - aligned_ptr = reinterpret_cast(alignedbuffer); - } - } - - ~AlignedData() { std::free(aligned_ptr); } -}; - -} // namespace sls \ No newline at end of file diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index 6a16284dd..6870442a1 100644 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -24,8 +24,6 @@ #include #include -#include "sls/utils.h" - namespace sls { const std::string DataProcessor::typeName = "DataProcessor"; @@ -576,10 +574,11 @@ void DataProcessor::Reorder(size_t &size, char *data) { } // make sure data is aligned to 8 bytes before casting to uint64_t - AlignedData aligned_data(data + nAnalogDataBytes + ctbDbitOffset, - ctbDigitalDataBytes); + // AlignedData aligned_data(data + nAnalogDataBytes + + // ctbDbitOffset, ctbDigitalDataBytes); - uint64_t *source = aligned_data.aligned_ptr; + char *source = + data + nAnalogDataBytes + ctbDbitOffset; // aligned_data.aligned_ptr; const size_t numDigitalSamples = (ctbDigitalDataBytes / sizeof(uint64_t)); @@ -652,11 +651,7 @@ void DataProcessor::ArrangeDbitData(size_t &size, char *data) { return; } - // make sure data is aligned to 8 bytes before casting to uint64_t - AlignedData aligned_data(data + nAnalogDataBytes + ctbDbitOffset, - ctbDigitalDataBytes); - - uint64_t *source = aligned_data.aligned_ptr; + char *source = (data + nAnalogDataBytes + ctbDbitOffset); const int numDigitalSamples = (ctbDigitalDataBytes / sizeof(uint64_t)); @@ -694,10 +689,13 @@ void DataProcessor::ArrangeDbitData(size_t &size, char *data) { ++dest; } + uint8_t byte_index = bi / 8; + // loop through the frame digital data - for (auto *ptr = source; ptr < (source + numDigitalSamples);) { + for (auto *ptr = source + byte_index; + ptr < (source + 8 * numDigitalSamples); ptr += 8) { // get selected bit from each 8 bit - uint8_t bit = (*ptr++ >> bi) & 1; + uint8_t bit = (*ptr >> bi % 8) & 1; *dest |= bit << bitoffset; // stored as least significant ++bitoffset; // extract destination in 8 bit batches @@ -710,7 +708,8 @@ void DataProcessor::ArrangeDbitData(size_t &size, char *data) { } else { // loop through the digital data int bitoffset = 0; - for (auto *ptr = source; ptr < (source + numDigitalSamples); ++ptr) { + for (auto *ptr = source; ptr < (source + 8 * numDigitalSamples); + ptr += 8) { // where bit enable vector size is not a multiple of 8 if (bitoffset != 0) { bitoffset = 0; @@ -720,7 +719,9 @@ void DataProcessor::ArrangeDbitData(size_t &size, char *data) { // loop through digital bit enable vector for (auto bi : ctbDbitList) { // get selected bit from each 64 bit - uint8_t bit = (*ptr >> bi) & 1; + uint8_t byte_index = bi / 8; + + uint8_t bit = (*(ptr + byte_index) >> (bi % 8)) & 1; *dest |= bit << bitoffset; ++bitoffset; // extract destination in 8 bit batches