diff --git a/include/aare/Hdf5File.hpp b/include/aare/Hdf5File.hpp index ef05a95..78ceabe 100644 --- a/include/aare/Hdf5File.hpp +++ b/include/aare/Hdf5File.hpp @@ -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 memspace; - std::vectordims; - std::vector count; - std::vector offset; + std::string file_name; + std::string dataset_name; + H5::H5File file; + H5::DataSet dataset; + H5::DataSpace dataspace; + H5::DataType datatype; + std::unique_ptr memspace; + std::vector dims; + std::vector count; + std::vector 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 get_dims() const { - return dims; - } + std::vector 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(frame_index); } - offset[0] = static_cast(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(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(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(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(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(rank, 1); // slice 1 value - offset = std::vector(rank, 0); - memspace = std::make_unique(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(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(rank, 1); // slice 1 value + offset = std::vector(rank, 0); + memspace = std::make_unique(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(2, dims_image); + } else { + throw std::runtime_error( + LOCATION + "Invalid rank for dataset: " + std::to_string(rank)); + } } - } }; - - template void read_hdf5_header_fields(DetectorHeader *header, Fn &&fn_read_field) { fn_read_field(0, reinterpret_cast(&(header->frameNumber))); diff --git a/include/aare/Hdf5MasterFile.hpp b/include/aare/Hdf5MasterFile.hpp index 7d6ea8c..3cba38c 100644 --- a/include/aare/Hdf5MasterFile.hpp +++ b/include/aare/Hdf5MasterFile.hpp @@ -6,8 +6,6 @@ #include #include - - 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> m_exptime_array{}; std::optional> m_gate_delay_array{}; std::optional m_gates{}; - std::optional> m_additional_json_header{}; + std::optional> + 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 digital_samples() const; std::optional dbit_offset() const; std::optional dbit_list() const; - std::optional transceiver_mask() const; + std::optional transceiver_mask() const; bool transceiver_flag() const; std::optional transceiver_samples() const; // g1 roi - will not be implemented? @@ -147,11 +139,11 @@ class Hdf5MasterFile { std::optional> exptime_array() const; std::optional> gate_delay_array() const; std::optional gates() const; - std::optional> additional_json_header() const; + std::optional> + 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); diff --git a/include/aare/RawMasterFile.hpp b/include/aare/RawMasterFile.hpp index 8fe25ec..f9d912a 100644 --- a/include/aare/RawMasterFile.hpp +++ b/include/aare/RawMasterFile.hpp @@ -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 diff --git a/include/aare/defs.hpp b/include/aare/defs.hpp index 47e4c97..81b8d84 100644 --- a/include/aare/defs.hpp +++ b/include/aare/defs.hpp @@ -224,33 +224,32 @@ struct ROI { using dynamic_shape = std::vector; - 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 ::value>> -std::string ToString(T arg) { return T(arg); } +template ::value>> +std::string ToString(T arg) { + return T(arg); +} -template ::value && !is_container::value, int> = 0 > -T StringTo(const std::string &arg) { return T(arg); } +template ::value && !is_container::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 std::enable_if::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(t); - if (abs(tns) -std::ostream& operator<<(std::ostream& os, - const std::chrono::duration& d) { +std::ostream &operator<<(std::ostream &os, + const std::chrono::duration &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(std::chrono::duration(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 ::value, int> = 0 > +template ::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::min() || value > std::numeric_limits::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(value); } @@ -424,7 +433,7 @@ template <> inline uint16_t StringTo(const std::string &s) { 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."); + "'. Value must be in range 0 - 65535."); } return static_cast(value); } @@ -449,8 +458,6 @@ template <> inline int StringTo(const std::string &s) { return std::stoull(s, nullptr, base); }*/ - - // vector template std::string ToString(const std::vector &vec) { std::ostringstream oss; @@ -465,23 +472,25 @@ template std::string ToString(const std::vector &vec) { } template -std::ostream& operator<<(std::ostream& os, const std::vector& v) { +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) { +template ::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()); + 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(item)); - } + } } return result; } - // map template std::string ToString(const std::map &m) { @@ -515,7 +523,8 @@ std::string ToString(const std::map &m) { return os.str(); } -template <> inline std::map StringTo(const std::string &s) { +template <> +inline std::map StringTo(const std::string &s) { std::map result; std::string str = s; @@ -531,7 +540,7 @@ template <> inline std::map 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 StringTo(const std::string return result; } - // optional template std::string ToString(const std::optional &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; } // namespace aare \ No newline at end of file diff --git a/include/aare/type_traits.hpp b/include/aare/type_traits.hpp index 2ec3bd8..b16a150 100644 --- a/include/aare/type_traits.hpp +++ b/include/aare/type_traits.hpp @@ -49,7 +49,6 @@ struct is_container< decltype(std::declval().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 -struct is_map : std::false_type {}; +template struct is_map : std::false_type {}; template struct is_map> : std::true_type {}; @@ -71,4 +69,4 @@ struct is_map> : std::true_type {}; template inline constexpr bool is_map_v = is_map>::value; -} // namsespace aare \ No newline at end of file +} // namespace aare \ No newline at end of file diff --git a/python/src/hdf5_master_file.hpp b/python/src/hdf5_master_file.hpp index 077f5b6..4d4aad3 100644 --- a/python/src/hdf5_master_file.hpp +++ b/python/src/hdf5_master_file.hpp @@ -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); } diff --git a/src/File.cpp b/src/File.cpp index 4f6fd26..eb43ff9 100644 --- a/src/File.cpp +++ b/src/File.cpp @@ -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(fname); } else { throw std::runtime_error("Unsupported file type"); diff --git a/src/Hdf5File.cpp b/src/Hdf5File.cpp index cea1700..dcfa914 100644 --- a/src/Hdf5File.cpp +++ b/src/Hdf5File.cpp @@ -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(&fnum)); + reinterpret_cast(&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 Hdf5File::header_dataset_names = { +const std::vector Hdf5File::header_dataset_names = { "frame number", "exp length or sub exposure time", "packets caught", @@ -183,21 +183,22 @@ const std::vector 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(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_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(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( + 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(); diff --git a/src/Hdf5MasterFile.cpp b/src/Hdf5MasterFile.cpp index 0301113..ab5b608 100644 --- a/src/Hdf5MasterFile.cpp +++ b/src/Hdf5MasterFile.cpp @@ -1,7 +1,7 @@ #include "aare/Hdf5MasterFile.hpp" #include "aare/logger.hpp" -#include #include +#include namespace aare { Hdf5FileNameComponents::Hdf5FileNameComponents( @@ -106,12 +106,8 @@ std::optional Hdf5MasterFile::scan_parameters() const { size_t Hdf5MasterFile::total_frames_expected() const { return m_total_frames_expected; } -std::optional Hdf5MasterFile::exptime() const { - return m_exptime; -} -std::optional Hdf5MasterFile::period() const { - return m_period; -} +std::optional Hdf5MasterFile::exptime() const { return m_exptime; } +std::optional Hdf5MasterFile::period() const { return m_period; } std::optional Hdf5MasterFile::burst_mode() const { return m_burst_mode; } @@ -119,22 +115,15 @@ std::optional Hdf5MasterFile::number_of_udp_interfaces() const { return m_number_of_udp_interfaces; } int Hdf5MasterFile::bitdepth() const { return m_bitdepth; } -std::optional Hdf5MasterFile::ten_giga() const { - return m_ten_giga; -} +std::optional Hdf5MasterFile::ten_giga() const { return m_ten_giga; } std::optional Hdf5MasterFile::threshold_energy() const { return m_threshold_energy; } -std::optional> -Hdf5MasterFile::threshold_energy_all() const { +std::optional> Hdf5MasterFile::threshold_energy_all() const { return m_threshold_energy_all; } -std::optional Hdf5MasterFile::subexptime() const { - return m_subexptime; -} -std::optional Hdf5MasterFile::subperiod() const { - return m_subperiod; -} +std::optional Hdf5MasterFile::subexptime() const { return m_subexptime; } +std::optional Hdf5MasterFile::subperiod() const { return m_subperiod; } std::optional Hdf5MasterFile::quad() const { return m_quad; } std::optional Hdf5MasterFile::number_of_rows() const { return m_number_of_rows; @@ -143,7 +132,7 @@ std::optional> Hdf5MasterFile::rate_corrections() const { return m_rate_corrections; } std::optional 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 Hdf5MasterFile::analog_samples() const { return m_analog_samples; } @@ -151,9 +140,7 @@ 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 { - return m_dbit_offset; -} +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 { return m_transceiver_mask; @@ -164,7 +151,9 @@ std::optional Hdf5MasterFile::transceiver_samples() const { } // g1 roi std::optional Hdf5MasterFile::roi() const { return m_roi; } -std::optional Hdf5MasterFile::counter_mask() const { return m_counter_mask; } +std::optional Hdf5MasterFile::counter_mask() const { + return m_counter_mask; +} std::optional> Hdf5MasterFile::exptime_array() const { return m_exptime_array; } @@ -172,12 +161,13 @@ 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 { +std::optional> +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( file, std::string(metadata_group_name + "Image Size")); @@ -281,7 +270,8 @@ void Hdf5MasterFile::parse_acquisition_metadata( 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(logDEBUG) << "Frame Discard Policy: " + << ToString(m_frame_discard_policy); // Frame Padding m_frame_padding = h5_get_scalar_dataset( @@ -378,15 +368,15 @@ void Hdf5MasterFile::parse_acquisition_metadata( // Threshold All Energy try { - m_threshold_energy_all = StringTo>( - h5_get_scalar_dataset( + 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) { - 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( 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( 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>( - h5_get_scalar_dataset( + m_exptime_array = + StringTo>(h5_get_scalar_dataset( 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>( - h5_get_scalar_dataset( + m_gate_delay_array = + StringTo>(h5_get_scalar_dataset( 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>(h5_get_scalar_dataset( - file, std::string(metadata_group_name + "Additional JSON Header"))); - LOG(logDEBUG) << "Additional JSON Header: " << ToString(m_additional_json_header); + 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); } catch (H5::FileIException &e) { // keep the optional empty } diff --git a/src/RawMasterFile.cpp b/src/RawMasterFile.cpp index ac6631b..ee51f5b 100644 --- a/src/RawMasterFile.cpp +++ b/src/RawMasterFile.cpp @@ -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)) { diff --git a/src/defs.cpp b/src/defs.cpp index c883ed7..d403fbc 100644 --- a/src/defs.cpp +++ b/src/defs.cpp @@ -1,7 +1,7 @@ #include "aare/defs.hpp" +#include #include #include -#include #include 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(std::string mode); } // namespace aare \ No newline at end of file