Skip to content

Commit b34cb35

Browse files
committed
Backends: openPath for empty groups, re-inquire variables
1 parent 5d33500 commit b34cb35

File tree

6 files changed

+54
-24
lines changed

6 files changed

+54
-24
lines changed

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
@@ -468,7 +468,9 @@ void ADIOS2IOHandlerImpl::openPath(
468468
std::string prefix =
469469
filePositionToString( setAndGetFilePosition( writable->parent ) );
470470
std::string suffix = auxiliary::removeSlashes( parameters.path );
471-
std::string infix = auxiliary::ends_with( prefix, '/' ) ? "" : "/";
471+
std::string infix = suffix.empty() || auxiliary::ends_with( prefix, '/' )
472+
? ""
473+
: "/";
472474

473475
/* ADIOS has no concept for explicitly creating paths.
474476
* They are implicitly created with the paths of variables/attributes. */
@@ -1379,9 +1381,27 @@ namespace detail
13791381
adios2::Dims const & count,
13801382
bool const constantDims )
13811383
{
1382-
adios2::Variable< T > var =
1383-
IO.DefineVariable< T >( name, shape, start, count, constantDims );
1384-
if ( !var )
1384+
/*
1385+
* Step/Variable-based iteration layout:
1386+
* The variable may already be defined from a previous step,
1387+
* so check if it's already here.
1388+
*/
1389+
adios2::Variable< T > var = IO.InquireVariable< T >( name );
1390+
if( !var )
1391+
{
1392+
var = IO.DefineVariable< T >(
1393+
name, shape, start, count, constantDims );
1394+
}
1395+
else
1396+
{
1397+
var.SetShape( shape );
1398+
if( count.size() > 0 )
1399+
{
1400+
var.SetSelection( { start, count } );
1401+
}
1402+
}
1403+
1404+
if( !var )
13851405
{
13861406
throw std::runtime_error(
13871407
"[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)