formatted my changes

This commit is contained in:
2025-06-11 15:13:35 +02:00
parent d89530ed22
commit cc57cc7c27
11 changed files with 203 additions and 214 deletions

View File

@ -9,89 +9,85 @@
namespace aare {
class H5Handles {
std::string file_name;
std::string dataset_name;
H5::H5File file;
H5::DataSet dataset;
H5::DataSpace dataspace;
H5::DataType datatype;
std::unique_ptr<H5::DataSpace> memspace;
std::vector<hsize_t>dims;
std::vector<hsize_t> count;
std::vector<hsize_t> offset;
std::string file_name;
std::string dataset_name;
H5::H5File file;
H5::DataSet dataset;
H5::DataSpace dataspace;
H5::DataType datatype;
std::unique_ptr<H5::DataSpace> memspace;
std::vector<hsize_t> dims;
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),
file(fname, H5F_ACC_RDONLY),
dataset(file.openDataSet(dname)),
dataspace(dataset.getSpace()),
datatype(dataset.getDataType()) {
intialize_dimensions();
initialize_memspace();
H5Handles(const std::string &fname, const std::string &dname)
: file_name(fname), dataset_name(dname), file(fname, H5F_ACC_RDONLY),
dataset(file.openDataSet(dname)), dataspace(dataset.getSpace()),
datatype(dataset.getDataType()) {
intialize_dimensions();
initialize_memspace();
}
std::vector<hsize_t> get_dims() const {
return dims;
}
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");
void seek(size_t frame_index) {
if (frame_index >= dims[0]) {
throw std::runtime_error(LOCATION + "Invalid frame number");
}
offset[0] = static_cast<hsize_t>(frame_index);
}
offset[0] = static_cast<hsize_t>(frame_index);
}
void get_data_into(size_t frame_index, std::byte *frame_buffer, size_t n_frames = 1) {
seek(frame_index);
count[0] = static_cast<hsize_t>(n_frames);
// std::cout << "offset:" << ToString(offset) << " count:" <<
// ToString(count) << std::endl;
dataspace.selectHyperslab(H5S_SELECT_SET, count.data(), offset.data());
dataset.read(frame_buffer, datatype, *memspace, dataspace);
}
void get_data_into(size_t frame_index, std::byte *frame_buffer,
size_t n_frames = 1) {
seek(frame_index);
count[0] = static_cast<hsize_t>(n_frames);
// std::cout << "offset:" << ToString(offset) << " count:" <<
// ToString(count) << std::endl;
dataspace.selectHyperslab(H5S_SELECT_SET, count.data(), offset.data());
dataset.read(frame_buffer, datatype, *memspace, dataspace);
}
void get_header_into(size_t frame_index, int part_index, std::byte *header_buffer) {
seek(frame_index);
offset[1] = static_cast<hsize_t>(part_index);
// std::cout << "offset:" << ToString(offset) << " count:" <<
// ToString(count) << std::endl;
dataspace.selectHyperslab(H5S_SELECT_SET, count.data(), offset.data());
dataset.read(header_buffer, datatype, *memspace, dataspace);
}
void get_header_into(size_t frame_index, int part_index,
std::byte *header_buffer) {
seek(frame_index);
offset[1] = static_cast<hsize_t>(part_index);
// std::cout << "offset:" << ToString(offset) << " count:" <<
// ToString(count) << std::endl;
dataspace.selectHyperslab(H5S_SELECT_SET, count.data(), offset.data());
dataset.read(header_buffer, datatype, *memspace, dataspace);
}
private:
void intialize_dimensions() {
int rank = dataspace.getSimpleExtentNdims();
dims.resize(rank);
dataspace.getSimpleExtentDims(dims.data(), nullptr);
}
void initialize_memspace() {
int rank = dataspace.getSimpleExtentNdims();
count.clear();
offset.clear();
// header datasets or header virtual datasets
if (rank == 1 || rank == 2) {
count = std::vector<hsize_t>(rank, 1); // slice 1 value
offset = std::vector<hsize_t>(rank, 0);
memspace = std::make_unique<H5::DataSpace>(H5S_SCALAR);
} else if (rank >= 3) {
// data dataset (frame x height x width)
count = {1, dims[1], dims[2]};
offset = {0, 0, 0};
hsize_t dims_image[2] = {dims[1], dims[2]};
memspace = std::make_unique<H5::DataSpace>(2, dims_image);
} else {
throw std::runtime_error(LOCATION + "Invalid rank for dataset: " + std::to_string(rank));
void intialize_dimensions() {
int rank = dataspace.getSimpleExtentNdims();
dims.resize(rank);
dataspace.getSimpleExtentDims(dims.data(), nullptr);
}
void initialize_memspace() {
int rank = dataspace.getSimpleExtentNdims();
count.clear();
offset.clear();
// header datasets or header virtual datasets
if (rank == 1 || rank == 2) {
count = std::vector<hsize_t>(rank, 1); // slice 1 value
offset = std::vector<hsize_t>(rank, 0);
memspace = std::make_unique<H5::DataSpace>(H5S_SCALAR);
} else if (rank >= 3) {
// data dataset (frame x height x width)
count = {1, dims[1], dims[2]};
offset = {0, 0, 0};
hsize_t dims_image[2] = {dims[1], dims[2]};
memspace = std::make_unique<H5::DataSpace>(2, dims_image);
} else {
throw std::runtime_error(
LOCATION + "Invalid rank for dataset: " + std::to_string(rank));
}
}
}
};
template <typename Fn>
void read_hdf5_header_fields(DetectorHeader *header, Fn &&fn_read_field) {
fn_read_field(0, reinterpret_cast<std::byte *>(&(header->frameNumber)));

View File

@ -6,8 +6,6 @@
#include <fstream>
#include <optional>
namespace aare {
using ns = std::chrono::nanoseconds;
@ -19,7 +17,7 @@ class Hdf5FileNameComponents {
std::filesystem::path m_base_path{};
std::string m_base_name{};
std::string m_ext{};
int m_file_index{};
int m_file_index{};
public:
Hdf5FileNameComponents(const std::filesystem::path &fname);
@ -40,13 +38,12 @@ class Hdf5FileNameComponents {
void set_old_scheme(bool old_scheme);
};
/**
* @brief Class for parsing a master file either in our .json format or the old
* .Hdf5 format
*/
class Hdf5MasterFile {
Hdf5FileNameComponents m_fnc;
std::string m_version;
DetectorType m_type;
@ -89,17 +86,12 @@ class Hdf5MasterFile {
std::optional<std::vector<ns>> m_exptime_array{};
std::optional<std::vector<ns>> m_gate_delay_array{};
std::optional<int> m_gates{};
std::optional<std::map<std::string, std::string>> m_additional_json_header{};
std::optional<std::map<std::string, std::string>>
m_additional_json_header{};
size_t m_frames_in_file{};
// TODO! should these be bool?
public:
Hdf5MasterFile(const std::filesystem::path &fpath);
@ -138,7 +130,7 @@ class Hdf5MasterFile {
std::optional<int> digital_samples() const;
std::optional<int> dbit_offset() const;
std::optional<size_t> dbit_list() const;
std::optional<int> transceiver_mask() const;
std::optional<int> transceiver_mask() const;
bool transceiver_flag() const;
std::optional<int> transceiver_samples() const;
// g1 roi - will not be implemented?
@ -147,11 +139,11 @@ class Hdf5MasterFile {
std::optional<std::vector<ns>> exptime_array() const;
std::optional<std::vector<ns>> gate_delay_array() const;
std::optional<int> gates() const;
std::optional<std::map<std::string, std::string>> additional_json_header() const;
std::optional<std::map<std::string, std::string>>
additional_json_header() const;
size_t frames_in_file() const;
size_t n_modules() const;
private:
static const std::string metadata_group_name;
void parse_acquisition_metadata(const std::filesystem::path &fpath);

View File

@ -39,7 +39,6 @@ class RawFileNameComponents {
void set_old_scheme(bool old_scheme);
};
/**
* @brief Class for parsing a master file either in our .json format or the old
* .raw format

View File

@ -224,33 +224,32 @@ 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
// 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::istringstream iss(par.substr(1, par.size() - 2));
std::string line;
while(std::getline(iss, line)){
if(line == "enabled"){
while (std::getline(iss, line)) {
if (line == "enabled") {
m_enabled = true;
}else if(line.find("dac") != std::string::npos){
} else if (line.find("dac") != std::string::npos) {
m_dac = line.substr(4);
}else if(line.find("start") != std::string::npos){
} else if (line.find("start") != std::string::npos) {
m_start = std::stoi(line.substr(6));
}else if(line.find("stop") != std::string::npos){
} else if (line.find("stop") != std::string::npos) {
m_stop = std::stoi(line.substr(5));
}else if(line.find("step") != std::string::npos){
} else if (line.find("step") != std::string::npos) {
m_step = std::stoi(line.substr(5));
}
}
}
};
ScanParameters() = default;
ScanParameters(const ScanParameters &) = default;
@ -264,7 +263,7 @@ class ScanParameters {
void increment_stop() { m_stop += 1; };
};
//TODO! Can we uniform enums between the libraries?
// TODO! Can we uniform enums between the libraries?
/**
* @brief Enum class to identify different detectors.
@ -292,29 +291,38 @@ enum class DetectorType {
enum class TimingMode { Auto, Trigger };
enum class FrameDiscardPolicy { NoDiscard, Discard, DiscardPartial };
enum class BurstMode { Burst_Interal, Burst_External, Continuous_Internal,
Continuous_External };
enum class BurstMode {
Burst_Interal,
Burst_External,
Continuous_Internal,
Continuous_External
};
/** ToString and StringTo Conversions */
// generic
template <class T, typename = std::enable_if_t<!is_duration<T>::value>>
std::string ToString(T arg) { return T(arg); }
template <class T, typename = std::enable_if_t<!is_duration<T>::value>>
std::string ToString(T arg) {
return T(arg);
}
template <typename T, std::enable_if_t<
!is_duration<T>::value && !is_container<T>::value, int> = 0 >
T StringTo(const std::string &arg) { return T(arg); }
template <typename T,
std::enable_if_t<!is_duration<T>::value && !is_container<T>::value,
int> = 0>
T StringTo(const std::string &arg) {
return T(arg);
}
// time
std::string RemoveUnit(std::string &str);
inline void TrimWhiteSpaces(std::string& s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(),
[](unsigned char c) { return !std::isspace(c); }));
inline void TrimWhiteSpaces(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char c) {
return !std::isspace(c);
}));
s.erase(std::find_if(s.rbegin(), s.rend(),
[](unsigned char c) { return !std::isspace(c); }).base(),
s.end());
[](unsigned char c) { return !std::isspace(c); })
.base(),
s.end());
}
/** Convert std::chrono::duration with specified output unit */
@ -342,13 +350,13 @@ template <typename From>
typename std::enable_if<is_duration<From>::value, std::string>::type
ToString(From t) {
using std::chrono::duration_cast;
using std::chrono::abs;
using std::chrono::nanoseconds;
using std::chrono::duration_cast;
using std::chrono::microseconds;
using std::chrono::milliseconds;
using std::chrono::nanoseconds;
auto tns = duration_cast<nanoseconds>(t);
if (abs(tns) <microseconds(1)) {
if (abs(tns) < microseconds(1)) {
return ToString(tns, "ns");
} else if (abs(tns) < milliseconds(1)) {
return ToString(tns, "us");
@ -359,8 +367,8 @@ ToString(From t) {
}
}
template <class Rep, class Period>
std::ostream& operator<<(std::ostream& os,
const std::chrono::duration<Rep, Period>& d) {
std::ostream &operator<<(std::ostream &os,
const std::chrono::duration<Rep, Period> &d) {
return os << ToString(d);
}
@ -384,11 +392,12 @@ T StringTo(const std::string &t, const std::string &unit) {
} else if (unit == "s" || unit.empty()) {
return duration_cast<T>(std::chrono::duration<double>(tval));
} else {
throw std::invalid_argument("[ERROR] Invalid unit in conversion from string to std::chrono::duration");
throw std::invalid_argument("[ERROR] Invalid unit in conversion from "
"string to std::chrono::duration");
}
}
template <typename T, std::enable_if_t<is_duration<T>::value, int> = 0 >
template <typename T, std::enable_if_t<is_duration<T>::value, int> = 0>
T StringTo(const std::string &t) {
std::string tmp{t};
auto unit = RemoveUnit(tmp);
@ -413,7 +422,7 @@ template <> inline uint8_t StringTo(const std::string &s) {
if (value < std::numeric_limits<uint8_t>::min() ||
value > std::numeric_limits<uint8_t>::max()) {
throw std::runtime_error("Cannot scan uint8_t from string '" + s +
"'. Value must be in range 0 - 255.");
"'. Value must be in range 0 - 255.");
}
return static_cast<uint8_t>(value);
}
@ -424,7 +433,7 @@ template <> inline uint16_t StringTo(const std::string &s) {
if (value < std::numeric_limits<uint16_t>::min() ||
value > std::numeric_limits<uint16_t>::max()) {
throw std::runtime_error("Cannot scan uint16_t from string '" + s +
"'. Value must be in range 0 - 65535.");
"'. Value must be in range 0 - 65535.");
}
return static_cast<uint16_t>(value);
}
@ -449,8 +458,6 @@ template <> inline int StringTo(const std::string &s) {
return std::stoull(s, nullptr, base);
}*/
// vector
template <typename T> std::string ToString(const std::vector<T> &vec) {
std::ostringstream oss;
@ -465,23 +472,25 @@ template <typename T> std::string ToString(const std::vector<T> &vec) {
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
return os << ToString(v);
}
template <
typename Container,
std::enable_if_t<is_container<Container>::value &&
!is_std_string_v<Container> /*&&
!is_map_v<Container>*/,
int> = 0>
Container StringTo(const std::string& s) {
template <typename Container,
std::enable_if_t<is_container<Container>::value &&
!is_std_string_v<Container> /*&&
!is_map_v<Container>*/
,
int> = 0>
Container StringTo(const std::string &s) {
using Value = typename Container::value_type;
// strip outer brackets
std::string str = s;
str.erase(std::remove_if(str.begin(), str.end(),
[](unsigned char c){ return c=='[' || c==']'; }), str.end());
str.erase(
std::remove_if(str.begin(), str.end(),
[](unsigned char c) { return c == '[' || c == ']'; }),
str.end());
std::stringstream ss(str);
std::string item;
@ -491,12 +500,11 @@ Container StringTo(const std::string& s) {
TrimWhiteSpaces(item);
if (!item.empty()) {
result.push_back(StringTo<Value>(item));
}
}
}
return result;
}
// map
template <typename KeyType, typename ValueType>
std::string ToString(const std::map<KeyType, ValueType> &m) {
@ -515,7 +523,8 @@ std::string ToString(const std::map<KeyType, ValueType> &m) {
return os.str();
}
template <> inline std::map<std::string, std::string> StringTo(const std::string &s) {
template <>
inline std::map<std::string, std::string> StringTo(const std::string &s) {
std::map<std::string, std::string> result;
std::string str = s;
@ -531,7 +540,7 @@ template <> inline std::map<std::string, std::string> StringTo(const std::string
auto colon_pos = item.find(':');
if (colon_pos == std::string::npos)
throw std::runtime_error("Missing ':' in item: " + item);
std::string key = item.substr(0, colon_pos);
std::string value = item.substr(colon_pos + 1);
@ -543,7 +552,6 @@ template <> inline std::map<std::string, std::string> StringTo(const std::string
return result;
}
// optional
template <class T> std::string ToString(const std::optional<T> &opt) {
return opt ? ToString(*opt) : "nullopt";
@ -571,14 +579,12 @@ template <> std::string ToString(FrameDiscardPolicy arg);
template <> BurstMode StringTo(const std::string & /*mode*/);
template <> std::string ToString(BurstMode arg);
std::ostream &operator<<(std::ostream &os,
const ScanParameters &r);
std::ostream &operator<<(std::ostream &os, const ScanParameters &r);
template <> std::string ToString(ScanParameters arg);
std::ostream &operator<<(std::ostream &os, const ROI &roi);
template <> std::string ToString(ROI arg);
using DataTypeVariants = std::variant<uint16_t, uint32_t>;
} // namespace aare

View File

@ -49,7 +49,6 @@ struct is_container<
decltype(std::declval<T>().empty())>,
void>::type> : public std::true_type {};
/**
* Type trait to evaluate if template parameter is
* complying with a std::string
@ -62,8 +61,7 @@ inline constexpr bool is_std_string_v =
* Type trait to evaluate if template parameter is
* complying with std::map
*/
template <typename T>
struct is_map : std::false_type {};
template <typename T> struct is_map : std::false_type {};
template <typename K, typename V, typename... Args>
struct is_map<std::map<K, V, Args...>> : std::true_type {};
@ -71,4 +69,4 @@ struct is_map<std::map<K, V, Args...>> : std::true_type {};
template <typename T>
inline constexpr bool is_map_v = is_map<std::decay_t<T>>::value;
} // namsespace aare
} // namespace aare

View File

@ -80,7 +80,7 @@ void define_hdf5_master_file_bindings(py::module &m) {
.def_property_readonly("number_of_rows",
&Hdf5MasterFile::number_of_rows)
.def_property_readonly("quad", &Hdf5MasterFile::quad);
//.def_property_readonly("scan_parameters",
// &Hdf5MasterFile::scan_parameters)
//.def_property_readonly("roi", &Hdf5MasterFile::roi);
//.def_property_readonly("scan_parameters",
// &Hdf5MasterFile::scan_parameters)
//.def_property_readonly("roi", &Hdf5MasterFile::roi);
}

View File

@ -40,7 +40,7 @@ File::File(const std::filesystem::path &fname, const std::string &mode,
throw std::runtime_error("Enable HDF5 compile option: AARE_HDF5=ON");
}
#endif
else if(fname.extension() == ".dat"){
else if (fname.extension() == ".dat") {
file_impl = std::make_unique<JungfrauDataFile>(fname);
} else {
throw std::runtime_error("Unsupported file type");

View File

@ -64,7 +64,7 @@ size_t Hdf5File::frame_number(size_t frame_index) {
uint64_t fnum{0};
int part_index = 0; // assuming first part
m_header_datasets[0]->get_header_into(frame_index, part_index,
reinterpret_cast<std::byte *>(&fnum));
reinterpret_cast<std::byte *>(&fnum));
return fnum;
}
@ -129,11 +129,11 @@ void Hdf5File::get_data_into(size_t frame_index, std::byte *frame_buffer,
void Hdf5File::get_header_into(size_t frame_index, int part_index,
DetectorHeader *header) {
try {
read_hdf5_header_fields(header,
[&](size_t iParameter, std::byte *dest) {
m_header_datasets[iParameter]->get_header_into(
frame_index, part_index, dest);
});
read_hdf5_header_fields(header, [&](size_t iParameter,
std::byte *dest) {
m_header_datasets[iParameter]->get_header_into(frame_index,
part_index, dest);
});
LOG(logDEBUG5) << "Read 1D header for frame " << frame_index;
} catch (const H5::Exception &e) {
fmt::print("Exception type: {}\n", typeid(e).name());
@ -169,7 +169,7 @@ DetectorHeader Hdf5File::read_header(const std::filesystem::path &fname) {
Hdf5File::~Hdf5File() {}
const std::string Hdf5File::metadata_group_name = "/entry/data/";
const std::vector<std::string> Hdf5File::header_dataset_names = {
const std::vector<std::string> Hdf5File::header_dataset_names = {
"frame number",
"exp length or sub exposure time",
"packets caught",
@ -183,21 +183,22 @@ const std::vector<std::string> Hdf5File::header_dataset_names = {
"detector specific 4",
"detector type",
"detector header version",
"packets caught bit mask"
};
"packets caught bit mask"};
void Hdf5File::open_data_file() {
if (m_mode != "r")
throw std::runtime_error(LOCATION +
"Unsupported mode. Can only read Hdf5 files.");
try {
m_data_dataset = std::make_unique<H5Handles>(m_master.master_fname().string(), metadata_group_name + "/data");
m_data_dataset = std::make_unique<H5Handles>(
m_master.master_fname().string(), metadata_group_name + "/data");
m_total_frames = m_data_dataset->get_dims()[0];
m_rows = m_data_dataset->get_dims()[1];
m_cols = m_data_dataset->get_dims()[2];
//fmt::print("Data Dataset dimensions: frames = {}, rows = {}, cols = {}\n",
// m_total_frames, m_rows, m_cols);
// fmt::print("Data Dataset dimensions: frames = {}, rows = {}, cols =
// {}\n",
// m_total_frames, m_rows, m_cols);
} catch (const H5::Exception &e) {
m_data_dataset.reset();
fmt::print("Exception type: {}\n", typeid(e).name());
@ -213,8 +214,12 @@ void Hdf5File::open_header_files() {
"Unsupported mode. Can only read Hdf5 files.");
try {
for (size_t i = 0; i != header_dataset_names.size(); ++i) {
m_header_datasets.push_back(std::make_unique<H5Handles>(m_master.master_fname().string(), metadata_group_name + header_dataset_names[i]));
LOG(logDEBUG) << header_dataset_names[i] << " Dataset dimensions: size = " << m_header_datasets[i]->get_dims()[0];
m_header_datasets.push_back(std::make_unique<H5Handles>(
m_master.master_fname().string(),
metadata_group_name + header_dataset_names[i]));
LOG(logDEBUG) << header_dataset_names[i]
<< " Dataset dimensions: size = "
<< m_header_datasets[i]->get_dims()[0];
}
} catch (const H5::Exception &e) {
m_header_datasets.clear();

View File

@ -1,7 +1,7 @@
#include "aare/Hdf5MasterFile.hpp"
#include "aare/logger.hpp"
#include <sstream>
#include <iomanip>
#include <sstream>
namespace aare {
Hdf5FileNameComponents::Hdf5FileNameComponents(
@ -106,12 +106,8 @@ std::optional<ScanParameters> Hdf5MasterFile::scan_parameters() const {
size_t Hdf5MasterFile::total_frames_expected() const {
return m_total_frames_expected;
}
std::optional<ns> Hdf5MasterFile::exptime() const {
return m_exptime;
}
std::optional<ns> Hdf5MasterFile::period() const {
return m_period;
}
std::optional<ns> Hdf5MasterFile::exptime() const { return m_exptime; }
std::optional<ns> Hdf5MasterFile::period() const { return m_period; }
std::optional<BurstMode> Hdf5MasterFile::burst_mode() const {
return m_burst_mode;
}
@ -119,22 +115,15 @@ std::optional<int> Hdf5MasterFile::number_of_udp_interfaces() const {
return m_number_of_udp_interfaces;
}
int Hdf5MasterFile::bitdepth() const { return m_bitdepth; }
std::optional<bool> Hdf5MasterFile::ten_giga() const {
return m_ten_giga;
}
std::optional<bool> Hdf5MasterFile::ten_giga() const { return m_ten_giga; }
std::optional<int> Hdf5MasterFile::threshold_energy() const {
return m_threshold_energy;
}
std::optional<std::vector<int>>
Hdf5MasterFile::threshold_energy_all() const {
std::optional<std::vector<int>> Hdf5MasterFile::threshold_energy_all() const {
return m_threshold_energy_all;
}
std::optional<ns> Hdf5MasterFile::subexptime() const {
return m_subexptime;
}
std::optional<ns> Hdf5MasterFile::subperiod() const {
return m_subperiod;
}
std::optional<ns> Hdf5MasterFile::subexptime() const { return m_subexptime; }
std::optional<ns> Hdf5MasterFile::subperiod() const { return m_subperiod; }
std::optional<bool> Hdf5MasterFile::quad() const { return m_quad; }
std::optional<int> Hdf5MasterFile::number_of_rows() const {
return m_number_of_rows;
@ -143,7 +132,7 @@ std::optional<std::vector<size_t>> Hdf5MasterFile::rate_corrections() const {
return m_rate_corrections;
}
std::optional<uint32_t> Hdf5MasterFile::adc_mask() const { return m_adc_mask; }
bool Hdf5MasterFile::analog_flag() const { return m_analog_flag; }
bool Hdf5MasterFile::analog_flag() const { return m_analog_flag; }
std::optional<int> Hdf5MasterFile::analog_samples() const {
return m_analog_samples;
}
@ -151,9 +140,7 @@ bool Hdf5MasterFile::digital_flag() const { return m_digital_flag; }
std::optional<int> Hdf5MasterFile::digital_samples() const {
return m_digital_samples;
}
std::optional<int> Hdf5MasterFile::dbit_offset() const {
return m_dbit_offset;
}
std::optional<int> Hdf5MasterFile::dbit_offset() const { return m_dbit_offset; }
std::optional<size_t> Hdf5MasterFile::dbit_list() const { return m_dbit_list; }
std::optional<int> Hdf5MasterFile::transceiver_mask() const {
return m_transceiver_mask;
@ -164,7 +151,9 @@ std::optional<int> Hdf5MasterFile::transceiver_samples() const {
}
// g1 roi
std::optional<ROI> Hdf5MasterFile::roi() const { return m_roi; }
std::optional<int> Hdf5MasterFile::counter_mask() const { return m_counter_mask; }
std::optional<int> Hdf5MasterFile::counter_mask() const {
return m_counter_mask;
}
std::optional<std::vector<ns>> Hdf5MasterFile::exptime_array() const {
return m_exptime_array;
}
@ -172,12 +161,13 @@ std::optional<std::vector<ns>> Hdf5MasterFile::gate_delay_array() const {
return m_gate_delay_array;
}
std::optional<int> Hdf5MasterFile::gates() const { return m_gates; }
std::optional<std::map<std::string, std::string>> Hdf5MasterFile::additional_json_header() const {
std::optional<std::map<std::string, std::string>>
Hdf5MasterFile::additional_json_header() const {
return m_additional_json_header;
}
size_t Hdf5MasterFile::frames_in_file() const { return m_frames_in_file; }
size_t Hdf5MasterFile::n_modules() const {
return m_geometry.row * m_geometry.col;
return m_geometry.row * m_geometry.col;
}
// optional values, these may or may not be present in the master file
@ -253,7 +243,6 @@ void Hdf5MasterFile::parse_acquisition_metadata(
file, std::string(metadata_group_name + "Geometry in x axis"));
LOG(logDEBUG) << "Geometry: " << m_geometry.to_string();
// Image Size
m_image_size_in_bytes = h5_get_scalar_dataset<int>(
file, std::string(metadata_group_name + "Image Size"));
@ -281,7 +270,8 @@ void Hdf5MasterFile::parse_acquisition_metadata(
StringTo<FrameDiscardPolicy>(h5_get_scalar_dataset<std::string>(
file,
std::string(metadata_group_name + "Frame Discard Policy")));
LOG(logDEBUG) << "Frame Discard Policy: " << ToString(m_frame_discard_policy);
LOG(logDEBUG) << "Frame Discard Policy: "
<< ToString(m_frame_discard_policy);
// Frame Padding
m_frame_padding = h5_get_scalar_dataset<int>(
@ -378,15 +368,15 @@ void Hdf5MasterFile::parse_acquisition_metadata(
// Threshold All Energy
try {
m_threshold_energy_all = StringTo<std::vector<int>>(
h5_get_scalar_dataset<std::string>(
m_threshold_energy_all =
StringTo<std::vector<int>>(h5_get_scalar_dataset<std::string>(
file,
std::string(metadata_group_name + "Threshold Energies")));
LOG(logDEBUG) << "Threshold Energies: "
<< ToString(m_threshold_energy_all);
} catch (H5::FileIException &e) {
std::cout << "No Threshold Energies found in file: "
<< fpath << std::endl;
std::cout << "No Threshold Energies found in file: " << fpath
<< std::endl;
// keep the optional empty
}
@ -533,7 +523,7 @@ void Hdf5MasterFile::parse_acquisition_metadata(
}
// Rx ROI
try{
try {
ROI tmp_roi;
tmp_roi.xmin = h5_get_scalar_dataset<int>(
file, std::string(metadata_group_name + "receiver roi xmin"));
@ -544,10 +534,11 @@ void Hdf5MasterFile::parse_acquisition_metadata(
tmp_roi.ymax = h5_get_scalar_dataset<int>(
file, std::string(metadata_group_name + "receiver roi ymax"));
//if any of the values are set update the roi
if (tmp_roi.xmin != 4294967295 || tmp_roi.xmax != 4294967295 || tmp_roi.ymin != 4294967295 || tmp_roi.ymax != 4294967295) {
//why?? TODO
if(dVersion < 6.61){
// if any of the values are set update the roi
if (tmp_roi.xmin != 4294967295 || tmp_roi.xmax != 4294967295 ||
tmp_roi.ymin != 4294967295 || tmp_roi.ymax != 4294967295) {
// why?? TODO
if (dVersion < 6.61) {
tmp_roi.xmax++;
tmp_roi.ymax++;
}
@ -588,8 +579,8 @@ void Hdf5MasterFile::parse_acquisition_metadata(
// Exposure Time Array
try {
m_exptime_array = StringTo<std::vector<ns>>(
h5_get_scalar_dataset<std::string>(
m_exptime_array =
StringTo<std::vector<ns>>(h5_get_scalar_dataset<std::string>(
file, std::string(metadata_group_name + "Exposure Times")));
LOG(logDEBUG) << "Exposure Times: " << ToString(m_exptime_array);
} catch (H5::FileIException &e) {
@ -598,8 +589,8 @@ void Hdf5MasterFile::parse_acquisition_metadata(
// Gate Delay Array
try {
m_gate_delay_array = StringTo<std::vector<ns>>(
h5_get_scalar_dataset<std::string>(
m_gate_delay_array =
StringTo<std::vector<ns>>(h5_get_scalar_dataset<std::string>(
file, std::string(metadata_group_name + "Gate Delays")));
LOG(logDEBUG) << "Gate Delays: " << ToString(m_gate_delay_array);
} catch (H5::FileIException &e) {
@ -617,9 +608,13 @@ void Hdf5MasterFile::parse_acquisition_metadata(
// Additional Json Header
try {
m_additional_json_header = StringTo<std::map<std::string, std::string>>(h5_get_scalar_dataset<std::string>(
file, std::string(metadata_group_name + "Additional JSON Header")));
LOG(logDEBUG) << "Additional JSON Header: " << ToString(m_additional_json_header);
m_additional_json_header =
StringTo<std::map<std::string, std::string>>(
h5_get_scalar_dataset<std::string>(
file, std::string(metadata_group_name +
"Additional JSON Header")));
LOG(logDEBUG) << "Additional JSON Header: "
<< ToString(m_additional_json_header);
} catch (H5::FileIException &e) {
// keep the optional empty
}

View File

@ -61,7 +61,6 @@ const std::string &RawFileNameComponents::base_name() const {
const std::string &RawFileNameComponents::ext() const { return m_ext; }
int RawFileNameComponents::file_index() const { return m_file_index; }
RawMasterFile::RawMasterFile(const std::filesystem::path &fpath)
: m_fnc(fpath) {
if (!std::filesystem::exists(fpath)) {

View File

@ -1,7 +1,7 @@
#include "aare/defs.hpp"
#include <chrono>
#include <stdexcept>
#include <string>
#include <chrono>
#include <fmt/core.h>
namespace aare {
@ -180,7 +180,8 @@ template <> BurstMode StringTo(const std::string &arg) {
return BurstMode::Continuous_Internal;
if (arg == "continuous_external")
return BurstMode::Continuous_External;
throw std::runtime_error("Could not decode burst mode from: \"" + arg + "\"");
throw std::runtime_error("Could not decode burst mode from: \"" + arg +
"\"");
}
/**
@ -196,9 +197,10 @@ template <> std::string ToString(ScanParameters arg) {
<< "dac " << arg.dac() << std::endl
<< "start " << arg.start() << std::endl
<< "stop " << arg.stop() << std::endl
<< "step " << arg.step() << std::endl
<< "step " << arg.step()
<< std::endl
//<< "settleTime "
// << ToString(std::chrono::nanoseconds{arg.dacSettleTime_ns})
// << ToString(std::chrono::nanoseconds{arg.dacSettleTime_ns})
<< std::endl;
} else {
oss << "disabled";
@ -207,12 +209,10 @@ template <> std::string ToString(ScanParameters arg) {
return oss.str();
}
std::ostream &operator<<(std::ostream &os,
const ScanParameters &r) {
std::ostream &operator<<(std::ostream &os, const ScanParameters &r) {
return os << ToString(r);
}
/**
* @brief Convert a ROI to a string
* @param type ROI
@ -245,7 +245,6 @@ std::string RemoveUnit(std::string &str) {
return unit;
}
// template <> TimingMode StringTo<TimingMode>(std::string mode);
} // namespace aare