mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-07-13 04:11:50 +02:00
skeleton
This commit is contained in:
@ -344,6 +344,7 @@ set(PUBLICHEADERS
|
|||||||
include/aare/FileInterface.hpp
|
include/aare/FileInterface.hpp
|
||||||
include/aare/Frame.hpp
|
include/aare/Frame.hpp
|
||||||
include/aare/geo_helpers.hpp
|
include/aare/geo_helpers.hpp
|
||||||
|
include/aare/JungfrauDataFile.hpp
|
||||||
include/aare/NDArray.hpp
|
include/aare/NDArray.hpp
|
||||||
include/aare/NDView.hpp
|
include/aare/NDView.hpp
|
||||||
include/aare/NumpyFile.hpp
|
include/aare/NumpyFile.hpp
|
||||||
@ -369,6 +370,7 @@ set(SourceFiles
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/File.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/File.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Fit.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/Fit.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/geo_helpers.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/geo_helpers.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/JungfrauDataFile.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/NumpyFile.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/NumpyFile.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/NumpyHelpers.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/NumpyHelpers.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Interpolator.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/Interpolator.cpp
|
||||||
@ -423,6 +425,7 @@ if(AARE_TESTS)
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/ClusterVector.test.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/ClusterVector.test.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/ClusterFile.test.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/ClusterFile.test.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Pedestal.test.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/Pedestal.test.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/JungfrauDataFile.test.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/NumpyFile.test.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/NumpyFile.test.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/NumpyHelpers.test.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/NumpyHelpers.test.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/RawFile.test.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/RawFile.test.cpp
|
||||||
|
41
include/aare/JungfrauDataFile.hpp
Normal file
41
include/aare/JungfrauDataFile.hpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <cstdint>
|
||||||
|
#include <filesystem>
|
||||||
|
namespace aare {
|
||||||
|
|
||||||
|
struct JungfrauDataHeader{
|
||||||
|
uint64_t framenum;
|
||||||
|
uint64_t bunchid;
|
||||||
|
};
|
||||||
|
|
||||||
|
class JungfrauDataFile {
|
||||||
|
|
||||||
|
size_t m_rows{};
|
||||||
|
size_t m_cols{};
|
||||||
|
size_t m_total_frames{};
|
||||||
|
|
||||||
|
//Data sizes to guess the frame size
|
||||||
|
using value_type = uint16_t;
|
||||||
|
static constexpr size_t header_size = sizeof(JungfrauDataHeader);
|
||||||
|
static constexpr size_t module_data_size = header_size + sizeof(value_type) * 512 * 1024;
|
||||||
|
static constexpr size_t half_data_size = header_size + sizeof(value_type) * 256 * 1024;
|
||||||
|
static constexpr size_t chip_data_size = header_size + sizeof(value_type) * 256 * 256;
|
||||||
|
|
||||||
|
public:
|
||||||
|
JungfrauDataFile(const std::filesystem::path &fname);
|
||||||
|
size_t bytes_per_frame() const;
|
||||||
|
size_t pixels_per_frame() const;
|
||||||
|
size_t bytes_per_pixel() const;
|
||||||
|
size_t bitdepth() const;
|
||||||
|
void seek(size_t frame_index); //!< seek to the given frame index
|
||||||
|
size_t tell() const; //!< get the frame index of the file pointer
|
||||||
|
size_t total_frames() const;
|
||||||
|
size_t rows() const;
|
||||||
|
size_t cols() const;
|
||||||
|
|
||||||
|
void read_into(std::byte *image_buf, JungfrauDataHeader *header);
|
||||||
|
|
||||||
|
static size_t guess_frame_size(const std::filesystem::path &fname);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace aare
|
@ -2,7 +2,7 @@
|
|||||||
from . import _aare
|
from . import _aare
|
||||||
|
|
||||||
|
|
||||||
from ._aare import File, RawMasterFile, RawSubFile
|
from ._aare import File, RawMasterFile, RawSubFile, JungfrauDataFile
|
||||||
from ._aare import Pedestal_d, Pedestal_f, ClusterFinder, VarClusterFinder
|
from ._aare import Pedestal_d, Pedestal_f, ClusterFinder, VarClusterFinder
|
||||||
from ._aare import DetectorType
|
from ._aare import DetectorType
|
||||||
from ._aare import ClusterFile
|
from ._aare import ClusterFile
|
||||||
|
53
python/src/jungfrau_data_file.hpp
Normal file
53
python/src/jungfrau_data_file.hpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
|
||||||
|
#include "aare/JungfrauDataFile.hpp"
|
||||||
|
#include "aare/defs.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <pybind11/iostream.h>
|
||||||
|
#include <pybind11/numpy.h>
|
||||||
|
#include <pybind11/pybind11.h>
|
||||||
|
#include <pybind11/stl.h>
|
||||||
|
#include <pybind11/stl/filesystem.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace py = pybind11;
|
||||||
|
using namespace ::aare;
|
||||||
|
|
||||||
|
void define_jungfrau_data_file_io_bindings(py::module &m) {
|
||||||
|
py::class_<JungfrauDataFile>(m, "JungfrauDataFile")
|
||||||
|
.def(py::init<const std::filesystem::path &>())
|
||||||
|
.def("guess_frame_size",
|
||||||
|
[](const std::filesystem::path &fname) {
|
||||||
|
return JungfrauDataFile::guess_frame_size(fname);
|
||||||
|
})
|
||||||
|
.def_property_readonly("rows", &JungfrauDataFile::rows)
|
||||||
|
.def_property_readonly("cols", &JungfrauDataFile::cols);
|
||||||
|
// .def("read_frame",
|
||||||
|
// [](RawFile &self) {
|
||||||
|
// py::array image;
|
||||||
|
// std::vector<ssize_t> shape;
|
||||||
|
// shape.reserve(2);
|
||||||
|
// shape.push_back(self.rows());
|
||||||
|
// shape.push_back(self.cols());
|
||||||
|
|
||||||
|
// // return headers from all subfiles
|
||||||
|
// py::array_t<DetectorHeader> header(self.n_mod());
|
||||||
|
|
||||||
|
// const uint8_t item_size = self.bytes_per_pixel();
|
||||||
|
// if (item_size == 1) {
|
||||||
|
// image = py::array_t<uint8_t>(shape);
|
||||||
|
// } else if (item_size == 2) {
|
||||||
|
// image = py::array_t<uint16_t>(shape);
|
||||||
|
// } else if (item_size == 4) {
|
||||||
|
// image = py::array_t<uint32_t>(shape);
|
||||||
|
// }
|
||||||
|
// self.read_into(
|
||||||
|
// reinterpret_cast<std::byte *>(image.mutable_data()),
|
||||||
|
// header.mutable_data());
|
||||||
|
|
||||||
|
// return py::make_tuple(header, image);
|
||||||
|
// })
|
||||||
|
|
||||||
|
}
|
@ -11,6 +11,8 @@
|
|||||||
#include "fit.hpp"
|
#include "fit.hpp"
|
||||||
#include "interpolation.hpp"
|
#include "interpolation.hpp"
|
||||||
|
|
||||||
|
#include "jungfrau_data_file.hpp"
|
||||||
|
|
||||||
//Pybind stuff
|
//Pybind stuff
|
||||||
#include <pybind11/pybind11.h>
|
#include <pybind11/pybind11.h>
|
||||||
#include <pybind11/stl.h>
|
#include <pybind11/stl.h>
|
||||||
@ -33,5 +35,6 @@ PYBIND11_MODULE(_aare, m) {
|
|||||||
define_cluster_file_sink_bindings(m);
|
define_cluster_file_sink_bindings(m);
|
||||||
define_fit_bindings(m);
|
define_fit_bindings(m);
|
||||||
define_interpolation_bindings(m);
|
define_interpolation_bindings(m);
|
||||||
|
define_jungfrau_data_file_io_bindings(m);
|
||||||
|
|
||||||
}
|
}
|
75
src/JungfrauDataFile.cpp
Normal file
75
src/JungfrauDataFile.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#include "aare/JungfrauDataFile.hpp"
|
||||||
|
#include "aare/defs.hpp"
|
||||||
|
|
||||||
|
namespace aare{
|
||||||
|
|
||||||
|
JungfrauDataFile::JungfrauDataFile(const std::filesystem::path& fname){
|
||||||
|
auto frame_size = guess_frame_size(fname);
|
||||||
|
if (frame_size == module_data_size) {
|
||||||
|
m_rows = 512;
|
||||||
|
m_cols = 1024;
|
||||||
|
} else if (frame_size == half_data_size) {
|
||||||
|
m_rows = 256;
|
||||||
|
m_cols = 1024;
|
||||||
|
} else if (frame_size == chip_data_size) {
|
||||||
|
m_rows = 256;
|
||||||
|
m_cols = 256;
|
||||||
|
} else {
|
||||||
|
throw std::runtime_error(LOCATION + "Cannot guess frame size: file size is not a multiple of any known frame size");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
size_t JungfrauDataFile::bytes_per_frame() const{
|
||||||
|
return m_rows * m_cols * bytes_per_pixel();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t JungfrauDataFile::pixels_per_frame()const {
|
||||||
|
return m_rows * m_cols;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t JungfrauDataFile::bytes_per_pixel() const {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t JungfrauDataFile::bitdepth()const {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
void seek(size_t frame_index){}; //!< seek to the given frame index
|
||||||
|
|
||||||
|
size_t JungfrauDataFile::tell() const{
|
||||||
|
return 0;
|
||||||
|
} //!< get the frame index of the file pointer
|
||||||
|
size_t JungfrauDataFile::total_frames() const {
|
||||||
|
return m_total_frames;
|
||||||
|
}
|
||||||
|
size_t JungfrauDataFile::rows() const {
|
||||||
|
return m_rows;
|
||||||
|
}
|
||||||
|
size_t JungfrauDataFile::cols() const {
|
||||||
|
return m_cols;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t JungfrauDataFile::guess_frame_size(const std::filesystem::path& fname) {
|
||||||
|
auto file_size = std::filesystem::file_size(fname);
|
||||||
|
if (file_size == 0) {
|
||||||
|
throw std::runtime_error(LOCATION + "Cannot guess frame size: file is empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (file_size % module_data_size == 0) {
|
||||||
|
return module_data_size;
|
||||||
|
} else if (file_size % half_data_size == 0) {
|
||||||
|
return half_data_size;
|
||||||
|
} else if (file_size % chip_data_size == 0) {
|
||||||
|
return chip_data_size;
|
||||||
|
} else {
|
||||||
|
throw std::runtime_error(LOCATION + "Cannot guess frame size: file size is not a multiple of any known frame size");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace aare
|
6
src/JungfrauDataFile.test.cpp
Normal file
6
src/JungfrauDataFile.test.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
#include "test_config.hpp"
|
||||||
|
|
||||||
|
TEST_CASE("fail"){
|
||||||
|
REQUIRE(false);
|
||||||
|
}
|
Reference in New Issue
Block a user