From b22f9d25c895526da39d0215119b7eccc8bff4a6 Mon Sep 17 00:00:00 2001
From: joana <uhfpm@student.kit.edu>
Date: Thu, 16 Nov 2023 14:05:06 +0100
Subject: [PATCH] removed old comments, added try-catch for setting export
 name, added ARMARX_INFO output for export name information

---
 .../libraries/armem/server/ltm/Memory.cpp     | 59 +++++++------------
 .../armem/server/ltm/detail/MemoryBase.h      | 11 +++-
 .../ltm/detail/mixins/DiskStorageMixin.cpp    |  5 +-
 .../libraries/armem/server/plugins/Plugin.cpp |  2 +-
 4 files changed, 34 insertions(+), 43 deletions(-)

diff --git a/source/RobotAPI/libraries/armem/server/ltm/Memory.cpp b/source/RobotAPI/libraries/armem/server/ltm/Memory.cpp
index 40c933521..4625dc616 100644
--- a/source/RobotAPI/libraries/armem/server/ltm/Memory.cpp
+++ b/source/RobotAPI/libraries/armem/server/ltm/Memory.cpp
@@ -18,27 +18,9 @@ namespace armarx::armem::server::ltm
         MongoDBStorageMixin::configureMixin(json);
     }
 
-    Memory::Memory() : Memory(std::filesystem::path("/tmp/ARMARX/LTM_Exports"), {}, "MemoryExport", "Test")
+    Memory::Memory() :
+        Memory(std::filesystem::path("/tmp/ARMARX/LTM_Exports"), {}, "MemoryExport", "Test")
     {
-        //set path to include date of creation as prefix:
-        this->current_date = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
-        std::tm* localTime = std::localtime(&this->current_date);
-
-        // convert current time into string:
-        std::stringstream ss;
-        ss << std::put_time(localTime, "%Y_%m_%d");
-        std::string dateString = ss.str();
-
-        // change memory base path to include current date (date of memory creation)
-        std::filesystem::path current_base_path = this->getMemoryBasePath();
-        this->setMemoryBasePath(current_base_path.append(dateString));
-
-        //inform user about change:
-        ARMARX_DEBUG << "Changed memory base path to include current date of "
-                    << dateString
-                    << " to "
-                    << this->getMemoryBasePath()
-                       ;
     }
 
     Memory::Memory(const detail::mixin::Path& p,
@@ -60,6 +42,26 @@ namespace armarx::armem::server::ltm
         DiskMemoryItemMixin(p, exportName, MemoryID(memoryName, "")),
         MongoDBStorageMixin(s, exportName, MemoryID(memoryName, ""))
     {
+        //set path to include date of creation as prefix:
+        this->current_date = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
+        std::tm* localTime = std::localtime(&this->current_date);
+
+        // convert current time into string:
+        std::stringstream ss;
+        ss << std::put_time(localTime, "%Y_%m_%d");
+        std::string dateString = ss.str();
+
+        // change memory base path to include current date (date of memory creation)
+        std::filesystem::path current_base_path = this->getMemoryBasePath();
+        this->setMemoryBasePath(current_base_path.append(dateString));
+
+        //inform user about change:
+        ARMARX_DEBUG << "Changed memory base path to include current date of "
+                    << dateString
+                    << " to "
+                    << this->getMemoryBasePath()
+                       ;
+
         ARMARX_INFO << "Creating a new memory at " << p.string() << " and " << exportName;
 
     }
@@ -101,23 +103,6 @@ namespace armarx::armem::server::ltm
     {
         std::lock_guard l(ltm_mutex);
 
-        // for each
-        /*if (connected() && collectionExists())
-        {
-            for (const auto& doc : getAllDocuments())
-            {
-                std::string segmentName = doc[FOREIGN_KEY];
-                CoreSegment c(getMemoryBasePath(),
-                              getSettings(),
-                              getExportName(),
-                              id().withCoreSegmentName(segmentName),
-                              processors);
-                func(c);
-            }
-        } else */
-
-        //ARMARX_INFO << "LTM: forEach CoreSegment";
-        //ARMARX_INFO << "";
         // legacy: check fs
         if (fullPathExists())
         {
diff --git a/source/RobotAPI/libraries/armem/server/ltm/detail/MemoryBase.h b/source/RobotAPI/libraries/armem/server/ltm/detail/MemoryBase.h
index 0719a427b..3db89a8eb 100644
--- a/source/RobotAPI/libraries/armem/server/ltm/detail/MemoryBase.h
+++ b/source/RobotAPI/libraries/armem/server/ltm/detail/MemoryBase.h
@@ -71,6 +71,13 @@ namespace armarx::armem::server::ltm::detail
             {
                 this->startRecording();
             }
+
+            try{
+                ARMARX_INFO << "Export name: " << p.export_name;
+                this->_setExportName(p.export_name);
+            } catch(...){
+                ARMARX_WARNING << "Could not read and/or set export name";
+            }
         }
 
         /// enable this LTM
@@ -79,6 +86,7 @@ namespace armarx::armem::server::ltm::detail
         {
             auto now = armarx::core::time::DateTime::Now();
             ARMARX_INFO << "Enabling LTM " << id().str() << " at " << now.toDateTimeString();
+            ARMARX_INFO << "Storing information at " << this->getExportName();
             enabled = true;
             if(statistics.firstStart){
                 statistics.firstStarted = armarx::core::time::DateTime::Now();
@@ -192,9 +200,6 @@ namespace armarx::armem::server::ltm::detail
             defs->optional(p.configuration_on_startup, prefix + "configuration");
             defs->optional(p.export_name, prefix + "exportName");
             defs->optional(p.export_path, prefix + "exportPath");
-
-            ARMARX_INFO << "Setting property definitions";
-            _setExportName(p.export_name);
         }
 
         /// enable/disable
diff --git a/source/RobotAPI/libraries/armem/server/ltm/detail/mixins/DiskStorageMixin.cpp b/source/RobotAPI/libraries/armem/server/ltm/detail/mixins/DiskStorageMixin.cpp
index 647c9025b..597453b07 100644
--- a/source/RobotAPI/libraries/armem/server/ltm/detail/mixins/DiskStorageMixin.cpp
+++ b/source/RobotAPI/libraries/armem/server/ltm/detail/mixins/DiskStorageMixin.cpp
@@ -34,8 +34,9 @@ namespace armarx::armem::server::ltm::detail::mixin
     void
     DiskMemoryItemMixin::setMixinExportName(const std::string& n)
     {
-        //ARMARX_INFO << "Currently setting export name to: " << n;
+        ARMARX_INFO << "Currently setting export name to: " << n;
         exportName = n;
+        ARMARX_INFO << "Currently export name in mixin is set to " << this->exportName;
     }
 
     void
@@ -51,7 +52,7 @@ namespace armarx::armem::server::ltm::detail::mixin
     {
         if (json.find("DiskMemory.memoryParentPath") != json.end())
         {
-            memoryBasePath = Path(json.at("DiskMemory.memoryParentPath"));
+            //memoryBasePath = Path(json.at("DiskMemory.memoryParentPath"));
         }
     }
 
diff --git a/source/RobotAPI/libraries/armem/server/plugins/Plugin.cpp b/source/RobotAPI/libraries/armem/server/plugins/Plugin.cpp
index a3bb52a64..ec5eca6cd 100644
--- a/source/RobotAPI/libraries/armem/server/plugins/Plugin.cpp
+++ b/source/RobotAPI/libraries/armem/server/plugins/Plugin.cpp
@@ -196,7 +196,7 @@ namespace armarx::armem::server::plugins
         iceAdapter.setMemoryListener(memoryTopic);
 
         connected = true;
-        ARMARX_INFO << "Export Name: " << longtermMemory.getExportName(); //TODO: remove after testing
+        //ARMARX_INFO << "Export Name: " << longtermMemory.getExportName(); //TODO: remove after testing
     }
 
     void
-- 
GitLab