diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index b0c45ce..7ee6465 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -10,31 +10,35 @@ configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) set(SPHINX_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src) set(SPHINX_BUILD ${CMAKE_CURRENT_BINARY_DIR}) -set(SPHINX_SOURCE_FILES - src/index.rst - src/Installation.rst - src/Requirements.rst - src/NDArray.rst - src/NDView.rst - src/File.rst - src/Frame.rst - src/Dtype.rst - src/ClusterFinder.rst - src/Pedestal.rst - src/RawFile.rst - src/RawSubFile.rst - src/RawMasterFile.rst - src/VarClusterFinder.rst - src/pyVarClusterFinder.rst - src/pyFile.rst - src/pyCtbRawFile.rst - src/pyRawFile.rst - src/pyRawMasterFile.rst -) + +file(GLOB SPHINX_SOURCE_FILES CONFIGURE_DEPENDS "src/*.rst") +# set(SPHINX_SOURCE_FILES +# src/index.rst +# src/Installation.rst +# src/Requirements.rst +# src/NDArray.rst +# src/NDView.rst +# src/File.rst +# src/Frame.rst +# src/Dtype.rst +# src/ClusterFinder.rst +# src/ClusterFile.rst +# src/Pedestal.rst +# src/RawFile.rst +# src/RawSubFile.rst +# src/RawMasterFile.rst +# src/VarClusterFinder.rst +# src/pyVarClusterFinder.rst +# src/pyFile.rst +# src/pyCtbRawFile.rst +# src/pyRawFile.rst +# src/pyRawMasterFile.rst +# ) foreach(filename ${SPHINX_SOURCE_FILES}) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${filename} - "${SPHINX_BUILD}/${filename}") + get_filename_component(fname ${filename} NAME) + message(STATUS "Copying ${filename} to ${SPHINX_BUILD}/src/${fname}") + configure_file(${filename} "${SPHINX_BUILD}/src/${fname}") endforeach(filename ${SPHINX_SOURCE_FILES}) configure_file( diff --git a/docs/src/ClusterFile.rst b/docs/src/ClusterFile.rst new file mode 100644 index 0000000..79de086 --- /dev/null +++ b/docs/src/ClusterFile.rst @@ -0,0 +1,7 @@ +ClusterFile +============= + +.. doxygenclass:: aare::ClusterFile + :members: + :undoc-members: + :private-members: \ No newline at end of file diff --git a/docs/src/index.rst b/docs/src/index.rst index 588d651..a43ae4a 100644 --- a/docs/src/index.rst +++ b/docs/src/index.rst @@ -20,21 +20,12 @@ AARE pyFile pyCtbRawFile + pyClusterFile pyRawFile pyRawMasterFile pyVarClusterFinder -.. toctree:: - :caption: Python API - :maxdepth: 1 - - pyFile - pyCtbRawFile - pyRawMasterFile - pyVarClusterFinder - - .. toctree:: :caption: C++ API :maxdepth: 1 @@ -45,6 +36,7 @@ AARE File Dtype ClusterFinder + ClusterFile Pedestal RawFile RawSubFile diff --git a/docs/src/pyClusterFile.rst b/docs/src/pyClusterFile.rst new file mode 100644 index 0000000..bdf898c --- /dev/null +++ b/docs/src/pyClusterFile.rst @@ -0,0 +1,11 @@ + +ClusterFile +============ + +.. py:currentmodule:: aare + +.. autoclass:: ClusterFile + :members: + :undoc-members: + :show-inheritance: + :inherited-members: \ No newline at end of file diff --git a/include/aare/ClusterFile.hpp b/include/aare/ClusterFile.hpp index 76937e0..50d9d6f 100644 --- a/include/aare/ClusterFile.hpp +++ b/include/aare/ClusterFile.hpp @@ -38,6 +38,8 @@ struct ClusterAnalysis { double etay; }; + + class ClusterFile { FILE *fp{}; uint32_t m_num_left{}; @@ -46,6 +48,7 @@ class ClusterFile { public: ClusterFile(const std::filesystem::path &fname, size_t chunk_size = 1000); std::vector read_clusters(size_t n_clusters); + std::vector read_frame(int32_t &out_fnum); std::vector read_cluster_with_cut(size_t n_clusters, double *noise_map, int nx, int ny); diff --git a/python/examples/play.py b/python/examples/play.py index bac7c18..633b7e2 100644 --- a/python/examples/play.py +++ b/python/examples/play.py @@ -6,8 +6,10 @@ from aare import ClusterFile base = Path('~/data/aare_test_data/clusters').expanduser() -# f = ClusterFile(base / 'beam_En700eV_-40deg_300V_10us_d0_f0_100.clust') -f = ClusterFile(base / 'single_frame_97_clustrers.clust') - +f = ClusterFile(base / 'beam_En700eV_-40deg_300V_10us_d0_f0_100.clust') +# f = ClusterFile(base / 'single_frame_97_clustrers.clust') +for i in range(10): + fn, cl = f.read_frame() + print(fn, cl.size) diff --git a/python/src/cluster_file.hpp b/python/src/cluster_file.hpp index 1801924..bdb18b1 100644 --- a/python/src/cluster_file.hpp +++ b/python/src/cluster_file.hpp @@ -24,6 +24,12 @@ void define_cluster_file_io_bindings(py::module &m) { auto* vec = new std::vector(self.read_clusters(n_clusters)); return return_vector(vec); }) + .def("read_frame", + [](ClusterFile &self) { + int32_t frame_number; + auto* vec = new std::vector(self.read_frame(frame_number)); + return py::make_tuple(frame_number, return_vector(vec)); + }) .def("read_cluster_with_cut", [](ClusterFile &self, size_t n_clusters, py::array_t noise_map, int nx, int ny) { auto view = make_view_2d(noise_map); diff --git a/src/ClusterFile.cpp b/src/ClusterFile.cpp index aff4625..72da597 100644 --- a/src/ClusterFile.cpp +++ b/src/ClusterFile.cpp @@ -13,14 +13,9 @@ std::vector ClusterFile::read_clusters(size_t n_clusters) { std::vector clusters(n_clusters); int32_t iframe = 0; // frame number needs to be 4 bytes! - size_t nph_read = 0; - - // uint32_t nn = *n_left; uint32_t nn = m_num_left; - // uint32_t nph = *n_left; // number of clusters in frame needs to be 4 - // bytes! - uint32_t nph = m_num_left; + uint32_t nph = m_num_left; // number of clusters in frame needs to be 4 auto buf = reinterpret_cast(clusters.data()); // if there are photons left from previous frame read them first @@ -61,6 +56,28 @@ std::vector ClusterFile::read_clusters(size_t n_clusters) { return clusters; } +std::vector ClusterFile::read_frame(int32_t &out_fnum) { + if (m_num_left) { + throw std::runtime_error("There are still photons left in the last frame"); + } + + if (fread(&out_fnum, sizeof(out_fnum), 1, fp) != 1) { + throw std::runtime_error("Could not read frame number"); + } + + int n_clusters; + if (fread(&n_clusters, sizeof(n_clusters), 1, fp) != 1) { + throw std::runtime_error("Could not read number of clusters"); + } + std::vector clusters(n_clusters); + + if (fread(clusters.data(), sizeof(Cluster), n_clusters, fp) != n_clusters) { + throw std::runtime_error("Could not read clusters"); + } + return clusters; + +} + std::vector ClusterFile::read_cluster_with_cut(size_t n_clusters, double *noise_map, int nx, int ny) {