Skip to content

Commit 942e214

Browse files
committed
WIP: Config for external block storage from JSON
1 parent 25ec92d commit 942e214

File tree

3 files changed

+341
-241
lines changed

3 files changed

+341
-241
lines changed

include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp

Lines changed: 82 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include <istream>
3535
#include <nlohmann/json.hpp>
36+
#include <variant>
3637
#if openPMD_HAVE_MPI
3738
#include <mpi.h>
3839
#endif
@@ -196,6 +197,15 @@ struct JsonDatatypeHandling
196197

197198
namespace openPMD
198199
{
200+
namespace dataset_mode_types
201+
{
202+
struct Dataset_t
203+
{};
204+
struct Template_t
205+
{};
206+
using External_t = std::shared_ptr<ExternalBlockStorage>;
207+
} // namespace dataset_mode_types
208+
199209
class JSONIOHandlerImpl : public AbstractIOHandlerImpl
200210
{
201211
using json = nlohmann::json;
@@ -218,8 +228,6 @@ class JSONIOHandlerImpl : public AbstractIOHandlerImpl
218228
std::string originalExtension);
219229
#endif
220230

221-
ExternalBlockStorage externalBlockStorage;
222-
223231
void init(openPMD::json::TracingJSON config);
224232

225233
~JSONIOHandlerImpl() override;
@@ -286,42 +294,6 @@ class JSONIOHandlerImpl : public AbstractIOHandlerImpl
286294

287295
std::future<void> flush();
288296

289-
private:
290-
#if openPMD_HAVE_MPI
291-
std::optional<MPI_Comm> m_communicator;
292-
#endif
293-
294-
using FILEHANDLE = std::fstream;
295-
296-
// map each Writable to its associated file
297-
// contains only the filename, without the OS path
298-
std::unordered_map<Writable *, File> m_files;
299-
300-
std::unordered_map<File, std::shared_ptr<nlohmann::json>> m_jsonVals;
301-
302-
// files that have logically, but not physically been written to
303-
std::unordered_set<File> m_dirty;
304-
305-
/*
306-
* Is set by constructor.
307-
*/
308-
FileFormat m_fileFormat{};
309-
310-
/*
311-
* Under which key do we find the backend configuration?
312-
* -> "json" for the JSON backend, "toml" for the TOML backend.
313-
*/
314-
std::string backendConfigKey() const;
315-
316-
/*
317-
* First return value: The location of the JSON value (either "json" or
318-
* "toml") Second return value: The value that was maybe found at this place
319-
*/
320-
std::pair<std::string, std::optional<openPMD::json::TracingJSON>>
321-
getBackendConfig(openPMD::json::TracingJSON &) const;
322-
323-
std::string m_originalExtension;
324-
325297
/*
326298
* Was the config value explicitly user-chosen, or are we still working with
327299
* defaults?
@@ -336,17 +308,36 @@ class JSONIOHandlerImpl : public AbstractIOHandlerImpl
336308
// Dataset IO mode //
337309
/////////////////////
338310

339-
enum class DatasetMode
311+
struct DatasetMode
312+
: std::variant<
313+
dataset_mode_types::Dataset_t,
314+
dataset_mode_types::Template_t,
315+
dataset_mode_types::External_t>
340316
{
341-
Dataset,
342-
Template
317+
using Dataset_t = dataset_mode_types::Dataset_t;
318+
using Template_t = dataset_mode_types::Template_t;
319+
using External_t = dataset_mode_types::External_t;
320+
constexpr static Dataset_t Dataset{};
321+
constexpr static Template_t Template{};
322+
323+
using variant_t = std::variant<
324+
dataset_mode_types::Dataset_t,
325+
dataset_mode_types::Template_t,
326+
External_t>;
327+
using variant_t ::operator=;
328+
329+
// casts needed because of
330+
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90943
331+
inline auto as_base() const -> variant_t const &
332+
{
333+
return *this;
334+
}
335+
inline auto as_base() -> variant_t &
336+
{
337+
return *this;
338+
}
343339
};
344340

345-
// IOMode m_mode{};
346-
// SpecificationVia m_IOModeSpecificationVia =
347-
// SpecificationVia::DefaultValue; bool m_printedSkippedWriteWarningAlready
348-
// = false;
349-
350341
struct DatasetMode_s
351342
{
352343
// Initialized in init()
@@ -361,8 +352,6 @@ class JSONIOHandlerImpl : public AbstractIOHandlerImpl
361352
m_mode, m_specificationVia, m_skipWarnings};
362353
}
363354
};
364-
DatasetMode_s m_datasetMode;
365-
DatasetMode_s retrieveDatasetMode(openPMD::json::TracingJSON &config) const;
366355

367356
///////////////////////
368357
// Attribute IO mode //
@@ -381,8 +370,50 @@ class JSONIOHandlerImpl : public AbstractIOHandlerImpl
381370
AttributeMode m_mode{};
382371
SpecificationVia m_specificationVia = SpecificationVia::DefaultValue;
383372
};
384-
AttributeMode_s m_attributeMode;
385373

374+
private:
375+
#if openPMD_HAVE_MPI
376+
std::optional<MPI_Comm> m_communicator;
377+
#endif
378+
379+
using FILEHANDLE = std::fstream;
380+
381+
// map each Writable to its associated file
382+
// contains only the filename, without the OS path
383+
std::unordered_map<Writable *, File> m_files;
384+
385+
std::unordered_map<File, std::shared_ptr<nlohmann::json>> m_jsonVals;
386+
387+
// files that have logically, but not physically been written to
388+
std::unordered_set<File> m_dirty;
389+
390+
/*
391+
* Is set by constructor.
392+
*/
393+
FileFormat m_fileFormat{};
394+
395+
/*
396+
* Under which key do we find the backend configuration?
397+
* -> "json" for the JSON backend, "toml" for the TOML backend.
398+
*/
399+
std::string backendConfigKey() const;
400+
401+
/*
402+
* First return value: The location of the JSON value (either "json" or
403+
* "toml") Second return value: The value that was maybe found at this place
404+
*/
405+
std::pair<std::string, std::optional<openPMD::json::TracingJSON>>
406+
getBackendConfig(openPMD::json::TracingJSON &) const;
407+
static std::pair<std::string, std::optional<openPMD::json::TracingJSON>>
408+
getBackendConfig(
409+
openPMD::json::TracingJSON &, std::string const &configLocation);
410+
411+
std::string m_originalExtension;
412+
413+
DatasetMode_s m_datasetMode;
414+
DatasetMode_s retrieveDatasetMode(openPMD::json::TracingJSON &config) const;
415+
416+
AttributeMode_s m_attributeMode;
386417
AttributeMode_s
387418
retrieveAttributeMode(openPMD::json::TracingJSON &config) const;
388419

@@ -432,7 +463,8 @@ class JSONIOHandlerImpl : public AbstractIOHandlerImpl
432463
// essentially: m_i = \prod_{j=0}^{i-1} extent_j
433464
static Extent getMultiplicators(Extent const &extent);
434465

435-
static std::pair<Extent, DatasetMode> getExtent(nlohmann::json &j);
466+
static std::pair<Extent, DatasetMode>
467+
getExtent(nlohmann::json &j, DatasetMode const &baseMode);
436468

437469
// remove single '/' in the beginning and end of a string
438470
static std::string removeSlashes(std::string);

include/openPMD/toolkit/ExternalBlockStorage.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ class ExternalBlockStorage
7171
std::optional<std::string> infix, // e.g. for distinguishing MPI ranks
7272
T const *data) -> std::string;
7373

74+
auto externalStorageLocation() const -> nlohmann::json
75+
{
76+
return "implement me";
77+
}
78+
7479
static void sanitizeString(std::string &s);
7580
};
7681

0 commit comments

Comments
 (0)