Skip to content

Commit f391901

Browse files
committed
Make automatic recognition of access mode more intelligent
Previous commits uncovered an old bug
1 parent 7d964c3 commit f391901

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@ class ADIOS2IOHandlerImpl
194194
* @brief The ADIOS2 access type to chose for Engines opened
195195
* within this instance.
196196
*/
197-
adios2::Mode adios2AccessMode( );
198-
197+
adios2::Mode adios2AccessMode( std::string const & fullPath );
199198

200199
private:
201200
adios2::ADIOS m_ADIOS;

src/IO/ADIOS/ADIOS2IOHandler.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -903,19 +903,31 @@ ADIOS2IOHandlerImpl::availableChunks(
903903
switchType( datatype, rbi, parameters, ba.m_IO, engine, varName );
904904
}
905905

906-
adios2::Mode ADIOS2IOHandlerImpl::adios2AccessMode( )
906+
adios2::Mode
907+
ADIOS2IOHandlerImpl::adios2AccessMode( std::string const & fullPath )
907908
{
908-
switch ( m_handler->m_backendAccess )
909+
switch( m_handler->m_backendAccess )
909910
{
910911
case Access::CREATE:
911912
return adios2::Mode::Write;
912913
case Access::READ_ONLY:
913914
return adios2::Mode::Read;
914915
case Access::READ_WRITE:
915-
std::cerr << "ADIOS2 does currently not yet implement ReadWrite "
916-
"(Append) mode. "
917-
<< "Replacing with Read mode." << std::endl;
918-
return adios2::Mode::Read;
916+
if( auxiliary::directory_exists( fullPath ) ||
917+
auxiliary::file_exists( fullPath ) )
918+
{
919+
std::cerr << "ADIOS2 does currently not yet implement ReadWrite "
920+
"(Append) mode. "
921+
<< "Replacing with Read mode." << std::endl;
922+
return adios2::Mode::Read;
923+
}
924+
else
925+
{
926+
std::cerr << "ADIOS2 does currently not yet implement ReadWrite "
927+
"(Append) mode. "
928+
<< "Replacing with Write mode." << std::endl;
929+
return adios2::Mode::Write;
930+
}
919931
default:
920932
return adios2::Mode::Undefined;
921933
}
@@ -2047,13 +2059,12 @@ namespace detail
20472059
}
20482060

20492061
BufferedActions::BufferedActions(
2050-
ADIOS2IOHandlerImpl & impl,
2051-
InvalidatableFile file )
2062+
ADIOS2IOHandlerImpl & impl, InvalidatableFile file )
20522063
: m_file( impl.fullPath( std::move( file ) ) )
20532064
, m_IOName( std::to_string( impl.nameCounter++ ) )
20542065
, m_ADIOS( impl.m_ADIOS )
20552066
, m_IO( impl.m_ADIOS.DeclareIO( m_IOName ) )
2056-
, m_mode( impl.adios2AccessMode() )
2067+
, m_mode( impl.adios2AccessMode( m_file ) )
20572068
, m_writeDataset( &impl )
20582069
, m_readDataset( &impl )
20592070
, m_attributeReader()

0 commit comments

Comments
 (0)