diff --git a/include/openPMD/IO/AbstractIOHandlerImpl.hpp b/include/openPMD/IO/AbstractIOHandlerImpl.hpp index 1bca04f5d3..b0a4907a6a 100644 --- a/include/openPMD/IO/AbstractIOHandlerImpl.hpp +++ b/include/openPMD/IO/AbstractIOHandlerImpl.hpp @@ -26,7 +26,6 @@ #include "openPMD/auxiliary/DerefDynamicCast.hpp" #include -#include namespace openPMD { @@ -41,193 +40,7 @@ class AbstractIOHandlerImpl virtual ~AbstractIOHandlerImpl() = default; - std::future flush() - { - using namespace auxiliary; - - while (!(*m_handler).m_work.empty()) - { - IOTask &i = (*m_handler).m_work.front(); - try - { - switch (i.operation) - { - using O = Operation; - case O::CREATE_FILE: - createFile( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::CHECK_FILE: - checkFile( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::CREATE_PATH: - createPath( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::CREATE_DATASET: - createDataset( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::EXTEND_DATASET: - extendDataset( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::OPEN_FILE: - openFile( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::CLOSE_FILE: - closeFile( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::OPEN_PATH: - openPath( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::CLOSE_PATH: - closePath( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::OPEN_DATASET: - openDataset( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::DELETE_FILE: - deleteFile( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::DELETE_PATH: - deletePath( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::DELETE_DATASET: - deleteDataset( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::DELETE_ATT: - deleteAttribute( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::WRITE_DATASET: - writeDataset( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::WRITE_ATT: - writeAttribute( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::READ_DATASET: - readDataset( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::GET_BUFFER_VIEW: - getBufferView( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::READ_ATT: - readAttribute( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::LIST_PATHS: - listPaths( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::LIST_DATASETS: - listDatasets( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::LIST_ATTS: - listAttributes( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::ADVANCE: - advance( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::AVAILABLE_CHUNKS: - availableChunks( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::KEEP_SYNCHRONOUS: - keepSynchronous( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - case O::DEREGISTER: - deregister( - i.writable, - deref_dynamic_cast >( - i.parameter.get())); - break; - } - } - catch (...) - { - std::cerr << "[AbstractIOHandlerImpl] IO Task " - << internal::operationAsString(i.operation) - << " failed with exception. Clearing IO queue and " - "passing on the exception." - << std::endl; - while (!m_handler->m_work.empty()) - { - m_handler->m_work.pop(); - } - throw; - } - (*m_handler).m_work.pop(); - } - return std::future(); - } + std::future flush(); /** * Close the file corresponding with the writable and release file handles. diff --git a/src/IO/AbstractIOHandlerImpl.cpp b/src/IO/AbstractIOHandlerImpl.cpp index d762df6a1f..34eabaa043 100644 --- a/src/IO/AbstractIOHandlerImpl.cpp +++ b/src/IO/AbstractIOHandlerImpl.cpp @@ -22,6 +22,8 @@ #include "openPMD/IO/AbstractIOHandlerImpl.hpp" #include "openPMD/backend/Writable.hpp" +#include + namespace openPMD { void AbstractIOHandlerImpl::keepSynchronous( @@ -30,4 +32,341 @@ void AbstractIOHandlerImpl::keepSynchronous( writable->abstractFilePosition = param.otherWritable->abstractFilePosition; writable->written = true; } + +template +inline void writeToStderr([[maybe_unused]] Args &&...args) +{ +#if OPENPMD_DEBUG + (std::cerr << ... << args) << std::endl; +#endif +} + +std::future AbstractIOHandlerImpl::flush() +{ + using namespace auxiliary; + + while (!(*m_handler).m_work.empty()) + { + IOTask &i = (*m_handler).m_work.front(); + try + { + switch (i.operation) + { + using O = Operation; + case O::CREATE_FILE: { + auto ¶meter = deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", + i.writable->parent, + "->", + i.writable, + "] CREATE_FILE: ", + parameter.name); + createFile(i.writable, parameter); + break; + } + case O::CHECK_FILE: { + auto ¶meter = deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", + i.writable->parent, + "->", + i.writable, + "] CHECK_FILE: ", + parameter.name); + checkFile(i.writable, parameter); + break; + } + case O::CREATE_PATH: { + auto ¶meter = deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", + i.writable->parent, + "->", + i.writable, + "] CREATE_PATH: ", + parameter.path); + createPath(i.writable, parameter); + break; + } + case O::CREATE_DATASET: { + auto ¶meter = + deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", + i.writable->parent, + "->", + i.writable, + "] CREATE_DATASET: ", + parameter.name); + createDataset(i.writable, parameter); + break; + } + case O::EXTEND_DATASET: { + auto ¶meter = + deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", + i.writable->parent, + "->", + i.writable, + "] EXTEND_DATASET"); + extendDataset(i.writable, parameter); + break; + } + case O::OPEN_FILE: { + auto ¶meter = deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", + i.writable->parent, + "->", + i.writable, + "] OPEN_FILE: ", + parameter.name); + openFile(i.writable, parameter); + break; + } + case O::CLOSE_FILE: { + auto ¶meter = deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", i.writable->parent, "->", i.writable, "] CLOSE_FILE"); + closeFile(i.writable, parameter); + break; + } + case O::OPEN_PATH: { + auto ¶meter = deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", + i.writable->parent, + "->", + i.writable, + "] OPEN_PATH: ", + parameter.path); + openPath(i.writable, parameter); + break; + } + case O::CLOSE_PATH: { + auto ¶meter = deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", i.writable->parent, "->", i.writable, "] CLOSE_PATH"); + closePath(i.writable, parameter); + break; + } + case O::OPEN_DATASET: { + auto ¶meter = + deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", + i.writable->parent, + "->", + i.writable, + "] OPEN_DATASET: ", + parameter.name); + openDataset(i.writable, parameter); + break; + } + case O::DELETE_FILE: { + auto ¶meter = deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", i.writable->parent, "->", i.writable, "] DELETE_FILE"); + deleteFile(i.writable, parameter); + break; + } + case O::DELETE_PATH: { + auto ¶meter = deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", i.writable->parent, "->", i.writable, "] DELETE_PATH"); + deletePath(i.writable, parameter); + break; + } + case O::DELETE_DATASET: { + auto ¶meter = + deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", + i.writable->parent, + "->", + i.writable, + "] DELETE_DATASET"); + deleteDataset(i.writable, parameter); + break; + } + case O::DELETE_ATT: { + auto ¶meter = deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", i.writable->parent, "->", i.writable, "] DELETE_ATT"); + deleteAttribute(i.writable, parameter); + break; + } + case O::WRITE_DATASET: { + auto ¶meter = + deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", + i.writable->parent, + "->", + i.writable, + "] WRITE_DATASET"); + writeDataset(i.writable, parameter); + break; + } + case O::WRITE_ATT: { + auto ¶meter = deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", + i.writable->parent, + "->", + i.writable, + "] WRITE_ATT: (", + parameter.dtype, + ") ", + parameter.name); + writeAttribute(i.writable, parameter); + break; + } + case O::READ_DATASET: { + auto ¶meter = + deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", + i.writable->parent, + "->", + i.writable, + "] READ_DATASET"); + readDataset(i.writable, parameter); + break; + } + case O::GET_BUFFER_VIEW: { + auto ¶meter = + deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", + i.writable->parent, + "->", + i.writable, + "] GET_BUFFER_VIEW"); + getBufferView(i.writable, parameter); + break; + } + case O::READ_ATT: { + auto ¶meter = deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", + i.writable->parent, + "->", + i.writable, + "] READ_ATT: ", + parameter.name); + readAttribute(i.writable, parameter); + break; + } + case O::LIST_PATHS: { + auto ¶meter = deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", i.writable->parent, "->", i.writable, "] LIST_PATHS"); + listPaths(i.writable, parameter); + break; + } + case O::LIST_DATASETS: { + auto ¶meter = + deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", + i.writable->parent, + "->", + i.writable, + "] LIST_DATASETS"); + listDatasets(i.writable, parameter); + break; + } + case O::LIST_ATTS: { + auto ¶meter = deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", i.writable->parent, "->", i.writable, "] LIST_ATTS"); + listAttributes(i.writable, parameter); + break; + } + case O::ADVANCE: { + auto ¶meter = deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", i.writable->parent, "->", i.writable, "] ADVANCE"); + advance(i.writable, parameter); + break; + } + case O::AVAILABLE_CHUNKS: { + auto ¶meter = + deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", + i.writable->parent, + "->", + i.writable, + "] AVAILABLE_CHUNKS"); + availableChunks(i.writable, parameter); + break; + } + case O::KEEP_SYNCHRONOUS: { + auto ¶meter = + deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", + i.writable->parent, + "->", + i.writable, + "] KEEP_SYNCHRONOUS"); + keepSynchronous(i.writable, parameter); + break; + } + case O::DEREGISTER: { + auto ¶meter = deref_dynamic_cast>( + i.parameter.get()); + writeToStderr( + "[", i.writable->parent, "->", i.writable, "] DEREGISTER"); + deregister(i.writable, parameter); + break; + } + } + } + catch (...) + { + std::cerr << "[AbstractIOHandlerImpl] IO Task " + << internal::operationAsString(i.operation) + << " failed with exception. Clearing IO queue and " + "passing on the exception." + << std::endl; + while (!m_handler->m_work.empty()) + { + m_handler->m_work.pop(); + } + throw; + } + (*m_handler).m_work.pop(); + } + return std::future(); +} } // namespace openPMD