Skip to content

Commit 569303d

Browse files
committed
Backends: openPath for empty groups, re-inquire variables
1 parent ef0ec3e commit 569303d

6 files changed

Lines changed: 54 additions & 24 deletions

File tree

include/openPMD/IO/AbstractIOHandlerImpl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ class AbstractIOHandlerImpl
238238
*
239239
* The operation should overwrite existing file positions, even when the Writable was already marked written.
240240
* The path parameters.path may contain multiple levels (e.g. first/second/third/). This path should be relative (i.e. it should not start with a slash "/").
241+
* The number of levels may be zero, i.e. parameters.path may be an empty string.
241242
* The Writables file position should correspond to the complete opened path (i.e. first/second/third/ should be assigned to the Writables file position).
242243
* The Writable should be marked written when the operation completes successfully.
243244
*/

src/IO/ADIOS/ADIOS1IOHandler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ ADIOS1IOHandlerImpl::flush()
9595
case O::CREATE_PATH:
9696
createPath(i.writable, deref_dynamic_cast< Parameter< O::CREATE_PATH > >(i.parameter.get()));
9797
break;
98+
case O::OPEN_PATH:
99+
openPath(i.writable, deref_dynamic_cast< Parameter< O::OPEN_PATH > >(i.parameter.get()));
100+
break;
98101
case O::CREATE_DATASET:
99102
createDataset(i.writable, deref_dynamic_cast< Parameter< O::CREATE_DATASET > >(i.parameter.get()));
100103
break;
@@ -129,9 +132,6 @@ ADIOS1IOHandlerImpl::flush()
129132
case O::EXTEND_DATASET:
130133
extendDataset(i.writable, deref_dynamic_cast< Parameter< O::EXTEND_DATASET > >(i.parameter.get()));
131134
break;
132-
case O::OPEN_PATH:
133-
openPath(i.writable, deref_dynamic_cast< Parameter< O::OPEN_PATH > >(i.parameter.get()));
134-
break;
135135
case O::CLOSE_PATH:
136136
closePath(i.writable, deref_dynamic_cast< Parameter< O::CLOSE_PATH > >(i.parameter.get()));
137137
break;
@@ -240,6 +240,7 @@ ADIOS1IOHandler::enqueue(IOTask const& i)
240240
{
241241
case Operation::CREATE_FILE:
242242
case Operation::CREATE_PATH:
243+
case Operation::OPEN_PATH:
243244
case Operation::CREATE_DATASET:
244245
case Operation::OPEN_FILE:
245246
case Operation::WRITE_ATT:

src/IO/ADIOS/ADIOS2IOHandler.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,9 @@ void ADIOS2IOHandlerImpl::openPath(
474474
std::string prefix =
475475
filePositionToString( setAndGetFilePosition( writable->parent ) );
476476
std::string suffix = auxiliary::removeSlashes( parameters.path );
477-
std::string infix = auxiliary::ends_with( prefix, '/' ) ? "" : "/";
477+
std::string infix = suffix.empty() || auxiliary::ends_with( prefix, '/' )
478+
? ""
479+
: "/";
478480

479481
/* ADIOS has no concept for explicitly creating paths.
480482
* They are implicitly created with the paths of variables/attributes. */
@@ -1836,9 +1838,27 @@ namespace detail
18361838
const adios2::Dims & count,
18371839
const bool constantDims )
18381840
{
1839-
adios2::Variable< T > var =
1840-
IO.DefineVariable< T >( name, shape, start, count, constantDims );
1841-
if ( !var )
1841+
/*
1842+
* Step/Variable-based iteration layout:
1843+
* The variable may already be defined from a previous step,
1844+
* so check if it's already here.
1845+
*/
1846+
adios2::Variable< T > var = IO.InquireVariable< T >( name );
1847+
if( !var )
1848+
{
1849+
var = IO.DefineVariable< T >(
1850+
name, shape, start, count, constantDims );
1851+
}
1852+
else
1853+
{
1854+
var.SetShape( shape );
1855+
if( count.size() > 0 )
1856+
{
1857+
var.SetSelection( { start, count } );
1858+
}
1859+
}
1860+
1861+
if( !var )
18421862
{
18431863
throw std::runtime_error(
18441864
"[ADIOS2] Internal error: Could not create Variable '" + name + "'." );

src/IO/ADIOS/CommonADIOS1IOHandler.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,13 @@ CommonADIOS1IOHandlerImpl::openPath(
677677
{
678678
/* Sanitize path */
679679
std::string path = parameters.path;
680-
if( auxiliary::starts_with(path, '/') )
681-
path = auxiliary::replace_first(path, "/", "");
682-
if( !auxiliary::ends_with(path, '/') )
683-
path += '/';
680+
if( !path.empty() )
681+
{
682+
if( auxiliary::starts_with(path, '/') )
683+
path = auxiliary::replace_first(path, "/", "");
684+
if( !auxiliary::ends_with(path, '/') )
685+
path += '/';
686+
}
684687

685688
writable->written = true;
686689
writable->abstractFilePosition = std::make_shared< ADIOS1FilePosition >(path);

src/IO/ADIOS/ParallelADIOS1IOHandler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ ParallelADIOS1IOHandlerImpl::flush()
119119
case O::CREATE_PATH:
120120
createPath(i.writable, deref_dynamic_cast< Parameter< O::CREATE_PATH > >(i.parameter.get()));
121121
break;
122+
case O::OPEN_PATH:
123+
openPath(i.writable, deref_dynamic_cast< Parameter< O::OPEN_PATH > >(i.parameter.get()));
124+
break;
122125
case O::CREATE_DATASET:
123126
createDataset(i.writable, deref_dynamic_cast< Parameter< O::CREATE_DATASET > >(i.parameter.get()));
124127
break;
@@ -151,9 +154,6 @@ ParallelADIOS1IOHandlerImpl::flush()
151154
case O::EXTEND_DATASET:
152155
extendDataset(i.writable, deref_dynamic_cast< Parameter< O::EXTEND_DATASET > >(i.parameter.get()));
153156
break;
154-
case O::OPEN_PATH:
155-
openPath(i.writable, deref_dynamic_cast< Parameter< O::OPEN_PATH > >(i.parameter.get()));
156-
break;
157157
case O::CLOSE_PATH:
158158
closePath(i.writable, deref_dynamic_cast< Parameter< O::CLOSE_PATH > >(i.parameter.get()));
159159
break;
@@ -262,6 +262,7 @@ ParallelADIOS1IOHandler::enqueue(IOTask const& i)
262262
{
263263
case Operation::CREATE_FILE:
264264
case Operation::CREATE_PATH:
265+
case Operation::OPEN_PATH:
265266
case Operation::CREATE_DATASET:
266267
case Operation::OPEN_FILE:
267268
case Operation::WRITE_ATT:

src/IO/HDF5/HDF5IOHandler.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -519,19 +519,23 @@ HDF5IOHandlerImpl::openPath(
519519

520520
/* Sanitize path */
521521
std::string path = parameters.path;
522-
if( auxiliary::starts_with(path, '/') )
523-
path = auxiliary::replace_first(path, "/", "");
524-
if( !auxiliary::ends_with(path, '/') )
525-
path += '/';
522+
if( !path.empty() )
523+
{
524+
if( auxiliary::starts_with(path, '/') )
525+
path = auxiliary::replace_first(path, "/", "");
526+
if( !auxiliary::ends_with(path, '/') )
527+
path += '/';
528+
path_id = H5Gopen(node_id,
529+
path.c_str(),
530+
H5P_DEFAULT);
531+
VERIFY(path_id >= 0, "[HDF5] Internal error: Failed to open HDF5 group during path opening");
526532

527-
path_id = H5Gopen(node_id,
528-
path.c_str(),
529-
H5P_DEFAULT);
530-
VERIFY(path_id >= 0, "[HDF5] Internal error: Failed to open HDF5 group during path opening");
533+
herr_t status;
534+
status = H5Gclose(path_id);
535+
VERIFY(status == 0, "[HDF5] Internal error: Failed to close HDF5 group during path opening");
536+
}
531537

532538
herr_t status;
533-
status = H5Gclose(path_id);
534-
VERIFY(status == 0, "[HDF5] Internal error: Failed to close HDF5 group during path opening");
535539
status = H5Gclose(node_id);
536540
VERIFY(status == 0, "[HDF5] Internal error: Failed to close HDF5 group during path opening");
537541

0 commit comments

Comments
 (0)