BioCMAMC-ST
data_exporter.hpp
1#ifndef __CORE_DATA_EXPORTER_HPP__
2#define __CORE_DATA_EXPORTER_HPP__
3
4#include "common/logger.hpp"
5#include <common/common.hpp>
6#include <common/execinfo.hpp>
7#include <core/simulation_parameters.hpp>
8#include <cstddef>
9#include <cstdint>
10#include <memory>
11#include <optional>
12#include <span>
13#include <string>
14#include <string_view>
15#include <unordered_map>
16#include <variant>
17#include <vector>
18namespace Core
19{
20
21 // static inline std::string get_filename(std::string_view filename,
22 // std::size_t current_rank)
23 // {
24 // return std::string(filename) + "_partial_" + std::to_string(current_rank)
25 // + ".h5";
26 // }
45 {
46 public:
47 DataExporter(const DataExporter&) = delete;
51 DataExporter() = default;
64 void do_link(std::string_view filename,
65 std::string_view link_name,
66 std::string_view groupname);
67
68 void set_logger(std::shared_ptr<IO::Logger> _logger)
69 {
70 logger = std::move(_logger);
71 }
72
73 protected:
74 std::shared_ptr<IO::Logger> logger;
75
87 {
88 std::string name;
89 std::vector<size_t> dims;
90 std::vector<size_t> max_dims;
91 std::optional<std::vector<unsigned long long>>
95 };
96
97 // Using type definitions with aligned comments
99 std::variant<uint64_t, int, std::string>;
101 std::unordered_map<std::string,
104 Kokkos::View<double**,
105 Kokkos::LayoutRight,
106 HostSpace>;
107 using simple_export_t = std::variant<size_t,
108 std::string,
109 std::vector<size_t>,
110 double,
111 uint32_t>;
114 std::unordered_map<std::string,
116
118 std::variant<std::span<const double>,
119 std::span<const std::size_t>,
120 double>;
121
122 // Methods
123
124 explicit DataExporter(
125 const ExecInfo& info,
126 std::string_view _filename,
127 std::optional<export_metadata_t> user_description = std::nullopt);
129
130 void write_matrix(std::string_view name,
131 std::span<const double> values,
132 bool compress = false);
133
134 void write_matrix(std::string_view name,
135 std::span<const double> values,
136 size_t n_row,
137 size_t n_col,
138 bool compress = false);
139
140 void prepare_matrix(MultiMatrixDescription description);
141
142 void append_matrix(std::string_view name, matrix_variant_t data);
143
144 void append_array(std::string_view name,
145 std::span<const double> data,
146 uint64_t last_size = 0);
147
148 void write_properties(std::optional<std::string> specific_dataspace,
149 const export_metadata_kv& values);
150
151 void write_simple(const export_initial_kv& values, std::string_view root);
152
153 void write_simple(std::string specific_dataspace,
154 const simple_export_t& values);
155
157 uint64_t export_counter = 0;
158
159 private:
160 std::unordered_map<std::string, MultiMatrixDescription> descriptors;
161 class impl;
162 std::unique_ptr<impl> pimpl;
163 };
164
165} // namespace Core
166#endif
Definition impl_default_dataexporter.cpp:8
void append_matrix(std::string_view name, matrix_variant_t data)
Definition impl_default_dataexporter.cpp:37
void append_array(std::string_view name, std::span< const double > data, uint64_t last_size=0)
Definition impl_default_dataexporter.cpp:41
void do_link(std::string_view filename, std::string_view link_name, std::string_view groupname)
Creates a link to a specified file.
Definition impl_default_dataexporter.cpp:10
std::variant< uint64_t, int, std::string > export_metadata_t
Metadata types for export.
Definition data_exporter.hpp:98
void write_simple(const export_initial_kv &values, std::string_view root)
Definition impl_default_dataexporter.cpp:61
std::unordered_map< std::string, MultiMatrixDescription > descriptors
Definition data_exporter.hpp:160
std::shared_ptr< IO::Logger > logger
Definition data_exporter.hpp:74
void write_matrix(std::string_view name, std::span< const double > values, bool compress=false)
Definition impl_default_dataexporter.cpp:27
std::variant< std::span< const double >, std::span< const std::size_t >, double > matrix_variant_t
Variant for matrix data types.
Definition data_exporter.hpp:117
uint64_t export_counter
Definition data_exporter.hpp:157
void write_properties(std::optional< std::string > specific_dataspace, const export_metadata_kv &values)
Definition impl_default_dataexporter.cpp:48
std::variant< size_t, std::string, std::vector< size_t >, double, uint32_t > simple_export_t
Definition data_exporter.hpp:107
DataExporter()=default
void prepare_matrix(MultiMatrixDescription description)
Definition impl_default_dataexporter.cpp:33
DataExporter(const DataExporter &)=delete
DataExporter & operator=(DataExporter &&)=delete
std::unordered_map< std::string, export_metadata_t > export_metadata_kv
Key-value pairs for metadata.
Definition data_exporter.hpp:100
export_metadata_kv metadata
Definition data_exporter.hpp:156
std::unordered_map< std::string, simple_export_t > export_initial_kv
Initial export key-value pairs.
Definition data_exporter.hpp:113
std::unique_ptr< impl > pimpl
Definition data_exporter.hpp:162
void set_logger(std::shared_ptr< IO::Logger > _logger)
Definition data_exporter.hpp:68
Kokkos::View< double **, Kokkos::LayoutRight, HostSpace > ViewParticleProperties
View for particle properties.
Definition data_exporter.hpp:103
DataExporter(DataExporter &&)=delete
DataExporter & operator=(const DataExporter &)=delete
Core component to perform simulation.
Definition data_exporter.hpp:19
bool check_results_file_name(Core::UserControlParameters &params)
Definition main_exporter.cpp:193
Describes the properties of a multi-dimensional matrix for export operations.
Definition data_exporter.hpp:87
std::vector< size_t > dims
Dataset dimensions.
Definition data_exporter.hpp:89
std::optional< std::vector< unsigned long long > > chunk_dims
Data chunk along each dimension.
Definition data_exporter.hpp:92
bool is_integer
Matrix data is integer type or floating point.
Definition data_exporter.hpp:94
std::vector< size_t > max_dims
Expected dataset max dimensions.
Definition data_exporter.hpp:90
bool compression
Matrix data has to be compressed or not.
Definition data_exporter.hpp:93
std::string name
Dataset name.
Definition data_exporter.hpp:88
A structure to hold user-defined control parameters for simulation settings.
Definition simulation_parameters.hpp:24
Definition execinfo.hpp:12