mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-14 08:17:13 +02:00
formatted my changes
This commit is contained in:
@ -9,89 +9,85 @@
|
|||||||
namespace aare {
|
namespace aare {
|
||||||
|
|
||||||
class H5Handles {
|
class H5Handles {
|
||||||
std::string file_name;
|
std::string file_name;
|
||||||
std::string dataset_name;
|
std::string dataset_name;
|
||||||
H5::H5File file;
|
H5::H5File file;
|
||||||
H5::DataSet dataset;
|
H5::DataSet dataset;
|
||||||
H5::DataSpace dataspace;
|
H5::DataSpace dataspace;
|
||||||
H5::DataType datatype;
|
H5::DataType datatype;
|
||||||
std::unique_ptr<H5::DataSpace> memspace;
|
std::unique_ptr<H5::DataSpace> memspace;
|
||||||
std::vector<hsize_t>dims;
|
std::vector<hsize_t> dims;
|
||||||
std::vector<hsize_t> count;
|
std::vector<hsize_t> count;
|
||||||
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),
|
datatype(dataset.getDataType()) {
|
||||||
dataset(file.openDataSet(dname)),
|
intialize_dimensions();
|
||||||
dataspace(dataset.getSpace()),
|
initialize_memspace();
|
||||||
datatype(dataset.getDataType()) {
|
|
||||||
intialize_dimensions();
|
|
||||||
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]) {
|
||||||
throw std::runtime_error(LOCATION + "Invalid frame number");
|
throw std::runtime_error(LOCATION + "Invalid frame number");
|
||||||
|
}
|
||||||
|
offset[0] = static_cast<hsize_t>(frame_index);
|
||||||
}
|
}
|
||||||
offset[0] = static_cast<hsize_t>(frame_index);
|
|
||||||
}
|
|
||||||
|
|
||||||
void get_data_into(size_t frame_index, std::byte *frame_buffer, size_t n_frames = 1) {
|
void get_data_into(size_t frame_index, std::byte *frame_buffer,
|
||||||
seek(frame_index);
|
size_t n_frames = 1) {
|
||||||
count[0] = static_cast<hsize_t>(n_frames);
|
seek(frame_index);
|
||||||
// std::cout << "offset:" << ToString(offset) << " count:" <<
|
count[0] = static_cast<hsize_t>(n_frames);
|
||||||
// ToString(count) << std::endl;
|
// std::cout << "offset:" << ToString(offset) << " count:" <<
|
||||||
dataspace.selectHyperslab(H5S_SELECT_SET, count.data(), offset.data());
|
// ToString(count) << std::endl;
|
||||||
dataset.read(frame_buffer, datatype, *memspace, dataspace);
|
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) {
|
void get_header_into(size_t frame_index, int part_index,
|
||||||
seek(frame_index);
|
std::byte *header_buffer) {
|
||||||
offset[1] = static_cast<hsize_t>(part_index);
|
seek(frame_index);
|
||||||
// std::cout << "offset:" << ToString(offset) << " count:" <<
|
offset[1] = static_cast<hsize_t>(part_index);
|
||||||
// ToString(count) << std::endl;
|
// std::cout << "offset:" << ToString(offset) << " count:" <<
|
||||||
dataspace.selectHyperslab(H5S_SELECT_SET, count.data(), offset.data());
|
// ToString(count) << std::endl;
|
||||||
dataset.read(header_buffer, datatype, *memspace, dataspace);
|
dataspace.selectHyperslab(H5S_SELECT_SET, count.data(), offset.data());
|
||||||
}
|
dataset.read(header_buffer, datatype, *memspace, dataspace);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void intialize_dimensions() {
|
void intialize_dimensions() {
|
||||||
int rank = dataspace.getSimpleExtentNdims();
|
int rank = dataspace.getSimpleExtentNdims();
|
||||||
dims.resize(rank);
|
dims.resize(rank);
|
||||||
dataspace.getSimpleExtentDims(dims.data(), nullptr);
|
dataspace.getSimpleExtentDims(dims.data(), nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void initialize_memspace() {
|
void initialize_memspace() {
|
||||||
int rank = dataspace.getSimpleExtentNdims();
|
int rank = dataspace.getSimpleExtentNdims();
|
||||||
count.clear();
|
count.clear();
|
||||||
offset.clear();
|
offset.clear();
|
||||||
|
|
||||||
// header datasets or header virtual datasets
|
// header datasets or header virtual datasets
|
||||||
if (rank == 1 || rank == 2) {
|
if (rank == 1 || rank == 2) {
|
||||||
count = std::vector<hsize_t>(rank, 1); // slice 1 value
|
count = std::vector<hsize_t>(rank, 1); // slice 1 value
|
||||||
offset = std::vector<hsize_t>(rank, 0);
|
offset = std::vector<hsize_t>(rank, 0);
|
||||||
memspace = std::make_unique<H5::DataSpace>(H5S_SCALAR);
|
memspace = std::make_unique<H5::DataSpace>(H5S_SCALAR);
|
||||||
} else if (rank >= 3) {
|
} else if (rank >= 3) {
|
||||||
// data dataset (frame x height x width)
|
// data dataset (frame x height x width)
|
||||||
count = {1, dims[1], dims[2]};
|
count = {1, dims[1], dims[2]};
|
||||||
offset = {0, 0, 0};
|
offset = {0, 0, 0};
|
||||||
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)));
|
||||||
|
@ -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;
|
||||||
@ -19,7 +17,7 @@ class Hdf5FileNameComponents {
|
|||||||
std::filesystem::path m_base_path{};
|
std::filesystem::path m_base_path{};
|
||||||
std::string m_base_name{};
|
std::string m_base_name{};
|
||||||
std::string m_ext{};
|
std::string m_ext{};
|
||||||
int m_file_index{};
|
int m_file_index{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Hdf5FileNameComponents(const std::filesystem::path &fname);
|
Hdf5FileNameComponents(const std::filesystem::path &fname);
|
||||||
@ -40,13 +38,12 @@ 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
|
||||||
*/
|
*/
|
||||||
class Hdf5MasterFile {
|
class Hdf5MasterFile {
|
||||||
|
|
||||||
Hdf5FileNameComponents m_fnc;
|
Hdf5FileNameComponents m_fnc;
|
||||||
std::string m_version;
|
std::string m_version;
|
||||||
DetectorType m_type;
|
DetectorType m_type;
|
||||||
@ -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);
|
||||||
|
|
||||||
@ -138,7 +130,7 @@ class Hdf5MasterFile {
|
|||||||
std::optional<int> digital_samples() const;
|
std::optional<int> digital_samples() const;
|
||||||
std::optional<int> dbit_offset() const;
|
std::optional<int> dbit_offset() const;
|
||||||
std::optional<size_t> dbit_list() const;
|
std::optional<size_t> dbit_list() const;
|
||||||
std::optional<int> transceiver_mask() const;
|
std::optional<int> transceiver_mask() const;
|
||||||
bool transceiver_flag() const;
|
bool transceiver_flag() const;
|
||||||
std::optional<int> transceiver_samples() const;
|
std::optional<int> transceiver_samples() const;
|
||||||
// g1 roi - will not be implemented?
|
// g1 roi - will not be implemented?
|
||||||
@ -147,11 +139,11 @@ class Hdf5MasterFile {
|
|||||||
std::optional<std::vector<ns>> exptime_array() const;
|
std::optional<std::vector<ns>> 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);
|
||||||
|
@ -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
|
||||||
|
@ -224,33 +224,32 @@ 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;
|
||||||
int m_start = 0;
|
int m_start = 0;
|
||||||
int m_stop = 0;
|
int m_stop = 0;
|
||||||
int m_step = 0;
|
int m_step = 0;
|
||||||
//TODO! add settleTime, requires string to time conversion
|
// TODO! add settleTime, requires string to time conversion
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// "[enabled\ndac dac 4\nstart 500\nstop 2200\nstep 5\nsettleTime 100us\n]"
|
// "[enabled\ndac dac 4\nstart 500\nstop 2200\nstep 5\nsettleTime 100us\n]"
|
||||||
ScanParameters(const std::string &par) {
|
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;
|
std::string line;
|
||||||
while(std::getline(iss, line)){
|
while (std::getline(iss, line)) {
|
||||||
if(line == "enabled"){
|
if (line == "enabled") {
|
||||||
m_enabled = true;
|
m_enabled = true;
|
||||||
}else if(line.find("dac") != std::string::npos){
|
} else if (line.find("dac") != std::string::npos) {
|
||||||
m_dac = line.substr(4);
|
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));
|
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));
|
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));
|
m_step = std::stoi(line.substr(5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ScanParameters() = default;
|
ScanParameters() = default;
|
||||||
ScanParameters(const ScanParameters &) = default;
|
ScanParameters(const ScanParameters &) = default;
|
||||||
@ -264,7 +263,7 @@ class ScanParameters {
|
|||||||
void increment_stop() { m_stop += 1; };
|
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.
|
* @brief Enum class to identify different detectors.
|
||||||
@ -292,29 +291,38 @@ 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); })
|
||||||
s.end());
|
.base(),
|
||||||
|
s.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convert std::chrono::duration with specified output unit */
|
/** Convert std::chrono::duration with specified output unit */
|
||||||
@ -342,13 +350,13 @@ template <typename From>
|
|||||||
typename std::enable_if<is_duration<From>::value, std::string>::type
|
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");
|
||||||
} else if (abs(tns) < milliseconds(1)) {
|
} else if (abs(tns) < milliseconds(1)) {
|
||||||
return ToString(tns, "us");
|
return ToString(tns, "us");
|
||||||
@ -359,8 +367,8 @@ ToString(From t) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
template <class Rep, class Period>
|
template <class Rep, class Period>
|
||||||
std::ostream& operator<<(std::ostream& os,
|
std::ostream &operator<<(std::ostream &os,
|
||||||
const std::chrono::duration<Rep, Period>& d) {
|
const std::chrono::duration<Rep, Period> &d) {
|
||||||
return os << ToString(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()) {
|
} 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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, std::enable_if_t<is_duration<T>::value, int> = 0 >
|
template <typename T, std::enable_if_t<is_duration<T>::value, int> = 0>
|
||||||
T StringTo(const std::string &t) {
|
T StringTo(const std::string &t) {
|
||||||
std::string tmp{t};
|
std::string tmp{t};
|
||||||
auto unit = RemoveUnit(tmp);
|
auto unit = RemoveUnit(tmp);
|
||||||
@ -413,7 +422,7 @@ template <> inline uint8_t StringTo(const std::string &s) {
|
|||||||
if (value < std::numeric_limits<uint8_t>::min() ||
|
if (value < std::numeric_limits<uint8_t>::min() ||
|
||||||
value > std::numeric_limits<uint8_t>::max()) {
|
value > std::numeric_limits<uint8_t>::max()) {
|
||||||
throw std::runtime_error("Cannot scan uint8_t from string '" + s +
|
throw std::runtime_error("Cannot scan uint8_t from string '" + s +
|
||||||
"'. Value must be in range 0 - 255.");
|
"'. Value must be in range 0 - 255.");
|
||||||
}
|
}
|
||||||
return static_cast<uint8_t>(value);
|
return static_cast<uint8_t>(value);
|
||||||
}
|
}
|
||||||
@ -424,7 +433,7 @@ template <> inline uint16_t StringTo(const std::string &s) {
|
|||||||
if (value < std::numeric_limits<uint16_t>::min() ||
|
if (value < std::numeric_limits<uint16_t>::min() ||
|
||||||
value > std::numeric_limits<uint16_t>::max()) {
|
value > std::numeric_limits<uint16_t>::max()) {
|
||||||
throw std::runtime_error("Cannot scan uint16_t from string '" + s +
|
throw std::runtime_error("Cannot scan uint16_t from string '" + s +
|
||||||
"'. Value must be in range 0 - 65535.");
|
"'. Value must be in range 0 - 65535.");
|
||||||
}
|
}
|
||||||
return static_cast<uint16_t>(value);
|
return static_cast<uint16_t>(value);
|
||||||
}
|
}
|
||||||
@ -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;
|
||||||
@ -465,23 +472,25 @@ template <typename T> std::string ToString(const std::vector<T> &vec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
|
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
|
||||||
return os << ToString(v);
|
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;
|
||||||
@ -491,12 +500,11 @@ Container StringTo(const std::string& s) {
|
|||||||
TrimWhiteSpaces(item);
|
TrimWhiteSpaces(item);
|
||||||
if (!item.empty()) {
|
if (!item.empty()) {
|
||||||
result.push_back(StringTo<Value>(item));
|
result.push_back(StringTo<Value>(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
|
||||||
@ -531,7 +540,7 @@ template <> inline std::map<std::string, std::string> StringTo(const std::string
|
|||||||
auto colon_pos = item.find(':');
|
auto colon_pos = item.find(':');
|
||||||
if (colon_pos == std::string::npos)
|
if (colon_pos == std::string::npos)
|
||||||
throw std::runtime_error("Missing ':' in item: " + item);
|
throw std::runtime_error("Missing ':' in item: " + item);
|
||||||
|
|
||||||
std::string key = item.substr(0, colon_pos);
|
std::string key = item.substr(0, colon_pos);
|
||||||
std::string value = item.substr(colon_pos + 1);
|
std::string value = item.substr(colon_pos + 1);
|
||||||
|
|
||||||
@ -543,7 +552,6 @@ template <> inline std::map<std::string, std::string> StringTo(const std::string
|
|||||||
return result;
|
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
|
@ -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
|
@ -80,7 +80,7 @@ void define_hdf5_master_file_bindings(py::module &m) {
|
|||||||
.def_property_readonly("number_of_rows",
|
.def_property_readonly("number_of_rows",
|
||||||
&Hdf5MasterFile::number_of_rows)
|
&Hdf5MasterFile::number_of_rows)
|
||||||
.def_property_readonly("quad", &Hdf5MasterFile::quad);
|
.def_property_readonly("quad", &Hdf5MasterFile::quad);
|
||||||
//.def_property_readonly("scan_parameters",
|
//.def_property_readonly("scan_parameters",
|
||||||
// &Hdf5MasterFile::scan_parameters)
|
// &Hdf5MasterFile::scan_parameters)
|
||||||
//.def_property_readonly("roi", &Hdf5MasterFile::roi);
|
//.def_property_readonly("roi", &Hdf5MasterFile::roi);
|
||||||
}
|
}
|
||||||
|
@ -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");
|
throw std::runtime_error("Enable HDF5 compile option: AARE_HDF5=ON");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else if(fname.extension() == ".dat"){
|
else if (fname.extension() == ".dat") {
|
||||||
file_impl = std::make_unique<JungfrauDataFile>(fname);
|
file_impl = std::make_unique<JungfrauDataFile>(fname);
|
||||||
} else {
|
} else {
|
||||||
throw std::runtime_error("Unsupported file type");
|
throw std::runtime_error("Unsupported file type");
|
||||||
|
@ -64,7 +64,7 @@ size_t Hdf5File::frame_number(size_t frame_index) {
|
|||||||
uint64_t fnum{0};
|
uint64_t fnum{0};
|
||||||
int part_index = 0; // assuming first part
|
int part_index = 0; // assuming first part
|
||||||
m_header_datasets[0]->get_header_into(frame_index, part_index,
|
m_header_datasets[0]->get_header_into(frame_index, part_index,
|
||||||
reinterpret_cast<std::byte *>(&fnum));
|
reinterpret_cast<std::byte *>(&fnum));
|
||||||
return 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,
|
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) {
|
||||||
fmt::print("Exception type: {}\n", typeid(e).name());
|
fmt::print("Exception type: {}\n", typeid(e).name());
|
||||||
@ -169,7 +169,7 @@ DetectorHeader Hdf5File::read_header(const std::filesystem::path &fname) {
|
|||||||
Hdf5File::~Hdf5File() {}
|
Hdf5File::~Hdf5File() {}
|
||||||
|
|
||||||
const std::string Hdf5File::metadata_group_name = "/entry/data/";
|
const std::string Hdf5File::metadata_group_name = "/entry/data/";
|
||||||
const std::vector<std::string> Hdf5File::header_dataset_names = {
|
const std::vector<std::string> Hdf5File::header_dataset_names = {
|
||||||
"frame number",
|
"frame number",
|
||||||
"exp length or sub exposure time",
|
"exp length or sub exposure time",
|
||||||
"packets caught",
|
"packets caught",
|
||||||
@ -183,21 +183,22 @@ 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 =
|
||||||
// m_total_frames, m_rows, m_cols);
|
// {}\n",
|
||||||
|
// 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();
|
||||||
fmt::print("Exception type: {}\n", typeid(e).name());
|
fmt::print("Exception type: {}\n", typeid(e).name());
|
||||||
@ -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();
|
||||||
|
@ -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;
|
||||||
@ -143,7 +132,7 @@ std::optional<std::vector<size_t>> Hdf5MasterFile::rate_corrections() const {
|
|||||||
return m_rate_corrections;
|
return m_rate_corrections;
|
||||||
}
|
}
|
||||||
std::optional<uint32_t> Hdf5MasterFile::adc_mask() const { return m_adc_mask; }
|
std::optional<uint32_t> Hdf5MasterFile::adc_mask() const { return m_adc_mask; }
|
||||||
bool Hdf5MasterFile::analog_flag() const { return m_analog_flag; }
|
bool Hdf5MasterFile::analog_flag() const { return m_analog_flag; }
|
||||||
std::optional<int> Hdf5MasterFile::analog_samples() const {
|
std::optional<int> Hdf5MasterFile::analog_samples() const {
|
||||||
return m_analog_samples;
|
return m_analog_samples;
|
||||||
}
|
}
|
||||||
@ -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,12 +161,13 @@ 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; }
|
||||||
size_t Hdf5MasterFile::n_modules() const {
|
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
|
// 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"));
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -533,7 +523,7 @@ void Hdf5MasterFile::parse_acquisition_metadata(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rx ROI
|
// Rx ROI
|
||||||
try{
|
try {
|
||||||
ROI tmp_roi;
|
ROI tmp_roi;
|
||||||
tmp_roi.xmin = h5_get_scalar_dataset<int>(
|
tmp_roi.xmin = h5_get_scalar_dataset<int>(
|
||||||
file, std::string(metadata_group_name + "receiver roi xmin"));
|
file, std::string(metadata_group_name + "receiver roi xmin"));
|
||||||
@ -544,10 +534,11 @@ void Hdf5MasterFile::parse_acquisition_metadata(
|
|||||||
tmp_roi.ymax = h5_get_scalar_dataset<int>(
|
tmp_roi.ymax = h5_get_scalar_dataset<int>(
|
||||||
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 ||
|
||||||
//why?? TODO
|
tmp_roi.ymin != 4294967295 || tmp_roi.ymax != 4294967295) {
|
||||||
if(dVersion < 6.61){
|
// why?? TODO
|
||||||
|
if (dVersion < 6.61) {
|
||||||
tmp_roi.xmax++;
|
tmp_roi.xmax++;
|
||||||
tmp_roi.ymax++;
|
tmp_roi.ymax++;
|
||||||
}
|
}
|
||||||
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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)) {
|
||||||
|
15
src/defs.cpp
15
src/defs.cpp
@ -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,9 +197,10 @@ 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;
|
||||||
} else {
|
} else {
|
||||||
oss << "disabled";
|
oss << "disabled";
|
||||||
@ -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
|
Reference in New Issue
Block a user