diff --git a/include/aare/Hdf5File.hpp b/include/aare/Hdf5File.hpp index 7dcb6c2..ef05a95 100644 --- a/include/aare/Hdf5File.hpp +++ b/include/aare/Hdf5File.hpp @@ -90,6 +90,8 @@ class H5Handles { } }; + + template void read_hdf5_header_fields(DetectorHeader *header, Fn &&fn_read_field) { fn_read_field(0, reinterpret_cast(&(header->frameNumber))); @@ -124,8 +126,8 @@ class Hdf5File : public FileInterface { static const std::string metadata_group_name; static const std::vector header_dataset_names; - std::unique_ptr m_data_file{nullptr}; - std::vector> m_header_files; + std::unique_ptr m_data_dataset{nullptr}; + std::vector> m_header_datasets{}; public: /** diff --git a/include/aare/Hdf5MasterFile.hpp b/include/aare/Hdf5MasterFile.hpp index 196c130..7d6ea8c 100644 --- a/include/aare/Hdf5MasterFile.hpp +++ b/include/aare/Hdf5MasterFile.hpp @@ -52,43 +52,43 @@ class Hdf5MasterFile { DetectorType m_type; TimingMode m_timing_mode; xy m_geometry{}; - size_t m_image_size_in_bytes{}; - size_t m_pixels_y{}; - size_t m_pixels_x{}; - size_t m_max_frames_per_file{}; + int m_image_size_in_bytes{}; + int m_pixels_y{}; + int m_pixels_x{}; + int m_max_frames_per_file{}; FrameDiscardPolicy m_frame_discard_policy{}; - size_t m_frame_padding{}; + int m_frame_padding{}; 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{}; - size_t m_bitdepth{}; - std::optional m_ten_giga{}; - std::optional m_threshold_energy{}; - std::optional> m_threshold_energy_all{}; + std::optional m_number_of_udp_interfaces{}; + int m_bitdepth{}; + 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{}; + 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{}; - uint8_t m_digital_flag{}; - std::optional m_digital_samples{}; - std::optional m_dbit_offset{}; + uint32_t m_adc_mask{}; + bool m_analog_flag{}; + std::optional m_analog_samples{}; + bool m_digital_flag{}; + 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{}; - // g1 roi + std::optional m_transceiver_mask{}; + bool m_transceiver_flag{}; + std::optional m_transceiver_samples{}; + // g1 roi - will not be implemented? std::optional m_roi{}; - std::optional m_counter_mask{}; - // exptimearray - // gatedelay array - std::optional m_gates{}; + std::optional m_counter_mask{}; + std::optional> m_exptime_array{}; + std::optional> m_gate_delay_array{}; + std::optional m_gates{}; std::optional> m_additional_json_header{}; size_t m_frames_in_file{}; @@ -110,43 +110,43 @@ class Hdf5MasterFile { const DetectorType &detector_type() const; const TimingMode &timing_mode() const; xy geometry() const; - size_t image_size_in_bytes() const; - size_t pixels_y() const; - size_t pixels_x() const; - size_t max_frames_per_file() const; + int image_size_in_bytes() const; + int pixels_y() const; + int pixels_x() const; + int max_frames_per_file() const; const FrameDiscardPolicy &frame_discard_policy() const; - size_t frame_padding() const; + int frame_padding() const; std::optional scan_parameters() const; size_t total_frames_expected() const; std::optional exptime() const; std::optional period() const; std::optional burst_mode() const; - std::optional number_of_udp_interfaces() const; - size_t bitdepth() const; - std::optional ten_giga() const; - std::optional threshold_energy() const; - std::optional> threshold_energy_all() const; + std::optional number_of_udp_interfaces() const; + int bitdepth() const; + std::optional ten_giga() const; + std::optional threshold_energy() const; + std::optional> threshold_energy_all() const; std::optional subexptime() const; std::optional subperiod() const; - std::optional quad() const; - std::optional number_of_rows() const; + std::optional quad() const; + std::optional number_of_rows() const; 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; + std::optional adc_mask() const; + bool analog_flag() const; + std::optional analog_samples() const; + bool digital_flag() const; + std::optional digital_samples() const; + std::optional dbit_offset() const; std::optional dbit_list() const; - std::optional transceiver_mask() const; - std::optional transceiver_flag() const; - std::optional transceiver_samples() const; - // g1 roi + std::optional transceiver_mask() const; + bool transceiver_flag() const; + std::optional transceiver_samples() const; + // g1 roi - will not be implemented? std::optional roi() const; - std::optional counter_mask() const; - // exptimearray - // gatedelay array - std::optional gates() const; + std::optional counter_mask() const; + std::optional> exptime_array() const; + std::optional> gate_delay_array() const; + std::optional gates() const; std::optional> additional_json_header() const; size_t frames_in_file() const; size_t n_modules() const; diff --git a/include/aare/defs.hpp b/include/aare/defs.hpp index 537175a..629ec1b 100644 --- a/include/aare/defs.hpp +++ b/include/aare/defs.hpp @@ -307,102 +307,19 @@ enum class BurstMode { Burst_Interal, Burst_External, Continuous_Internal, template ::value>> std::string ToString(T arg) { return T(arg); } -template ::value, int> = 0 > +template ::value && !is_container::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); -} - - -// vector -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 <> 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; -} - - -// map -template -std::string ToString(const std::map &m) { - std::ostringstream os; - os << '{'; - if (!m.empty()) { - auto it = m.cbegin(); - os << ToString(it->first) << ": " << ToString(it->second); - it++; - while (it != m.cend()) { - os << ", " << ToString(it->first) << ": " << ToString(it->second); - it++; - } - } - os << '}'; - return os.str(); -} -template <> inline std::map StringTo(const std::string &s) { - std::map result; - std::string str = s; - - // Remove outer braces if present - if (!str.empty() && str.front() == '{' && str.back() == '}') { - str = str.substr(1, str.size() - 2); - } - - std::stringstream ss(str); - std::string item; - - auto trim = [](std::string& t) { - // trim leading white spaces - t.erase(t.begin(), std::find_if(t.begin(), t.end(), [](unsigned char c){ return !std::isspace(c); })); - // trim trailing white spaces - t.erase(std::find_if(t.rbegin(), t.rend(), [](unsigned char c){ return !std::isspace(c); }).base(), t.end()); - }; - - while (std::getline(ss, item, ',')) { - 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); - - trim(key); - trim(value); - - result[key] = value; - } - return result; -} - // 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); })); + s.erase(std::find_if(s.rbegin(), s.rend(), + [](unsigned char c) { return !std::isspace(c); }).base(), + s.end()); +} /** Convert std::chrono::duration with specified output unit */ template @@ -445,6 +362,11 @@ ToString(From t) { return ToString(tns, "s"); } } +template +std::ostream& operator<<(std::ostream& os, + const std::chrono::duration& d) { + return os << ToString(d); +} template T StringTo(const std::string &t, const std::string &unit) { @@ -477,10 +399,160 @@ T StringTo(const std::string &t) { return StringTo(tmp, unit); } +template <> inline bool StringTo(const std::string &s) { + int i = std::stoi(s, nullptr, 10); + switch (i) { + case 0: + return false; + case 1: + return true; + default: + throw std::runtime_error("Unknown boolean. Expecting be 0 or 1."); + } +} + +template <> inline uint8_t StringTo(const std::string &s) { + int base = s.find("0x") != std::string::npos ? 16 : 10; + int value = std::stoi(s, nullptr, base); + if (value < std::numeric_limits::min() || + value > std::numeric_limits::max()) { + throw std::runtime_error("Cannot scan uint8_t from string '" + s + + "'. Value must be in range 0 - 255."); + } + return static_cast(value); +} + +template <> inline uint16_t StringTo(const std::string &s) { + int base = s.find("0x") != std::string::npos ? 16 : 10; + int value = std::stoi(s, nullptr, base); + if (value < std::numeric_limits::min() || + value > std::numeric_limits::max()) { + throw std::runtime_error("Cannot scan uint16_t from string '" + s + + "'. Value must be in range 0 - 65535."); + } + return static_cast(value); +} + +template <> inline uint32_t StringTo(const std::string &s) { + int base = s.find("0x") != std::string::npos ? 16 : 10; + return std::stoul(s, nullptr, base); +} + +template <> inline uint64_t StringTo(const std::string &s) { + int base = s.find("0x") != std::string::npos ? 16 : 10; + return std::stoull(s, nullptr, base); +} + +template <> inline int StringTo(const std::string &s) { + int base = s.find("0x") != std::string::npos ? 16 : 10; + return std::stoi(s, nullptr, base); +} + +/*template <> inline size_t StringTo(const std::string &s) { + int base = s.find("0x") != std::string::npos ? 16 : 10; + return std::stoull(s, nullptr, base); +}*/ + + + +// vector +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 +std::ostream& operator<<(std::ostream& os, const std::vector& v) { + return os << ToString(v); +} + +template < + typename Container, + std::enable_if_t::value && + !is_std_string_v /*&& + !is_map_v*/, + 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()); + + std::stringstream ss(str); + std::string item; + Container result; + + while (std::getline(ss, item, ',')) { + TrimWhiteSpaces(item); + if (!item.empty()) { + result.push_back(StringTo(item)); + } + } + return result; +} + + +// map +template +std::string ToString(const std::map &m) { + std::ostringstream os; + os << '{'; + if (!m.empty()) { + auto it = m.cbegin(); + os << ToString(it->first) << ": " << ToString(it->second); + it++; + while (it != m.cend()) { + os << ", " << ToString(it->first) << ": " << ToString(it->second); + it++; + } + } + os << '}'; + return os.str(); +} + +template <> inline std::map StringTo(const std::string &s) { + std::map result; + std::string str = s; + + // Remove outer braces if present + if (!str.empty() && str.front() == '{' && str.back() == '}') { + str = str.substr(1, str.size() - 2); + } + + std::stringstream ss(str); + std::string item; + + while (std::getline(ss, item, ',')) { + 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); + + TrimWhiteSpaces(key); + TrimWhiteSpaces(value); + + result[key] = value; + } + return result; +} + + // optional template std::string ToString(const std::optional &opt) { return opt ? ToString(*opt) : "nullopt"; } + template std::ostream &operator<<(std::ostream &os, const std::optional &opt) { if (opt) diff --git a/include/aare/type_traits.hpp b/include/aare/type_traits.hpp index 20a8d8d..2ec3bd8 100644 --- a/include/aare/type_traits.hpp +++ b/include/aare/type_traits.hpp @@ -23,4 +23,52 @@ struct is_duration().zero())>, void>::type> : public std::true_type {}; +/** + * Type trait to evaluate if template parameter is + * complying with a standard container + */ +template +struct is_container : std::false_type {}; + +template struct is_container_helper {}; + +template +struct is_container< + T, typename std::conditional< + false, + is_container_helper< + typename std::remove_reference::type::value_type, + typename std::remove_reference::type::size_type, + typename std::remove_reference::type::iterator, + typename std::remove_reference::type::const_iterator, + decltype(std::declval().size()), + decltype(std::declval().begin()), + decltype(std::declval().end()), + decltype(std::declval().cbegin()), + decltype(std::declval().cend()), + decltype(std::declval().empty())>, + void>::type> : public std::true_type {}; + + +/** + * Type trait to evaluate if template parameter is + * complying with a std::string + */ +template +inline constexpr bool is_std_string_v = + std::is_same_v, std::string>; + +/** + * Type trait to evaluate if template parameter is + * complying with std::map + */ +template +struct is_map : std::false_type {}; + +template +struct is_map> : std::true_type {}; + +template +inline constexpr bool is_map_v = is_map>::value; + } // namsespace aare \ No newline at end of file diff --git a/src/Hdf5File.cpp b/src/Hdf5File.cpp index f6a3854..cea1700 100644 --- a/src/Hdf5File.cpp +++ b/src/Hdf5File.cpp @@ -63,7 +63,7 @@ size_t Hdf5File::frame_number(size_t frame_index) { } uint64_t fnum{0}; int part_index = 0; // assuming first part - m_header_files[0]->get_header_into(frame_index, part_index, + m_header_datasets[0]->get_header_into(frame_index, part_index, reinterpret_cast(&fnum)); return fnum; } @@ -76,9 +76,9 @@ size_t Hdf5File::pixels_per_frame() { return m_rows * m_cols; } size_t Hdf5File::bytes_per_pixel() const { return m_master.bitdepth() / 8; } void Hdf5File::seek(size_t frame_index) { - m_data_file->seek(frame_index); + m_data_dataset->seek(frame_index); for (size_t i = 0; i != header_dataset_names.size(); ++i) { - m_header_files[i]->seek(frame_index); + m_header_datasets[i]->seek(frame_index); } m_current_frame = frame_index; } @@ -123,7 +123,7 @@ void Hdf5File::get_frame_into(size_t frame_index, std::byte *frame_buffer, void Hdf5File::get_data_into(size_t frame_index, std::byte *frame_buffer, size_t n_frames) { - m_data_file->get_data_into(frame_index, frame_buffer, n_frames); + m_data_dataset->get_data_into(frame_index, frame_buffer, n_frames); } void Hdf5File::get_header_into(size_t frame_index, int part_index, @@ -131,7 +131,7 @@ void Hdf5File::get_header_into(size_t frame_index, int part_index, try { read_hdf5_header_fields(header, [&](size_t iParameter, std::byte *dest) { - m_header_files[iParameter]->get_header_into( + m_header_datasets[iParameter]->get_header_into( frame_index, part_index, dest); }); LOG(logDEBUG5) << "Read 1D header for frame " << frame_index; @@ -191,15 +191,15 @@ void Hdf5File::open_data_file() { throw std::runtime_error(LOCATION + "Unsupported mode. Can only read Hdf5 files."); try { - m_data_file = std::make_unique(m_master.master_fname().string(), metadata_group_name + "/data"); + m_data_dataset = std::make_unique(m_master.master_fname().string(), metadata_group_name + "/data"); - m_total_frames = m_data_file->get_dims()[0]; - m_rows = m_data_file->get_dims()[1]; - m_cols = m_data_file->get_dims()[2]; + 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); } catch (const H5::Exception &e) { - m_data_file.reset(); + m_data_dataset.reset(); fmt::print("Exception type: {}\n", typeid(e).name()); e.printErrorStack(); throw std::runtime_error( @@ -213,13 +213,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_files.push_back(std::make_unique(m_master.master_fname().string(), metadata_group_name + header_dataset_names[i])); - //fmt::print("{} Dataset dimensions: size = {}\n", - // header_dataset_names[i], m_header_files[i]->dims[0]); + m_header_datasets.push_back(std::make_unique(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_files.clear(); - m_data_file.reset(); + m_header_datasets.clear(); + m_data_dataset.reset(); fmt::print("Exception type: {}\n", typeid(e).name()); e.printErrorStack(); throw std::runtime_error( diff --git a/src/Hdf5MasterFile.cpp b/src/Hdf5MasterFile.cpp index 15ffe36..bb0b39d 100644 --- a/src/Hdf5MasterFile.cpp +++ b/src/Hdf5MasterFile.cpp @@ -88,18 +88,18 @@ const std::string &Hdf5MasterFile::version() const { return m_version; } const DetectorType &Hdf5MasterFile::detector_type() const { return m_type; } const TimingMode &Hdf5MasterFile::timing_mode() const { return m_timing_mode; } xy Hdf5MasterFile::geometry() const { return m_geometry; } -size_t Hdf5MasterFile::image_size_in_bytes() const { +int Hdf5MasterFile::image_size_in_bytes() const { return m_image_size_in_bytes; } -size_t Hdf5MasterFile::pixels_y() const { return m_pixels_y; } -size_t Hdf5MasterFile::pixels_x() const { return m_pixels_x; } -size_t Hdf5MasterFile::max_frames_per_file() const { +int Hdf5MasterFile::pixels_y() const { return m_pixels_y; } +int Hdf5MasterFile::pixels_x() const { return m_pixels_x; } +int Hdf5MasterFile::max_frames_per_file() const { return m_max_frames_per_file; } const FrameDiscardPolicy &Hdf5MasterFile::frame_discard_policy() const { return m_frame_discard_policy; } -size_t Hdf5MasterFile::frame_padding() const { return m_frame_padding; } +int Hdf5MasterFile::frame_padding() const { return m_frame_padding; } std::optional Hdf5MasterFile::scan_parameters() const { return m_scan_parameters; } @@ -115,17 +115,17 @@ std::optional Hdf5MasterFile::period() const { std::optional Hdf5MasterFile::burst_mode() const { return m_burst_mode; } -std::optional Hdf5MasterFile::number_of_udp_interfaces() const { +std::optional Hdf5MasterFile::number_of_udp_interfaces() const { return m_number_of_udp_interfaces; } -size_t Hdf5MasterFile::bitdepth() const { return m_bitdepth; } -std::optional Hdf5MasterFile::ten_giga() const { +int Hdf5MasterFile::bitdepth() const { return m_bitdepth; } +std::optional Hdf5MasterFile::ten_giga() const { return m_ten_giga; } -std::optional Hdf5MasterFile::threshold_energy() const { +std::optional Hdf5MasterFile::threshold_energy() const { return m_threshold_energy; } -std::optional> +std::optional> Hdf5MasterFile::threshold_energy_all() const { return m_threshold_energy_all; } @@ -135,39 +135,43 @@ std::optional Hdf5MasterFile::subexptime() const { std::optional Hdf5MasterFile::subperiod() const { return m_subperiod; } -std::optional Hdf5MasterFile::quad() const { return m_quad; } -std::optional Hdf5MasterFile::number_of_rows() const { +std::optional Hdf5MasterFile::quad() const { return m_quad; } +std::optional Hdf5MasterFile::number_of_rows() const { return m_number_of_rows; } 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 { +std::optional Hdf5MasterFile::adc_mask() const { return m_adc_mask; } +bool Hdf5MasterFile::analog_flag() const { return m_analog_flag; } +std::optional Hdf5MasterFile::analog_samples() const { return m_analog_samples; } -std::optional Hdf5MasterFile::digital_flag() const { return m_digital_flag; } -std::optional Hdf5MasterFile::digital_samples() const { +bool Hdf5MasterFile::digital_flag() const { return m_digital_flag; } +std::optional Hdf5MasterFile::digital_samples() const { return m_digital_samples; } -std::optional Hdf5MasterFile::dbit_offset() const { +std::optional Hdf5MasterFile::dbit_offset() const { return m_dbit_offset; } std::optional Hdf5MasterFile::dbit_list() const { return m_dbit_list; } -std::optional Hdf5MasterFile::transceiver_mask() const { +std::optional Hdf5MasterFile::transceiver_mask() const { return m_transceiver_mask; } -std::optional Hdf5MasterFile::transceiver_flag() const { return m_transceiver_flag; } -std::optional Hdf5MasterFile::transceiver_samples() const { +bool Hdf5MasterFile::transceiver_flag() const { return m_transceiver_flag; } +std::optional Hdf5MasterFile::transceiver_samples() const { return m_transceiver_samples; } // g1 roi std::optional Hdf5MasterFile::roi() const { return m_roi; } -std::optional Hdf5MasterFile::counter_mask() const { return m_counter_mask; } -// exptimearray -// gatedelay array -std::optional Hdf5MasterFile::gates() const { return m_gates; } +std::optional Hdf5MasterFile::counter_mask() const { return m_counter_mask; } +std::optional> Hdf5MasterFile::exptime_array() const { + return m_exptime_array; +} +std::optional> Hdf5MasterFile::gate_delay_array() const { + return m_gate_delay_array; +} +std::optional Hdf5MasterFile::gates() const { return m_gates; } std::optional> Hdf5MasterFile::additional_json_header() const { return m_additional_json_header; } @@ -193,9 +197,10 @@ T Hdf5MasterFile::h5_read_scalar_dataset(const H5::DataSet &dataset, template <> std::string Hdf5MasterFile::h5_read_scalar_dataset( const H5::DataSet &dataset, const H5::DataType &data_type) { - char buffer[257]{0}; - dataset.read(buffer, data_type); - return std::string(buffer); + size_t size = data_type.getSize(); + std::vector buffer(size + 1, 0); + dataset.read(buffer.data(), data_type); + return std::string(buffer.data()); } template @@ -225,7 +230,7 @@ void Hdf5MasterFile::parse_acquisition_metadata( std::ostringstream oss; oss << std::fixed << std::setprecision(1) << dVersion; m_version = oss.str(); - LOG(logDEBUG) << "Version: " << m_version; + LOG(logINFOBLUE) << "Version: " << m_version; } // Scalar Dataset @@ -234,54 +239,54 @@ void Hdf5MasterFile::parse_acquisition_metadata( // Detector Type m_type = StringTo(h5_get_scalar_dataset( file, std::string(metadata_group_name + "Detector Type"))); - LOG(logDEBUG) << "Detector Type: " << ToString(m_type); + LOG(logINFOBLUE) << "Detector Type: " << ToString(m_type); // Timing Mode m_timing_mode = StringTo(h5_get_scalar_dataset( file, std::string(metadata_group_name + "Timing Mode"))); - LOG(logDEBUG) << "Timing Mode: " << ToString(m_timing_mode); + LOG(logINFOBLUE) << "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(); + LOG(logINFOBLUE) << "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; + LOG(logINFOBLUE) << "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; + LOG(logINFOBLUE) << "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; + LOG(logINFOBLUE) << "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; + LOG(logINFOBLUE) << "Max frames per File: " << m_max_frames_per_file; // Frame Discard Policy m_frame_discard_policy = StringTo(h5_get_scalar_dataset( file, std::string(metadata_group_name + "Frame Discard Policy"))); - LOG(logDEBUG) << "Frame Discard Policy: " << ToString(m_frame_discard_policy); + LOG(logINFOBLUE) << "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; + LOG(logINFOBLUE) << "Frame Padding: " << m_frame_padding; // Scan Parameters try { @@ -292,7 +297,7 @@ void Hdf5MasterFile::parse_acquisition_metadata( m_scan_parameters ->increment_stop(); // adjust for endpoint being included } - LOG(logDEBUG) << "Scan Parameters: " << ToString(m_scan_parameters); + LOG(logINFOBLUE) << "Scan Parameters: " << ToString(m_scan_parameters); } catch (H5::FileIException &e) { // keep the optional empty } @@ -300,13 +305,13 @@ void Hdf5MasterFile::parse_acquisition_metadata( // Total Frames Expected m_total_frames_expected = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Total Frames")); - LOG(logDEBUG) << "Total Frames: " << m_total_frames_expected; + LOG(logINFOBLUE) << "Total Frames: " << m_total_frames_expected; // Exptime try { m_exptime = StringTo(h5_get_scalar_dataset( file, std::string(metadata_group_name + "Exposure Time"))); - LOG(logDEBUG) << "Exptime: " << ToString(m_exptime); + LOG(logINFOBLUE) << "Exptime: " << ToString(m_exptime); } catch (H5::FileIException &e) { // keep the optional empty } @@ -315,7 +320,7 @@ void Hdf5MasterFile::parse_acquisition_metadata( try { m_period = StringTo(h5_get_scalar_dataset( file, std::string(metadata_group_name + "Acquisition Period"))); - LOG(logDEBUG) << "Period: " << ToString(m_period); + LOG(logINFOBLUE) << "Period: " << ToString(m_period); } catch (H5::FileIException &e) { // keep the optional empty } @@ -325,7 +330,7 @@ void Hdf5MasterFile::parse_acquisition_metadata( m_burst_mode = StringTo(h5_get_scalar_dataset( file, std::string(metadata_group_name + "Burst Mode"))); - LOG(logDEBUG) << "Burst Mode: " << ToString(m_burst_mode); + LOG(logINFOBLUE) << "Burst Mode: " << ToString(m_burst_mode); } catch (H5::FileIException &e) { // keep the optional empty } @@ -333,10 +338,10 @@ 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( + 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: " + LOG(logINFOBLUE) << "Number of UDP Interfaces: " << m_number_of_udp_interfaces; } catch (H5::FileIException &e) { // keep the optional empty @@ -346,40 +351,42 @@ 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; + LOG(logINFOBLUE) << "Bit Depth: " << m_bitdepth; } catch (H5::FileIException &e) { m_bitdepth = 16; } // Ten Giga try { - m_ten_giga = h5_get_scalar_dataset( - file, std::string(metadata_group_name + "Ten Giga")); - LOG(logDEBUG) << "Ten Giga: " << m_ten_giga; + m_ten_giga = h5_get_scalar_dataset( + file, std::string(metadata_group_name + "Ten Giga Enable")); + LOG(logINFOBLUE) << "Ten Giga Enable: " << m_ten_giga; } catch (H5::FileIException &e) { // keep the optional empty } // 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; + LOG(logINFOBLUE) << "Threshold Energy: " << m_threshold_energy; } catch (H5::FileIException &e) { // keep the optional empty } // Threshold All Energy try { - m_threshold_energy_all = StringTo>( + m_threshold_energy_all = StringTo>( h5_get_scalar_dataset( file, std::string(metadata_group_name + "Threshold Energies"))); - LOG(logDEBUG) << "Threshold Energies: " + LOG(logINFOBLUE) << "Threshold Energies: " << ToString(m_threshold_energy_all); } catch (H5::FileIException &e) { + std::cout << "No Threshold Energies found in file: " + << fpath << std::endl; // keep the optional empty } @@ -387,7 +394,7 @@ void Hdf5MasterFile::parse_acquisition_metadata( try { m_subexptime = StringTo(h5_get_scalar_dataset( file, std::string(metadata_group_name + "Sub Exposure Time"))); - LOG(logDEBUG) << "Subexptime: " << ToString(m_subexptime); + LOG(logINFOBLUE) << "Subexptime: " << ToString(m_subexptime); } catch (H5::FileIException &e) { // keep the optional empty } @@ -396,16 +403,16 @@ void Hdf5MasterFile::parse_acquisition_metadata( try { m_subperiod = StringTo(h5_get_scalar_dataset( file, std::string(metadata_group_name + "Sub Period"))); - LOG(logDEBUG) << "Subperiod: " << ToString(m_subperiod); + LOG(logINFOBLUE) << "Subperiod: " << ToString(m_subperiod); } catch (H5::FileIException &e) { // keep the optional empty } // 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; + LOG(logINFOBLUE) << "Quad: " << m_quad; } catch (H5::FileIException &e) { // keep the optional empty } @@ -413,9 +420,9 @@ 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; + LOG(logINFOBLUE) << "Number of rows: " << m_number_of_rows; } catch (H5::FileIException &e) { // keep the optional empty } @@ -426,7 +433,7 @@ void Hdf5MasterFile::parse_acquisition_metadata( h5_get_scalar_dataset( file, std::string(metadata_group_name + "Rate Corrections"))); - LOG(logDEBUG) << "Rate Corrections: " + LOG(logINFOBLUE) << "Rate Corrections: " << ToString(m_rate_corrections); } catch (H5::FileIException &e) { // keep the optional empty @@ -434,12 +441,12 @@ void Hdf5MasterFile::parse_acquisition_metadata( // 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 } - LOG(logDEBUG) << "ADC Mask: " << m_adc_mask; + LOG(logINFOBLUE) << "ADC Mask: " << m_adc_mask; // Analog Flag // ---------------------------------------------------------------- @@ -447,7 +454,7 @@ void Hdf5MasterFile::parse_acquisition_metadata( try { m_analog_flag = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Analog Flag")); - LOG(logDEBUG) << "Analog Flag: " << m_analog_flag; + LOG(logINFOBLUE) << "Analog Flag: " << m_analog_flag; } catch (H5::FileIException &e) { // if it doesn't work still set it to one // to try to decode analog samples (Old Moench03) @@ -457,36 +464,36 @@ 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; + LOG(logINFOBLUE) << "Analog Samples: " << m_analog_samples; } } catch (H5::FileIException &e) { // keep the optional empty // and set analog flag to 0 - m_analog_flag = 0; + m_analog_flag = false; } //----------------------------------------------------------------- // 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( - file, std::string(metadata_group_name + "Digital Samples")); - } - LOG(logDEBUG) << "Digital Samples: " << m_digital_samples; + LOG(logINFOBLUE) << "Digital Flag: " << m_digital_flag; + if (m_digital_flag) { + m_digital_samples = h5_get_scalar_dataset( + file, std::string(metadata_group_name + "Digital Samples")); + } + LOG(logINFOBLUE) << "Digital Samples: " << m_digital_samples; } catch (H5::FileIException &e) { - // keep the optional empty + m_digital_flag = false; } // 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; + LOG(logINFOBLUE) << "Dbit Offset: " << m_dbit_offset; } catch (H5::FileIException &e) { // keep the optional empty } @@ -495,46 +502,46 @@ void Hdf5MasterFile::parse_acquisition_metadata( try { m_dbit_list = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Dbit Bitset List")); - LOG(logDEBUG) << "Dbit list: " << m_dbit_list; + LOG(logINFOBLUE) << "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; + LOG(logINFOBLUE) << "Transceiver Mask: " << m_transceiver_mask; } catch (H5::FileIException &e) { // keep the optional empty } // 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; + LOG(logINFOBLUE) << "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) + LOG(logINFOBLUE) << "Transceiver Samples: " << m_transceiver_samples; } } catch (H5::FileIException &e) { - // keep the optional empty + m_transceiver_flag = false; } // 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 @@ -550,7 +557,7 @@ void Hdf5MasterFile::parse_acquisition_metadata( // if we have an roi we need to update the geometry for the subfiles if (m_roi) { } - LOG(logDEBUG) << "ROI: " << m_roi; + LOG(logINFOBLUE) << "ROI: " << m_roi; } catch (H5::FileIException &e) { // keep the optional empty } @@ -572,33 +579,47 @@ 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; + LOG(logINFOBLUE) << "Counter Mask: " << m_counter_mask; } catch (H5::FileIException &e) { // keep the optional empty } - // exptimearray - //std::vector exptimearray = {std::chrono::nanoseconds(10), std::chrono::milliseconds(500)}; - //std::cout << "exptimearray: " << ToString(exptimearray) << std::endl; + // Exposure Time Array + try { + m_exptime_array = StringTo>( + h5_get_scalar_dataset( + file, std::string(metadata_group_name + "Exposure Times"))); + LOG(logINFOBLUE) << "Exposure Times: " << ToString(m_exptime_array); + } catch (H5::FileIException &e) { + // keep the optional empty + } - // gatedelay array + // Gate Delay Array + try { + m_gate_delay_array = StringTo>( + h5_get_scalar_dataset( + file, std::string(metadata_group_name + "Gate Delays"))); + LOG(logINFOBLUE) << "Gate Delays: " << ToString(m_gate_delay_array); + } catch (H5::FileIException &e) { + // keep the optional empty + } // Gates try { - m_gates = h5_get_scalar_dataset( + m_gates = h5_get_scalar_dataset( file, std::string(metadata_group_name + "Gates")); - LOG(logDEBUG) << "Gates: " << m_gates; + LOG(logINFOBLUE) << "Gates: " << m_gates; } catch (H5::FileIException &e) { // keep the optional empty } - // additional json header + // Additional Json Header try { m_additional_json_header = StringTo>(h5_get_scalar_dataset( file, std::string(metadata_group_name + "Additional JSON Header"))); - LOG(logDEBUG) << "Additional JSON Header: " << ToString(m_additional_json_header); + LOG(logINFOBLUE) << "Additional JSON Header: " << ToString(m_additional_json_header); } catch (H5::FileIException &e) { // keep the optional empty } @@ -606,7 +627,7 @@ void Hdf5MasterFile::parse_acquisition_metadata( // Frames in File 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; + LOG(logINFOBLUE) << "Frames in File: " << m_frames_in_file; H5Eset_auto(H5E_DEFAULT, reinterpret_cast(H5Eprint2), stderr); diff --git a/src/defs.cpp b/src/defs.cpp index e26ab9a..926e7cc 100644 --- a/src/defs.cpp +++ b/src/defs.cpp @@ -247,6 +247,7 @@ std::string RemoveUnit(std::string &str) { return unit; } + // template <> TimingMode StringTo(std::string mode); } // namespace aare \ No newline at end of file