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
69 set_logger(std::shared_ptr<IO::Logger> _logger)
70 {
71 logger = std::move(_logger);
72 }
73
74 protected:
75 std::shared_ptr<IO::Logger> logger;
76
88 {
89 std::string name;
90 std::vector<size_t> dims;
91 std::vector<size_t> max_dims;
92 std::optional<std::vector<unsigned long long> >
96 };
97
98 // Using type definitions with aligned comments
100 = std::variant<uint64_t, int, std::string>;
103 = std::unordered_map<std::string,
107 = Kokkos::View<double**,
108 Kokkos::LayoutRight,
109 HostSpace>;
110 using simple_export_t = std::variant<size_t,
111 std::string,
112 std::vector<size_t>,
113 double,
114 uint32_t>;
117 = std::unordered_map<std::string,
120
121 using matrix_variant_t
122 = std::variant<std::span<const double>,
123 std::span<const std::size_t>,
124 double>;
125
126 // Methods
128 explicit DataExporter(const ExecInfo& info,
129 std::string_view _filename,
130 std::optional<export_metadata_t> user_description
131 = std::nullopt);
133
134 void write_matrix(std::string_view name,
135 std::span<const double> values,
136 bool compress = false);
137
138 void write_matrix(std::string_view name,
139 std::span<const double> values,
140 size_t n_row,
141 size_t n_col,
142 bool compress = false);
143
144 void prepare_matrix(MultiMatrixDescription description);
145
146 void append_matrix(std::string_view name, matrix_variant_t data);
147
148 void append_array(std::string_view name,
149 std::span<const double> data,
150 uint64_t last_size = 0);
151
152 void write_properties(std::optional<std::string> specific_dataspace,
153 const export_metadata_kv& values);
154
155 void write_simple(const export_initial_kv& values, std::string_view root);
157 void write_simple(std::string specific_dataspace,
158 const simple_export_t& values);
161 uint64_t export_counter = 0;
162
163 private:
164 std::unordered_map<std::string, MultiMatrixDescription> descriptors;
165 class impl;
166 std::unique_ptr<impl> pimpl;
167 };
168
169} // namespace Core
170#endif
Definition impl_default_dataexporter.cpp:8
void append_matrix(std::string_view name, matrix_variant_t data)
Definition impl_default_dataexporter.cpp:41
void append_array(std::string_view name, std::span< const double > data, uint64_t last_size=0)
Definition impl_default_dataexporter.cpp:46
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:11
std::variant< uint64_t, int, std::string > export_metadata_t
Definition data_exporter.hpp:99
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
void write_simple(const export_initial_kv &values, std::string_view root)
Definition impl_default_dataexporter.cpp:68
std::unordered_map< std::string, MultiMatrixDescription > descriptors
Definition data_exporter.hpp:159
std::shared_ptr< IO::Logger > logger
Definition data_exporter.hpp:75
void write_matrix(std::string_view name, std::span< const double > values, bool compress=false)
Definition impl_default_dataexporter.cpp:29
uint64_t export_counter
Definition data_exporter.hpp:156
void write_properties(std::optional< std::string > specific_dataspace, const export_metadata_kv &values)
Definition impl_default_dataexporter.cpp:53
std::variant< size_t, std::string, std::vector< size_t >, double, uint32_t > simple_export_t
Definition data_exporter.hpp:107
std::unordered_map< std::string, export_metadata_t > export_metadata_kv
Definition data_exporter.hpp:101
DataExporter()=default
void prepare_matrix(MultiMatrixDescription description)
Definition impl_default_dataexporter.cpp:36
DataExporter(const DataExporter &)=delete
DataExporter & operator=(DataExporter &&)=delete
Kokkos::View< double **, Kokkos::LayoutRight, HostSpace > ViewParticleProperties
View for particle properties.
Definition data_exporter.hpp:104
export_metadata_kv metadata
Definition data_exporter.hpp:155
std::unique_ptr< impl > pimpl
Definition data_exporter.hpp:161
std::unordered_map< std::string, simple_export_t > export_initial_kv
Definition data_exporter.hpp:113
void set_logger(std::shared_ptr< IO::Logger > _logger)
Definition data_exporter.hpp:69
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:198
Describes the properties of a multi-dimensional matrix for export operations.
Definition data_exporter.hpp:88
std::vector< size_t > dims
Dataset dimensions.
Definition data_exporter.hpp:90
std::optional< std::vector< unsigned long long > > chunk_dims
Data chunk along each dimension.
Definition data_exporter.hpp:93
bool is_integer
Matrix data is integer type or floating point.
Definition data_exporter.hpp:95
std::vector< size_t > max_dims
Expected dataset max dimensions.
Definition data_exporter.hpp:91
bool compression
Matrix data has to be compressed or not.
Definition data_exporter.hpp:94
std::string name
Dataset name.
Definition data_exporter.hpp:89
A structure to hold user-defined control parameters for simulation settings.
Definition simulation_parameters.hpp:24
Definition execinfo.hpp:12