Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
erikfrojdh committed Feb 4, 2025
1 parent 078e5d8 commit 2654289
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ set(PUBLICHEADERS
include/aare/ClusterFile.hpp
include/aare/CtbRawFile.hpp
include/aare/ClusterVector.hpp
include/aare/decode.hpp
include/aare/defs.hpp
include/aare/Dtype.hpp
include/aare/File.hpp
Expand All @@ -307,6 +308,7 @@ set(SourceFiles
${CMAKE_CURRENT_SOURCE_DIR}/src/ClusterFile.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/defs.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Dtype.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/decode.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Frame.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/File.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/NumpyFile.cpp
Expand Down
12 changes: 12 additions & 0 deletions include/aare/decode.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <cstdint>
#include <aare/NDView.hpp>
namespace aare {


uint16_t decode_adc(uint64_t input);

void decode_adc(NDView<uint64_t, 2> input, NDView<uint16_t,2> output);

} // namespace aare
27 changes: 27 additions & 0 deletions python/src/ctb_raw_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "aare/RawSubFile.hpp"

#include "aare/defs.hpp"
#include "aare/decode.hpp"
// #include "aare/fClusterFileV2.hpp"

#include <cstdint>
Expand All @@ -23,6 +24,32 @@ using namespace ::aare;

void define_ctb_raw_file_io_bindings(py::module &m) {

m.def("decode_adc", [](py::array_t<uint8_t> input) {


if(input.ndim() != 2){
throw std::runtime_error("Only 2D arrays are supported at this moment");
}

//Create a 2D output array with the same shape as the input
std::vector<ssize_t> shape{input.shape(0), input.shape(1)/8};
py::array_t<uint16_t> output(shape);

//Create a view of the input and output arrays
NDView<uint64_t, 2> input_view(reinterpret_cast<uint64_t*>(input.mutable_data()), {output.shape(0), output.shape(1)});

NDView<uint16_t, 2> output_view(output.mutable_data(), {output.shape(0), output.shape(1)});

decode_adc(input_view, output_view);
// for (size_t i=0; i!=input_view.size(); ++i) {
// output_view(i) = decode_adc(input_view(i));
// }



return output;
});

py::class_<CtbRawFile>(m, "CtbRawFile")
.def(py::init<const std::filesystem::path &>())
.def("read_frame",
Expand Down
32 changes: 32 additions & 0 deletions src/decode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "aare/decode.hpp"

namespace aare {

uint16_t decode_adc(uint64_t input){

//we want bits 29,19,28,18,31,21,27,20,24,23,25,22 and then pad to 16
uint16_t output = 0;
output |= ((input >> 29) & 1) << 15;
output |= ((input >> 19) & 1) << 14;
output |= ((input >> 28) & 1) << 13;
output |= ((input >> 18) & 1) << 12;
output |= ((input >> 31) & 1) << 11;
output |= ((input >> 21) & 1) << 10;
output |= ((input >> 27) & 1) << 9;
output |= ((input >> 20) & 1) << 8;
output |= ((input >> 24) & 1) << 7;
output |= ((input >> 23) & 1) << 6;
output |= ((input >> 25) & 1) << 5;
output |= ((input >> 22) & 1) << 4;
return output;
}

void decode_adc(NDView<uint64_t, 2> input, NDView<uint16_t,2> output){
for(size_t i = 0; i < input.shape(0); i++){
for(size_t j = 0; j < input.shape(1); j++){
output(i,j) = decode_adc(input(i,j));
}
}
}

} // namespace aare

0 comments on commit 2654289

Please sign in to comment.