diff --git a/source/RobotAPI/libraries/armem/CMakeLists.txt b/source/RobotAPI/libraries/armem/CMakeLists.txt index 4d8d4d3d64007b2fc68c1ee20699442be045f1ae..478f30dadee8437354b0e88a0f8fff1b43802fb0 100644 --- a/source/RobotAPI/libraries/armem/CMakeLists.txt +++ b/source/RobotAPI/libraries/armem/CMakeLists.txt @@ -33,6 +33,8 @@ set(LIB_FILES core/error/ArMemError.cpp + core/io/DiskReaderWriter.cpp + core/io/FileSystemLookupMemory.cpp core/io/MemoryFileSystemStorage.cpp core/io/DiskWriter/DiskWriter.cpp core/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.cpp diff --git a/source/RobotAPI/libraries/armem/core/Time.cpp b/source/RobotAPI/libraries/armem/core/Time.cpp index 9995b685123bf8eb8f7e53378f79548b5383346a..25bd9a8dc09fcda3c1f86d765e1bbd74f87c6525 100644 --- a/source/RobotAPI/libraries/armem/core/Time.cpp +++ b/source/RobotAPI/libraries/armem/core/Time.cpp @@ -45,6 +45,14 @@ namespace armarx return ss.str(); } + + + armem::Time armem::timeFromStringMicroSeconds(const std::string& microSeconds) + { + return Time::microSeconds(std::stol(microSeconds)); + } + } + diff --git a/source/RobotAPI/libraries/armem/core/Time.h b/source/RobotAPI/libraries/armem/core/Time.h index 6f743b74109a1a400b08f83d2d04b63957d3a5e4..cc00c9febfc9927d7a4985a63b1dabf2d8621300 100644 --- a/source/RobotAPI/libraries/armem/core/Time.h +++ b/source/RobotAPI/libraries/armem/core/Time.h @@ -1,5 +1,7 @@ #pragma once +#include <string> + #include <IceUtil/Time.h> @@ -26,4 +28,10 @@ namespace armarx::armem */ std::string toDateTimeMilliSeconds(const Time& time, int decimals = 6); + + /** + * @brief Get a `Time` from the microseconds as text. + */ + Time timeFromStringMicroSeconds(const std::string& microSeconds); + } diff --git a/source/RobotAPI/libraries/armem/core/error/ArMemError.h b/source/RobotAPI/libraries/armem/core/error/ArMemError.h index ce301206d31c72e29c49d786ad31cb59f307b21e..068283a519d74cfe86d7ffb31345d4404e4e0d7f 100644 --- a/source/RobotAPI/libraries/armem/core/error/ArMemError.h +++ b/source/RobotAPI/libraries/armem/core/error/ArMemError.h @@ -159,7 +159,7 @@ namespace armarx::armem::error }; /** - * @brief Indicates that an file is not a directory. + * @brief Indicates that a path does not point to a directory. */ class PathNotADirectory : public ArMemError { @@ -172,7 +172,7 @@ namespace armarx::armem::error }; /** - * @brief Indicates that an file is not a directory. + * @brief Indicates that a path does not point to a regular file. */ class PathNotARegularFile : public ArMemError { @@ -185,7 +185,7 @@ namespace armarx::armem::error }; /** - * @brief Indicates that an file is not a directory. + * @brief Indicates that a path does not exist. */ class PathDoesNotExist : public ArMemError { diff --git a/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.cpp b/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.cpp index df63ab589f076274d84982ee0ff67f6a3f8ec95f..5ddfd4be948e71e364bc349195589a29a60a85a4 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.cpp +++ b/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.cpp @@ -20,145 +20,156 @@ #include "DiskReader.h" +#include <sstream> +#include <fstream> +#include <iostream> -namespace armarx::armem +// ArmarX +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h> +#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronAllTypeNavigators.h> + +#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/LegacyAronDataConverter/LegacyAronDataConverter.h> +#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriter.h> + +#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/LegacyAronTypeConverter/LegacyAronTypeConverter.h> +#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NavigatorWriter/AronTypeNavigatorWriter.h> + +#include <RobotAPI/libraries/armem/core/error.h> + + +namespace armarx::armem::io { - namespace ltm + DiskReader::DiskReader(bool createFolder) : + DiskReaderWriter(createFolder) + {} + + DiskReader::DiskReader(const std::filesystem::path& rootPath, bool createFolder) : + DiskReaderWriter(rootPath, createFolder) { - namespace io - { - DiskReader::DiskReader(bool createFolder) : - DiskReaderWriter(createFolder) - {} + } - DiskReader::DiskReader(const std::string& r, bool createFolder) : - DiskReaderWriter(r, createFolder) - { - } + DiskReader::~DiskReader() + { + } - DiskReader::~DiskReader() + FileSystemLookupMemoryManager DiskReader::readMemoryStructureFromDisk() + { + FileSystemLookupMemoryManager ret; + + for (const auto& memoryFolder : std::filesystem::directory_iterator(rootPath)) + { + if (!std::filesystem::is_directory(memoryFolder)) { + continue; } - FileSystemLookupMemoryManager DiskReader::readMemoryStructureFromDisk() - { - FileSystemLookupMemoryManager ret; + std::string folderName = memoryFolder.path().filename(); + FileSystemLookupMemoryManager tmp = readMemoryStructureFromDisk(folderName); + ret.merge(tmp); + } + return ret; + } - for (const auto& memoryFolder : std::filesystem::directory_iterator(rootPath)) - { - if (!std::filesystem::is_directory(memoryFolder)) - { - continue; - } + FileSystemLookupMemoryManager DiskReader::readMemoryStructureFromDisk(const std::string& memoryFolderName) + { + FileSystemLookupMemoryManager ret; - std::string folderName = memoryFolder.path().filename(); - FileSystemLookupMemoryManager tmp = readMemoryStructureFromDisk(folderName); - ret.merge(tmp); - } - return ret; - } + std::filesystem::path p = rootPath / memoryFolderName; + if (!std::filesystem::is_directory(p)) + { + return ret; + } - FileSystemLookupMemoryManager DiskReader::readMemoryStructureFromDisk(const std::string& memoryFolderName) + for (const auto& coreSegmentFolder : std::filesystem::directory_iterator(p)) + { + if (!std::filesystem::is_directory(coreSegmentFolder)) { - FileSystemLookupMemoryManager ret; - - std::filesystem::path p = rootPath / memoryFolderName; - if (!std::filesystem::is_directory(p)) + continue; + } + std::string coreSegmentName = coreSegmentFolder.path().filename(); + for (const auto& providerSegmentFolder : std::filesystem::directory_iterator(coreSegmentFolder.path())) + { + if (!std::filesystem::is_directory(providerSegmentFolder)) { - return ret; + continue; } - - for (const auto& coreSegmentFolder : std::filesystem::directory_iterator(p)) + std::string providerSegmentName = providerSegmentFolder.path().filename(); + for (const auto& entityFolder : std::filesystem::directory_iterator(providerSegmentFolder.path())) { - if (!std::filesystem::is_directory(coreSegmentFolder)) + if (!std::filesystem::is_directory(entityFolder)) { continue; } - std::string coreSegmentName = coreSegmentFolder.path().filename(); - for (const auto& providerSegmentFolder : std::filesystem::directory_iterator(coreSegmentFolder.path())) + std::string entityName = entityFolder.path().filename(); + for (const auto& entityHistoryFolder : std::filesystem::directory_iterator(entityFolder.path())) { - if (!std::filesystem::is_directory(providerSegmentFolder)) + if (!std::filesystem::is_directory(entityHistoryFolder)) { continue; } - std::string providerSegmentName = providerSegmentFolder.path().filename(); - for (const auto& entityFolder : std::filesystem::directory_iterator(providerSegmentFolder.path())) + Time entityTimestamp = armem::timeFromStringMicroSeconds(entityHistoryFolder.path().filename()); + + // TODO: make this relative to amount of files in folder + for (unsigned int i = 0; i < 10000; ++i) { - if (!std::filesystem::is_directory(entityFolder)) - { - continue; - } - std::string entityName = entityFolder.path().filename(); - for (const auto& entityHistoryFolder : std::filesystem::directory_iterator(entityFolder.path())) + std::filesystem::path entityInstance = entityHistoryFolder / (std::to_string(i) + getEntityInstanceSuffix()); + if (!std::filesystem::is_regular_file(entityInstance)) { - if (!std::filesystem::is_directory(entityHistoryFolder)) - { - continue; - } - Time entityTimestamp = timeFromString(entityHistoryFolder.path().filename()); - - // TODO: make this relative to amount of files in folder - for (unsigned int i = 0; i < 10000; ++i) - { - std::filesystem::path entityInstance = entityHistoryFolder / (std::to_string(i) + getEntityInstanceSuffix()); - if (!std::filesystem::is_regular_file(entityInstance)) - { - break; - } - FileSystemLookupMemory& mem = ret.memoryLookupTable[memoryFolderName]; - FileSystemLookupCoreSegment& mem_core = mem[coreSegmentName]; - FileSystemLookupProviderSegment& mem_prov = mem_core[providerSegmentName]; - FileSystemLookupEntity& mem_entity = mem_prov[entityName]; - FileSystemLookupEntityHistory& mem_entity_history = mem_entity[entityTimestamp]; - - mem_entity_history.push_back(entityInstance); - } + break; } + FileSystemLookupMemory& mem = ret.memoryLookupTable[memoryFolderName]; + FileSystemLookupCoreSegment& mem_core = mem[coreSegmentName]; + FileSystemLookupProviderSegment& mem_prov = mem_core[providerSegmentName]; + FileSystemLookupEntity& mem_entity = mem_prov[entityName]; + FileSystemLookupEntityHistory& mem_entity_history = mem_entity[entityTimestamp]; + + mem_entity_history.push_back(entityInstance); } } } - return ret; } + } + return ret; + } - EntityInstancePtr DiskReader::readSingleInstanceFromDisk(const std::filesystem::path& p, const aron::typenavigator::AronTypeNavigatorPtr& expectedStructure) const - { - if (!std::filesystem::is_regular_file(p)) - { - throw error::PathNotARegularFile(p.string(), "During readSingleInstanceFromDisk tried to read an entityInstance from a non-file path."); - } + EntityInstancePtr DiskReader::readSingleInstanceFromDisk(const std::filesystem::path& p, const aron::typenavigator::AronTypeNavigatorPtr& expectedStructure) const + { + if (!std::filesystem::is_regular_file(p)) + { + throw error::PathNotARegularFile(p.string(), "During readSingleInstanceFromDisk tried to read an entityInstance from a non-file path."); + } - std::ifstream ifs(p); - std::string file_content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>())); + std::ifstream ifs(p); + std::string file_content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>())); - aron::datanavigator::AronDictDataNavigatorPtr dictdata = getStringAsDataNavigator(file_content, expectedStructure); - return unwrapData(dictdata); - } + aron::datanavigator::AronDictDataNavigatorPtr dictdata = getStringAsDataNavigator(file_content, expectedStructure); + return unwrapData(dictdata); + } - EntityInstancePtr DiskReader::unwrapData(const aron::datanavigator::AronDictDataNavigatorPtr& dataWrapped) const - { - EntityInstancePtr e = EntityInstancePtr(new EntityInstance()); - EntityInstanceMetadata& metadata = e->metadata(); + EntityInstancePtr DiskReader::unwrapData(const aron::datanavigator::AronDictDataNavigatorPtr& dataWrapped) const + { + EntityInstancePtr e = EntityInstancePtr(new EntityInstance()); + EntityInstanceMetadata& metadata = e->metadata(); - aron::datanavigator::AronDictDataNavigatorPtr data = aron::datanavigator::AronDictDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_DATA_FIELD)); - e->setData(data); + aron::datanavigator::AronDictDataNavigatorPtr data = aron::datanavigator::AronDictDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_DATA_FIELD)); + e->setData(data); - // not used right now - //aron::datanavigator::AronLongDataNavigatorPtr timeWrapped = aron::datanavigator::AronLongDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_TIME_WRAPPED_FIELD)); + // not used right now + //aron::datanavigator::AronLongDataNavigatorPtr timeWrapped = aron::datanavigator::AronLongDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_TIME_WRAPPED_FIELD)); - aron::datanavigator::AronLongDataNavigatorPtr timeCreated = aron::datanavigator::AronLongDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_TIME_CREATED_FIELD)); - metadata.timeCreated = Time::microSeconds(timeCreated->toAronLongPtr()->value); + aron::datanavigator::AronLongDataNavigatorPtr timeCreated = aron::datanavigator::AronLongDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_TIME_CREATED_FIELD)); + metadata.timeCreated = Time::microSeconds(timeCreated->toAronLongPtr()->value); - aron::datanavigator::AronLongDataNavigatorPtr timeSent = aron::datanavigator::AronLongDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_TIME_SENT_FIELD)); - metadata.timeSent = Time::microSeconds(timeSent->toAronLongPtr()->value); + aron::datanavigator::AronLongDataNavigatorPtr timeSent = aron::datanavigator::AronLongDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_TIME_SENT_FIELD)); + metadata.timeSent = Time::microSeconds(timeSent->toAronLongPtr()->value); - aron::datanavigator::AronLongDataNavigatorPtr timeArrived = aron::datanavigator::AronLongDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_TIME_ARRIVED_FIELD)); - metadata.timeArrived = Time::microSeconds(timeArrived->toAronLongPtr()->value); + aron::datanavigator::AronLongDataNavigatorPtr timeArrived = aron::datanavigator::AronLongDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_TIME_ARRIVED_FIELD)); + metadata.timeArrived = Time::microSeconds(timeArrived->toAronLongPtr()->value); - aron::datanavigator::AronDoubleDataNavigatorPtr confidence = aron::datanavigator::AronDoubleDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_CONFIDENCE_FIELD)); - metadata.confidence = confidence->toAronDoublePtr()->value; + aron::datanavigator::AronDoubleDataNavigatorPtr confidence = aron::datanavigator::AronDoubleDataNavigator::DynamicCastAndCheck(dataWrapped->getElement(DISK_READER_WRITER_CONFIDENCE_FIELD)); + metadata.confidence = confidence->toAronDoublePtr()->value; - return e; - } - } + return e; } } diff --git a/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.h b/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.h index af23d4e069b199cc875795fdd977e70075f36862..3f3b29594ebf86c67e7a897e3346cfbec4e92765 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.h +++ b/source/RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.h @@ -21,58 +21,40 @@ #pragma once // STD/STL +#include <filesystem> #include <memory> #include <string> -#include <sstream> -#include <fstream> -#include <iostream> -#include <filesystem> - -// BaseClass -#include <RobotAPI/libraries/armem/core/io/DiskReaderWriter.h> - -// ArmarX -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronAllTypeNavigators.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/LegacyAronDataConverter/LegacyAronDataConverter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriter.h> +#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.h> +#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.h> +#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/LegacyAronTypeConverter/LegacyAronTypeConverter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NavigatorWriter/AronTypeNavigatorWriter.h> +#include <RobotAPI/libraries/armem/core/EntityInstance.h> -#include <RobotAPI/libraries/armem/core/io/FileSystemLookupMemory.h> +#include "../DiskReaderWriter.h" +#include "../FileSystemLookupMemory.h" - -namespace armarx::armem +namespace armarx::armem::io { - namespace ltm - { - namespace io - { - class DiskReader; - typedef std::shared_ptr<DiskReader> DiskReaderPtr; + class DiskReader; + using DiskReaderPtr = std::shared_ptr<DiskReader>; - class DiskReader : - virtual public DiskReaderWriter - { - public: - DiskReader(bool createFolder); - DiskReader(const std::string&, bool createFolder); - virtual ~DiskReader(); + class DiskReader : virtual public DiskReaderWriter + { + public: + DiskReader(bool createFolder); + DiskReader(const std::filesystem::path& rootPath, bool createFolder); + virtual ~DiskReader(); - FileSystemLookupMemoryManager readMemoryStructureFromDisk(); - FileSystemLookupMemoryManager readMemoryStructureFromDisk(const std::string&); - EntityInstancePtr readSingleInstanceFromDisk(const std::filesystem::path&, const aron::typenavigator::AronTypeNavigatorPtr& expectedStructure = nullptr) const; + FileSystemLookupMemoryManager readMemoryStructureFromDisk(); + FileSystemLookupMemoryManager readMemoryStructureFromDisk(const std::string&); + EntityInstancePtr readSingleInstanceFromDisk(const std::filesystem::path&, const aron::typenavigator::AronTypeNavigatorPtr& expectedStructure = nullptr) const; - protected: - EntityInstancePtr unwrapData(const aron::datanavigator::AronDictDataNavigatorPtr&) const; + protected: + EntityInstancePtr unwrapData(const aron::datanavigator::AronDictDataNavigatorPtr&) const; - virtual aron::datanavigator::AronDictDataNavigatorPtr getStringAsDataNavigator(const std::string&, const aron::typenavigator::AronTypeNavigatorPtr&) const = 0; - virtual aron::typenavigator::AronObjectTypeNavigatorPtr getStringAsTypeNavigator(const std::string& s) const = 0; - }; - } - } + virtual aron::datanavigator::AronDictDataNavigatorPtr getStringAsDataNavigator(const std::string&, const aron::typenavigator::AronTypeNavigatorPtr&) const = 0; + virtual aron::typenavigator::AronObjectTypeNavigatorPtr getStringAsTypeNavigator(const std::string& s) const = 0; + }; } diff --git a/source/RobotAPI/libraries/armem/core/io/DiskReader/NlohmannJSONDiskReader/NlohmannJSONDiskReader.cpp b/source/RobotAPI/libraries/armem/core/io/DiskReader/NlohmannJSONDiskReader/NlohmannJSONDiskReader.cpp index dc9d473694eee1b5b0761dd45f61ea48034f141a..3b2f6afeb7fbb403063142a8fbd305028f6a3c2f 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskReader/NlohmannJSONDiskReader/NlohmannJSONDiskReader.cpp +++ b/source/RobotAPI/libraries/armem/core/io/DiskReader/NlohmannJSONDiskReader/NlohmannJSONDiskReader.cpp @@ -1,6 +1,13 @@ #include "NlohmannJSONDiskReader.h" -namespace armarx::armem::ltm::io +#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/LegacyAronDataConverter/LegacyAronDataConverter.h> +#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NlohmannJSONReader/AronDataNlohmannJSONReader.h> +#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NavigatorWriter/AronDataNavigatorWriter.h> +#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/LegacyAronTypeConverter/LegacyAronTypeConverter.h> +#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NlohmannJSONReader/AronTypeNlohmannJSONReader.h> + + +namespace armarx::armem::io { NlohmannJSONDiskReader::NlohmannJSONDiskReader(bool createFolder) : diff --git a/source/RobotAPI/libraries/armem/core/io/DiskReader/NlohmannJSONDiskReader/NlohmannJSONDiskReader.h b/source/RobotAPI/libraries/armem/core/io/DiskReader/NlohmannJSONDiskReader/NlohmannJSONDiskReader.h index 1bb0cd1066f142b4ec328c3305bea7e00670cd70..0efdfbdc4047b8a19b0ff00fe3323c1032070cfd 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskReader/NlohmannJSONDiskReader/NlohmannJSONDiskReader.h +++ b/source/RobotAPI/libraries/armem/core/io/DiskReader/NlohmannJSONDiskReader/NlohmannJSONDiskReader.h @@ -25,42 +25,34 @@ #include <string> // Base Class -#include <RobotAPI/libraries/armem/core/io/DiskReader/DiskReader.h> +#include "../DiskReader.h" -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classReaders/NlohmannJSONReader/AronDataNlohmannJSONReader.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classReaders/NlohmannJSONReader/AronTypeNlohmannJSONReader.h> -namespace armarx::armem +namespace armarx::armem::io { - namespace ltm + class NlohmannJSONDiskReader; + using NlohmannJSONDiskReaderPtr = std::shared_ptr<NlohmannJSONDiskReader>; + + class NlohmannJSONDiskReader : virtual public DiskReader { - namespace io - { - class NlohmannJSONDiskReader; - typedef std::shared_ptr<NlohmannJSONDiskReader> NlohmannJSONDiskReaderPtr; + public: + NlohmannJSONDiskReader(bool createFolder); + NlohmannJSONDiskReader(const std::string& rootPath, bool createFolder); - class NlohmannJSONDiskReader : - virtual public DiskReader - { - public: - NlohmannJSONDiskReader(bool createFolder); - NlohmannJSONDiskReader(const std::string& rootPath, bool createFolder); - aron::datanavigator::AronDictDataNavigatorPtr getStringAsDataNavigator(const std::string&, const aron::typenavigator::AronTypeNavigatorPtr& expectedStructure = nullptr) const override; - aron::typenavigator::AronObjectTypeNavigatorPtr getStringAsTypeNavigator(const std::string& s) const override; + protected: + aron::datanavigator::AronDictDataNavigatorPtr getStringAsDataNavigator( + const std::string&, const aron::typenavigator::AronTypeNavigatorPtr& expectedStructure = nullptr) const override; + aron::typenavigator::AronObjectTypeNavigatorPtr getStringAsTypeNavigator(const std::string& s) const override; - protected: - std::string getEntityInstanceSuffix() const override - { - return ".data.nlohmann_json_serializer.json"; - } + std::string getEntityInstanceSuffix() const override + { + return ".data.nlohmann_json_serializer.json"; + } - std::string getTypeSuffix() const override - { - return ".type.nlohmann_json_serializer.json"; - } - }; + std::string getTypeSuffix() const override + { + return ".type.nlohmann_json_serializer.json"; } - } + }; } diff --git a/source/RobotAPI/libraries/armem/core/io/DiskReaderWriter.cpp b/source/RobotAPI/libraries/armem/core/io/DiskReaderWriter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fbe938d812baae54bd0dd0771fa34e18871bb4ba --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/io/DiskReaderWriter.cpp @@ -0,0 +1,65 @@ +/* +* This file is part of ArmarX. +* +* ArmarX is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* ArmarX is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* @author Fabian Peller (fabian dot peller at kit dot edu) +* @copyright http://www.gnu.org/licenses/gpl-2.0.txt +* GNU General Public License +*/ + +#include "DiskReaderWriter.h" + +#include <RobotAPI/libraries/armem/core/error.h> + + +namespace armarx::armem::io +{ + + DiskReaderWriter::DiskReaderWriter(const std::filesystem::path& rootPath, bool createIfNotExistent) : + rootPath(rootPath) + { + if (!std::filesystem::exists(rootPath.parent_path())) + { + throw error::PathDoesNotExist(rootPath.parent_path().string(), + "The parent path does not exist. At least this directory must exist!"); + } + + if (!std::filesystem::is_directory(rootPath.parent_path())) + { + throw error::PathDoesNotExist(rootPath.parent_path().string(), "The parent path is not a directory. It must be a directory."); + } + + if (!std::filesystem::exists(rootPath)) + { + if (createIfNotExistent) + { + std::filesystem::create_directory(rootPath); + } + else + { + throw error::PathDoesNotExist(rootPath.string(), "The path does not exist and a new folder should not be created!"); + } + } + + if (!std::filesystem::is_directory(rootPath)) + { + throw error::PathNotADirectory(rootPath.string(), "The Path is not valid. It points to a file instead of a folder!"); + } + } + + DiskReaderWriter::~DiskReaderWriter() + { + } + +} diff --git a/source/RobotAPI/libraries/armem/core/io/DiskReaderWriter.h b/source/RobotAPI/libraries/armem/core/io/DiskReaderWriter.h index 56dc4afaf490d4cc0f058bf60be9aee86a67c428..fc67ec7838e011c603092439ecd074897a500676 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskReaderWriter.h +++ b/source/RobotAPI/libraries/armem/core/io/DiskReaderWriter.h @@ -21,81 +21,43 @@ #pragma once // STD/STL -#include <memory> #include <string> -#include <sstream> -#include <fstream> -#include <iostream> #include <filesystem> // ArmarX #include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/armem/core/error.h> -#include <RobotAPI/libraries/armem/core/Memory.h> -#include <RobotAPI/libraries/armem/core/CoreSegment.h> -#include <RobotAPI/libraries/armem/core/Entity.h> +#include <RobotAPI/libraries/armem/core/Time.h> -namespace armarx::armem +namespace armarx::armem::io { - namespace ltm + class DiskReaderWriter { - class DiskReaderWriter - { - public: - DiskReaderWriter(bool createIfNotExistent) : - DiskReaderWriter("/tmp/MemoryExport", createIfNotExistent) - {} - DiskReaderWriter(const std::string& p, bool createIfNotExistent) : - rootPath(p) - { - if (!std::filesystem::exists(rootPath.parent_path())) - { - throw error::PathDoesNotExist(rootPath.parent_path().string(), "The parent path does not exist. At least this directory must exist!"); - } + public: + DiskReaderWriter(bool createIfNotExistent) : + DiskReaderWriter("/tmp/MemoryExport", createIfNotExistent) + {} + DiskReaderWriter(const std::filesystem::path& rootPath, bool createIfNotExistent); - if (!std::filesystem::is_directory(rootPath.parent_path())) - { - throw error::PathDoesNotExist(rootPath.parent_path().string(), "The parent path is not a directory. It must be a directory."); - } + virtual ~DiskReaderWriter(); - if (!std::filesystem::exists(rootPath)) - { - if (createIfNotExistent) - { - std::filesystem::create_directory(rootPath); - } - else - { - throw error::PathDoesNotExist(rootPath.string(), "The path does not exist and a new folder should not be created!"); - } - } - if (!std::filesystem::is_directory(rootPath)) - { - throw error::PathNotADirectory(rootPath.string(), "The Path is not valid. It points to a file instead of a folder!"); - } - } + protected: + virtual std::string getEntityInstanceSuffix() const = 0; + virtual std::string getTypeSuffix() const = 0; - protected: - virtual std::string getEntityInstanceSuffix() const = 0; - virtual std::string getTypeSuffix() const = 0; + protected: + std::filesystem::path rootPath; - Time timeFromString(const std::string& s) const - { - return Time::microSeconds(std::stol(s)); - } + const std::string DISK_READER_WRITER_DATA_FIELD = "LTM_WRAPPER_DATA"; + const std::string DISK_READER_WRITER_TIME_WRAPPED_FIELD = "LTM_WRAPPER_TIME_WRAPPED"; + const std::string DISK_READER_WRITER_TIME_CREATED_FIELD = "ENTITY_METADATA_TIME_CREATED"; + const std::string DISK_READER_WRITER_TIME_SENT_FIELD = "ENTITY_METADATA_TIME_SENT"; + const std::string DISK_READER_WRITER_TIME_ARRIVED_FIELD = "ENTITY_METADATA_TIME_ARRIVED"; + const std::string DISK_READER_WRITER_CONFIDENCE_FIELD = "ENTITY_METADATA_CONFIDENCE"; - protected: - std::filesystem::path rootPath; + }; - const std::string DISK_READER_WRITER_DATA_FIELD = "LTM_WRAPPER_DATA"; - const std::string DISK_READER_WRITER_TIME_WRAPPED_FIELD = "LTM_WRAPPER_TIME_WRAPPED"; - const std::string DISK_READER_WRITER_TIME_CREATED_FIELD = "ENTITY_METADATA_TIME_CREATED"; - const std::string DISK_READER_WRITER_TIME_SENT_FIELD = "ENTITY_METADATA_TIME_SENT"; - const std::string DISK_READER_WRITER_TIME_ARRIVED_FIELD = "ENTITY_METADATA_TIME_ARRIVED"; - const std::string DISK_READER_WRITER_CONFIDENCE_FIELD = "ENTITY_METADATA_CONFIDENCE"; - }; - } + using DiskReaderWriterPtr = std::shared_ptr<DiskReaderWriter>; } diff --git a/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.cpp b/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.cpp index cfd780fc3ea879d80b32398315aab9c537b60a28..d9c1fab74202809d14c5be790d67f173a5414aab 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.cpp +++ b/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.cpp @@ -21,267 +21,277 @@ // STD/STL #include "DiskWriter.h" +#include <fstream> +#include <iostream> -namespace armarx::armem -{ - namespace ltm - { - namespace io - { - DiskWriter::DiskWriter(bool createFolder) : - DiskReaderWriter(createFolder) - {} +// ArmarX +#include <RobotAPI/interface/aron.h> +#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h> +#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronAllTypeNavigators.h> - DiskWriter::DiskWriter(const std::string& r, bool createFolder) : - DiskReaderWriter(r, createFolder) - { - } +#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/LegacyAronDataWriter/LegacyAronDataWriter.h> +#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataWriter.h> +#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/LegacyAronTypeWriter/LegacyAronTypeWriter.h> +#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeWriter.h> - DiskWriterReturnInformation DiskWriter::writeOnDisk(const Memory& m) - { - MemoryID id; - id.memoryName = m.name(); - std::string memoryName = id.memoryName; +// BaseClass +#include "../DiskReaderWriter.h" +#include "../FileSystemLookupMemory.h" - DiskWriterReturnInformation ret(memoryName); +#include <RobotAPI/libraries/armem/core/Memory.h> +#include <RobotAPI/libraries/armem/core/CoreSegment.h> +#include <RobotAPI/libraries/armem/core/Entity.h> - std::filesystem::path p = rootPath / id.str(); - if (!ensureDirectoryPathExists(p)) - { - ret.hasError = true; - return ret; - } - for (const auto& [coreKey, coreSegment] : m.coreSegments) - { - MemoryID storeCore(id); - storeCore.coreSegmentName = coreKey; - DiskWriterReturnInformation other = writeOnDisk(storeCore, *coreSegment); - ret.append(other); - } - return ret; - } - - DiskWriterReturnInformation DiskWriter::writeOnDisk(const MemoryID& i, const CoreSegment& s) - { - MemoryID id; - id.memoryName = i.memoryName; - id.coreSegmentName = i.coreSegmentName; +namespace armarx::armem::io +{ + DiskWriter::DiskWriter(bool createFolder) : + DiskReaderWriter(createFolder) + {} - std::string memoryName = id.memoryName; + DiskWriter::DiskWriter(const std::filesystem::path& rootPath, bool createFolder) : + DiskReaderWriter(rootPath, createFolder) + { + } - DiskWriterReturnInformation ret(memoryName); + DiskWriterReturnInformation DiskWriter::writeOnDisk(const Memory& m) + { + MemoryID id = m.id().getMemoryID(); + DiskWriterReturnInformation ret(id.memoryName); - std::filesystem::path p = rootPath / id.str(); - if (!ensureDirectoryPathExists(p)) - { - ret.coreSegmentsError.push_back(id.str()); - ret.hasError = true; - return ret; - } + std::filesystem::path p = rootPath / id.str(); + if (!ensureDirectoryPathExists(p)) + { + ret.hasError = true; + return ret; + } - if (s.hasAronType()) - { - std::string val = getTypeAsString(s.aronType()); + for (const auto& [coreKey, coreSegment] : m.coreSegments) + { + MemoryID storeCore(id); + storeCore.coreSegmentName = coreKey; + DiskWriterReturnInformation other = writeOnDisk(storeCore, *coreSegment); + ret.append(other); + } + return ret; + } - std::filesystem::path coreSegmentProviderPath = rootPath / id.str() / (id.coreSegmentName + getEntityInstanceSuffix()); - std::ofstream ofs; - ofs.open(coreSegmentProviderPath); - ofs << val; - ofs.close(); - } + DiskWriterReturnInformation DiskWriter::writeOnDisk(const MemoryID& i, const CoreSegment& s) + { + MemoryID id = i.getCoreSegmentID(); + DiskWriterReturnInformation ret(id.memoryName); - for (const auto& [providerKey, providerSegment] : s.providerSegments) - { - MemoryID storeProvider(id); - storeProvider.providerSegmentName = providerKey; - DiskWriterReturnInformation other = writeOnDisk(storeProvider, *providerSegment); - ret.append(other); - } - return ret; - } + std::filesystem::path p = rootPath / id.str(); + if (!ensureDirectoryPathExists(p)) + { + ret.coreSegmentsError.push_back(id.str()); + ret.hasError = true; + return ret; + } - DiskWriterReturnInformation DiskWriter::writeOnDisk(const MemoryID& i, const ProviderSegment& s) - { - MemoryID id; - id.memoryName = i.memoryName; - id.coreSegmentName = i.coreSegmentName; - id.providerSegmentName = i.providerSegmentName; + if (s.hasAronType()) + { + std::string val = getTypeAsString(s.aronType()); - std::string memoryName = id.memoryName; + std::filesystem::path coreSegmentProviderPath = rootPath / id.str() / (id.coreSegmentName + getEntityInstanceSuffix()); + std::ofstream ofs; + ofs.open(coreSegmentProviderPath); + ofs << val; + ofs.close(); + } - DiskWriterReturnInformation ret(memoryName); + for (const auto& [providerKey, providerSegment] : s.providerSegments) + { + MemoryID storeProvider(id); + storeProvider.providerSegmentName = providerKey; + DiskWriterReturnInformation other = writeOnDisk(storeProvider, *providerSegment); + ret.append(other); + } + return ret; + } - std::filesystem::path p = rootPath / id.str(); - if (!ensureDirectoryPathExists(p)) - { - ret.providerSegmentsError.push_back(id.str()); - ret.hasError = true; - return ret; - } + DiskWriterReturnInformation DiskWriter::writeOnDisk(const MemoryID& i, const ProviderSegment& s) + { + MemoryID id = i.getProviderSegmentID(); + DiskWriterReturnInformation ret(id.memoryName); - if (s.hasAronType()) - { - std::string val = getTypeAsString(s.aronType()); + std::filesystem::path p = rootPath / id.str(); + if (!ensureDirectoryPathExists(p)) + { + ret.providerSegmentsError.push_back(id.str()); + ret.hasError = true; + return ret; + } - std::filesystem::path providerSegmentProviderPath = rootPath / id.str() / (id.coreSegmentName + getEntityInstanceSuffix()); - std::ofstream ofs; - ofs.open(providerSegmentProviderPath); - ofs << val; - ofs.close(); - } + if (s.hasAronType()) + { + std::string val = getTypeAsString(s.aronType()); - for (const auto& [entityKey, entity] : s.entities) - { - MemoryID storeEntity(id); - storeEntity.entityName = entityKey; - DiskWriterReturnInformation other = writeOnDisk(storeEntity, *entity); - ret.append(other); - } - return ret; - } + std::filesystem::path providerSegmentProviderPath = rootPath / id.str() / (id.coreSegmentName + getEntityInstanceSuffix()); + std::ofstream ofs; + ofs.open(providerSegmentProviderPath); + ofs << val; + ofs.close(); + } - DiskWriterReturnInformation DiskWriter::writeOnDisk(const MemoryID& i, const Entity& s) - { - MemoryID id; - id.memoryName = i.memoryName; - id.coreSegmentName = i.coreSegmentName; - id.providerSegmentName = i.providerSegmentName; - id.entityName = i.entityName; + for (const auto& [entityKey, entity] : s.entities) + { + MemoryID storeEntity(id); + storeEntity.entityName = entityKey; + DiskWriterReturnInformation other = writeOnDisk(storeEntity, *entity); + ret.append(other); + } + return ret; + } - std::string memoryName = id.memoryName; + DiskWriterReturnInformation DiskWriter::writeOnDisk(const MemoryID& i, const Entity& s) + { + MemoryID id = i.getEntityID(); + DiskWriterReturnInformation ret(id.memoryName); - DiskWriterReturnInformation ret(memoryName); + std::filesystem::path p = rootPath / id.str(); + if (!ensureDirectoryPathExists(p)) + { + ret.entitiesError.push_back(id.str()); + ret.hasError = true; + return ret; + } - std::filesystem::path p = rootPath / id.str(); - if (!ensureDirectoryPathExists(p)) - { - ret.entitiesError.push_back(id.str()); - ret.hasError = true; - return ret; - } + for (const auto& [ts, snapshot] : s.history) + { + MemoryID storeSnapshot(id); + storeSnapshot.timestamp = ts; + DiskWriterReturnInformation other = writeOnDisk(storeSnapshot, *snapshot); + ret.append(other); + } + return ret; + } - for (const auto& [ts, snapshot] : s.history) - { - MemoryID storeSnapshot(id); - storeSnapshot.timestamp = ts; - DiskWriterReturnInformation other = writeOnDisk(storeSnapshot, *snapshot); - ret.append(other); - } - return ret; - } + DiskWriterReturnInformation DiskWriter::writeOnDisk(const MemoryID& _id, const EntitySnapshot& s) + { + MemoryID id = _id.getEntitySnapshotID(); + DiskWriterReturnInformation ret(id.memoryName); - DiskWriterReturnInformation DiskWriter::writeOnDisk(const MemoryID& i, const EntitySnapshot& s) - { - MemoryID id; - id.memoryName = i.memoryName; - id.coreSegmentName = i.coreSegmentName; - id.providerSegmentName = i.providerSegmentName; - id.entityName = i.entityName; - id.timestamp = i.timestamp; + std::filesystem::path p = rootPath / id.str(); + if (!ensureDirectoryPathExists(p)) + { + ret.historyTimestampsError.push_back(id.str()); + ret.hasError = true; + return ret; + } - std::string memoryName = id.memoryName; + int i = 0; + for (const auto& instance : s.instances) + { + MemoryID storeInstance(id); + storeInstance.instanceIndex = i; - DiskWriterReturnInformation ret(memoryName); + std::filesystem::path entityElementPath = rootPath / (storeInstance.str() + getEntityInstanceSuffix()); + std::string val = getDataAsString(wrapData(*instance)); - std::filesystem::path p = rootPath / id.str(); - if (!ensureDirectoryPathExists(p)) + if (filePathExists(entityElementPath)) + { + if (std::filesystem::is_directory(entityElementPath)) { - ret.historyTimestampsError.push_back(id.str()); + ret.entityInstancesError.push_back(id.str()); ret.hasError = true; return ret; } - - unsigned int x = 0; - for (const auto& instance : s.instances) - { - MemoryID storeInstance(id); - storeInstance.instanceIndex = x; - - std::filesystem::path entityElementPath = rootPath / (storeInstance.str() + getEntityInstanceSuffix()); - std::string val = getDataAsString(wrapData(*instance)); - - if (filePathExists(entityElementPath)) - { - if (std::filesystem::is_directory(entityElementPath)) - { - ret.entityInstancesError.push_back(id.str()); - ret.hasError = true; - return ret; - } - //std::ifstream ifs(entityElementPath); - //std::string file_content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>())); - //if (file_content == val) - //{ - // // already written. skip - // continue; - //} - } - - std::ofstream ofs; - ofs.open(entityElementPath); - ofs << val; - ofs.close(); - ret.storedElements.memoryLookupTable[id.memoryName] - [id.coreSegmentName] - [id.providerSegmentName] - [id.entityName] - [id.timestamp].push_back(entityElementPath); - - x++; - } - return ret; + //std::ifstream ifs(entityElementPath); + //std::string file_content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>())); + //if (file_content == val) + //{ + // // already written. skip + // continue; + //} } - aron::datanavigator::AronDictDataNavigatorPtr DiskWriter::wrapData(const EntityInstance& e) const - { - aron::datanavigator::AronDictDataNavigatorPtr dataWrapped(new aron::datanavigator::AronDictDataNavigator()); - dataWrapped->addElement(DISK_READER_WRITER_DATA_FIELD, e.data()); + std::ofstream ofs; + ofs.open(entityElementPath); + ofs << val; + ofs.close(); + ret.storedElements.memoryLookupTable[id.memoryName] + [id.coreSegmentName] + [id.providerSegmentName] + [id.entityName] + [id.timestamp].push_back(entityElementPath); + + i++; + } + return ret; + } - aron::datanavigator::AronLongDataNavigatorPtr timeWrapped(new aron::datanavigator::AronLongDataNavigator()); - timeWrapped->setValue(Time::now().toMicroSeconds()); - dataWrapped->addElement(DISK_READER_WRITER_TIME_WRAPPED_FIELD, timeWrapped); + aron::datanavigator::AronDictDataNavigatorPtr DiskWriter::wrapData(const EntityInstance& e) const + { + aron::datanavigator::AronDictDataNavigatorPtr dataWrapped(new aron::datanavigator::AronDictDataNavigator()); + dataWrapped->addElement(DISK_READER_WRITER_DATA_FIELD, e.data()); + aron::datanavigator::AronLongDataNavigatorPtr timeWrapped(new aron::datanavigator::AronLongDataNavigator()); + timeWrapped->setValue(Time::now().toMicroSeconds()); + dataWrapped->addElement(DISK_READER_WRITER_TIME_WRAPPED_FIELD, timeWrapped); - const EntityInstanceMetadata& metadata = e.metadata(); - aron::datanavigator::AronLongDataNavigatorPtr timeCreated(new aron::datanavigator::AronLongDataNavigator()); - timeCreated->setValue(metadata.timeCreated.toMicroSeconds()); - dataWrapped->addElement(DISK_READER_WRITER_TIME_CREATED_FIELD, timeCreated); - aron::datanavigator::AronLongDataNavigatorPtr timeSent(new aron::datanavigator::AronLongDataNavigator()); - timeSent->setValue(metadata.timeSent.toMicroSeconds()); - dataWrapped->addElement(DISK_READER_WRITER_TIME_SENT_FIELD, timeSent); + const EntityInstanceMetadata& metadata = e.metadata(); + aron::datanavigator::AronLongDataNavigatorPtr timeCreated(new aron::datanavigator::AronLongDataNavigator()); + timeCreated->setValue(metadata.timeCreated.toMicroSeconds()); + dataWrapped->addElement(DISK_READER_WRITER_TIME_CREATED_FIELD, timeCreated); - aron::datanavigator::AronLongDataNavigatorPtr timeArrived(new aron::datanavigator::AronLongDataNavigator()); - timeArrived->setValue(metadata.timeArrived.toMicroSeconds()); - dataWrapped->addElement(DISK_READER_WRITER_TIME_ARRIVED_FIELD, timeArrived); + aron::datanavigator::AronLongDataNavigatorPtr timeSent(new aron::datanavigator::AronLongDataNavigator()); + timeSent->setValue(metadata.timeSent.toMicroSeconds()); + dataWrapped->addElement(DISK_READER_WRITER_TIME_SENT_FIELD, timeSent); - aron::datanavigator::AronDoubleDataNavigatorPtr confidence(new aron::datanavigator::AronDoubleDataNavigator()); - confidence->setValue(metadata.confidence); - dataWrapped->addElement(DISK_READER_WRITER_CONFIDENCE_FIELD, confidence); + aron::datanavigator::AronLongDataNavigatorPtr timeArrived(new aron::datanavigator::AronLongDataNavigator()); + timeArrived->setValue(metadata.timeArrived.toMicroSeconds()); + dataWrapped->addElement(DISK_READER_WRITER_TIME_ARRIVED_FIELD, timeArrived); - return dataWrapped; - } + aron::datanavigator::AronDoubleDataNavigatorPtr confidence(new aron::datanavigator::AronDoubleDataNavigator()); + confidence->setValue(metadata.confidence); + dataWrapped->addElement(DISK_READER_WRITER_CONFIDENCE_FIELD, confidence); - bool DiskWriter::directoryPathExists(const std::filesystem::path& p) const - { - return std::filesystem::exists(p) && std::filesystem::is_directory(p); - } + return dataWrapped; + } - bool DiskWriter::ensureDirectoryPathExists(const std::filesystem::path& p) const - { - if (!std::filesystem::exists(p)) - { - return std::filesystem::create_directory(p); - } - return directoryPathExists(p); - } + bool DiskWriter::directoryPathExists(const std::filesystem::path& p) const + { + return std::filesystem::exists(p) && std::filesystem::is_directory(p); + } - bool DiskWriter::filePathExists(const std::filesystem::path& p) const - { - return std::filesystem::exists(p) && std::filesystem::is_regular_file(p); - } + bool DiskWriter::ensureDirectoryPathExists(const std::filesystem::path& p) const + { + if (!std::filesystem::exists(p)) + { + return std::filesystem::create_directory(p); + } + return directoryPathExists(p); + } + + bool DiskWriter::filePathExists(const std::filesystem::path& p) const + { + return std::filesystem::exists(p) && std::filesystem::is_regular_file(p); + } + + + io::DiskWriterReturnInformation::DiskWriterReturnInformation(const std::string& m) : + memoryName(m) + { + } + + void io::DiskWriterReturnInformation::append(const io::DiskWriterReturnInformation& o) + { + if (memoryName != o.memoryName) + { + // The memory name must be equal + return; } + + storedElements.merge(o.storedElements); + + coreSegmentsError.insert(coreSegmentsError.end(), o.coreSegmentsError.begin(), o.coreSegmentsError.end()); + providerSegmentsError.insert(providerSegmentsError.end(), o.providerSegmentsError.begin(), o.providerSegmentsError.end()); + entitiesError.insert(entitiesError.end(), o.entitiesError.begin(), o.entitiesError.end()); + historyTimestampsError.insert(historyTimestampsError.end(), o.historyTimestampsError.begin(), o.historyTimestampsError.end()); + entityInstancesError.insert(entityInstancesError.end(), o.entityInstancesError.begin(), o.entityInstancesError.end()); } + } diff --git a/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.h b/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.h index 4b02e861547b1c15435d754e83f917e7ef3945f5..aed47b150994385037fa7a15a20fa4d24d89b846 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.h +++ b/source/RobotAPI/libraries/armem/core/io/DiskWriter/DiskWriter.h @@ -23,20 +23,12 @@ // STD/STL #include <memory> #include <string> -#include <sstream> -#include <fstream> -#include <iostream> #include <filesystem> // ArmarX -#include <RobotAPI/interface/aron.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronAllDataNavigators.h> -#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronAllTypeNavigators.h> - -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/LegacyAronDataWriter/LegacyAronDataWriter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/AronDataWriter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/LegacyAronTypeWriter/LegacyAronTypeWriter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/AronTypeWriter.h> +#include <RobotAPI/libraries/aron/aroncore/navigators/datanavigator/AronDictDataNavigator.h> +#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronTypeNavigator.h> +#include <RobotAPI/libraries/aron/aroncore/navigators/typenavigator/AronObjectTypeNavigator.h> // BaseClass @@ -44,78 +36,55 @@ #include "../FileSystemLookupMemory.h" #include <RobotAPI/libraries/armem/core/Memory.h> -#include <RobotAPI/libraries/armem/core/CoreSegment.h> -#include <RobotAPI/libraries/armem/core/Entity.h> -namespace armarx::armem +namespace armarx::armem::io { - namespace ltm + struct DiskWriterReturnInformation; + + + class DiskWriter; + using DiskWriterPtr = std::shared_ptr<DiskWriter>; + + class DiskWriter : virtual public DiskReaderWriter { - namespace io - { - struct DiskWriterReturnInformation - { - std::string memoryName = ""; - bool hasError = false; - - FileSystemLookupMemoryManager storedElements; - std::vector<std::string> coreSegmentsError; - std::vector<std::string> providerSegmentsError; - std::vector<std::string> entitiesError; - std::vector<std::string> historyTimestampsError; - std::vector<std::string> entityInstancesError; - - DiskWriterReturnInformation(const std::string& m) : - memoryName(m) - { - } - - void append(const DiskWriterReturnInformation& o) - { - if (memoryName != o.memoryName) - { - // The memory name must be equal - return; - } - - storedElements.merge(o.storedElements); - - coreSegmentsError.insert(coreSegmentsError.end(), o.coreSegmentsError.begin(), o.coreSegmentsError.end()); - providerSegmentsError.insert(providerSegmentsError.end(), o.providerSegmentsError.begin(), o.providerSegmentsError.end()); - entitiesError.insert(entitiesError.end(), o.entitiesError.begin(), o.entitiesError.end()); - historyTimestampsError.insert(historyTimestampsError.end(), o.historyTimestampsError.begin(), o.historyTimestampsError.end()); - entityInstancesError.insert(entityInstancesError.end(), o.entityInstancesError.begin(), o.entityInstancesError.end()); - } - }; - - class DiskWriter; - using DiskWriterPtr = std::shared_ptr<DiskWriter>; - - class DiskWriter : - virtual public DiskReaderWriter - { - public: - DiskWriter(bool createFolder); - DiskWriter(const std::string& r, bool createFolder); - - DiskWriterReturnInformation writeOnDisk(const Memory& m); - DiskWriterReturnInformation writeOnDisk(const MemoryID&, const CoreSegment&); - DiskWriterReturnInformation writeOnDisk(const MemoryID&, const ProviderSegment&); - DiskWriterReturnInformation writeOnDisk(const MemoryID&, const Entity&); - DiskWriterReturnInformation writeOnDisk(const MemoryID&, const EntitySnapshot&); - - protected: - aron::datanavigator::AronDictDataNavigatorPtr wrapData(const EntityInstance& e) const; - - virtual std::string getDataAsString(const aron::datanavigator::AronDictDataNavigatorPtr&) const = 0; - virtual std::string getTypeAsString(const aron::typenavigator::AronObjectTypeNavigatorPtr&) const = 0; - - bool directoryPathExists(const std::filesystem::path& p) const; - bool ensureDirectoryPathExists(const std::filesystem::path& p) const; - - bool filePathExists(const std::filesystem::path& p) const; - }; - } - } + public: + DiskWriter(bool createFolder); + DiskWriter(const std::filesystem::path& rootPath, bool createFolder); + + DiskWriterReturnInformation writeOnDisk(const Memory& m); + DiskWriterReturnInformation writeOnDisk(const MemoryID&, const CoreSegment&); + DiskWriterReturnInformation writeOnDisk(const MemoryID&, const ProviderSegment&); + DiskWriterReturnInformation writeOnDisk(const MemoryID&, const Entity&); + DiskWriterReturnInformation writeOnDisk(const MemoryID&, const EntitySnapshot&); + + protected: + aron::datanavigator::AronDictDataNavigatorPtr wrapData(const EntityInstance& e) const; + + virtual std::string getDataAsString(const aron::datanavigator::AronDictDataNavigatorPtr&) const = 0; + virtual std::string getTypeAsString(const aron::typenavigator::AronObjectTypeNavigatorPtr&) const = 0; + + bool directoryPathExists(const std::filesystem::path& p) const; + bool ensureDirectoryPathExists(const std::filesystem::path& p) const; + + bool filePathExists(const std::filesystem::path& p) const; + }; + + + struct DiskWriterReturnInformation + { + std::string memoryName = ""; + bool hasError = false; + + FileSystemLookupMemoryManager storedElements; + std::vector<std::string> coreSegmentsError; + std::vector<std::string> providerSegmentsError; + std::vector<std::string> entitiesError; + std::vector<std::string> historyTimestampsError; + std::vector<std::string> entityInstancesError; + + DiskWriterReturnInformation(const std::string& m); + + void append(const DiskWriterReturnInformation& o); + }; } diff --git a/source/RobotAPI/libraries/armem/core/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.cpp b/source/RobotAPI/libraries/armem/core/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.cpp index ffdb1a0fb254d410feae0f7ebab73b692a4357de..3dc7f61f7898b74be69b6b11a0d7cf44b60c4a4f 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.cpp +++ b/source/RobotAPI/libraries/armem/core/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.cpp @@ -1,6 +1,12 @@ #include "NlohmannJSONDiskWriter.h" -namespace armarx::armem::ltm::io +#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/LegacyAronDataWriter/LegacyAronDataWriter.h> +#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/LegacyAronTypeWriter/LegacyAronTypeWriter.h> +#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NlohmannJSONWriter/AronDataNlohmannJSONWriter.h> +#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NlohmannJSONWriter/AronTypeNlohmannJSONWriter.h> + + +namespace armarx::armem::io { NlohmannJSONDiskWriter::NlohmannJSONDiskWriter(bool createFolder) : DiskReaderWriter(createFolder), @@ -18,15 +24,14 @@ namespace armarx::armem::ltm::io { aron::io::AronDataNlohmannJSONWriter dataWriter; aron::io::LegacyAronDataWriter::SetupWriterFromAronDataPtr(dataWriter, aronDataNav->getResult()); - return dataWriter.getResult().dump(4); + return dataWriter.getResult().dump(2); } std::string NlohmannJSONDiskWriter::getTypeAsString(const aron::typenavigator::AronObjectTypeNavigatorPtr& aronTypeNav) const { aron::io::AronTypeNlohmannJSONWriter typeWriter; aron::io::LegacyAronTypeWriter::SetupWriterFromAronTypePtr(typeWriter, aronTypeNav->getResult()); - return typeWriter.getResult().dump(4); + return typeWriter.getResult().dump(2); } - } diff --git a/source/RobotAPI/libraries/armem/core/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.h b/source/RobotAPI/libraries/armem/core/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.h index d4e4e57fe6c65625c02c290acbf8feaab4131d4d..2eb094107b270f98ebbb2ed7b0ff3e3895c0015e 100644 --- a/source/RobotAPI/libraries/armem/core/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.h +++ b/source/RobotAPI/libraries/armem/core/io/DiskWriter/NlohmannJSONDiskWriter/NlohmannJSONDiskWriter.h @@ -24,44 +24,34 @@ #include <memory> #include <string> -// ArmarX -#include <RobotAPI/libraries/aron/aroncore/io/AronDataIO/classWriters/NlohmannJSONWriter/AronDataNlohmannJSONWriter.h> -#include <RobotAPI/libraries/aron/aroncore/io/AronTypeIO/classWriters/NlohmannJSONWriter/AronTypeNlohmannJSONWriter.h> - // Base Class #include "../DiskWriter.h" -namespace armarx::armem +namespace armarx::armem::io { - namespace ltm + class NlohmannJSONDiskWriter; + using NlohmannJSONDiskWriterPtr = std::shared_ptr<NlohmannJSONDiskWriter>; + + class NlohmannJSONDiskWriter : virtual public DiskWriter { - namespace io - { - class NlohmannJSONDiskWriter; - typedef std::shared_ptr<NlohmannJSONDiskWriter> NlohmannJSONDiskWriterPtr; + public: + NlohmannJSONDiskWriter(bool createFolder); + NlohmannJSONDiskWriter(const std::string& rootPath, bool createFolder); - class NlohmannJSONDiskWriter : - virtual public DiskWriter - { - public: - NlohmannJSONDiskWriter(bool createFolder); - NlohmannJSONDiskWriter(const std::string& rootPath, bool createFolder); - std::string getDataAsString(const aron::datanavigator::AronDictDataNavigatorPtr&) const override; - std::string getTypeAsString(const aron::typenavigator::AronObjectTypeNavigatorPtr&) const override; + protected: + std::string getDataAsString(const aron::datanavigator::AronDictDataNavigatorPtr&) const override; + std::string getTypeAsString(const aron::typenavigator::AronObjectTypeNavigatorPtr&) const override; - protected: - std::string getEntityInstanceSuffix() const override - { - return ".data.nlohmann_json_serializer.json"; - } + std::string getEntityInstanceSuffix() const override + { + return ".data.nlohmann_json_serializer.json"; + } - std::string getTypeSuffix() const override - { - return ".type.nlohmann_json_serializer.json"; - } - }; + std::string getTypeSuffix() const override + { + return ".type.nlohmann_json_serializer.json"; } - } + }; } diff --git a/source/RobotAPI/libraries/armem/core/io/FileSystemLookupMemory.cpp b/source/RobotAPI/libraries/armem/core/io/FileSystemLookupMemory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4dac570166c3e07ecd3c90cc0cc5c3fdd5068932 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/io/FileSystemLookupMemory.cpp @@ -0,0 +1,90 @@ +/* +* This file is part of ArmarX. +* +* ArmarX is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* ArmarX is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* @author Fabian Peller (fabian dot peller at kit dot edu) +* @copyright http://www.gnu.org/licenses/gpl-2.0.txt +* GNU General Public License +*/ + +#include "FileSystemLookupMemory.h" + + +namespace armarx::armem::io +{ + + void FileSystemLookupMemoryManager::merge(const FileSystemLookupMemoryManager& m) + { + for (const auto& [memoryName, memory] : m.memoryLookupTable) + { + if (memoryLookupTable.find(memoryName) == memoryLookupTable.end()) + { + memoryLookupTable[memoryName] = memory; + continue; + } + + FileSystemLookupMemory& lutMemory = memoryLookupTable[memoryName]; + for (const auto& [coreKey, coreSegment] : memory) + { + if (lutMemory.find(coreKey) == lutMemory.end()) + { + lutMemory[coreKey] = coreSegment; + continue; + } + + FileSystemLookupCoreSegment& lutCoreSegment = lutMemory[coreKey]; + for (const auto& [providerKey, providerSegment] : coreSegment) + { + if (lutCoreSegment.find(providerKey) == lutCoreSegment.end()) + { + lutCoreSegment[providerKey] = providerSegment; + continue; + } + + FileSystemLookupProviderSegment& lutProviderSegment = lutCoreSegment[providerKey]; + for (const auto& [entityKey, entity] : providerSegment) + { + if (lutProviderSegment.find(entityKey) == lutProviderSegment.end()) + { + lutProviderSegment[entityKey] = entity; + continue; + } + + FileSystemLookupEntity& lutEntity = lutProviderSegment[entityKey]; + for (const auto& [entityHistoryTimestamp, entitySnapshot] : entity) + { + if (lutEntity.find(entityHistoryTimestamp) == lutEntity.end()) + { + lutEntity[entityHistoryTimestamp] = entitySnapshot; + continue; + } + + FileSystemLookupEntityHistory& lutEntitySnapshot = lutEntity[entityHistoryTimestamp]; + //for (unsigned int i = 0; i < entitySnapshot.size(); ++i) + //{ + // // clear internal stored memory of that snapshot + // internalMemoryEntitySnapshot.clear(); + // internalMemoryEntitySnapshot.push_back(entitySnapshot[i]); + //} + // for now, simply overwrite all values since one history timestamp should not have two different snapshots + lutEntitySnapshot = entitySnapshot; + } + } + } + } + } + } + + +} diff --git a/source/RobotAPI/libraries/armem/core/io/FileSystemLookupMemory.h b/source/RobotAPI/libraries/armem/core/io/FileSystemLookupMemory.h index 7e20fdf08be1baa46bae0a1ca6b617ba5ee91a2d..cb88b37183da7d183fcc9bb3465e1c1ed5db3735 100644 --- a/source/RobotAPI/libraries/armem/core/io/FileSystemLookupMemory.h +++ b/source/RobotAPI/libraries/armem/core/io/FileSystemLookupMemory.h @@ -21,92 +21,30 @@ #pragma once // STD/STL -#include <memory> -#include <string> #include <filesystem> +#include <map> +#include <string> +#include <vector> -// ArmarX -#include <RobotAPI/libraries/armem/core/Memory.h> +#include "../Time.h" -namespace armarx::armem +namespace armarx::armem::io { - namespace ltm - { - typedef std::vector<std::filesystem::path> FileSystemLookupEntityHistory; // absolute paths to stored files - typedef std::map<Time, FileSystemLookupEntityHistory> FileSystemLookupEntity; - typedef std::map<std::string, FileSystemLookupEntity> FileSystemLookupProviderSegment; - typedef std::map<std::string, FileSystemLookupProviderSegment> FileSystemLookupCoreSegment; - typedef std::map<std::string, FileSystemLookupCoreSegment> FileSystemLookupMemory; - - class FileSystemLookupMemoryManager - { - public: - FileSystemLookupMemoryManager() = default; + using FileSystemLookupEntityHistory = std::vector<std::filesystem::path>; // absolute paths to stored files + using FileSystemLookupEntity = std::map<Time, FileSystemLookupEntityHistory>; + using FileSystemLookupProviderSegment = std::map<std::string, FileSystemLookupEntity>; + using FileSystemLookupCoreSegment = std::map<std::string, FileSystemLookupProviderSegment>; + using FileSystemLookupMemory = std::map<std::string, FileSystemLookupCoreSegment>; - void merge(const FileSystemLookupMemoryManager& m) - { - for (const auto& [memoryName, memory] : m.memoryLookupTable) - { - if (memoryLookupTable.find(memoryName) == memoryLookupTable.end()) - { - memoryLookupTable[memoryName] = memory; - continue; - } - FileSystemLookupMemory& lutMemory = memoryLookupTable[memoryName]; - for (const auto& [coreKey, coreSegment] : memory) - { - if (lutMemory.find(coreKey) == lutMemory.end()) - { - lutMemory[coreKey] = coreSegment; - continue; - } - - FileSystemLookupCoreSegment& lutCoreSegment = lutMemory[coreKey]; - for (const auto& [providerKey, providerSegment] : coreSegment) - { - if (lutCoreSegment.find(providerKey) == lutCoreSegment.end()) - { - lutCoreSegment[providerKey] = providerSegment; - continue; - } - - FileSystemLookupProviderSegment& lutProviderSegment = lutCoreSegment[providerKey]; - for (const auto& [entityKey, entity] : providerSegment) - { - if (lutProviderSegment.find(entityKey) == lutProviderSegment.end()) - { - lutProviderSegment[entityKey] = entity; - continue; - } - - FileSystemLookupEntity& lutEntity = lutProviderSegment[entityKey]; - for (const auto& [entityHistoryTimestamp, entitySnapshot] : entity) - { - if (lutEntity.find(entityHistoryTimestamp) == lutEntity.end()) - { - lutEntity[entityHistoryTimestamp] = entitySnapshot; - continue; - } + class FileSystemLookupMemoryManager + { + public: + FileSystemLookupMemoryManager() = default; - FileSystemLookupEntityHistory& lutEntitySnapshot = lutEntity[entityHistoryTimestamp]; - //for (unsigned int i = 0; i < entitySnapshot.size(); ++i) - //{ - // // clear internal stored memory of that snapshot - // internalMemoryEntitySnapshot.clear(); - // internalMemoryEntitySnapshot.push_back(entitySnapshot[i]); - //} - // for now, simply overwrite all values since one history timestamp should not have two different snapshots - lutEntitySnapshot = entitySnapshot; - } - } - } - } - } - } + void merge(const FileSystemLookupMemoryManager& m); - std::map<std::string, FileSystemLookupMemory> memoryLookupTable; - }; - } + std::map<std::string, FileSystemLookupMemory> memoryLookupTable; + }; } diff --git a/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.cpp b/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.cpp index dd9fb2bceea66868e9eab8b3eb3648673c85dca8..2cde6249d434bbe3e72bb13dc827c0519119f57e 100644 --- a/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.cpp +++ b/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.cpp @@ -1,10 +1,11 @@ #include "MemoryFileSystemStorage.h" -namespace armarx::armem::ltm + +namespace armarx::armem::io { - MemoryFileSystemStorage::MemoryFileSystemStorage(const std::string& r, bool createFolder) : - writer(new io::NlohmannJSONDiskWriter(r, createFolder)), - reader(new io::NlohmannJSONDiskReader(r, createFolder)) + MemoryFileSystemStorage::MemoryFileSystemStorage(const std::filesystem::path& rootPath, bool createFolder) : + MemoryFileSystemStorage(std::make_shared<io::NlohmannJSONDiskWriter>(rootPath, createFolder), + std::make_shared<io::NlohmannJSONDiskReader>(rootPath, createFolder)) { } @@ -12,7 +13,6 @@ namespace armarx::armem::ltm writer(w), reader(r) { - } void MemoryFileSystemStorage::writeOnDisk(const Memory& m) @@ -79,7 +79,7 @@ namespace armarx::armem::ltm id.timestamp = entityHistoryTimestamp; for (unsigned int i = 0; i < entitySnapshot.size(); ++i) { - id.instanceIndex = i; + id.instanceIndex = static_cast<int>(i); EntityInstancePtr instance = reader->readSingleInstanceFromDisk(entitySnapshot[i]); es.instances.push_back(std::move(instance)); } diff --git a/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.h b/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.h index 8ba3480ac0dd8e5c70940b3a0bb04a1e625ee577..f90b687534b01093c30047a41c73f26eeb885c1a 100644 --- a/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.h +++ b/source/RobotAPI/libraries/armem/core/io/MemoryFileSystemStorage.h @@ -21,8 +21,9 @@ #pragma once // STD/STL -#include <memory> +#include <filesystem> #include <string> +#include <utility> // std::pair // ArmarX #include <RobotAPI/interface/aron.h> @@ -35,51 +36,37 @@ #include "DiskReader/NlohmannJSONDiskReader/NlohmannJSONDiskReader.h" -namespace armarx::armem +namespace armarx::armem::io { - namespace ltm + class MemoryFileSystemStorage { - class MemoryFileSystemStorage; - typedef std::shared_ptr<MemoryFileSystemStorage> LongTermMemoryLUTPtr; + public: + MemoryFileSystemStorage() = delete; + MemoryFileSystemStorage(const std::filesystem::path& rootPath, bool createFolder = false); + MemoryFileSystemStorage(const io::DiskWriterPtr&, const io::DiskReaderPtr&); - class MemoryFileSystemStorage - { - public: - MemoryFileSystemStorage() = delete; - MemoryFileSystemStorage(const std::string&, bool createFolder = false); - MemoryFileSystemStorage(const io::DiskWriterPtr&, const io::DiskReaderPtr&); + void writeOnDisk(const Memory&); + void writeOnDisk(const MemoryID&, const CoreSegment&); + void writeOnDisk(const MemoryID&, const ProviderSegment&); + void writeOnDisk(const MemoryID&, const Entity&); + void writeOnDisk(const MemoryID&, const EntitySnapshot&); - void writeOnDisk(const Memory&); - void writeOnDisk(const MemoryID&, const CoreSegment&); - void writeOnDisk(const MemoryID&, const ProviderSegment&); - void writeOnDisk(const MemoryID&, const Entity&); - // void writeOnDisk(const MemoryID&, const Entity&, aron::typenavigator::AronObjectTypeNavigatorPtr = nullptr); - void writeOnDisk(const MemoryID&, const EntitySnapshot&); - Memory readMemoryFromDisk(); - CoreSegment readCoreSegmentFromDisk(); - ProviderSegment readFromDisk(); - Entity readEntityFromDisk(); - EntitySnapshot readEntitySnapshotFromDisk(); - std::pair<Entity, aron::typenavigator::AronObjectTypeNavigatorPtr> readTypedEntityFromDisk(); - std::pair<EntitySnapshot, aron::typenavigator::AronObjectTypeNavigatorPtr> readTypedEntitySnapshotFromDisk(); + void updateInternalMemoryFromFileSystem(); + EntityPtr getEntityFromFileSystem(const MemoryID&); - void updateInternalMemoryFromFileSystem(); - EntityPtr getEntityFromFileSystem(const MemoryID&); + std::map<std::string, MemoryPtr> getInternalMemoryAsRealMemory() const; + std::string getInternalMemoryAsString(); - std::map<std::string, MemoryPtr> getInternalMemoryAsRealMemory() const; - std::string getInternalMemoryAsString(); + private: + void updateInternalMemory(const FileSystemLookupMemoryManager& info); - private: - void updateInternalMemory(const FileSystemLookupMemoryManager& info); + private: + FileSystemLookupMemoryManager internalMemory; - private: - FileSystemLookupMemoryManager internalMemory; - - io::DiskWriterPtr writer; - io::DiskReaderPtr reader; - }; - } + DiskWriterPtr writer; + DiskReaderPtr reader; + }; } diff --git a/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp b/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp index c6b5e568e514b9dc478b1308f391031bb2370415..ee844296915279b898135a9e235e002a6f49c7fe 100644 --- a/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp +++ b/source/RobotAPI/libraries/armem/test/ArMemLTMTest.cpp @@ -86,23 +86,23 @@ BOOST_AUTO_TEST_CASE(test_memory_heavy_setup_and_export) // export memory std::string storagePath = "/tmp/MemoryExport"; // important! without tailing / - armem::ltm::MemoryFileSystemStorage ltm(storagePath, true); - ltm.writeOnDisk(*memory); + armem::io::MemoryFileSystemStorage mfs(storagePath, true); + mfs.writeOnDisk(*memory); - std::string ltm_str = ltm.getInternalMemoryAsString(); + std::string mfs_str = mfs.getInternalMemoryAsString(); - armem::ltm::MemoryFileSystemStorage ltm2(storagePath); - ltm2.updateInternalMemoryFromFileSystem(); + armem::io::MemoryFileSystemStorage mfs2(storagePath); + mfs2.updateInternalMemoryFromFileSystem(); - std::string ltm2_str = ltm2.getInternalMemoryAsString(); + std::string mfs2_str = mfs2.getInternalMemoryAsString(); - std::cout << "LTM1: " << std::endl; - std::cout << ltm_str << std::endl; - std::cout << "LTM2: " << std::endl; - std::cout << ltm2_str << std::endl; - BOOST_CHECK_EQUAL(ltm_str == ltm2_str, true); + std::cout << "MFS1: " << std::endl; + std::cout << mfs_str << std::endl; + std::cout << "MFS2: " << std::endl; + std::cout << mfs2_str << std::endl; + BOOST_CHECK_EQUAL(mfs_str == mfs_str, true); - //std::map<std::string, armem::MemoryPtr> loaded_memories = ltm.getInternalMemoryAsRealMemory(); + //std::map<std::string, armem::MemoryPtr> loaded_memories = mfs.getInternalMemoryAsRealMemory(); //armem::MemoryPtr& memory2 = loaded_memories["Memory"]; //BOOST_CHECK_EQUAL(memory->equalsDeep(*memory2), true);