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

@ -21,20 +21,15 @@ class H5Handles {
std::vector<hsize_t> offset; std::vector<hsize_t> offset;
public: public:
H5Handles(const std::string& fname, const std::string& dname): H5Handles(const std::string &fname, const std::string &dname)
file_name(fname), : file_name(fname), dataset_name(dname), file(fname, H5F_ACC_RDONLY),
dataset_name(dname), dataset(file.openDataSet(dname)), dataspace(dataset.getSpace()),
file(fname, H5F_ACC_RDONLY),
dataset(file.openDataSet(dname)),
dataspace(dataset.getSpace()),
datatype(dataset.getDataType()) { datatype(dataset.getDataType()) {
intialize_dimensions(); intialize_dimensions();
initialize_memspace(); initialize_memspace();
} }
std::vector<hsize_t> get_dims() const { std::vector<hsize_t> get_dims() const { return dims; }
return dims;
}
void seek(size_t frame_index) { void seek(size_t frame_index) {
if (frame_index >= dims[0]) { if (frame_index >= dims[0]) {
@ -43,7 +38,8 @@ class H5Handles {
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) { void get_data_into(size_t frame_index, std::byte *frame_buffer,
size_t n_frames = 1) {
seek(frame_index); seek(frame_index);
count[0] = static_cast<hsize_t>(n_frames); count[0] = static_cast<hsize_t>(n_frames);
// std::cout << "offset:" << ToString(offset) << " count:" << // std::cout << "offset:" << ToString(offset) << " count:" <<
@ -52,7 +48,8 @@ class H5Handles {
dataset.read(frame_buffer, datatype, *memspace, dataspace); dataset.read(frame_buffer, datatype, *memspace, dataspace);
} }
void get_header_into(size_t frame_index, int part_index, std::byte *header_buffer) { void get_header_into(size_t frame_index, int part_index,
std::byte *header_buffer) {
seek(frame_index); seek(frame_index);
offset[1] = static_cast<hsize_t>(part_index); offset[1] = static_cast<hsize_t>(part_index);
// std::cout << "offset:" << ToString(offset) << " count:" << // std::cout << "offset:" << ToString(offset) << " count:" <<
@ -85,13 +82,12 @@ class H5Handles {
hsize_t dims_image[2] = {dims[1], dims[2]}; hsize_t dims_image[2] = {dims[1], dims[2]};
memspace = std::make_unique<H5::DataSpace>(2, dims_image); memspace = std::make_unique<H5::DataSpace>(2, dims_image);
} else { } else {
throw std::runtime_error(LOCATION + "Invalid rank for dataset: " + std::to_string(rank)); throw std::runtime_error(
LOCATION + "Invalid rank for dataset: " + std::to_string(rank));
} }
} }
}; };
template <typename Fn> template <typename Fn>
void read_hdf5_header_fields(DetectorHeader *header, Fn &&fn_read_field) { void read_hdf5_header_fields(DetectorHeader *header, Fn &&fn_read_field) {
fn_read_field(0, reinterpret_cast<std::byte *>(&(header->frameNumber))); fn_read_field(0, reinterpret_cast<std::byte *>(&(header->frameNumber)));

View File

@ -6,8 +6,6 @@
#include <fstream> #include <fstream>
#include <optional> #include <optional>
namespace aare { namespace aare {
using ns = std::chrono::nanoseconds; using ns = std::chrono::nanoseconds;
@ -40,7 +38,6 @@ class Hdf5FileNameComponents {
void set_old_scheme(bool old_scheme); void set_old_scheme(bool old_scheme);
}; };
/** /**
* @brief Class for parsing a master file either in our .json format or the old * @brief Class for parsing a master file either in our .json format or the old
* .Hdf5 format * .Hdf5 format
@ -89,17 +86,12 @@ class Hdf5MasterFile {
std::optional<std::vector<ns>> m_exptime_array{}; std::optional<std::vector<ns>> m_exptime_array{};
std::optional<std::vector<ns>> m_gate_delay_array{}; std::optional<std::vector<ns>> m_gate_delay_array{};
std::optional<int> m_gates{}; 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{}; size_t m_frames_in_file{};
// TODO! should these be bool? // TODO! should these be bool?
public: public:
Hdf5MasterFile(const std::filesystem::path &fpath); Hdf5MasterFile(const std::filesystem::path &fpath);
@ -147,11 +139,11 @@ class Hdf5MasterFile {
std::optional<std::vector<ns>> exptime_array() const; std::optional<std::vector<ns>> exptime_array() const;
std::optional<std::vector<ns>> gate_delay_array() const; std::optional<std::vector<ns>> gate_delay_array() const;
std::optional<int> gates() 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 frames_in_file() const;
size_t n_modules() const; size_t n_modules() const;
private: private:
static const std::string metadata_group_name; static const std::string metadata_group_name;
void parse_acquisition_metadata(const std::filesystem::path &fpath); void parse_acquisition_metadata(const std::filesystem::path &fpath);

View File

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

View File

@ -224,7 +224,6 @@ struct ROI {
using dynamic_shape = std::vector<ssize_t>; using dynamic_shape = std::vector<ssize_t>;
class ScanParameters { class ScanParameters {
bool m_enabled = false; bool m_enabled = false;
std::string m_dac; std::string m_dac;
@ -292,28 +291,37 @@ enum class DetectorType {
enum class TimingMode { Auto, Trigger }; enum class TimingMode { Auto, Trigger };
enum class FrameDiscardPolicy { NoDiscard, Discard, DiscardPartial }; enum class FrameDiscardPolicy { NoDiscard, Discard, DiscardPartial };
enum class BurstMode { Burst_Interal, Burst_External, Continuous_Internal, enum class BurstMode {
Continuous_External }; Burst_Interal,
Burst_External,
Continuous_Internal,
Continuous_External
};
/** ToString and StringTo Conversions */ /** ToString and StringTo Conversions */
// generic // generic
template <class T, typename = std::enable_if_t<!is_duration<T>::value>> template <class T, typename = std::enable_if_t<!is_duration<T>::value>>
std::string ToString(T arg) { return T(arg); } std::string ToString(T arg) {
return T(arg);
}
template <typename T, std::enable_if_t< template <typename T,
!is_duration<T>::value && !is_container<T>::value, int> = 0 > std::enable_if_t<!is_duration<T>::value && !is_container<T>::value,
T StringTo(const std::string &arg) { return T(arg); } int> = 0>
T StringTo(const std::string &arg) {
return T(arg);
}
// time // time
std::string RemoveUnit(std::string &str); std::string RemoveUnit(std::string &str);
inline void TrimWhiteSpaces(std::string &s) { inline void TrimWhiteSpaces(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char c) {
[](unsigned char c) { return !std::isspace(c); })); return !std::isspace(c);
}));
s.erase(std::find_if(s.rbegin(), s.rend(), s.erase(std::find_if(s.rbegin(), s.rend(),
[](unsigned char c) { return !std::isspace(c); }).base(), [](unsigned char c) { return !std::isspace(c); })
.base(),
s.end()); s.end());
} }
@ -342,11 +350,11 @@ template <typename From>
typename std::enable_if<is_duration<From>::value, std::string>::type typename std::enable_if<is_duration<From>::value, std::string>::type
ToString(From t) { ToString(From t) {
using std::chrono::duration_cast;
using std::chrono::abs; using std::chrono::abs;
using std::chrono::nanoseconds; using std::chrono::duration_cast;
using std::chrono::microseconds; using std::chrono::microseconds;
using std::chrono::milliseconds; using std::chrono::milliseconds;
using std::chrono::nanoseconds;
auto tns = duration_cast<nanoseconds>(t); auto tns = duration_cast<nanoseconds>(t);
if (abs(tns) < microseconds(1)) { if (abs(tns) < microseconds(1)) {
return ToString(tns, "ns"); return ToString(tns, "ns");
@ -384,7 +392,8 @@ T StringTo(const std::string &t, const std::string &unit) {
} else if (unit == "s" || unit.empty()) { } else if (unit == "s" || unit.empty()) {
return duration_cast<T>(std::chrono::duration<double>(tval)); return duration_cast<T>(std::chrono::duration<double>(tval));
} else { } 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");
} }
} }
@ -449,8 +458,6 @@ template <> inline int StringTo(const std::string &s) {
return std::stoull(s, nullptr, base); return std::stoull(s, nullptr, base);
}*/ }*/
// vector // vector
template <typename T> std::string ToString(const std::vector<T> &vec) { template <typename T> std::string ToString(const std::vector<T> &vec) {
std::ostringstream oss; std::ostringstream oss;
@ -469,19 +476,21 @@ std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
return os << ToString(v); return os << ToString(v);
} }
template < template <typename Container,
typename Container,
std::enable_if_t<is_container<Container>::value && std::enable_if_t<is_container<Container>::value &&
!is_std_string_v<Container> /*&& !is_std_string_v<Container> /*&&
!is_map_v<Container>*/, !is_map_v<Container>*/
,
int> = 0> int> = 0>
Container StringTo(const std::string &s) { Container StringTo(const std::string &s) {
using Value = typename Container::value_type; using Value = typename Container::value_type;
// strip outer brackets // strip outer brackets
std::string str = s; std::string str = s;
str.erase(std::remove_if(str.begin(), str.end(), str.erase(
[](unsigned char c){ return c=='[' || c==']'; }), str.end()); std::remove_if(str.begin(), str.end(),
[](unsigned char c) { return c == '[' || c == ']'; }),
str.end());
std::stringstream ss(str); std::stringstream ss(str);
std::string item; std::string item;
@ -496,7 +505,6 @@ Container StringTo(const std::string& s) {
return result; return result;
} }
// map // map
template <typename KeyType, typename ValueType> template <typename KeyType, typename ValueType>
std::string ToString(const std::map<KeyType, ValueType> &m) { 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(); 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::map<std::string, std::string> result;
std::string str = s; std::string str = s;
@ -543,7 +552,6 @@ template <> inline std::map<std::string, std::string> StringTo(const std::string
return result; return result;
} }
// optional // optional
template <class T> std::string ToString(const std::optional<T> &opt) { template <class T> std::string ToString(const std::optional<T> &opt) {
return opt ? ToString(*opt) : "nullopt"; return opt ? ToString(*opt) : "nullopt";
@ -571,14 +579,12 @@ template <> std::string ToString(FrameDiscardPolicy arg);
template <> BurstMode StringTo(const std::string & /*mode*/); template <> BurstMode StringTo(const std::string & /*mode*/);
template <> std::string ToString(BurstMode arg); template <> std::string ToString(BurstMode arg);
std::ostream &operator<<(std::ostream &os, std::ostream &operator<<(std::ostream &os, const ScanParameters &r);
const ScanParameters &r);
template <> std::string ToString(ScanParameters arg); template <> std::string ToString(ScanParameters arg);
std::ostream &operator<<(std::ostream &os, const ROI &roi); std::ostream &operator<<(std::ostream &os, const ROI &roi);
template <> std::string ToString(ROI arg); template <> std::string ToString(ROI arg);
using DataTypeVariants = std::variant<uint16_t, uint32_t>; using DataTypeVariants = std::variant<uint16_t, uint32_t>;
} // namespace aare } // namespace aare

View File

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

View File

@ -129,10 +129,10 @@ 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, void Hdf5File::get_header_into(size_t frame_index, int part_index,
DetectorHeader *header) { DetectorHeader *header) {
try { try {
read_hdf5_header_fields(header, read_hdf5_header_fields(header, [&](size_t iParameter,
[&](size_t iParameter, std::byte *dest) { std::byte *dest) {
m_header_datasets[iParameter]->get_header_into( m_header_datasets[iParameter]->get_header_into(frame_index,
frame_index, part_index, dest); part_index, dest);
}); });
LOG(logDEBUG5) << "Read 1D header for frame " << frame_index; LOG(logDEBUG5) << "Read 1D header for frame " << frame_index;
} catch (const H5::Exception &e) { } catch (const H5::Exception &e) {
@ -183,20 +183,21 @@ const std::vector<std::string> Hdf5File::header_dataset_names = {
"detector specific 4", "detector specific 4",
"detector type", "detector type",
"detector header version", "detector header version",
"packets caught bit mask" "packets caught bit mask"};
};
void Hdf5File::open_data_file() { void Hdf5File::open_data_file() {
if (m_mode != "r") if (m_mode != "r")
throw std::runtime_error(LOCATION + throw std::runtime_error(LOCATION +
"Unsupported mode. Can only read Hdf5 files."); "Unsupported mode. Can only read Hdf5 files.");
try { 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_total_frames = m_data_dataset->get_dims()[0];
m_rows = m_data_dataset->get_dims()[1]; m_rows = m_data_dataset->get_dims()[1];
m_cols = m_data_dataset->get_dims()[2]; m_cols = m_data_dataset->get_dims()[2];
//fmt::print("Data Dataset dimensions: frames = {}, rows = {}, cols = {}\n", // fmt::print("Data Dataset dimensions: frames = {}, rows = {}, cols =
// {}\n",
// m_total_frames, m_rows, m_cols); // m_total_frames, m_rows, m_cols);
} catch (const H5::Exception &e) { } catch (const H5::Exception &e) {
m_data_dataset.reset(); m_data_dataset.reset();
@ -213,8 +214,12 @@ void Hdf5File::open_header_files() {
"Unsupported mode. Can only read Hdf5 files."); "Unsupported mode. Can only read Hdf5 files.");
try { try {
for (size_t i = 0; i != header_dataset_names.size(); ++i) { 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])); m_header_datasets.push_back(std::make_unique<H5Handles>(
LOG(logDEBUG) << header_dataset_names[i] << " Dataset dimensions: size = " << m_header_datasets[i]->get_dims()[0]; 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) { } catch (const H5::Exception &e) {
m_header_datasets.clear(); m_header_datasets.clear();

View File

@ -1,7 +1,7 @@
#include "aare/Hdf5MasterFile.hpp" #include "aare/Hdf5MasterFile.hpp"
#include "aare/logger.hpp" #include "aare/logger.hpp"
#include <sstream>
#include <iomanip> #include <iomanip>
#include <sstream>
namespace aare { namespace aare {
Hdf5FileNameComponents::Hdf5FileNameComponents( Hdf5FileNameComponents::Hdf5FileNameComponents(
@ -106,12 +106,8 @@ std::optional<ScanParameters> Hdf5MasterFile::scan_parameters() const {
size_t Hdf5MasterFile::total_frames_expected() const { size_t Hdf5MasterFile::total_frames_expected() const {
return m_total_frames_expected; return m_total_frames_expected;
} }
std::optional<ns> Hdf5MasterFile::exptime() const { std::optional<ns> Hdf5MasterFile::exptime() const { return m_exptime; }
return m_exptime; std::optional<ns> Hdf5MasterFile::period() const { return m_period; }
}
std::optional<ns> Hdf5MasterFile::period() const {
return m_period;
}
std::optional<BurstMode> Hdf5MasterFile::burst_mode() const { std::optional<BurstMode> Hdf5MasterFile::burst_mode() const {
return m_burst_mode; return m_burst_mode;
} }
@ -119,22 +115,15 @@ std::optional<int> Hdf5MasterFile::number_of_udp_interfaces() const {
return m_number_of_udp_interfaces; return m_number_of_udp_interfaces;
} }
int Hdf5MasterFile::bitdepth() const { return m_bitdepth; } int Hdf5MasterFile::bitdepth() const { return m_bitdepth; }
std::optional<bool> Hdf5MasterFile::ten_giga() const { std::optional<bool> Hdf5MasterFile::ten_giga() const { return m_ten_giga; }
return m_ten_giga;
}
std::optional<int> Hdf5MasterFile::threshold_energy() const { std::optional<int> Hdf5MasterFile::threshold_energy() const {
return m_threshold_energy; return m_threshold_energy;
} }
std::optional<std::vector<int>> std::optional<std::vector<int>> Hdf5MasterFile::threshold_energy_all() const {
Hdf5MasterFile::threshold_energy_all() const {
return m_threshold_energy_all; return m_threshold_energy_all;
} }
std::optional<ns> Hdf5MasterFile::subexptime() const { std::optional<ns> Hdf5MasterFile::subexptime() const { return m_subexptime; }
return m_subexptime; std::optional<ns> Hdf5MasterFile::subperiod() const { return m_subperiod; }
}
std::optional<ns> Hdf5MasterFile::subperiod() const {
return m_subperiod;
}
std::optional<bool> Hdf5MasterFile::quad() const { return m_quad; } std::optional<bool> Hdf5MasterFile::quad() const { return m_quad; }
std::optional<int> Hdf5MasterFile::number_of_rows() const { std::optional<int> Hdf5MasterFile::number_of_rows() const {
return m_number_of_rows; return m_number_of_rows;
@ -151,9 +140,7 @@ bool Hdf5MasterFile::digital_flag() const { return m_digital_flag; }
std::optional<int> Hdf5MasterFile::digital_samples() const { std::optional<int> Hdf5MasterFile::digital_samples() const {
return m_digital_samples; return m_digital_samples;
} }
std::optional<int> Hdf5MasterFile::dbit_offset() const { std::optional<int> Hdf5MasterFile::dbit_offset() const { return m_dbit_offset; }
return m_dbit_offset;
}
std::optional<size_t> Hdf5MasterFile::dbit_list() const { return m_dbit_list; } std::optional<size_t> Hdf5MasterFile::dbit_list() const { return m_dbit_list; }
std::optional<int> Hdf5MasterFile::transceiver_mask() const { std::optional<int> Hdf5MasterFile::transceiver_mask() const {
return m_transceiver_mask; return m_transceiver_mask;
@ -164,7 +151,9 @@ std::optional<int> Hdf5MasterFile::transceiver_samples() const {
} }
// g1 roi // g1 roi
std::optional<ROI> Hdf5MasterFile::roi() const { return m_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 { std::optional<std::vector<ns>> Hdf5MasterFile::exptime_array() const {
return m_exptime_array; return m_exptime_array;
} }
@ -172,7 +161,8 @@ std::optional<std::vector<ns>> Hdf5MasterFile::gate_delay_array() const {
return m_gate_delay_array; return m_gate_delay_array;
} }
std::optional<int> Hdf5MasterFile::gates() const { return m_gates; } 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; return m_additional_json_header;
} }
size_t Hdf5MasterFile::frames_in_file() const { return m_frames_in_file; } size_t Hdf5MasterFile::frames_in_file() const { return m_frames_in_file; }
@ -253,7 +243,6 @@ void Hdf5MasterFile::parse_acquisition_metadata(
file, std::string(metadata_group_name + "Geometry in x axis")); file, std::string(metadata_group_name + "Geometry in x axis"));
LOG(logDEBUG) << "Geometry: " << m_geometry.to_string(); LOG(logDEBUG) << "Geometry: " << m_geometry.to_string();
// Image Size // Image Size
m_image_size_in_bytes = h5_get_scalar_dataset<int>( m_image_size_in_bytes = h5_get_scalar_dataset<int>(
file, std::string(metadata_group_name + "Image Size")); 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>( StringTo<FrameDiscardPolicy>(h5_get_scalar_dataset<std::string>(
file, file,
std::string(metadata_group_name + "Frame Discard Policy"))); 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 // Frame Padding
m_frame_padding = h5_get_scalar_dataset<int>( m_frame_padding = h5_get_scalar_dataset<int>(
@ -378,15 +368,15 @@ void Hdf5MasterFile::parse_acquisition_metadata(
// Threshold All Energy // Threshold All Energy
try { try {
m_threshold_energy_all = StringTo<std::vector<int>>( m_threshold_energy_all =
h5_get_scalar_dataset<std::string>( StringTo<std::vector<int>>(h5_get_scalar_dataset<std::string>(
file, file,
std::string(metadata_group_name + "Threshold Energies"))); std::string(metadata_group_name + "Threshold Energies")));
LOG(logDEBUG) << "Threshold Energies: " LOG(logDEBUG) << "Threshold Energies: "
<< ToString(m_threshold_energy_all); << ToString(m_threshold_energy_all);
} catch (H5::FileIException &e) { } catch (H5::FileIException &e) {
std::cout << "No Threshold Energies found in file: " std::cout << "No Threshold Energies found in file: " << fpath
<< fpath << std::endl; << std::endl;
// keep the optional empty // keep the optional empty
} }
@ -545,7 +535,8 @@ void Hdf5MasterFile::parse_acquisition_metadata(
file, std::string(metadata_group_name + "receiver roi ymax")); file, std::string(metadata_group_name + "receiver roi ymax"));
// if any of the values are set update the roi // 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) { if (tmp_roi.xmin != 4294967295 || tmp_roi.xmax != 4294967295 ||
tmp_roi.ymin != 4294967295 || tmp_roi.ymax != 4294967295) {
// why?? TODO // why?? TODO
if (dVersion < 6.61) { if (dVersion < 6.61) {
tmp_roi.xmax++; tmp_roi.xmax++;
@ -588,8 +579,8 @@ void Hdf5MasterFile::parse_acquisition_metadata(
// Exposure Time Array // Exposure Time Array
try { try {
m_exptime_array = StringTo<std::vector<ns>>( m_exptime_array =
h5_get_scalar_dataset<std::string>( StringTo<std::vector<ns>>(h5_get_scalar_dataset<std::string>(
file, std::string(metadata_group_name + "Exposure Times"))); file, std::string(metadata_group_name + "Exposure Times")));
LOG(logDEBUG) << "Exposure Times: " << ToString(m_exptime_array); LOG(logDEBUG) << "Exposure Times: " << ToString(m_exptime_array);
} catch (H5::FileIException &e) { } catch (H5::FileIException &e) {
@ -598,8 +589,8 @@ void Hdf5MasterFile::parse_acquisition_metadata(
// Gate Delay Array // Gate Delay Array
try { try {
m_gate_delay_array = StringTo<std::vector<ns>>( m_gate_delay_array =
h5_get_scalar_dataset<std::string>( StringTo<std::vector<ns>>(h5_get_scalar_dataset<std::string>(
file, std::string(metadata_group_name + "Gate Delays"))); file, std::string(metadata_group_name + "Gate Delays")));
LOG(logDEBUG) << "Gate Delays: " << ToString(m_gate_delay_array); LOG(logDEBUG) << "Gate Delays: " << ToString(m_gate_delay_array);
} catch (H5::FileIException &e) { } catch (H5::FileIException &e) {
@ -617,9 +608,13 @@ void Hdf5MasterFile::parse_acquisition_metadata(
// Additional Json Header // Additional Json Header
try { try {
m_additional_json_header = StringTo<std::map<std::string, std::string>>(h5_get_scalar_dataset<std::string>( m_additional_json_header =
file, std::string(metadata_group_name + "Additional JSON Header"))); StringTo<std::map<std::string, std::string>>(
LOG(logDEBUG) << "Additional JSON Header: " << ToString(m_additional_json_header); 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) { } catch (H5::FileIException &e) {
// keep the optional empty // 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; } const std::string &RawFileNameComponents::ext() const { return m_ext; }
int RawFileNameComponents::file_index() const { return m_file_index; } int RawFileNameComponents::file_index() const { return m_file_index; }
RawMasterFile::RawMasterFile(const std::filesystem::path &fpath) RawMasterFile::RawMasterFile(const std::filesystem::path &fpath)
: m_fnc(fpath) { : m_fnc(fpath) {
if (!std::filesystem::exists(fpath)) { if (!std::filesystem::exists(fpath)) {

View File

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