wip at fixing hdf5 master file
Some checks failed
Build on RHEL9 / build (push) Failing after 1m27s
Build on RHEL8 / build (push) Failing after 1m36s

This commit is contained in:
2025-06-06 16:36:40 +02:00
parent d7242671b2
commit 480e28c927
8 changed files with 148 additions and 189 deletions

View File

@@ -8,7 +8,7 @@
namespace aare {
struct H5Handles {
class H5Handles {
std::string file_name;
std::string dataset_name;
H5::H5File file;
@@ -20,6 +20,7 @@ struct H5Handles {
std::vector<hsize_t> count;
std::vector<hsize_t> offset;
public:
H5Handles(const std::string& fname, const std::string& dname):
file_name(fname),
dataset_name(dname),
@@ -31,6 +32,10 @@ struct H5Handles {
initialize_memspace();
}
std::vector<hsize_t> get_dims() const {
return dims;
}
void seek(size_t frame_index) {
if (frame_index >= dims[0]) {
throw std::runtime_error(LOCATION + "Invalid frame number");

View File

@@ -6,18 +6,6 @@
#include <fstream>
#include <optional>
namespace fmt {
template <typename T> struct formatter<std::optional<T>> : formatter<T> {
template <typename FormatContext>
auto format(const std::optional<T> &opt, FormatContext &ctx) {
if (opt) {
return formatter<T>::format(*opt, ctx);
} else {
return format_to(ctx.out(), "nullopt");
}
}
};
} // namespace fmt
namespace aare {
@@ -29,7 +17,7 @@ class Hdf5FileNameComponents {
std::filesystem::path m_base_path{};
std::string m_base_name{};
std::string m_ext{};
int m_file_index{}; // TODO! is this measurement_index?
int m_file_index{};
public:
Hdf5FileNameComponents(const std::filesystem::path &fname);
@@ -50,39 +38,6 @@ class Hdf5FileNameComponents {
void set_old_scheme(bool old_scheme);
};
/*
class ScanParameters {
bool m_enabled = false;
std::string m_dac;
int m_start = 0;
int m_stop = 0;
int m_step = 0;
// TODO! add settleTime, requires string to time conversion
public:
ScanParameters(const std::string &par);
ScanParameters() = default;
ScanParameters(const ScanParameters &) = default;
ScanParameters &operator=(const ScanParameters &) = default;
ScanParameters(ScanParameters &&) = default;
int start() const;
int stop() const;
int step() const;
const std::string &dac() const;
bool enabled() const;
void increment_stop();
};
struct ROI {
int64_t xmin{};
int64_t xmax{};
int64_t ymin{};
int64_t ymax{};
int64_t height() const { return ymax - ymin; }
int64_t width() const { return xmax - xmin; }
};
*/
/**
* @brief Class for parsing a master file either in our .json format or the old
@@ -104,7 +59,7 @@ class Hdf5MasterFile {
xy m_geometry{};
size_t m_max_frames_per_file{};
// uint32_t m_adc_mask{}; // TODO! implement reading
uint32_t m_adc_mask{}; // TODO! implement reading
FrameDiscardPolicy m_frame_discard_policy{};
size_t m_frame_padding{};
@@ -113,7 +68,7 @@ class Hdf5MasterFile {
uint8_t m_digital_flag{};
uint8_t m_transceiver_flag{};
// ScanParameters m_scan_parameters;
ScanParameters m_scan_parameters;
std::optional<size_t> m_analog_samples;
std::optional<size_t> m_digital_samples;
@@ -121,7 +76,7 @@ class Hdf5MasterFile {
std::optional<size_t> m_number_of_rows;
std::optional<uint8_t> m_quad;
// std::optional<ROI> m_roi;
std::optional<ROI> m_roi;
public:
Hdf5MasterFile(const std::filesystem::path &fpath);
@@ -151,9 +106,9 @@ class Hdf5MasterFile {
std::optional<size_t> number_of_rows() const;
std::optional<uint8_t> quad() const;
// std::optional<ROI> roi() const;
std::optional<ROI> roi() const;
// ScanParameters scan_parameters() const;
ScanParameters scan_parameters() const;
private:
static const std::string metadata_group_name;

View File

@@ -39,28 +39,6 @@ class RawFileNameComponents {
void set_old_scheme(bool old_scheme);
};
class ScanParameters {
bool m_enabled = false;
std::string m_dac;
int m_start = 0;
int m_stop = 0;
int m_step = 0;
//TODO! add settleTime, requires string to time conversion
public:
ScanParameters(const std::string &par);
ScanParameters() = default;
ScanParameters(const ScanParameters &) = default;
ScanParameters &operator=(const ScanParameters &) = default;
ScanParameters(ScanParameters &&) = default;
int start() const;
int stop() const;
int step() const;
const std::string &dac() const;
bool enabled() const;
void increment_stop();
};
/**
* @brief Class for parsing a master file either in our .json format or the old
@@ -132,7 +110,6 @@ class RawMasterFile {
std::optional<ROI> roi() const;
ScanParameters scan_parameters() const;
private:

View File

@@ -12,7 +12,8 @@
#include <variant>
#include <vector>
#include <iostream>
#include <sstream>
#include <optional>
/**
* @brief LOCATION macro to get the current location in the code
@@ -225,6 +226,46 @@ struct ROI{
using dynamic_shape = std::vector<ssize_t>;
class ScanParameters {
bool m_enabled = false;
std::string m_dac;
int m_start = 0;
int m_stop = 0;
int m_step = 0;
//TODO! add settleTime, requires string to time conversion
public:
// "[enabled\ndac dac 4\nstart 500\nstop 2200\nstep 5\nsettleTime 100us\n]"
ScanParameters(const std::string &par) {
std::istringstream iss(par.substr(1, par.size()-2));
std::string line;
while(std::getline(iss, line)){
if(line == "enabled"){
m_enabled = true;
}else if(line.find("dac") != std::string::npos){
m_dac = line.substr(4);
}else if(line.find("start") != std::string::npos){
m_start = std::stoi(line.substr(6));
}else if(line.find("stop") != std::string::npos){
m_stop = std::stoi(line.substr(5));
}else if(line.find("step") != std::string::npos){
m_step = std::stoi(line.substr(5));
}
}
};
ScanParameters() = default;
ScanParameters(const ScanParameters &) = default;
ScanParameters &operator=(const ScanParameters &) = default;
ScanParameters(ScanParameters &&) = default;
int start() const { return m_start; };
int stop() const { return m_stop; };
int step() const { return m_step; };
const std::string &dac() const { return m_dac; };
bool enabled() const { return m_enabled; };
void increment_stop() { m_stop += 1; };
};
//TODO! Can we uniform enums between the libraries?
/**
@@ -266,6 +307,8 @@ template <> std::string ToString(TimingMode arg);
template <> FrameDiscardPolicy StringTo(const std::string & /*mode*/);
template <> std::string ToString(FrameDiscardPolicy arg);
template <> std::string ToString(ScanParameters arg);
using DataTypeVariants = std::variant<uint16_t, uint32_t>;
template <typename T>
@@ -280,5 +323,14 @@ std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) {
return os;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::optional<T> &opt) {
if (opt)
os << *opt;
else
os << "nullopt";
return os;
}
} // namespace aare