From 031d9503d8f1985e68a7d239e741237d290626dc Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 10 Jun 2025 17:20:56 +0200 Subject: [PATCH] fixed size_t for consistencies, done everything except array of ns and map --- include/aare/Hdf5File.hpp | 6 +- include/aare/Hdf5MasterFile.hpp | 48 ++++++------- include/aare/defs.hpp | 73 ++++++++++++-------- src/Hdf5MasterFile.cpp | 119 ++++++++++++++++++++++---------- 4 files changed, 154 insertions(+), 92 deletions(-) diff --git a/include/aare/Hdf5File.hpp b/include/aare/Hdf5File.hpp index 1cd4230..7dcb6c2 100644 --- a/include/aare/Hdf5File.hpp +++ b/include/aare/Hdf5File.hpp @@ -46,7 +46,8 @@ class H5Handles { void get_data_into(size_t frame_index, std::byte *frame_buffer, size_t n_frames = 1) { seek(frame_index); count[0] = static_cast(n_frames); - //std::cout << "offset:" << offset << " count:" << count << std::endl; + // 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); } @@ -54,7 +55,8 @@ class H5Handles { void get_header_into(size_t frame_index, int part_index, std::byte *header_buffer) { seek(frame_index); offset[1] = static_cast(part_index); - //std::cout << "offset:" << offset << " count:" << count << std::endl; + // 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); } diff --git a/include/aare/Hdf5MasterFile.hpp b/include/aare/Hdf5MasterFile.hpp index 8ddd0d1..27154f5 100644 --- a/include/aare/Hdf5MasterFile.hpp +++ b/include/aare/Hdf5MasterFile.hpp @@ -58,37 +58,37 @@ class Hdf5MasterFile { size_t m_max_frames_per_file{}; FrameDiscardPolicy m_frame_discard_policy{}; size_t m_frame_padding{}; - std::optional m_scan_parameters; + std::optional m_scan_parameters{}; size_t m_total_frames_expected{}; std::optional m_exptime{}; std::optional m_period{}; - std::optional m_burst_mode; - std::optional m_number_of_udp_interfaces; + std::optional m_burst_mode{}; + std::optional m_number_of_udp_interfaces{}; size_t m_bitdepth{}; - std::optional m_ten_giga; - std::optional m_threshold_energy; - // thresholdall energy + std::optional m_ten_giga{}; + std::optional m_threshold_energy{}; + std::optional> m_threshold_energy_all{}; std::optional m_subexptime{}; std::optional m_subperiod{}; - std::optional m_quad; - std::optional m_number_of_rows; - // ratecorr - uint32_t m_adc_mask{}; // TODO! implement reading + std::optional m_quad{}; + std::optional m_number_of_rows{}; + std::optional> m_rate_corrections{}; + size_t m_adc_mask{}; uint8_t m_analog_flag{}; - std::optional m_analog_samples; + std::optional m_analog_samples{}; uint8_t m_digital_flag{}; - std::optional m_digital_samples; - std::optional m_dbit_offset; - // dbitlist - std::optional m_transceiver_mask; + std::optional m_digital_samples{}; + std::optional m_dbit_offset{}; + std::optional m_dbit_list{}; + std::optional m_transceiver_mask{}; uint8_t m_transceiver_flag{}; - std::optional m_transceiver_samples; + std::optional m_transceiver_samples{}; // g1 roi - std::optional m_roi; - std::optional m_counter_mask; + std::optional m_roi{}; + std::optional m_counter_mask{}; // exptimearray // gatedelay array - // gates + std::optional m_gates{}; // additional json header size_t m_frames_in_file{}; @@ -125,19 +125,19 @@ class Hdf5MasterFile { size_t bitdepth() const; std::optional ten_giga() const; std::optional threshold_energy() const; - // thresholdall energy + std::optional> threshold_energy_all() const; std::optional subexptime() const; std::optional subperiod() const; std::optional quad() const; std::optional number_of_rows() const; - // ratecorr - std::optional adc_mask() const; // TODO! implement reading + std::optional> rate_corrections() const; + std::optional adc_mask() const; std::optional analog_flag() const; std::optional analog_samples() const; std::optional digital_flag() const; std::optional digital_samples() const; std::optional dbit_offset() const; - // dbitlist + std::optional dbit_list() const; std::optional transceiver_mask() const; std::optional transceiver_flag() const; std::optional transceiver_samples() const; @@ -146,7 +146,7 @@ class Hdf5MasterFile { std::optional counter_mask() const; // exptimearray // gatedelay array - // gates + std::optional gates() const; // additional json header size_t frames_in_file() const; size_t n_modules() const; diff --git a/include/aare/defs.hpp b/include/aare/defs.hpp index 344267e..9e26dc8 100644 --- a/include/aare/defs.hpp +++ b/include/aare/defs.hpp @@ -3,19 +3,20 @@ #include "aare/Dtype.hpp" #include "aare/type_traits.hpp" +#include #include -#include #include +#include #include #include +#include +#include +#include +#include #include #include #include #include -#include -#include -#include -#include /** * @brief LOCATION macro to get the current location in the code @@ -377,9 +378,45 @@ T StringTo(const std::string &t) { template ::value, int> = 0 > T StringTo(const std::string &arg) { return T(arg); } +// so that StringTo> below doesnt complain about the above +// generic overload +template <> inline size_t StringTo(const std::string &arg) { + return std::stoi(arg); +} + +template <> inline std::vector StringTo(const std::string &s) { + std::vector result; + std::string str = s; + // Remove brackets and spaces + str.erase(std::remove_if(str.begin(), str.end(), + [](unsigned char c) { + return c == '[' || c == ']' || std::isspace(c); + }), + str.end()); + std::stringstream ss(str); + std::string item; + while (std::getline(ss, item, ',')) { + if (!item.empty()) + result.push_back(StringTo(item)); + } + return result; +} + template ::value>> std::string ToString(T arg) { return T(arg); } +template std::string ToString(const std::vector &vec) { + std::ostringstream oss; + oss << "["; + for (size_t i = 0; i < vec.size(); ++i) { + oss << vec[i]; + if (i != vec.size() - 1) + oss << ", "; + } + oss << "]"; + return oss.str(); +} + template <> DetectorType StringTo(const std::string & /*name*/); template <> std::string ToString(DetectorType arg); @@ -399,19 +436,8 @@ 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; - -template -std::ostream &operator<<(std::ostream &os, const std::vector &vec) { - os << "["; - for (size_t i = 0; i < vec.size(); ++i) { - os << vec[i]; - if (i != vec.size() - 1) - os << ", "; - } - os << "]"; - return os; +template std::string ToString(const std::optional &opt) { + return opt ? ToString(*opt) : "nullopt"; } template @@ -423,15 +449,6 @@ std::ostream &operator<<(std::ostream &os, const std::optional &opt) { return os; } - -template -std::string ToString(const std::optional& opt) -{ - return opt ? ToString(*opt) : "nullopt"; -} - - - - +using DataTypeVariants = std::variant; } // namespace aare \ No newline at end of file diff --git a/src/Hdf5MasterFile.cpp b/src/Hdf5MasterFile.cpp index 423478a..35e53e4 100644 --- a/src/Hdf5MasterFile.cpp +++ b/src/Hdf5MasterFile.cpp @@ -125,7 +125,10 @@ std::optional Hdf5MasterFile::ten_giga() const { std::optional Hdf5MasterFile::threshold_energy() const { return m_threshold_energy; } -// thresholdall energy +std::optional> +Hdf5MasterFile::threshold_energy_all() const { + return m_threshold_energy_all; +} std::optional Hdf5MasterFile::subexptime() const { return m_subexptime; } @@ -136,7 +139,10 @@ std::optional Hdf5MasterFile::quad() const { return m_quad; } std::optional Hdf5MasterFile::number_of_rows() const { return m_number_of_rows; } -std::optional Hdf5MasterFile::adc_mask() const { return m_adc_mask;} +std::optional> Hdf5MasterFile::rate_corrections() const { + return m_rate_corrections; +} +std::optional Hdf5MasterFile::adc_mask() const { return m_adc_mask; } std::optional Hdf5MasterFile::analog_flag() const { return m_analog_flag; } std::optional Hdf5MasterFile::analog_samples() const { return m_analog_samples; @@ -148,7 +154,7 @@ std::optional Hdf5MasterFile::digital_samples() const { std::optional Hdf5MasterFile::dbit_offset() const { return m_dbit_offset; } -// dbitlist +std::optional Hdf5MasterFile::dbit_list() const { return m_dbit_list; } std::optional Hdf5MasterFile::transceiver_mask() const { return m_transceiver_mask; } @@ -161,7 +167,7 @@ std::optional Hdf5MasterFile::roi() const { return m_roi; } std::optional Hdf5MasterFile::counter_mask() const { return m_counter_mask; } // exptimearray // gatedelay array -// gates +std::optional Hdf5MasterFile::gates() const { return m_gates; } // additional json header size_t Hdf5MasterFile::frames_in_file() const { return m_frames_in_file; } size_t Hdf5MasterFile::n_modules() const { @@ -234,32 +240,32 @@ void Hdf5MasterFile::parse_acquisition_metadata( LOG(logDEBUG) << "Timing Mode: " << ToString(m_timing_mode); // Geometry - m_geometry.row = h5_get_scalar_dataset( + m_geometry.row = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Geometry in y axis")); - m_geometry.col = h5_get_scalar_dataset( + m_geometry.col = h5_get_scalar_dataset( 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( + m_image_size_in_bytes = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Image Size")); LOG(logDEBUG) << "Image size: {}\n" << m_image_size_in_bytes; // Pixels y - m_pixels_y = h5_get_scalar_dataset( + m_pixels_y = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Number of pixels in y axis")); LOG(logDEBUG) << "Pixels in y: " << m_pixels_y; // Pixels x - m_pixels_x = h5_get_scalar_dataset( + m_pixels_x = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Number of pixels in x axis")); LOG(logDEBUG) << "Pixels in x: " << m_pixels_x; // Max Frames Per File - m_max_frames_per_file = h5_get_scalar_dataset( + m_max_frames_per_file = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Maximum frames per file")); LOG(logDEBUG) << "Max frames per File: " << m_max_frames_per_file; @@ -271,7 +277,7 @@ void Hdf5MasterFile::parse_acquisition_metadata( LOG(logDEBUG) << "Frame Discard Policy: " << ToString(m_frame_discard_policy); // Frame Padding - m_frame_padding = h5_get_scalar_dataset( + m_frame_padding = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Frame Padding")); LOG(logDEBUG) << "Frame Padding: " << m_frame_padding; @@ -290,7 +296,7 @@ void Hdf5MasterFile::parse_acquisition_metadata( } // Total Frames Expected - m_total_frames_expected = h5_get_scalar_dataset( + m_total_frames_expected = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Total Frames")); LOG(logDEBUG) << "Total Frames: " << m_total_frames_expected; @@ -325,8 +331,9 @@ void Hdf5MasterFile::parse_acquisition_metadata( // Number of UDP Interfaces // Not all detectors write the Number of UDP Interfaces but in case try { - m_number_of_udp_interfaces = h5_get_scalar_dataset( - file, std::string(metadata_group_name + "Number of UDP Interfaces")); + m_number_of_udp_interfaces = h5_get_scalar_dataset( + file, + std::string(metadata_group_name + "Number of UDP Interfaces")); LOG(logDEBUG) << "Number of UDP Interfaces: " << m_number_of_udp_interfaces; } catch (H5::FileIException &e) { @@ -337,7 +344,7 @@ void Hdf5MasterFile::parse_acquisition_metadata( // Not all detectors write the bitdepth but in case // its not there it is 16 try { - m_bitdepth = h5_get_scalar_dataset( + m_bitdepth = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Dynamic Range")); LOG(logDEBUG) << "Bit Depth: " << m_bitdepth; } catch (H5::FileIException &e) { @@ -346,7 +353,7 @@ void Hdf5MasterFile::parse_acquisition_metadata( // Ten Giga try { - m_ten_giga = h5_get_scalar_dataset( + m_ten_giga = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Ten Giga")); LOG(logDEBUG) << "Ten Giga: " << m_ten_giga; } catch (H5::FileIException &e) { @@ -355,14 +362,24 @@ void Hdf5MasterFile::parse_acquisition_metadata( // Threshold Energy try { - m_threshold_energy = h5_get_scalar_dataset( + m_threshold_energy = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Threshold Energy")); LOG(logDEBUG) << "Threshold Energy: " << m_threshold_energy; } catch (H5::FileIException &e) { // keep the optional empty } - // thresholdall energy + // Threshold All Energy + try { + m_threshold_energy_all = StringTo>( + h5_get_scalar_dataset( + file, + std::string(metadata_group_name + "Threshold Energies"))); + LOG(logDEBUG) << "Threshold Energies: " + << ToString(m_threshold_energy_all); + } catch (H5::FileIException &e) { + // keep the optional empty + } // Subexptime try { @@ -384,7 +401,7 @@ void Hdf5MasterFile::parse_acquisition_metadata( // Quad try { - m_quad = h5_get_scalar_dataset( + m_quad = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Quad")); LOG(logDEBUG) << "Quad: " << m_quad; } catch (H5::FileIException &e) { @@ -394,18 +411,28 @@ void Hdf5MasterFile::parse_acquisition_metadata( // Number of Rows // Not all detectors write the Number of rows but in case try { - m_number_of_rows = h5_get_scalar_dataset( + m_number_of_rows = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Number of rows")); LOG(logDEBUG) << "Number of rows: " << m_number_of_rows; } catch (H5::FileIException &e) { // keep the optional empty } - // ratecorr + // Rate Corrections + try { + m_rate_corrections = StringTo>( + h5_get_scalar_dataset( + file, + std::string(metadata_group_name + "Rate Corrections"))); + LOG(logDEBUG) << "Rate Corrections: " + << ToString(m_rate_corrections); + } catch (H5::FileIException &e) { + // keep the optional empty + } // ADC Mask try { - m_adc_mask = h5_get_scalar_dataset( + m_adc_mask = h5_get_scalar_dataset( file, std::string(metadata_group_name + "ADC Mask")); } catch (H5::FileIException &e) { // keep the optional empty @@ -416,7 +443,7 @@ void Hdf5MasterFile::parse_acquisition_metadata( // ---------------------------------------------------------------- // Special treatment of analog flag because of Moench03 try { - m_analog_flag = h5_get_scalar_dataset( + m_analog_flag = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Analog Flag")); LOG(logDEBUG) << "Analog Flag: " << m_analog_flag; } catch (H5::FileIException &e) { @@ -428,7 +455,7 @@ void Hdf5MasterFile::parse_acquisition_metadata( // Analog Samples try { if (m_analog_flag) { - m_analog_samples = h5_get_scalar_dataset( + m_analog_samples = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Analog Samples")); LOG(logDEBUG) << "Analog Samples: " << m_analog_samples; } @@ -441,11 +468,11 @@ void Hdf5MasterFile::parse_acquisition_metadata( // Digital Flag, Digital Samples try { - m_digital_flag = h5_get_scalar_dataset( + m_digital_flag = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Digital Flag")); LOG(logDEBUG) << "Digital Flag: " << m_digital_flag; if (m_digital_flag) { - m_digital_samples = h5_get_scalar_dataset( + m_digital_samples = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Digital Samples")); } LOG(logDEBUG) << "Digital Samples: " << m_digital_samples; @@ -455,18 +482,25 @@ void Hdf5MasterFile::parse_acquisition_metadata( // Dbit Offset try { - m_dbit_offset = h5_get_scalar_dataset( + m_dbit_offset = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Dbit Offset")); LOG(logDEBUG) << "Dbit Offset: " << m_dbit_offset; } catch (H5::FileIException &e) { // keep the optional empty } - // dbitlist + // Dbit List + try { + m_dbit_list = h5_get_scalar_dataset( + file, std::string(metadata_group_name + "Dbit Bitset List")); + LOG(logDEBUG) << "Dbit list: " << m_dbit_list; + } catch (H5::FileIException &e) { + // keep the optional empty + } // Transceiver Mask try { - m_transceiver_mask = h5_get_scalar_dataset( + m_transceiver_mask = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Transceiver Mask")); LOG(logDEBUG) << "Transceiver Mask: " << m_transceiver_mask; } catch (H5::FileIException &e) { @@ -475,11 +509,11 @@ void Hdf5MasterFile::parse_acquisition_metadata( // Transceiver Flag, Transceiver Samples try { - m_transceiver_flag = h5_get_scalar_dataset( + m_transceiver_flag = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Transceiver Flag")); LOG(logDEBUG) << "Transceiver Flag: " << m_transceiver_flag; if (m_transceiver_flag) { - m_transceiver_samples = h5_get_scalar_dataset( + m_transceiver_samples = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Transceiver Samples")); LOG(logDEBUG) @@ -492,13 +526,13 @@ void Hdf5MasterFile::parse_acquisition_metadata( // Rx ROI try{ ROI tmp_roi; - tmp_roi.xmin = h5_get_scalar_dataset( + tmp_roi.xmin = h5_get_scalar_dataset( file, std::string(metadata_group_name + "receiver roi xmin")); - tmp_roi.xmax = h5_get_scalar_dataset( + tmp_roi.xmax = h5_get_scalar_dataset( file, std::string(metadata_group_name + "receiver roi xmax")); - tmp_roi.ymin = h5_get_scalar_dataset( + tmp_roi.ymin = h5_get_scalar_dataset( file, std::string(metadata_group_name + "receiver roi ymin")); - tmp_roi.ymax = h5_get_scalar_dataset( + tmp_roi.ymax = h5_get_scalar_dataset( file, std::string(metadata_group_name + "receiver roi ymax")); //if any of the values are set update the roi @@ -536,7 +570,7 @@ void Hdf5MasterFile::parse_acquisition_metadata( // Counter Mask try { - m_counter_mask = h5_get_scalar_dataset( + m_counter_mask = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Counter Mask")); LOG(logDEBUG) << "Counter Mask: " << m_counter_mask; } catch (H5::FileIException &e) { @@ -545,11 +579,20 @@ void Hdf5MasterFile::parse_acquisition_metadata( // exptimearray // gatedelay array - // gates + + // Gates + try { + m_gates = h5_get_scalar_dataset( + file, std::string(metadata_group_name + "Gates")); + LOG(logDEBUG) << "Gates: " << m_gates; + } catch (H5::FileIException &e) { + // keep the optional empty + } + // additional json header // Frames in File - m_frames_in_file = h5_get_scalar_dataset( + m_frames_in_file = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Frames in File")); LOG(logDEBUG) << "Frames in File: " << m_frames_in_file;