frame reading for cluster file

This commit is contained in:
Erik Fröjdh
2024-11-15 16:13:46 +01:00
parent e77b615293
commit 17f8d28019
8 changed files with 84 additions and 42 deletions

View File

@ -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
@ -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) {