fixing read bug

This commit is contained in:
froejdh_e
2025-01-10 15:33:56 +01:00
parent caf7b4ecdb
commit 7550a2cb97
3 changed files with 20 additions and 20 deletions

View File

@ -39,14 +39,14 @@ void define_cluster_vector(py::module &m, const std::string &typestr) {
&ClusterVector<T>::set_frame_number) &ClusterVector<T>::set_frame_number)
.def_buffer([typestr](ClusterVector<T> &self) -> py::buffer_info { .def_buffer([typestr](ClusterVector<T> &self) -> py::buffer_info {
return py::buffer_info( return py::buffer_info(
self.data(), /* Pointer to buffer */ self.data(), /* Pointer to buffer */
self.item_size(), /* Size of one scalar */ self.item_size(), /* Size of one scalar */
fmt::format(self.fmt_base(), self.cluster_size_x(), fmt::format(self.fmt_base(), self.cluster_size_x(),
self.cluster_size_y(), self.cluster_size_y(),
typestr), /* Format descriptor */ typestr), /* Format descriptor */
1, /* Number of dimensions */ 1, /* Number of dimensions */
{self.size()}, /* Buffer dimensions */ {self.size()}, /* Buffer dimensions */
{self.item_size()} /* Strides (in bytes) for each index */ {self.item_size()} /* Strides (in bytes) for each index */
); );
}); });
} }
@ -75,18 +75,18 @@ void define_cluster_finder_mt_bindings(py::module &m) {
.def("sync", &ClusterFinderMT<uint16_t, pd_type>::sync) .def("sync", &ClusterFinderMT<uint16_t, pd_type>::sync)
.def("stop", &ClusterFinderMT<uint16_t, pd_type>::stop) .def("stop", &ClusterFinderMT<uint16_t, pd_type>::stop)
.def("start", &ClusterFinderMT<uint16_t, pd_type>::start) .def("start", &ClusterFinderMT<uint16_t, pd_type>::start)
.def_property_readonly("pedestal", .def("pedestal",
[](ClusterFinderMT<uint16_t, pd_type> &self) { [](ClusterFinderMT<uint16_t, pd_type> &self, size_t thread_index) {
auto pd = new NDArray<pd_type, 2>{}; auto pd = new NDArray<pd_type, 2>{};
*pd = self.pedestal(); *pd = self.pedestal(thread_index);
return return_image_data(pd); return return_image_data(pd);
}) },py::arg("thread_index") = 0)
.def_property_readonly("noise", .def("noise",
[](ClusterFinderMT<uint16_t, pd_type> &self) { [](ClusterFinderMT<uint16_t, pd_type> &self, size_t thread_index) {
auto arr = new NDArray<pd_type, 2>{}; auto arr = new NDArray<pd_type, 2>{};
*arr = self.noise(); *arr = self.noise(thread_index);
return return_image_data(arr); return return_image_data(arr);
}); },py::arg("thread_index") = 0);
} }
void define_cluster_collector_bindings(py::module &m) { void define_cluster_collector_bindings(py::module &m) {

View File

@ -35,7 +35,7 @@ void define_cluster_file_io_bindings(py::module &m) {
[](ClusterFile &self) { [](ClusterFile &self) {
auto v = new ClusterVector<int32_t>(self.read_frame()); auto v = new ClusterVector<int32_t>(self.read_frame());
return v; return v;
},py::return_value_policy::take_ownership) })
.def("write_frame", &ClusterFile::write_frame) .def("write_frame", &ClusterFile::write_frame)
.def("read_cluster_with_cut", .def("read_cluster_with_cut",
[](ClusterFile &self, size_t n_clusters, [](ClusterFile &self, size_t n_clusters,

View File

@ -72,7 +72,7 @@ ClusterVector<int32_t> ClusterFile::read_clusters(size_t n_clusters) {
} else { } else {
nn = nph; nn = nph;
} }
nph_read += fread(reinterpret_cast<void *>(buf + nph_read), nph_read += fread((buf + nph_read*clusters.item_size()),
clusters.item_size(), nn, fp); clusters.item_size(), nn, fp);
m_num_left = nph - nn; // write back the number of photons left m_num_left = nph - nn; // write back the number of photons left
} }
@ -87,7 +87,7 @@ ClusterVector<int32_t> ClusterFile::read_clusters(size_t n_clusters) {
else else
nn = nph; nn = nph;
nph_read += fread(reinterpret_cast<void *>(buf + nph_read), nph_read += fread((buf + nph_read*clusters.item_size()),
clusters.item_size(), nn, fp); clusters.item_size(), nn, fp);
m_num_left = nph - nn; m_num_left = nph - nn;
} }