|
| 1 | +/* Copyright 2017-2021 Fabian Koller and Franz Poeschel |
| 2 | + * |
| 3 | + * This file is part of openPMD-api. |
| 4 | + * |
| 5 | + * openPMD-api is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of of either the GNU General Public License or |
| 7 | + * the GNU Lesser General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * openPMD-api is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License and the GNU Lesser General Public License |
| 15 | + * for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * and the GNU Lesser General Public License along with openPMD-api. |
| 19 | + * If not, see <http://www.gnu.org/licenses/>. |
| 20 | + */ |
| 21 | +#pragma once |
| 22 | + |
| 23 | +#include "openPMD/config.hpp" |
| 24 | + |
| 25 | +#if openPMD_HAVE_ADIOS1 |
| 26 | + |
| 27 | +#include "openPMD/IO/AbstractIOHandler.hpp" |
| 28 | +#include "openPMD/auxiliary/Filesystem.hpp" |
| 29 | +#include "openPMD/auxiliary/DerefDynamicCast.hpp" |
| 30 | +#include "openPMD/auxiliary/Memory.hpp" |
| 31 | +#include "openPMD/auxiliary/StringManip.hpp" |
| 32 | +#include "openPMD/IO/AbstractIOHandlerImpl.hpp" |
| 33 | +#include "openPMD/IO/ADIOS/ADIOS1Auxiliary.hpp" |
| 34 | +#include "openPMD/IO/ADIOS/ADIOS1FilePosition.hpp" |
| 35 | + |
| 36 | +#include <adios.h> |
| 37 | +#include <adios_read.h> |
| 38 | + |
| 39 | +#include <future> |
| 40 | +#include <memory> |
| 41 | +#include <string> |
| 42 | +#include <utility> |
| 43 | +#include <unordered_map> |
| 44 | +#include <unordered_set> |
| 45 | + |
| 46 | +namespace openPMD |
| 47 | +{ |
| 48 | + template< typename ChildClass > // CRT pattern |
| 49 | + class CommonADIOS1IOHandlerImpl : public AbstractIOHandlerImpl |
| 50 | + { |
| 51 | + public: |
| 52 | + |
| 53 | + void createFile(Writable*, Parameter< Operation::CREATE_FILE > const&) override; |
| 54 | + void createPath(Writable*, Parameter< Operation::CREATE_PATH > const&) override; |
| 55 | + void createDataset(Writable*, Parameter< Operation::CREATE_DATASET > const&) override; |
| 56 | + void extendDataset(Writable*, Parameter< Operation::EXTEND_DATASET > const&) override; |
| 57 | + void openFile(Writable*, Parameter< Operation::OPEN_FILE > const&) override; |
| 58 | + void closeFile(Writable*, Parameter< Operation::CLOSE_FILE > const&) override; |
| 59 | + void availableChunks(Writable*, Parameter< Operation::AVAILABLE_CHUNKS > &) override; |
| 60 | + void openPath(Writable*, Parameter< Operation::OPEN_PATH > const&) override; |
| 61 | + void openDataset(Writable*, Parameter< Operation::OPEN_DATASET > &) override; |
| 62 | + void deleteFile(Writable*, Parameter< Operation::DELETE_FILE > const&) override; |
| 63 | + void deletePath(Writable*, Parameter< Operation::DELETE_PATH > const&) override; |
| 64 | + void deleteDataset(Writable*, Parameter< Operation::DELETE_DATASET > const&) override; |
| 65 | + void deleteAttribute(Writable*, Parameter< Operation::DELETE_ATT > const&) override; |
| 66 | + void writeDataset(Writable*, Parameter< Operation::WRITE_DATASET > const&) override; |
| 67 | + void writeAttribute(Writable*, Parameter< Operation::WRITE_ATT > const&) override; |
| 68 | + void readDataset(Writable*, Parameter< Operation::READ_DATASET > &) override; |
| 69 | + void readAttribute(Writable*, Parameter< Operation::READ_ATT > &) override; |
| 70 | + void listPaths(Writable*, Parameter< Operation::LIST_PATHS > &) override; |
| 71 | + void listDatasets(Writable*, Parameter< Operation::LIST_DATASETS > &) override; |
| 72 | + void listAttributes(Writable*, Parameter< Operation::LIST_ATTS > &) override; |
| 73 | + |
| 74 | + void close(int64_t); |
| 75 | + void close(ADIOS_FILE*); |
| 76 | + void flush_attribute(int64_t group, std::string const& name, Attribute const&); |
| 77 | + |
| 78 | + protected: |
| 79 | + template< typename... Args > |
| 80 | + CommonADIOS1IOHandlerImpl( Args &&... args) |
| 81 | + : AbstractIOHandlerImpl{ std::forward< Args >( args )... } |
| 82 | + {} |
| 83 | + |
| 84 | + ADIOS_READ_METHOD m_readMethod; |
| 85 | + std::unordered_map< Writable*, std::shared_ptr< std::string > > m_filePaths; |
| 86 | + std::unordered_map< std::shared_ptr< std::string >, int64_t > m_groups; |
| 87 | + std::unordered_map< std::shared_ptr< std::string >, bool > m_existsOnDisk; |
| 88 | + std::unordered_map< std::shared_ptr< std::string >, int64_t > m_openWriteFileHandles; |
| 89 | + std::unordered_map< std::shared_ptr< std::string >, ADIOS_FILE* > m_openReadFileHandles; |
| 90 | + std::unordered_map< ADIOS_FILE*, std::vector< ADIOS_SELECTION* > > m_scheduledReads; |
| 91 | + std::unordered_map< int64_t, std::unordered_map< std::string, Attribute > > m_attributeWrites; |
| 92 | + /** |
| 93 | + * Call this function to get adios file id for a Writable. Will create one if does not exist |
| 94 | + * @return returns an adios file id. |
| 95 | + */ |
| 96 | + int64_t GetFileHandle(Writable*); |
| 97 | + }; // ParallelADIOS1IOHandlerImpl |
| 98 | +} // openPMD |
| 99 | + |
| 100 | +#endif |
0 commit comments