mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-21 19:27:58 +02:00
removed hdf5 componenets. not needed
This commit is contained in:
@ -9,42 +9,13 @@
|
|||||||
namespace aare {
|
namespace aare {
|
||||||
|
|
||||||
using ns = std::chrono::nanoseconds;
|
using ns = std::chrono::nanoseconds;
|
||||||
/**
|
|
||||||
* @brief Implementation used in Hdf5MasterFile to parse the file name
|
|
||||||
*/
|
|
||||||
class Hdf5FileNameComponents {
|
|
||||||
bool m_old_scheme{false};
|
|
||||||
std::filesystem::path m_base_path{};
|
|
||||||
std::string m_base_name{};
|
|
||||||
std::string m_ext{};
|
|
||||||
int m_file_index{};
|
|
||||||
|
|
||||||
public:
|
|
||||||
Hdf5FileNameComponents(const std::filesystem::path &fname);
|
|
||||||
|
|
||||||
/// @brief Get the filename including path of the master file.
|
|
||||||
/// (i.e. what was passed in to the constructor))
|
|
||||||
std::filesystem::path master_fname() const;
|
|
||||||
|
|
||||||
/// @brief Get the filename including path of the data file.
|
|
||||||
/// @param mod_id module id run_d[module_id]_f0_0
|
|
||||||
/// @param file_id file id run_d0_f[file_id]_0
|
|
||||||
std::filesystem::path data_fname(size_t mod_id, size_t file_id) const;
|
|
||||||
|
|
||||||
const std::filesystem::path &base_path() const;
|
|
||||||
const std::string &base_name() const;
|
|
||||||
const std::string &ext() const;
|
|
||||||
int file_index() const;
|
|
||||||
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 {
|
||||||
|
std::filesystem::path m_file_name{};
|
||||||
Hdf5FileNameComponents m_fnc;
|
|
||||||
std::string m_version;
|
std::string m_version;
|
||||||
DetectorType m_type;
|
DetectorType m_type;
|
||||||
TimingMode m_timing_mode;
|
TimingMode m_timing_mode;
|
||||||
@ -95,8 +66,7 @@ class Hdf5MasterFile {
|
|||||||
public:
|
public:
|
||||||
Hdf5MasterFile(const std::filesystem::path &fpath);
|
Hdf5MasterFile(const std::filesystem::path &fpath);
|
||||||
|
|
||||||
std::filesystem::path master_fname() const;
|
std::filesystem::path file_name() const;
|
||||||
std::filesystem::path data_fname(size_t mod_id, size_t file_id) const;
|
|
||||||
|
|
||||||
const std::string &version() const; //!< For example "7.2"
|
const std::string &version() const; //!< For example "7.2"
|
||||||
const DetectorType &detector_type() const;
|
const DetectorType &detector_type() const;
|
||||||
|
@ -191,7 +191,7 @@ void Hdf5File::open_data_file() {
|
|||||||
"Unsupported mode. Can only read Hdf5 files.");
|
"Unsupported mode. Can only read Hdf5 files.");
|
||||||
try {
|
try {
|
||||||
m_data_dataset = std::make_unique<H5Handles>(
|
m_data_dataset = std::make_unique<H5Handles>(
|
||||||
m_master.master_fname().string(), metadata_group_name + "/data");
|
m_master.file_name().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];
|
||||||
@ -215,7 +215,7 @@ void Hdf5File::open_header_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_header_datasets.push_back(std::make_unique<H5Handles>(
|
||||||
m_master.master_fname().string(),
|
m_master.file_name().string(),
|
||||||
metadata_group_name + header_dataset_names[i]));
|
metadata_group_name + header_dataset_names[i]));
|
||||||
LOG(logDEBUG) << header_dataset_names[i]
|
LOG(logDEBUG) << header_dataset_names[i]
|
||||||
<< " Dataset dimensions: size = "
|
<< " Dataset dimensions: size = "
|
||||||
|
@ -4,84 +4,16 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
namespace aare {
|
namespace aare {
|
||||||
|
|
||||||
Hdf5FileNameComponents::Hdf5FileNameComponents(
|
|
||||||
const std::filesystem::path &fname) {
|
|
||||||
m_base_path = fname.parent_path();
|
|
||||||
m_base_name = fname.stem();
|
|
||||||
m_ext = fname.extension();
|
|
||||||
|
|
||||||
if (m_ext != ".h5") {
|
|
||||||
throw std::runtime_error(LOCATION +
|
|
||||||
"Unsupported file type. (only .h5)");
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse file index
|
|
||||||
try {
|
|
||||||
auto pos = m_base_name.rfind('_');
|
|
||||||
m_file_index = std::stoi(m_base_name.substr(pos + 1));
|
|
||||||
} catch (const std::invalid_argument &e) {
|
|
||||||
throw std::runtime_error(LOCATION + "Could not parse file index");
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove master from base name
|
|
||||||
auto pos = m_base_name.find("_master_");
|
|
||||||
if (pos != std::string::npos) {
|
|
||||||
m_base_name.erase(pos);
|
|
||||||
} else {
|
|
||||||
throw std::runtime_error(LOCATION +
|
|
||||||
"Could not find _master_ in file name");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::filesystem::path Hdf5FileNameComponents::master_fname() const {
|
|
||||||
return m_base_path /
|
|
||||||
fmt::format("{}_master_{}{}", m_base_name, m_file_index, m_ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::filesystem::path Hdf5FileNameComponents::data_fname(size_t mod_id,
|
|
||||||
size_t file_id) const {
|
|
||||||
|
|
||||||
std::string fmt = "{}_d{}_f{}_{}.h5";
|
|
||||||
// Before version X we used to name the data files f000000000000
|
|
||||||
if (m_old_scheme) {
|
|
||||||
fmt = "{}_d{}_f{:012}_{}.h5";
|
|
||||||
}
|
|
||||||
return m_base_path /
|
|
||||||
fmt::format(fmt, m_base_name, mod_id, file_id, m_file_index);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Hdf5FileNameComponents::set_old_scheme(bool old_scheme) {
|
|
||||||
m_old_scheme = old_scheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::filesystem::path &Hdf5FileNameComponents::base_path() const {
|
|
||||||
return m_base_path;
|
|
||||||
}
|
|
||||||
const std::string &Hdf5FileNameComponents::base_name() const {
|
|
||||||
return m_base_name;
|
|
||||||
}
|
|
||||||
const std::string &Hdf5FileNameComponents::ext() const { return m_ext; }
|
|
||||||
int Hdf5FileNameComponents::file_index() const { return m_file_index; }
|
|
||||||
|
|
||||||
Hdf5MasterFile::Hdf5MasterFile(const std::filesystem::path &fpath)
|
Hdf5MasterFile::Hdf5MasterFile(const std::filesystem::path &fpath)
|
||||||
: m_fnc(fpath) {
|
: m_file_name(fpath) {
|
||||||
if (!std::filesystem::exists(fpath)) {
|
if (!std::filesystem::exists(fpath)) {
|
||||||
throw std::runtime_error(LOCATION + " File does not exist");
|
throw std::runtime_error(LOCATION + " File does not exist");
|
||||||
}
|
}
|
||||||
if (m_fnc.ext() == ".h5") {
|
parse_acquisition_metadata(fpath);
|
||||||
parse_acquisition_metadata(fpath);
|
|
||||||
} else {
|
|
||||||
throw std::runtime_error(LOCATION + "Unsupported file type");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path Hdf5MasterFile::master_fname() const {
|
std::filesystem::path Hdf5MasterFile::file_name() const {
|
||||||
return m_fnc.master_fname();
|
return m_file_name;
|
||||||
}
|
|
||||||
|
|
||||||
std::filesystem::path Hdf5MasterFile::data_fname(size_t mod_id,
|
|
||||||
size_t file_id) const {
|
|
||||||
return m_fnc.data_fname(mod_id, file_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &Hdf5MasterFile::version() const { return m_version; }
|
const std::string &Hdf5MasterFile::version() const { return m_version; }
|
||||||
|
Reference in New Issue
Block a user