Skip to content

Commit e15e440

Browse files
committed
Backend additions
1) New streaming status: RANDOM_ACCESS, for non-streaming situations 2) Variable attributes, to be written only if the backend has support for steps
1 parent 05eff02 commit e15e440

File tree

8 files changed

+51
-13
lines changed

8 files changed

+51
-13
lines changed

include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,13 +1225,6 @@ namespace detail
12251225
void
12261226
invalidateVariablesMap();
12271227

1228-
private:
1229-
ADIOS2IOHandlerImpl * m_impl;
1230-
auxiliary::Option< adios2::Engine > m_engine; //! ADIOS engine
1231-
/**
1232-
* The ADIOS2 engine type, to be passed to adios2::IO::SetEngine
1233-
*/
1234-
std::string m_engineType;
12351228
/*
12361229
* streamStatus is NoStream for file-based ADIOS engines.
12371230
* This is relevant for the method BufferedActions::requireActiveStep,
@@ -1322,6 +1315,14 @@ namespace detail
13221315
Undecided
13231316
};
13241317
StreamStatus streamStatus = StreamStatus::OutsideOfStep;
1318+
1319+
private:
1320+
ADIOS2IOHandlerImpl * m_impl;
1321+
auxiliary::Option< adios2::Engine > m_engine; //! ADIOS engine
1322+
/**
1323+
* The ADIOS2 engine type, to be passed to adios2::IO::SetEngine
1324+
*/
1325+
std::string m_engineType;
13251326
adios2::StepStatus m_lastStepStatus = adios2::StepStatus::OK;
13261327

13271328
/**

include/openPMD/IO/AbstractIOHandlerImpl.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,10 @@ class AbstractIOHandlerImpl
156156
* The return status code shall be stored as parameters.status.
157157
*/
158158
virtual void
159-
advance( Writable *, Parameter< Operation::ADVANCE > & )
160-
{}
159+
advance( Writable *, Parameter< Operation::ADVANCE > & parameters )
160+
{
161+
*parameters.status = AdvanceStatus::RANDOMACCESS;
162+
}
161163

162164
/** Close an openPMD group.
163165
*
@@ -336,6 +338,11 @@ class AbstractIOHandlerImpl
336338
* The attribute should be of datatype parameters.dtype.
337339
* Any existing attribute with the same name should be overwritten. If possible, only the value should be changed if the datatype stays the same.
338340
* The attribute should be written to physical storage after the operation completes successfully.
341+
* If the parameter changesOverSteps is true, then the attribute must be able
342+
* to hold different values across IO steps. If the backend does not support
343+
* IO steps in such a way, the attribute should not be written.
344+
* (IO steps are an optional backend feature and the frontend must implement
345+
* fallback measures in such a case)
339346
* All datatypes of Datatype should be supported in a type-safe way.
340347
*/
341348
virtual void writeAttribute(Writable*, Parameter< Operation::WRITE_ATT > const&) = 0;

include/openPMD/IO/IOTask.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,8 @@ struct OPENPMDAPI_EXPORT Parameter< Operation::WRITE_ATT > : public AbstractPara
485485
{
486486
Parameter() = default;
487487
Parameter(Parameter const & p) : AbstractParameter(),
488-
name(p.name), dtype(p.dtype), resource(p.resource) {}
488+
name(p.name), dtype(p.dtype), changesOverSteps(p.changesOverSteps),
489+
resource(p.resource) {}
489490

490491
std::unique_ptr< AbstractParameter >
491492
clone() const override
@@ -496,6 +497,7 @@ struct OPENPMDAPI_EXPORT Parameter< Operation::WRITE_ATT > : public AbstractPara
496497

497498
std::string name = "";
498499
Datatype dtype = Datatype::UNDEFINED;
500+
bool changesOverSteps = false;
499501
Attribute::resource resource;
500502
};
501503

include/openPMD/Streaming.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ namespace openPMD
1919
*/
2020
enum class AdvanceStatus : unsigned char
2121
{
22-
OK, /* stream goes on */
23-
OVER /* stream is over */
22+
OK, /* stream goes on */
23+
OVER, /* stream is over */
24+
RANDOMACCESS /* there is no stream, it will never be over */
2425
};
2526

2627
/**

src/IO/ADIOS/ADIOS2IOHandler.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,11 @@ void ADIOS2IOHandlerImpl::writeAttribute(
617617
switch( attributeLayout() )
618618
{
619619
case AttributeLayout::ByAdiosAttributes:
620+
if( parameters.changesOverSteps )
621+
{
622+
// cannot do this
623+
return;
624+
}
620625
switchType< detail::OldAttributeWriter >(
621626
parameters.dtype,
622627
this,
@@ -634,6 +639,13 @@ void ADIOS2IOHandlerImpl::writeAttribute(
634639
auto prefix = filePositionToString( pos );
635640

636641
auto & filedata = getFileData( file, IfFileNotOpen::ThrowError );
642+
if( parameters.changesOverSteps &&
643+
filedata.streamStatus ==
644+
detail::BufferedActions::StreamStatus::NoStream )
645+
{
646+
// cannot do this
647+
return;
648+
}
637649
filedata.invalidateAttributesMap();
638650
m_dirty.emplace( std::move( file ) );
639651

@@ -2785,7 +2797,7 @@ namespace detail
27852797
m_IO.DefineAttribute< bool_representation >(
27862798
ADIOS2Defaults::str_usesstepsAttribute, 0 );
27872799
flush( FlushLevel::UserFlush, /* writeAttributes = */ false );
2788-
return AdvanceStatus::OK;
2800+
return AdvanceStatus::RANDOMACCESS;
27892801
}
27902802

27912803
m_IO.DefineAttribute< bool_representation >(

src/IO/ADIOS/CommonADIOS1IOHandler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,11 @@ void
10521052
CommonADIOS1IOHandlerImpl< ChildClass >::writeAttribute(Writable* writable,
10531053
Parameter< Operation::WRITE_ATT > const& parameters)
10541054
{
1055+
if( parameters.changesOverSteps )
1056+
{
1057+
// cannot do this
1058+
return;
1059+
}
10551060
if( m_handler->m_backendAccess == Access::READ_ONLY )
10561061
throw std::runtime_error("[ADIOS1] Writing an attribute in a file opened as read only is not possible.");
10571062

src/IO/HDF5/HDF5IOHandler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,11 @@ void
10441044
HDF5IOHandlerImpl::writeAttribute(Writable* writable,
10451045
Parameter< Operation::WRITE_ATT > const& parameters)
10461046
{
1047+
if( parameters.changesOverSteps )
1048+
{
1049+
// cannot do this
1050+
return;
1051+
}
10471052
if( m_handler->m_backendAccess == Access::READ_ONLY )
10481053
throw std::runtime_error("[HDF5] Writing an attribute in a file opened as read only is not possible.");
10491054

src/IO/JSON/JSONIOHandlerImpl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,11 @@ namespace openPMD
907907
Parameter< Operation::WRITE_ATT > const & parameter
908908
)
909909
{
910+
if( parameter.changesOverSteps )
911+
{
912+
// cannot do this
913+
return;
914+
}
910915
if(m_handler->m_backendAccess == Access::READ_ONLY )
911916
{
912917
throw std::runtime_error( "[JSON] Creating a dataset in a file opened as read only is not possible." );

0 commit comments

Comments
 (0)