diff --git a/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp b/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp index b6a5a79ccfdeddca218dfc8068c0bc69285353b5..dd9bc72a216b592b2752e4d8cf586b3fd6b3cdf7 100644 --- a/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp +++ b/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp @@ -1,5 +1,7 @@ #include "MemoryToIceAdapter.h" +#include <thread> + #include <ArmarXCore/core/exceptions/local/ExpressionException.h> #include <ArmarXCore/core/ice_conversions/ice_conversions_templates.h> #include <ArmarXCore/core/logging/Logging.h> @@ -16,8 +18,6 @@ #include "query_proc/ltm/disk/ltm.h" #include "query_proc/wm/wm.h" -#include <thread> - namespace armarx::armem::server { @@ -33,7 +33,8 @@ namespace armarx::armem::server this->memoryListenerTopic = memoryListener; } - void MemoryToIceAdapter::addSecondLTM(ltm::Memory *longtermMemory) + void + MemoryToIceAdapter::addSecondLTM(ltm::Memory* longtermMemory) { std::string name = longtermMemory->getExportName(); /* @@ -89,8 +90,6 @@ namespace armarx::armem::server "You tried to add " << name; } */ - - } // WRITING @@ -228,7 +227,7 @@ namespace armarx::armem::server armem::CommitResult MemoryToIceAdapter::_commit(const armem::Commit& commit, bool locking) - { + { ARMARX_TRACE; std::vector<data::MemoryID> updatedIDs; const bool publishUpdates = bool(memoryListenerTopic); @@ -392,7 +391,8 @@ namespace armarx::armem::server result.success = false; result.errorMessage = e.what(); } - catch (...){ + catch (...) + { ARMARX_INFO << "Error during LTM consollidation"; } } @@ -546,8 +546,9 @@ namespace armarx::armem::server ltms.push_back(fifteenthLTM); ltms.push_back(sixteenthLTM); */ - for(int i = 0; i < static_cast<int>(ltms.size()); i++){ - ltms.at(i)->startRecording(); + for (int i = 0; i < static_cast<int>(ltms.size()); i++) + { + ltms.at(i)->startRecording(); } //longtermMemory->startRecording(); // TODO: config and execution time! @@ -585,25 +586,25 @@ namespace armarx::armem::server ltms.push_back(sixteenthLTM); */ std::vector<std::thread> threads; - for(int i = 0; i < static_cast<int>(ltms.size()); ++i){ - threads.push_back(std::thread([i, <ms]{ - ltms.at(i)->stopRecording(); - })); + for (int i = 0; i < static_cast<int>(ltms.size()); ++i) + { + threads.push_back(std::thread([i, <ms] { ltms.at(i)->stopRecording(); })); } - - ARMARX_IMPORTANT << "Stopped all LTM recordings, please wait with stopping the component until " - "all files are written"; + ARMARX_IMPORTANT + << "Stopped all LTM recordings, please wait with stopping the component until " + "all files are written"; dto::StopRecordResult ret; ret.success = true; - for(auto& thread: threads){ + for (auto& thread : threads) + { thread.detach(); } - + /* try { auto l = longtermMemory; //ARMARX_INFO << "Current buffer status: " << longtermMemory->bufferFinished(); @@ -614,6 +615,7 @@ namespace armarx::armem::server } catch (...) { ARMARX_WARNING << "Problem when accessing storing task thread information"; } +*/ return ret; diff --git a/source/RobotAPI/libraries/armem/server/ltm/EntityInstance.cpp b/source/RobotAPI/libraries/armem/server/ltm/EntityInstance.cpp index 0f22975cf5959ef7af19a71d45c24982aaff7222..f1fb07d0aaf284fa01e6c4896988276aab0f63ff 100644 --- a/source/RobotAPI/libraries/armem/server/ltm/EntityInstance.cpp +++ b/source/RobotAPI/libraries/armem/server/ltm/EntityInstance.cpp @@ -193,14 +193,27 @@ namespace armarx::armem::server::ltm auto metadataAron = std::make_shared<aron::data::Dict>(); to_aron(metadataAron, dataAron, e); - auto deep_copy_dataAron = dataAron->clone(); //this is only a fix for now, I need to find out what is actually happening + std::shared_ptr<aron::data::Dict> source; + + bool saveAndExtract = true; + + if (saveAndExtract) + { + source = dataAron->clone(); + } + else + { + source = dataAron; + } + + //auto deep_copy_dataAron = dataAron->clone(); //this is only a fix for now, I need to find out what is actually happening // check special members for special converters for (auto& c : processors->converters) { ARMARX_CHECK_NOT_NULL(c); ARMARX_CHECK_NOT_NULL(c->extractor); - auto dataExt = c->extractor->extract(deep_copy_dataAron); + auto dataExt = c->extractor->extract(source); for (const auto& [memberName, var] : dataExt.extraction) { @@ -212,10 +225,9 @@ namespace armarx::armem::server::ltm ensureFileExists(filename, true); writeDataToFile(filename, memberDataVec); - } + } //deep_copy_dataAron = dataExt.dataWithoutExtraction; - } // convert dict and metadata diff --git a/source/RobotAPI/libraries/armem/server/ltm/detail/mixins/BufferedMemoryMixin.h b/source/RobotAPI/libraries/armem/server/ltm/detail/mixins/BufferedMemoryMixin.h index 7c774394b83c199f6a3ae52eca25bdac631ea718..7f490b5419fe9dc631ef5408e55ae12d09ce3d07 100644 --- a/source/RobotAPI/libraries/armem/server/ltm/detail/mixins/BufferedMemoryMixin.h +++ b/source/RobotAPI/libraries/armem/server/ltm/detail/mixins/BufferedMemoryMixin.h @@ -1,14 +1,15 @@ #pragma once +#include <atomic> +#include <chrono> +#include <thread> + #include <SimoxUtility/json.h> #include <ArmarXCore/core/services/tasks/PeriodicTask.h> #include <RobotAPI/libraries/armem/core/wm/memory_definitions.h> -#include <chrono> -#include <thread> - namespace armarx::armem::server::ltm::detail::mixin { template <class _CoreSegmentT> @@ -35,17 +36,34 @@ namespace armarx::armem::server::ltm::detail::mixin } void - bufferFinished(){ - while(!(buffer->empty())){ //wait until buffer is empty - ARMARX_INFO << deactivateSpam() << "Writing data to files, please do not stop this component"; + bufferFinished() + { + ARMARX_INFO << "Saving data in files..."; + + while (!(buffer->empty())) + { //wait until buffer is empty + ARMARX_INFO << deactivateSpam() + << "Writing data to files, please do not stop this component"; sleep(5); //do not test too often } - while(storeFlag.test()){ //and then wait until the store_buffer was emptied, indicated by the store flag - ARMARX_INFO << deactivateSpam() << "Writing data from memory to files, pleaso do not stop this component"; + /* + sleep(30); + ARMARX_INFO << "Test"; + bool store = storeFlag.test_and_set(); + storeFlag.clear(); + while (store) + { //and then wait until the store_buffer was emptied, indicated by the store flag + ARMARX_INFO + << deactivateSpam() + << "Writing data from memory to files, pleaso do not stop this component"; sleep(2); + store = storeFlag.test_and_set(); + storeFlag.clear(); } sleep(5); //make sure last buffer was also written - ARMARX_IMPORTANT << "All buffers empty, all information stored on disk. You can stop this component now"; + ARMARX_IMPORTANT << "All buffers empty, all information stored on disk. You can stop " + "this component now"; +*/ } protected: @@ -68,7 +86,8 @@ namespace armarx::armem::server::ltm::detail::mixin task = new armarx::PeriodicTask<BufferedMemoryMixin>( this, &BufferedMemoryMixin::storeBuffer, waitingTimeMs); task->start(); - task->setDelayWarningTolerance(waitingTimeMs); //a warning will be issued if the task takes longer than the waitingTime + task->setDelayWarningTolerance( + waitingTimeMs); //a warning will be issued if the task takes longer than the waitingTime } } @@ -105,13 +124,16 @@ namespace armarx::armem::server::ltm::detail::mixin return; } - while(storeFlag.test_and_set(std::memory_order_acquire)){ + while (storeFlag.test_and_set(std::memory_order_acquire)) + { std::this_thread::yield(); } - std::thread storingThread([&]{ - this->directlyStore(*to_store); - storeFlag.clear(std::memory_order_release); - }); + std::thread storingThread( + [&] + { + this->directlyStore(*to_store); + storeFlag.clear(std::memory_order_release); + }); storingThread.detach(); } @@ -128,7 +150,7 @@ namespace armarx::armem::server::ltm::detail::mixin } void - createPropertyDefinitions(PropertyDefinitionsPtr &defs, const std::string &prefix) + createPropertyDefinitions(PropertyDefinitionsPtr& defs, const std::string& prefix) { defs->optional(storeFrequency, prefix + "storeFrequency"); } @@ -143,7 +165,6 @@ namespace armarx::armem::server::ltm::detail::mixin } - protected: /// Internal memory for data consolidated from wm to ltm (double-buffer) /// The to-put-to-ltm buffer (contains data in plain text) diff --git a/source/RobotAPI/libraries/armem/server/ltm/processors/converter/data/image/png/PngConverter.h b/source/RobotAPI/libraries/armem/server/ltm/processors/converter/data/image/png/PngConverter.h index 8fb622d281147068c2c01d4902258867ce3545e3..34904df5c275158b25f9aebd64e60a3ef4f96499 100644 --- a/source/RobotAPI/libraries/armem/server/ltm/processors/converter/data/image/png/PngConverter.h +++ b/source/RobotAPI/libraries/armem/server/ltm/processors/converter/data/image/png/PngConverter.h @@ -21,6 +21,7 @@ namespace armarx::armem::server::ltm::processor::converter::data::image void configure(const nlohmann::json& json) override; + protected: ConversionResult _convert(const aron::data::NDArrayPtr& data) final; aron::data::NDArrayPtr _convert(const ConversionResult& data,