Skip to content

Commit ba1d0ff

Browse files
committed
Basically working reading
needed also support for availableChunks
1 parent aa17b83 commit ba1d0ff

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

include/openPMD/toolkit/ExternalBlockStorage.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class ExternalBlockStorage
101101
void read(
102102
Offset blockOffset,
103103
Extent blockExtent,
104-
nlohmann::json &fullJsonDataset,
104+
nlohmann::json const &fullJsonDataset,
105105
nlohmann::json::json_pointer const &path,
106106
T *data);
107107

src/IO/JSON/JSONIOHandlerImpl.cpp

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,9 +1104,44 @@ void JSONIOHandlerImpl::availableChunks(
11041104
{
11051105
refreshFileFromParent(writable);
11061106
auto filePosition = setAndGetFilePosition(writable);
1107-
auto &j = obtainJsonContents(writable)["data"];
1108-
*parameters.chunks = chunksInJSON(j);
1109-
chunk_assignment::mergeChunks(*parameters.chunks);
1107+
auto &j = obtainJsonContents(writable);
1108+
1109+
auto [extent, datasetmode] = getExtent(j, m_datasetMode.m_mode);
1110+
1111+
std::visit(
1112+
auxiliary::overloaded{
1113+
[&](DatasetMode::Dataset_t const &) {
1114+
*parameters.chunks = chunksInJSON(j.at("data"));
1115+
chunk_assignment::mergeChunks(*parameters.chunks);
1116+
},
1117+
[&](DatasetMode::Template_t const &) {
1118+
/* no-op, no chunks to be loaded */
1119+
},
1120+
[&](DatasetMode::External_t &) {
1121+
auto external_blocks = j.at("external_blocks");
1122+
auto &res = *parameters.chunks;
1123+
res.reserve(external_blocks.size());
1124+
for (auto it = external_blocks.begin();
1125+
it != external_blocks.end();
1126+
++it)
1127+
{
1128+
auto const &block = it.value();
1129+
try
1130+
{
1131+
auto const &o = block.at("offset").get<Offset>();
1132+
auto const &e = block.at("extent").get<Extent>();
1133+
res.emplace_back(o, e);
1134+
}
1135+
catch (nlohmann::json::exception const &e)
1136+
{
1137+
std::cerr << "[JSONIOHandlerImpl::availableChunks] "
1138+
"Could not parse block '"
1139+
<< it.key() << "'. Original error was:\n"
1140+
<< e.what();
1141+
}
1142+
}
1143+
}},
1144+
datasetmode.as_base());
11101145
}
11111146

11121147
void JSONIOHandlerImpl::openFile(

src/toolkit/ExternalBlockStorage.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ template <typename DatatypeHandling, typename T>
167167
void ExternalBlockStorage::read(
168168
Offset blockOffset,
169169
Extent blockExtent,
170-
nlohmann::json &fullJsonDataset,
170+
nlohmann::json const &fullJsonDataset,
171171
nlohmann::json::json_pointer const &path,
172172
T *data)
173173
{
@@ -176,7 +176,7 @@ void ExternalBlockStorage::read(
176176
{
177177
throw std::runtime_error("Inconsistent chunk storage in datatype.");
178178
}
179-
auto external_blocks = dataset["external_blocks"];
179+
auto external_blocks = dataset.at("external_blocks");
180180
bool found_a_precise_match = false;
181181
for (auto it = external_blocks.begin(); it != external_blocks.end(); ++it)
182182
{
@@ -247,7 +247,7 @@ void ExternalBlockStorage::sanitizeString(std::string &s)
247247
template void ExternalBlockStorage::read<datatypehandling, type>( \
248248
Offset blockOffset, \
249249
Extent blockExtent, \
250-
nlohmann::json & fullJsonDataset, \
250+
nlohmann::json const &fullJsonDataset, \
251251
nlohmann::json::json_pointer const &path, \
252252
type *data);
253253
#define OPENPMD_INSTANTIATE(type) \

0 commit comments

Comments
 (0)