24 #include "openPMD/config.hpp"
25 #include "openPMD/auxiliary/Filesystem.hpp"
26 #include "openPMD/IO/AbstractIOHandler.hpp"
27 #include "openPMD/IO/AbstractIOHandlerImpl.hpp"
28 #include "openPMD/IO/Access.hpp"
29 #include "openPMD/IO/JSON/JSONFilePosition.hpp"
31 #include <nlohmann/json.hpp>
37 #include <unordered_map>
38 #include <unordered_set>
60 explicit File( std::string s ) :
61 fileState { std::make_shared< FileState >( s ) }
71 name { std::move( s ) }
79 std::shared_ptr< FileState > fileState;
84 fileState->valid =
false;
90 return fileState->valid;
94 File & operator=( std::string s )
102 fileState = std::make_shared< FileState >( s );
112 return this->fileState == f.fileState;
116 std::string & operator*( )
const
118 return fileState->name;
122 std::string * operator->( )
const
124 return &fileState->name;
128 explicit operator bool( )
const
130 return fileState.operator bool( );
141 typedef std::size_t result_type;
144 result_type operator()(
argument_type const & s )
const noexcept
146 return std::hash< shared_ptr< openPMD::File::FileState>> {}( s.fileState );
151 template<
class T >
void to_json(nlohmann::json &j,
const std::complex< T > &p) {
152 j = nlohmann::json {p.real(), p.imag()};
155 template<
class T >
void from_json(
const nlohmann::json &j, std::complex< T > &p) {
166 using json = nlohmann::json;
274 std::future< void > flush( )
override;
279 using FILEHANDLE = std::fstream;
290 std::shared_ptr< nlohmann::json >> m_jsonVals;
293 std::unordered_set< File > m_dirty;
302 std::shared_ptr< FILEHANDLE > getFilehandle(
308 std::string fullPath(
File );
310 std::string fullPath( std::string
const & );
314 static void parentDir( std::string & );
318 static std::string filepositionOf(
Writable * w );
328 static void syncMultidimensionalJson(
330 Offset
const & offset,
331 Extent
const & extent,
332 Extent
const & multiplicator,
335 size_t currentdim = 0
342 static Extent getMultiplicators( Extent
const & extent );
344 static nlohmann::json initializeNDArray( Extent
const & extent );
346 static Extent getExtent( nlohmann::json & j );
350 static std::string removeSlashes( std::string );
352 template<
typename KeyT >
360 static void ensurePath(
361 nlohmann::json * json,
377 > getPossiblyExisting(
383 std::shared_ptr< nlohmann::json > obtainJsonContents(
File );
386 nlohmann::json & obtainJsonContents(
Writable * writable );
390 void putJsonContents(
392 bool unsetDirty =
true
398 std::shared_ptr< JSONFilePosition > setAndGetFilePosition(
406 std::shared_ptr< JSONFilePosition > setAndGetFilePosition(
416 void associateWithFile(
422 static bool isGroup( nlohmann::json::const_iterator it );
424 static bool isDataset( nlohmann::json
const & j );
428 template<
typename Param >
430 Param
const & parameters,
434 static nlohmann::json platformSpecifics( );
438 template<
typename T >
440 nlohmann::json & json,
444 std::string errorMsg =
"JSON: writeDataset";
449 template<
typename T >
451 nlohmann::json & json,
455 std::string errorMsg =
"JSON: readDataset";
458 struct AttributeWriter
460 template<
typename T >
463 Attribute::resource
const &
466 std::string errorMsg =
"JSON: writeAttribute";
469 struct AttributeReader
471 template<
typename T >
477 std::string errorMsg =
"JSON: writeAttribute";
480 template<
typename T >
483 nlohmann::json operator()(
T const & );
486 template<
typename T >
487 struct CppToJSON< std::vector< T>>
489 nlohmann::json operator()( std::vector< T >
const & );
492 template<
typename T,
int n >
498 nlohmann::json operator()(
512 T operator()( nlohmann::json
const & );
515 template<
typename T >
516 struct JsonToCpp< std::vector< T > >
518 std::vector< T > operator()( nlohmann::json
const & );
521 template<
typename T,
int n >
532 > operator()( nlohmann::json
const & );
535 template<
typename T >
538 typename std::enable_if<
539 std::is_floating_point<
545 T operator()( nlohmann::json
const & );
Definition: IOTask.hpp:149
Definition: IOTask.hpp:514
Layer to mirror structure of logical data and persistent data in file.
Definition: Writable.hpp:64
Definition: IOTask.hpp:373
Definition: IOTask.hpp:163
Definition: IOTask.hpp:467
Definition: IOTask.hpp:555
Definition: IOTask.hpp:108
void listAttributes(Writable *, Parameter< Operation::LIST_ATTS > &) override
List all attributes associated with an object.
Definition: JSONIOHandlerImpl.cpp:1070
void deletePath(Writable *, Parameter< Operation::DELETE_PATH > const &) override
Delete all objects within an existing path.
Definition: JSONIOHandlerImpl.cpp:701
void deleteDataset(Writable *, Parameter< Operation::DELETE_DATASET > const &) override
Delete an existing dataset.
Definition: JSONIOHandlerImpl.cpp:807
void openPath(Writable *, Parameter< Operation::OPEN_PATH > const &) override
Open all contained groups in a path, possibly recursively.
Definition: JSONIOHandlerImpl.cpp:604
Definition: IOTask.hpp:233
void listPaths(Writable *, Parameter< Operation::LIST_PATHS > &) override
List all paths/sub-groups inside a group, non-recursively.
Definition: JSONIOHandlerImpl.cpp:1024
Definition: IOTask.hpp:344
void createFile(Writable *, Parameter< Operation::CREATE_FILE > const &) override
Create a new file in physical storage, possibly overriding an existing file.
Definition: JSONIOHandlerImpl.cpp:84
void listDatasets(Writable *, Parameter< Operation::LIST_DATASETS > &) override
List all datasets inside a group, non-recursively.
Definition: JSONIOHandlerImpl.cpp:1047
Definition: JSONIOHandlerImpl.hpp:163
Definition: IOTask.hpp:249
Interface for communicating between logical and physically persistent data.
Definition: AbstractIOHandler.hpp:98
Definition: JSONIOHandlerImpl.hpp:58
void createDataset(Writable *, Parameter< Operation::CREATE_DATASET > const &) override
Create a new dataset of given type, extent and storage properties.
Definition: JSONIOHandlerImpl.cpp:203
Definition: IOTask.hpp:402
void openDataset(Writable *, Parameter< Operation::OPEN_DATASET > &) override
Open an existing dataset and determine its datatype and extent.
Definition: JSONIOHandlerImpl.cpp:640
Definition: AbstractIOHandlerImpl.hpp:35
Public definitions of openPMD-api.
Definition: Date.cpp:29
void createPath(Writable *, Parameter< Operation::CREATE_PATH > const &) override
Create all necessary groups for a path, possibly recursively.
Definition: JSONIOHandlerImpl.cpp:144
Definition: IOTask.hpp:291
Definition: IOTask.hpp:451
Definition: IOTask.hpp:307
void deleteFile(Writable *, Parameter< Operation::DELETE_FILE > const &) override
Delete an existing file from physical storage.
Definition: JSONIOHandlerImpl.cpp:667
Definition: IOTask.hpp:328
Definition: IOTask.hpp:266
Definition: IOTask.hpp:179
void extendDataset(Writable *, Parameter< Operation::EXTEND_DATASET > const &) override
Increase the extent of an existing dataset.
Definition: JSONIOHandlerImpl.cpp:277
void readAttribute(Writable *, Parameter< Operation::READ_ATT > &) override
Read the value of an existing attribute.
Definition: JSONIOHandlerImpl.cpp:985
Definition: JSONIOHandlerImpl.hpp:68
void closeFile(Writable *, Parameter< Operation::CLOSE_FILE > const &) override
Close the file corresponding with the writable and release file handles.
Definition: JSONIOHandlerImpl.cpp:588
Access
File access mode to use during IO.
Definition: Access.hpp:28
void availableChunks(Writable *, Parameter< Operation::AVAILABLE_CHUNKS > &) override
Report chunks that are available for loading from the dataset represented by this writable.
Definition: JSONIOHandlerImpl.cpp:543
Definition: IOTask.hpp:217
void readDataset(Writable *, Parameter< Operation::READ_DATASET > &) override
Read a chunk of data from an existing dataset.
Definition: JSONIOHandlerImpl.cpp:956
void deleteAttribute(Writable *, Parameter< Operation::DELETE_ATT > const &) override
Delete an existing attribute.
Definition: JSONIOHandlerImpl.cpp:862
Definition: IOTask.hpp:126
void openFile(Writable *, Parameter< Operation::OPEN_FILE > const &) override
Open an existing file assuming it conforms to openPMD.
Definition: JSONIOHandlerImpl.cpp:554
void writeDataset(Writable *, Parameter< Operation::WRITE_DATASET > const &) override
Write a chunk of data into an existing dataset.
Definition: JSONIOHandlerImpl.cpp:881
Definition: IOTask.hpp:486
void writeAttribute(Writable *, Parameter< Operation::WRITE_ATT > const &) override
Create a single attribute and fill the value, possibly overwriting an existing attribute.
Definition: JSONIOHandlerImpl.cpp:912