Skip to content

Commit

Permalink
frame reading for cluster file
Browse files Browse the repository at this point in the history
  • Loading branch information
erikfrojdh committed Nov 15, 2024
1 parent e77b615 commit 17f8d28
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 42 deletions.
50 changes: 27 additions & 23 deletions docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions docs/src/ClusterFile.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ClusterFile
=============

.. doxygenclass:: aare::ClusterFile
:members:
:undoc-members:
:private-members:
12 changes: 2 additions & 10 deletions docs/src/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,6 +36,7 @@ AARE
File
Dtype
ClusterFinder
ClusterFile
Pedestal
RawFile
RawSubFile
Expand Down
11 changes: 11 additions & 0 deletions docs/src/pyClusterFile.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

ClusterFile
============

.. py:currentmodule:: aare
.. autoclass:: ClusterFile
:members:
:undoc-members:
:show-inheritance:
:inherited-members:
3 changes: 3 additions & 0 deletions include/aare/ClusterFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ struct ClusterAnalysis {
double etay;
};



class ClusterFile {
FILE *fp{};
uint32_t m_num_left{};
Expand All @@ -46,6 +48,7 @@ class ClusterFile {
public:
ClusterFile(const std::filesystem::path &fname, size_t chunk_size = 1000);
std::vector<Cluster> read_clusters(size_t n_clusters);
std::vector<Cluster> read_frame(int32_t &out_fnum);
std::vector<Cluster>
read_cluster_with_cut(size_t n_clusters, double *noise_map, int nx, int ny);

Expand Down
8 changes: 5 additions & 3 deletions python/examples/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

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)
6 changes: 6 additions & 0 deletions python/src/cluster_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ void define_cluster_file_io_bindings(py::module &m) {
auto* vec = new std::vector<Cluster>(self.read_clusters(n_clusters));
return return_vector(vec);
})
.def("read_frame",
[](ClusterFile &self) {
int32_t frame_number;
auto* vec = new std::vector<Cluster>(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<double> noise_map, int nx, int ny) {
auto view = make_view_2d(noise_map);
Expand Down
29 changes: 23 additions & 6 deletions src/ClusterFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@ std::vector<Cluster> ClusterFile::read_clusters(size_t n_clusters) {
std::vector<Cluster> 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<Cluster *>(clusters.data());
// if there are photons left from previous frame read them first
Expand Down Expand Up @@ -61,6 +56,28 @@ std::vector<Cluster> ClusterFile::read_clusters(size_t n_clusters) {
return clusters;
}

std::vector<Cluster> 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<Cluster> 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<Cluster> ClusterFile::read_cluster_with_cut(size_t n_clusters,
double *noise_map,
int nx, int ny) {
Expand Down

0 comments on commit 17f8d28

Please sign in to comment.