diff --git a/python/src/jungfrau_data_file.hpp b/python/src/jungfrau_data_file.hpp index dd4f524..955e9a4 100644 --- a/python/src/jungfrau_data_file.hpp +++ b/python/src/jungfrau_data_file.hpp @@ -78,30 +78,5 @@ void define_jungfrau_data_file_io_bindings(py::module &m) { return py::make_tuple(header, image); }); - // .def("read_frame", - // [](RawFile &self) { - // py::array image; - // std::vector shape; - // shape.reserve(2); - // shape.push_back(self.rows()); - // shape.push_back(self.cols()); - - // // return headers from all subfiles - // py::array_t header(self.n_mod()); - - // const uint8_t item_size = self.bytes_per_pixel(); - // if (item_size == 1) { - // image = py::array_t(shape); - // } else if (item_size == 2) { - // image = py::array_t(shape); - // } else if (item_size == 4) { - // image = py::array_t(shape); - // } - // self.read_into( - // reinterpret_cast(image.mutable_data()), - // header.mutable_data()); - - // return py::make_tuple(header, image); - // }) } \ No newline at end of file diff --git a/src/ClusterFile.test.cpp b/src/ClusterFile.test.cpp index a0eed04..a7fc044 100644 --- a/src/ClusterFile.test.cpp +++ b/src/ClusterFile.test.cpp @@ -11,9 +11,9 @@ using aare::ClusterFile; -TEST_CASE("Read one frame from a a cluster file", "[.integration]") { +TEST_CASE("Read one frame from a a cluster file", "[.files]") { //We know that the frame has 97 clusters - auto fpath = test_data_path() / "clusters" / "single_frame_97_clustrers.clust"; + auto fpath = test_data_path() / "clust" / "single_frame_97_clustrers.clust"; REQUIRE(std::filesystem::exists(fpath)); ClusterFile f(fpath); @@ -22,9 +22,9 @@ TEST_CASE("Read one frame from a a cluster file", "[.integration]") { REQUIRE(clusters.frame_number() == 135); } -TEST_CASE("Read one frame using ROI", "[.integration]") { +TEST_CASE("Read one frame using ROI", "[.files]") { //We know that the frame has 97 clusters - auto fpath = test_data_path() / "clusters" / "single_frame_97_clustrers.clust"; + auto fpath = test_data_path() / "clust" / "single_frame_97_clustrers.clust"; REQUIRE(std::filesystem::exists(fpath)); ClusterFile f(fpath); @@ -50,9 +50,9 @@ TEST_CASE("Read one frame using ROI", "[.integration]") { } -TEST_CASE("Read clusters from single frame file", "[.integration]") { +TEST_CASE("Read clusters from single frame file", "[.files]") { - auto fpath = test_data_path() / "clusters" / "single_frame_97_clustrers.clust"; + auto fpath = test_data_path() / "clust" / "single_frame_97_clustrers.clust"; REQUIRE(std::filesystem::exists(fpath)); SECTION("Read fewer clusters than available") { diff --git a/src/JungfrauDataFile.cpp b/src/JungfrauDataFile.cpp index 27c2708..20ce969 100644 --- a/src/JungfrauDataFile.cpp +++ b/src/JungfrauDataFile.cpp @@ -130,7 +130,7 @@ void JungfrauDataFile::read_into(std::byte *image_buf, // prepare for next read // if we are at the end of the file, open the next file ++ m_current_frame; - if(m_current_frame >= m_frame_index[m_current_file_index]){ + if(m_current_frame >= m_frame_index[m_current_file_index] && (m_current_frame < m_total_frames)){ ++m_current_file_index; open_file(m_current_file_index); } diff --git a/src/JungfrauDataFile.test.cpp b/src/JungfrauDataFile.test.cpp index 7131165..69f3b72 100644 --- a/src/JungfrauDataFile.test.cpp +++ b/src/JungfrauDataFile.test.cpp @@ -1,6 +1,36 @@ +#include "aare/JungfrauDataFile.hpp" + #include #include "test_config.hpp" -TEST_CASE("fail"){ - REQUIRE(false); +using aare::JungfrauDataFile; +using aare::JungfrauDataHeader; +TEST_CASE("Open a Jungfrau data file", "[.files]") { + //we know we have 4 files with 7, 7, 7, and 3 frames + //firs frame number if 1 and the bunch id is frame_number**2 + //so we can check the header + auto fpath = test_data_path() / "dat" / "AldoJF500k_000000.dat"; + REQUIRE(std::filesystem::exists(fpath)); + + JungfrauDataFile f(fpath); + REQUIRE(f.rows() == 512); + REQUIRE(f.cols() == 1024); + REQUIRE(f.bytes_per_frame() == 1048576); + REQUIRE(f.pixels_per_frame() == 524288); + REQUIRE(f.bytes_per_pixel() == 2); + REQUIRE(f.bitdepth() == 16); + REQUIRE(f.base_name() == "AldoJF500k"); + REQUIRE(f.n_files() == 4); + REQUIRE(f.tell() == 0); + REQUIRE(f.total_frames() == 24); + REQUIRE(f.current_file() == fpath); + + for (size_t i = 0; i < 24; ++i) { + JungfrauDataHeader header; + auto image = f.read_frame(header); + REQUIRE(header.framenum == i + 1); + REQUIRE(header.bunchid == (i + 1) * (i + 1)); + REQUIRE(image.shape(0) == 512); + REQUIRE(image.shape(1) == 1024); + } } \ No newline at end of file