diff --git a/source/RobotAPI/interface/armem/query.ice b/source/RobotAPI/interface/armem/query.ice index 2a0eb6e217a769fe4bab33dd0ab896e2faeda8e5..2a1586fece346e89cbe491cd21c026ddab603e0e 100644 --- a/source/RobotAPI/interface/armem/query.ice +++ b/source/RobotAPI/interface/armem/query.ice @@ -13,15 +13,16 @@ module armarx { enum QueryTarget { - WMAndLTM, WM, - LTM // only for debug. remove later + LTM, + Disk }; + sequence<QueryTarget> QueryTargets; /// Which entity snapshots to get from an entity? class EntityQuery { - QueryTarget target = QueryTarget::WMAndLTM; + QueryTargets targets; }; sequence<EntityQuery> EntityQuerySeq; @@ -115,7 +116,7 @@ module armarx class ProviderSegmentQuery { EntityQuerySeq entityQueries; - QueryTarget target = QueryTarget::WMAndLTM; + QueryTargets targets; }; sequence<ProviderSegmentQuery> ProviderSegmentQuerySeq; module provider @@ -138,7 +139,7 @@ module armarx class CoreSegmentQuery { ProviderSegmentQuerySeq providerSegmentQueries; - QueryTarget target = QueryTarget::WMAndLTM; + QueryTargets targets; }; sequence<CoreSegmentQuery> CoreSegmentQuerySeq; @@ -162,7 +163,7 @@ module armarx class MemoryQuery { CoreSegmentQuerySeq coreSegmentQueries; - QueryTarget target = QueryTarget::WMAndLTM; + QueryTargets targets; }; sequence<MemoryQuery> MemoryQuerySeq; dictionary<string, MemoryQuerySeq> MemoryQueriesDict; @@ -188,7 +189,6 @@ module armarx { /// Dict of memory name to MemoryQueriesDict memoryQueries; - QueryTarget target = QueryTarget::WMAndLTM; }; struct Input diff --git a/source/RobotAPI/libraries/armem/CMakeLists.txt b/source/RobotAPI/libraries/armem/CMakeLists.txt index 38d9515cc25818652636ca4b8c5e969eaaf9519a..7f949da5645c81c449a9035edc87e3fa42f49403 100644 --- a/source/RobotAPI/libraries/armem/CMakeLists.txt +++ b/source/RobotAPI/libraries/armem/CMakeLists.txt @@ -122,6 +122,12 @@ set(LIB_FILES server/query_proc/longtermmemory/CoreSegmentQueryProcessor.cpp server/query_proc/longtermmemory/MemoryQueryProcessor.cpp + server/query_proc/diskmemory/BaseQueryProcessor.cpp + server/query_proc/diskmemory/EntityQueryProcessor.cpp + server/query_proc/diskmemory/ProviderSegmentQueryProcessor.cpp + server/query_proc/diskmemory/CoreSegmentQueryProcessor.cpp + server/query_proc/diskmemory/MemoryQueryProcessor.cpp + mns/MemoryNameSystem.cpp mns/ComponentPlugin.cpp @@ -237,6 +243,12 @@ set(LIB_HEADERS server/query_proc/longtermmemory/CoreSegmentQueryProcessor.h server/query_proc/longtermmemory/MemoryQueryProcessor.h + server/query_proc/diskmemory/BaseQueryProcessor.h + server/query_proc/diskmemory/EntityQueryProcessor.h + server/query_proc/diskmemory/ProviderSegmentQueryProcessor.h + server/query_proc/diskmemory/CoreSegmentQueryProcessor.h + server/query_proc/diskmemory/MemoryQueryProcessor.h + mns.h mns/MemoryNameSystem.h mns/ComponentPlugin.h diff --git a/source/RobotAPI/libraries/armem/client/Query.h b/source/RobotAPI/libraries/armem/client/Query.h index 4f5a87bdccfc84458210d0811b02d99275b54ae4..916278a8fcde1679545ed39d59531f5772852c13 100644 --- a/source/RobotAPI/libraries/armem/client/Query.h +++ b/source/RobotAPI/libraries/armem/client/Query.h @@ -28,6 +28,37 @@ namespace armarx::armem::client armem::query::data::MemoryQuerySeq memoryQueries; DataMode dataMode; + void addQueryTargetToAll(const armem::query::data::QueryTarget t) + { + for (const auto& memoryQuery : memoryQueries) + { + if (std::find(memoryQuery->targets.begin(), memoryQuery->targets.end(), t) == memoryQuery->targets.end()) + { + memoryQuery->targets.push_back(t); + } + for (const auto& coreSegmentQuery : memoryQuery->coreSegmentQueries) + { + if (std::find(coreSegmentQuery->targets.begin(), coreSegmentQuery->targets.end(), t) == coreSegmentQuery->targets.end()) + { + coreSegmentQuery->targets.push_back(t); + } + for (const auto& providerSegmentQuery : coreSegmentQuery->providerSegmentQueries) + { + if (std::find(providerSegmentQuery->targets.begin(), providerSegmentQuery->targets.end(), t) == providerSegmentQuery->targets.end()) + { + providerSegmentQuery->targets.push_back(t); + } + for (const auto& entityQuery : providerSegmentQuery->entityQueries) + { + if (std::find(entityQuery->targets.begin(), entityQuery->targets.end(), t) == entityQuery->targets.end()) + { + entityQuery->targets.push_back(t); + } + } + } + } + } + } static QueryInput fromIce(const armem::query::data::Input& ice); armem::query::data::Input toIce() const; diff --git a/source/RobotAPI/libraries/armem/client/query/Builder.cpp b/source/RobotAPI/libraries/armem/client/query/Builder.cpp index 5979ea365a863dc0ce1c0c0b91a0d77fc3f331e9..59ae0b7c082bc25a8b1084f8ac49611df107d132 100644 --- a/source/RobotAPI/libraries/armem/client/query/Builder.cpp +++ b/source/RobotAPI/libraries/armem/client/query/Builder.cpp @@ -8,12 +8,6 @@ namespace armarx::armem::client::query { } - Builder& Builder::queryTarget(const armem::query::data::QueryTarget target) - { - this->_target = target; - return *this; - } - QueryInput Builder::buildQueryInput() const { QueryInput input; @@ -31,9 +25,9 @@ namespace armarx::armem::client::query armem::query::data::MemoryQuerySeq memoryQueries; for (const CoreSegmentSelector& child : _children) { - for (const armem::query::data::MemoryQueryPtr& query : child.buildQueries()) + for (armem::query::data::MemoryQueryPtr& query : child.buildQueries()) { - query->target = _target; + query->targets = _targets; memoryQueries.push_back(query); } } diff --git a/source/RobotAPI/libraries/armem/client/query/Builder.h b/source/RobotAPI/libraries/armem/client/query/Builder.h index eae09294320f216aa3e996821c429376ff7675a0..dc6147ef03e7de81518e64bddc9bb486f0062b07 100644 --- a/source/RobotAPI/libraries/armem/client/query/Builder.h +++ b/source/RobotAPI/libraries/armem/client/query/Builder.h @@ -28,7 +28,6 @@ namespace armarx::armem::client::query public: Builder(DataMode dataMode = DataMode::WithData); - Builder& queryTarget(const armem::query::data::QueryTarget target); /// Start specifying core segments. CoreSegmentSelector& coreSegments(); @@ -66,7 +65,6 @@ namespace armarx::armem::client::query public: - armem::query::data::QueryTarget _target = armem::query::data::QueryTarget::WMAndLTM; DataMode dataMode; }; diff --git a/source/RobotAPI/libraries/armem/client/query/detail/SelectorOps.h b/source/RobotAPI/libraries/armem/client/query/detail/SelectorOps.h index 0a0e89e0ab7f651aa40ff3e2f564d48293f64a40..c6e153f0d7358b318c6966f2c9d5c9c2c35579a4 100644 --- a/source/RobotAPI/libraries/armem/client/query/detail/SelectorOps.h +++ b/source/RobotAPI/libraries/armem/client/query/detail/SelectorOps.h @@ -5,6 +5,7 @@ #include <Ice/Handle.h> #include <RobotAPI/libraries/armem/core/MemoryID.h> +#include <RobotAPI/interface/armem/query.h> namespace armarx::armem::client::query::detail @@ -17,7 +18,11 @@ namespace armarx::armem::client::query::detail using DerivedT = _DerivedT; using QueryT = _QueryT; - virtual ~ChildSelectorOps() = default; + ChildSelectorOps() = delete; + + ChildSelectorOps(const armem::query::data::QueryTargets& p) : + _parentTargets(p) + {} virtual DerivedT& all() = 0; @@ -36,6 +41,9 @@ namespace armarx::armem::client::query::detail } } + protected: + armem::query::data::QueryTargets _parentTargets; + protected: @@ -81,11 +89,21 @@ namespace armarx::armem::client::query::detail using ChildT = _ChildT; + public: + virtual ~ParentSelectorOps() = default; + + /// QueryTargets for this query + DerivedT& queryTargets(const armem::query::data::QueryTargets& targets) + { + this->_targets = targets; + return dynamic_cast<DerivedT&>(*this); + } + protected: ChildT& _addChild() { - return _children.emplace_back(); + return _children.emplace_back(_targets); } ChildT& _addChild(const ChildT& child) { @@ -102,7 +120,7 @@ namespace armarx::armem::client::query::detail std::vector<ChildT> _children; - + armem::query::data::QueryTargets _targets = {armem::query::data::QueryTarget::WM}; // if not specified we only query the WM }; @@ -114,17 +132,27 @@ namespace armarx::armem::client::query::detail { public: - virtual ~InnerSelectorOps() + InnerSelectorOps(const armem::query::data::QueryTargets& p) : + ChildSelectorOps<DerivedT, QueryT>(p) {} - virtual std::vector<QueryT> buildQueries() const { + // check own query targets and parent query targets + for (const auto& target : this->_targets) + { + if (std::find(this->_parentTargets.begin(), this->_parentTargets.end(), target) == this->_parentTargets.end()) + { + // TODO: Error, this makes no sense! or just ignore? + } + } + std::vector<typename ChildT::QueryT> childQueries; for (const auto& child : this->_children) { - for (const auto& query : child.buildQueries()) + for (auto& query : child.buildQueries()) { + query->targets = this->_targets; childQueries.push_back(query); } } diff --git a/source/RobotAPI/libraries/armem/client/query/selectors.cpp b/source/RobotAPI/libraries/armem/client/query/selectors.cpp index cc3a73829ab7c79eabc96c30b55c4ca350ac33ad..98e79d06ab3642b25bee40e89daf728ab3dfee2b 100644 --- a/source/RobotAPI/libraries/armem/client/query/selectors.cpp +++ b/source/RobotAPI/libraries/armem/client/query/selectors.cpp @@ -77,7 +77,6 @@ namespace armarx::armem::client::query return *this; } - SnapshotSelector& EntitySelector::snapshots() { return _addChild(); @@ -115,7 +114,6 @@ namespace armarx::armem::client::query } - EntitySelector& ProviderSegmentSelector::entities() { return _addChild(); @@ -153,7 +151,6 @@ namespace armarx::armem::client::query } - ProviderSegmentSelector& CoreSegmentSelector::providerSegments() { return _addChild(); diff --git a/source/RobotAPI/libraries/armem/client/query/selectors.h b/source/RobotAPI/libraries/armem/client/query/selectors.h index df642ded9a70ea2688eaca5865f730e8e99ee6de..b9c257dc6dd5ae1ec07fd7850322d8babef829e4 100644 --- a/source/RobotAPI/libraries/armem/client/query/selectors.h +++ b/source/RobotAPI/libraries/armem/client/query/selectors.h @@ -15,6 +15,10 @@ namespace armarx::armem::client::query { public: + SnapshotSelector(const armem::query::data::QueryTargets& p) : + detail::ChildSelectorOps<SnapshotSelector, armem::query::data::EntityQueryPtr>(p) + {} + armem::query::data::EntityQuerySeq buildQueries() const; @@ -44,6 +48,10 @@ namespace armarx::armem::client::query { public: + EntitySelector(const armem::query::data::QueryTargets& p) : + detail::InnerSelectorOps<EntitySelector, armem::query::data::ProviderSegmentQueryPtr, SnapshotSelector>(p) + {} + /// Start specifying entity snapshots. SnapshotSelector& snapshots(); SnapshotSelector& snapshots(const SnapshotSelector& selector); @@ -79,6 +87,10 @@ namespace armarx::armem::client::query { public: + ProviderSegmentSelector(const armem::query::data::QueryTargets& p) : + detail::InnerSelectorOps<ProviderSegmentSelector, armem::query::data::CoreSegmentQueryPtr, EntitySelector>(p) + {} + /// Start specifying entities. EntitySelector& entities(); EntitySelector& entities(const EntitySelector& selector); @@ -114,6 +126,10 @@ namespace armarx::armem::client::query { public: + CoreSegmentSelector(const armem::query::data::QueryTargets& p) : + detail::InnerSelectorOps<CoreSegmentSelector, armem::query::data::MemoryQueryPtr, ProviderSegmentSelector>(p) + {} + /// Start specifying provider segments. ProviderSegmentSelector& providerSegments(); ProviderSegmentSelector& providerSegments(const ProviderSegmentSelector& selector); diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.cpp index d838c716a87830fb8f8cde16a80c91861dee5970..2dd6fd615432b9245e308ba285b4be62f99578ab 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/CoreSegment.cpp @@ -24,7 +24,7 @@ namespace armarx::armem::d_ltm wm::CoreSegment CoreSegment::convert() const { - wm::CoreSegment m; + wm::CoreSegment m(id()); for (const auto& [_, s] : _container) { m.addProviderSegment(s.convert(_aronType)); diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp index 16f66c488e3bdfbff30e5de65ef754041155da25..5d784a097de4ef68ec2df0bdc1adce94fa737809 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/Entity.cpp @@ -18,7 +18,7 @@ namespace armarx::armem::d_ltm wm::Entity Entity::convert(const aron::typenavigator::NavigatorPtr& expectedStructure) const { - wm::Entity m; + wm::Entity m(id()); for (const auto& [_, s] : _container) { m.addSnapshot(s.convert(expectedStructure)); diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.cpp index 4da151bd537f98e0e5693d948f202d68859f0d76..dd0458b83bbb8ed461ddeab50af42181fda843e4 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/EntityInstance.cpp @@ -41,6 +41,7 @@ namespace armarx::armem::d_ltm void EntityInstance::_copySelf(EntityInstance& other) const { EntityInstanceBase<EntityInstance>::_copySelf(other); + other.path = path; } std::filesystem::path EntityInstance::_fullPath() const @@ -49,6 +50,7 @@ namespace armarx::armem::d_ltm { return _fullPath(*path); } + ARMARX_WARNING << "The path of the disk memory instance with id '" << id().str() << "' is not set. This may lead to errors."; return std::filesystem::path(); } @@ -59,7 +61,7 @@ namespace armarx::armem::d_ltm wm::EntityInstance EntityInstance::convert(const aron::typenavigator::NavigatorPtr& expectedStructure) const { - std::filesystem::path p = _fullPath(); + std::filesystem::path p = _fullPath(); // here we assume that "reload" has been called first std::filesystem::path d = p / (std::string(DATA_FILENAME) + ".json"); if (std::filesystem::is_regular_file(d)) @@ -67,7 +69,7 @@ namespace armarx::armem::d_ltm std::ifstream ifs(d); std::string file_content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>())); - nlohmann::json j(file_content); + nlohmann::json j = nlohmann::json::parse(file_content); auto aron = std::make_shared<aron::datanavigator::DictNavigator>(); to_aron(aron, j, expectedStructure); wm::EntityInstance e(id()); @@ -76,7 +78,7 @@ namespace armarx::armem::d_ltm } else { - throw error::ArMemError("An diskMemory EntityInstance is not leading to a regular file."); + throw error::ArMemError("An diskMemory EntityInstance is not leading to a regular file. The path was: " + d.string()); } } @@ -84,7 +86,7 @@ namespace armarx::armem::d_ltm { if (!p_ptr) { - ARMARX_WARNING << "The entered is NULL."; + ARMARX_WARNING << "The entered path is NULL."; } std::filesystem::path p = _fullPath(*p_ptr); if (!std::filesystem::is_directory(p)) diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp index 88e5c51dcbfa1889e2d2625873501b1a3d9981c1..ab5b56d2274f78c350818693c269af18f0a4a979 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/EntitySnapshot.cpp @@ -26,7 +26,7 @@ namespace armarx::armem::d_ltm wm::EntitySnapshot EntitySnapshot::convert(const aron::typenavigator::NavigatorPtr& expectedStructure) const { - wm::EntitySnapshot m; + wm::EntitySnapshot m(id()); for (const auto& s : _container) { m.addInstance(s.convert(expectedStructure)); @@ -56,7 +56,7 @@ namespace armarx::armem::d_ltm std::filesystem::path d = p / std::to_string(i); if (std::filesystem::is_directory(d)) { - auto wms = _container.emplace_back(id().withInstanceIndex(i)); + auto& wms = _container.emplace_back(id().withInstanceIndex(i)); wms.reload(p_ptr); } else @@ -95,7 +95,7 @@ namespace armarx::armem::d_ltm continue;; } - auto wms = _container.emplace_back(id().withInstanceIndex(i++)); + auto& wms = _container.emplace_back(id().withInstanceIndex(i++)); wms.path = path; wms.setTo(s); } diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp index be2415c2eb06658a79214580ca63c0faf37169dc..4a913f2b497fce236c3cb8f9343fa97179b2d757 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp @@ -24,8 +24,8 @@ namespace armarx::armem::d_ltm wm::Memory Memory::convert() const { - wm::Memory m; - for (const auto& [_, s] : _container) + wm::Memory m(id()); + for (const auto& [k, s] : _container) { m.addCoreSegment(s.convert()); } diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp index bca090b81a79eb380289acac2157f86fbc19918e..f46e165381bf0d9cbdcc12b4cdfa31e286f4a545 100644 --- a/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp +++ b/source/RobotAPI/libraries/armem/core/diskmemory/ProviderSegment.cpp @@ -23,7 +23,7 @@ namespace armarx::armem::d_ltm wm::ProviderSegment ProviderSegment::convert(const aron::typenavigator::NavigatorPtr& expectedStructure) const { - wm::ProviderSegment m; + wm::ProviderSegment m(id()); for (const auto& [_, s] : _container) { if (hasAronType()) diff --git a/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp b/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp index db546ddc586a83356d445202fdfaf94f5b1b916b..f35e9ecb4c330edf520cadbdf4fbc163fc431781 100644 --- a/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp +++ b/source/RobotAPI/libraries/armem/server/MemoryToIceAdapter.cpp @@ -28,7 +28,6 @@ namespace armarx::armem::server data::AddSegmentResult MemoryToIceAdapter::addSegment(const data::AddSegmentInput& input, bool addCoreSegments) { - ARMARX_DEBUG << "Adding segment '" << input.coreSegmentName << "/" << input.providerSegmentName << "'."; ARMARX_CHECK_NOT_NULL(workingMemory); data::AddSegmentResult output; @@ -205,10 +204,10 @@ namespace armarx::armem::server : armem::DataMode::NoData); armem::query::data::Result result; - wm::Memory wm_result = wm_processor.process(input, *workingMemory, /* ignore if: */ { query::data::QueryTarget::LTM }); + wm::Memory wm_result = wm_processor.process(input, *workingMemory, /* execute if: */ { query::data::QueryTarget::WM }); armem::ltm::query_proc::MemoryQueryProcessor ltm_processor; - ltm::Memory ltm_result = ltm_processor.process(input, *longtermMemory, /* ignore if: */ { query::data::QueryTarget::WM }); + ltm::Memory ltm_result = ltm_processor.process(input, *longtermMemory, /* execute if: */ { query::data::QueryTarget::LTM }); if (ltm_result.hasData()) @@ -237,6 +236,11 @@ namespace armarx::armem::server } result.success = true; + if (result.memory->coreSegments.size() == 0) + { + ARMARX_DEBUG << "No data in memory found after query."; + } + return result; } @@ -261,7 +265,7 @@ namespace armarx::armem::server { // force query to only query WM // TODO: Think about other query class (fabian.peller) - query->target = query::data::QueryTarget::WM; + query->targets = {query::data::QueryTarget::WM}; } armem::query::data::Result queryResult = this->query(input.query); diff --git a/source/RobotAPI/libraries/armem/server/query_proc/base/BaseQueryProcessorBase.h b/source/RobotAPI/libraries/armem/server/query_proc/base/BaseQueryProcessorBase.h index 69a305e45befca5a9189c6fb264985126d16fbf3..f71aede29731259471cf5e8dd660917b3e848bb1 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/base/BaseQueryProcessorBase.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/base/BaseQueryProcessorBase.h @@ -1,5 +1,6 @@ #pragma once +#include <ArmarXCore/core/logging/Logging.h> #include <RobotAPI/interface/armem/query.h> @@ -18,39 +19,67 @@ namespace armarx::armem::base::query_proc public: - DataT process(const QueryT& query, const DataT& data, const std::vector<query::data::QueryTarget>& ignoreTargets = {}) const + DataT process(const QueryT& query, const DataT& data, const query::data::QueryTargets& executeIf = {}) const { DataT result = data.copyEmpty(); - if (std::find(ignoreTargets.begin(), ignoreTargets.end(), query.target) != ignoreTargets.end()) + for (const auto queryTarget : query.targets) { - return result; + if (std::find(executeIf.begin(), executeIf.end(), queryTarget) != executeIf.end()) + { + this->process(result, query, data); + break; + } } - this->process(result, query, data); return result; } - DataT process(const QueryPtrT& query, const DataT& data, const std::vector<query::data::QueryTarget>& ignoreTargets = {}) const + DataT process(const QueryPtrT& query, const DataT& data, const query::data::QueryTargets& executeIf = {}) const { - return this->process(*query, *data, ignoreTargets); + return this->process(*query, *data, executeIf); } - DataT process(const QuerySeqT& queries, const DataT& data, const std::vector<query::data::QueryTarget>& ignoreTargets = {}) const + DataT process(const QuerySeqT& queries, const DataT& data, const query::data::QueryTargets& executeIf = {}) const { DataT result = data.copyEmpty(); - this->process(result, queries, data, ignoreTargets); + this->process(result, queries, data, executeIf); return result; } - void process(DataT& result, const QuerySeqT& queries, const DataT& data, const std::vector<query::data::QueryTarget>& ignoreTargets = {}) const + void process(DataT& result, const QuerySeqT& queries, const DataT& data, const query::data::QueryTargets& executeIf = {}) const { + if (queries.empty()) + { + ARMARX_DEBUG << "There are no queries to process."; + return; + } + + if (executeIf.empty()) + { + ARMARX_DEBUG << "Could not execute query. ExecuteIf s empty."; + return; + } + for (const auto& query : queries) { - if (std::find(ignoreTargets.begin(), ignoreTargets.end(), query->target) != ignoreTargets.end()) + if (query->targets.empty()) { + ARMARX_DEBUG << "The targets of a query are empty"; continue; } - this->process(result, *query, data); + + for (const auto queryTarget : query->targets) + { + if (std::find(executeIf.begin(), executeIf.end(), queryTarget) != executeIf.end()) + { + this->process(result, *query, data); + break; + } + else + { + ARMARX_DEBUG << "The query target " << queryTarget << " was not found in executeIf: " << executeIf; + } + } } } diff --git a/source/RobotAPI/libraries/armem/server/query_proc/base/MemoryQueryProcessorBase.h b/source/RobotAPI/libraries/armem/server/query_proc/base/MemoryQueryProcessorBase.h index 5de194d7ba2debada4ef9363005b1a7f2e927e94..cc06defc93976ea018ab8a7d3823a00d6121543d 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/base/MemoryQueryProcessorBase.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/base/MemoryQueryProcessorBase.h @@ -34,9 +34,9 @@ namespace armarx::armem::base::query_proc using Base::process; - _MemoryT process(const armem::query::data::Input& input, const _MemoryT& memory, const std::vector<query::data::QueryTarget>& ignoreTargets = {}) const + _MemoryT process(const armem::query::data::Input& input, const _MemoryT& memory, const std::vector<query::data::QueryTarget>& executeIf = {}) const { - return this->process(input.memoryQueries, memory, ignoreTargets); + return this->process(input.memoryQueries, memory, executeIf); } void process(_MemoryT& result, diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/BaseQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/BaseQueryProcessor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..68821bcd95cdf2aaccf7126d4055495d39d0393d --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/BaseQueryProcessor.cpp @@ -0,0 +1 @@ +#include "BaseQueryProcessor.h" diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/BaseQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/BaseQueryProcessor.h new file mode 100644 index 0000000000000000000000000000000000000000..84f967795fd26d79d173a14e71498dbec7d56ee1 --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/BaseQueryProcessor.h @@ -0,0 +1,26 @@ +#pragma once + +#include <RobotAPI/interface/armem/query.h> +#include <RobotAPI/libraries/armem/core/DataMode.h> + +#include "../base/BaseQueryProcessorBase.h" + + +namespace armarx::armem::d_ltm::query_proc +{ + /** + * @brief Base class for memory query processors. + */ + template <class DataT, class QueryT> + class BaseQueryProcessor : + virtual public base::query_proc::BaseQueryProcessorBase<DataT, QueryT> + { + using Base = base::query_proc::BaseQueryProcessorBase<DataT, QueryT>; + + public: + BaseQueryProcessor() + {} + + protected: + }; +} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/CoreSegmentQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/CoreSegmentQueryProcessor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..afbe35ad15eea0342b0b0d4df0200aaf0d32aa2a --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/CoreSegmentQueryProcessor.cpp @@ -0,0 +1 @@ +#include "CoreSegmentQueryProcessor.h" diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/CoreSegmentQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/CoreSegmentQueryProcessor.h new file mode 100644 index 0000000000000000000000000000000000000000..1c40f7fc64b0a2c59fdc3e54d968c6627480cbb0 --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/CoreSegmentQueryProcessor.h @@ -0,0 +1,36 @@ +#pragma once + +#include "BaseQueryProcessor.h" +#include "../base/CoreSegmentQueryProcessorBase.h" + +#include "../../../core/diskmemory/CoreSegment.h" + +#include "ProviderSegmentQueryProcessor.h" + + +namespace armarx::armem::d_ltm::query_proc +{ + /** + * @brief Handles memory queries. + */ + class CoreSegmentQueryProcessor : + virtual public BaseQueryProcessor<d_ltm::CoreSegment, armem::query::data::CoreSegmentQuery>, + virtual public base::query_proc::CoreSegmentQueryProcessorBase<d_ltm::CoreSegment> + { + using Base = BaseQueryProcessor<d_ltm::CoreSegment, armem::query::data::CoreSegmentQuery>; + + public: + CoreSegmentQueryProcessor() : + Base() + {} + + protected: + virtual ProviderSegmentT providerSegmentProcessorProcess(const armem::query::data::ProviderSegmentQuerySeq& q, const ProviderSegmentT& s) const override + { + return providerSegmentProcessor.process(q, s, {armem::query::data::QueryTarget::Disk}); + } + + private: + ProviderSegmentQueryProcessor providerSegmentProcessor; + }; +} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/EntityQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/EntityQueryProcessor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c1c321b026b173c6552758fb9d8b9fdf722ea5a4 --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/EntityQueryProcessor.cpp @@ -0,0 +1 @@ +#include "EntityQueryProcessor.h" diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/EntityQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/EntityQueryProcessor.h new file mode 100644 index 0000000000000000000000000000000000000000..4d1b9e14e21804f1e44f1a2fd6456da37a113c03 --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/EntityQueryProcessor.h @@ -0,0 +1,39 @@ +#pragma once + +#include "BaseQueryProcessor.h" +#include "../base/EntityQueryProcessorBase.h" + +#include "../../../core/diskmemory/Entity.h" + +#include "EntityQueryProcessor.h" + +namespace armarx::armem::d_ltm::query_proc +{ + /** + * @brief Handles memory queries. + */ + class EntityQueryProcessor : + virtual public BaseQueryProcessor<d_ltm::Entity, armem::query::data::EntityQuery>, + virtual public base::query_proc::EntityQueryProcessorBase<d_ltm::Entity> + { + using Base = BaseQueryProcessor<d_ltm::Entity, armem::query::data::EntityQuery>; + + public: + EntityQueryProcessor() : + Base() + {} + + private: + void addResultSnapshot(d_ltm::Entity& result, d_ltm::Entity::ContainerT::const_iterator it) const override + { + addResultSnapshot(result, it->second); + } + + void addResultSnapshot(d_ltm::Entity& result, const d_ltm::EntitySnapshot& snapshot) const override + { + result.addSnapshot(snapshot.copy()); + } + + }; + +} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/MemoryQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/MemoryQueryProcessor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..69b04de6c9e623286a5bda836dddfdc8b551b64a --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/MemoryQueryProcessor.cpp @@ -0,0 +1 @@ +#include "MemoryQueryProcessor.h" diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/MemoryQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/MemoryQueryProcessor.h new file mode 100644 index 0000000000000000000000000000000000000000..2abdcc1ccc7c25a317edc67e36835cb4a4df2f9b --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/MemoryQueryProcessor.h @@ -0,0 +1,35 @@ +#pragma once + +#include "BaseQueryProcessor.h" +#include "../base/MemoryQueryProcessorBase.h" + +#include "../../../core/diskmemory/Memory.h" + +#include "CoreSegmentQueryProcessor.h" + +namespace armarx::armem::d_ltm::query_proc +{ + /** + * @brief Handles memory queries. + */ + class MemoryQueryProcessor : + virtual public BaseQueryProcessor<d_ltm::Memory, armem::query::data::MemoryQuery>, + virtual public base::query_proc::MemoryQueryProcessorBase<d_ltm::Memory> + { + using Base = BaseQueryProcessor<d_ltm::Memory, armem::query::data::MemoryQuery>; + + public: + MemoryQueryProcessor() : + Base() + {} + + protected: + virtual CoreSegmentT coreSegmentProcessorProcess(const armem::query::data::CoreSegmentQuerySeq& q, const CoreSegmentT& s) const override + { + return coreSegmentProcessor.process(q, s, {armem::query::data::QueryTarget::Disk}); + } + + private: + CoreSegmentQueryProcessor coreSegmentProcessor; + }; +} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/ProviderSegmentQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/ProviderSegmentQueryProcessor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9a2a4405001f0904b74fc6afcf96813eef0879cd --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/ProviderSegmentQueryProcessor.cpp @@ -0,0 +1 @@ +#include "ProviderSegmentQueryProcessor.h" diff --git a/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/ProviderSegmentQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/ProviderSegmentQueryProcessor.h new file mode 100644 index 0000000000000000000000000000000000000000..94c2e756875c1152f8018f70c5e0d691a5704582 --- /dev/null +++ b/source/RobotAPI/libraries/armem/server/query_proc/diskmemory/ProviderSegmentQueryProcessor.h @@ -0,0 +1,37 @@ +#pragma once + +#include "BaseQueryProcessor.h" +#include "../base/ProviderSegmentQueryProcessorBase.h" + +#include "../../../core/diskmemory/ProviderSegment.h" + +#include "EntityQueryProcessor.h" + +namespace armarx::armem::d_ltm::query_proc +{ + /** + * @brief Handles memory queries. + */ + class ProviderSegmentQueryProcessor : + virtual public BaseQueryProcessor<d_ltm::ProviderSegment, armem::query::data::ProviderSegmentQuery>, + virtual public base::query_proc::ProviderSegmentQueryProcessorBase<d_ltm::ProviderSegment> + { + using Base = BaseQueryProcessor<d_ltm::ProviderSegment, armem::query::data::ProviderSegmentQuery>; + + public: + ProviderSegmentQueryProcessor() : + Base() + {} + + protected: + virtual EntityT entityProcessorProcess(const armem::query::data::EntityQuerySeq& q, const EntityT& s) const override + { + return entityProcessor.process(q, s, {armem::query::data::QueryTarget::Disk}); + } + + private: + EntityQueryProcessor entityProcessor; + + }; + +} diff --git a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/CoreSegmentQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/CoreSegmentQueryProcessor.h index dc379f1d88fa82bbe886e412e0341079fa43fce9..e333dd816aedabbb8dfa7209c687caf727d9ccf9 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/CoreSegmentQueryProcessor.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/CoreSegmentQueryProcessor.h @@ -27,7 +27,7 @@ namespace armarx::armem::ltm::query_proc protected: virtual ProviderSegmentT providerSegmentProcessorProcess(const armem::query::data::ProviderSegmentQuerySeq& q, const ProviderSegmentT& s) const override { - return providerSegmentProcessor.process(q, s); + return providerSegmentProcessor.process(q, s, {armem::query::data::QueryTarget::LTM}); } private: diff --git a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/EntityQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/EntityQueryProcessor.h index 952d759c8552c7939f6e08266e7feb880a85438e..5ec4c5dde481e16f0af30589d57ff2a447d81221 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/EntityQueryProcessor.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/EntityQueryProcessor.h @@ -31,7 +31,6 @@ namespace armarx::armem::ltm::query_proc void addResultSnapshot(ltm::Entity& result, const ltm::EntitySnapshot& snapshot) const override { - ARMARX_INFO << "addResultSnapshot" << __LINE__; result.addSnapshot(snapshot.copy()); } diff --git a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/MemoryQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/MemoryQueryProcessor.h index a5129417262515975efa247398602272865ee5ec..569014d6579eeb6c99996e4be5b7cb68f65457b1 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/MemoryQueryProcessor.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/MemoryQueryProcessor.h @@ -26,7 +26,7 @@ namespace armarx::armem::ltm::query_proc protected: virtual CoreSegmentT coreSegmentProcessorProcess(const armem::query::data::CoreSegmentQuerySeq& q, const CoreSegmentT& s) const override { - return coreSegmentProcessor.process(q, s); + return coreSegmentProcessor.process(q, s, {armem::query::data::QueryTarget::LTM}); } private: diff --git a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/ProviderSegmentQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/ProviderSegmentQueryProcessor.h index e0c6db9e3ef06e6241e9af8c572bb7fc78eec452..5443acfd6594b98250711cf2acfd434a98414066 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/ProviderSegmentQueryProcessor.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/longtermmemory/ProviderSegmentQueryProcessor.h @@ -26,7 +26,7 @@ namespace armarx::armem::ltm::query_proc protected: virtual EntityT entityProcessorProcess(const armem::query::data::EntityQuerySeq& q, const EntityT& s) const override { - return entityProcessor.process(q, s); + return entityProcessor.process(q, s, {armem::query::data::QueryTarget::LTM}); } private: diff --git a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/CoreSegmentQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/CoreSegmentQueryProcessor.h index 079f63ac59928f2bd4ace9ab7ab033bef93c04a1..390ab66f656ece6010457f12f09917d9fca413f6 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/CoreSegmentQueryProcessor.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/CoreSegmentQueryProcessor.h @@ -31,7 +31,7 @@ namespace armarx::armem::wm::query_proc protected: virtual ProviderSegmentT providerSegmentProcessorProcess(const armem::query::data::ProviderSegmentQuerySeq& q, const ProviderSegmentT& s) const override { - return providerSegmentProcessor.process(q, s); + return providerSegmentProcessor.process(q, s, {armem::query::data::QueryTarget::WM}); } private: diff --git a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/MemoryQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/MemoryQueryProcessor.h index b0616c658a7915568fd910a8f35c9d4701aa1d0b..8284df202bbcf602e2433639fe85388ca13d75ff 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/MemoryQueryProcessor.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/MemoryQueryProcessor.h @@ -24,7 +24,7 @@ namespace armarx::armem::wm::query_proc protected: virtual CoreSegmentT coreSegmentProcessorProcess(const armem::query::data::CoreSegmentQuerySeq& q, const CoreSegmentT& s) const override { - return coreSegmentProcessor.process(q, s); + return coreSegmentProcessor.process(q, s, {armem::query::data::QueryTarget::WM}); } diff --git a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/ProviderSegmentQueryProcessor.h b/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/ProviderSegmentQueryProcessor.h index 1b2e9ba97850ed1f62f2d761a51996f3b2bb2665..468138d9e2bbd526db3632019beca6a5a29f8269 100644 --- a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/ProviderSegmentQueryProcessor.h +++ b/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/ProviderSegmentQueryProcessor.h @@ -30,7 +30,7 @@ namespace armarx::armem::wm::query_proc protected: virtual EntityT entityProcessorProcess(const armem::query::data::EntityQuerySeq& q, const EntityT& s) const override { - return entityProcessor.process(q, s); + return entityProcessor.process(q, s, {armem::query::data::QueryTarget::WM}); } private: diff --git a/source/RobotAPI/libraries/armem/test/ArMemQueryTest.cpp b/source/RobotAPI/libraries/armem/test/ArMemQueryTest.cpp index b2d07571d619531f45381d1238ca8201b8e0175e..4b83fd43261e1d97da45495f5da94279931e606f 100644 --- a/source/RobotAPI/libraries/armem/test/ArMemQueryTest.cpp +++ b/source/RobotAPI/libraries/armem/test/ArMemQueryTest.cpp @@ -134,7 +134,7 @@ BOOST_AUTO_TEST_CASE(test_entity_Single_latest) BOOST_AUTO_TEST_CASE(test_entity_Single_existing) { - addResults(query::entity::Single { query::QueryTarget::WMAndLTM, 3000 }); + addResults(query::entity::Single({query::QueryTarget::WM, query::QueryTarget::LTM}, 3000)); BOOST_REQUIRE_GT(results.size(), 0); for (const armem::wm::Entity& result : results) @@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(test_entity_Single_existing) BOOST_AUTO_TEST_CASE(test_entity_Single_non_existing) { - addResults(query::entity::Single { query::QueryTarget::WMAndLTM, 3500 }); + addResults(query::entity::Single({query::QueryTarget::WM, query::QueryTarget::LTM}, 3500)); BOOST_REQUIRE_GT(results.size(), 0); for (const armem::wm::Entity& result : results) @@ -182,7 +182,7 @@ BOOST_AUTO_TEST_CASE(test_entity_All) BOOST_AUTO_TEST_CASE(test_entity_TimeRange_slice) { - addResults(query::entity::TimeRange{ query::QueryTarget::WMAndLTM, 1500, 3500 }); + addResults(query::entity::TimeRange({query::QueryTarget::WM, query::QueryTarget::LTM}, 1500, 3500)); BOOST_REQUIRE_GT(results.size(), 0); for (const armem::wm::Entity& result : results) @@ -203,7 +203,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_slice) BOOST_AUTO_TEST_CASE(test_entity_TimeRange_exact) { - addResults(query::entity::TimeRange{ query::QueryTarget::WMAndLTM, 2000, 4000 }); + addResults(query::entity::TimeRange({query::QueryTarget::WM, query::QueryTarget::LTM}, 2000, 4000)); BOOST_REQUIRE_GT(results.size(), 0); for (const armem::wm::Entity& result : results) @@ -223,8 +223,8 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_exact) BOOST_AUTO_TEST_CASE(test_entity_TimeRange_all) { - addResults(query::entity::TimeRange{ query::QueryTarget::WMAndLTM, 0, 10000 }); - addResults(query::entity::TimeRange{ query::QueryTarget::WMAndLTM, -1, -1 }); + addResults(query::entity::TimeRange({query::QueryTarget::WM, query::QueryTarget::LTM}, 0, 10000)); + addResults(query::entity::TimeRange({query::QueryTarget::WM, query::QueryTarget::LTM}, -1, -1)); BOOST_REQUIRE_GT(results.size(), 0); for (const armem::wm::Entity& result : results) @@ -242,8 +242,8 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_all) BOOST_AUTO_TEST_CASE(test_entity_TimeRange_empty) { - addResults(query::entity::TimeRange{ query::QueryTarget::WMAndLTM, 2400, 2600 }); - addResults(query::entity::TimeRange{ query::QueryTarget::WMAndLTM, 6000, 1000 }); + addResults(query::entity::TimeRange({query::QueryTarget::WM, query::QueryTarget::LTM}, 2400, 2600)); + addResults(query::entity::TimeRange({query::QueryTarget::WM, query::QueryTarget::LTM}, 6000, 1000)); BOOST_REQUIRE_GT(results.size(), 0); for (const armem::wm::Entity& result : results) @@ -257,7 +257,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_empty) BOOST_AUTO_TEST_CASE(test_entity_TimeRange_from_start) { - addResults(query::entity::TimeRange{ query::QueryTarget::WMAndLTM, -1, 2500 }); + addResults(query::entity::TimeRange({query::QueryTarget::WM, query::QueryTarget::LTM}, -1, 2500)); BOOST_REQUIRE_GT(results.size(), 0); for (const armem::wm::Entity& result : results) @@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_from_start) BOOST_AUTO_TEST_CASE(test_entity_TimeRange_to_end) { - addResults(query::entity::TimeRange{ query::QueryTarget::WMAndLTM, 2500, -1 }); + addResults(query::entity::TimeRange({query::QueryTarget::WM, query::QueryTarget::LTM}, 2500, -1)); BOOST_REQUIRE_GT(results.size(), 0); for (const armem::wm::Entity& result : results) @@ -302,7 +302,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeRange_to_end) BOOST_AUTO_TEST_CASE(test_entity_BeforeTime_1) { BOOST_REQUIRE_EQUAL(entity.size(), 5); - addResults(query::entity::BeforeTime{ query::QueryTarget::WMAndLTM, 3500, 1 }); + addResults(query::entity::BeforeTime({query::QueryTarget::WM, query::QueryTarget::LTM}, 3500, 1)); BOOST_REQUIRE_EQUAL(results.size(), 2); for (const auto& result : results) @@ -318,7 +318,7 @@ BOOST_AUTO_TEST_CASE(test_entity_BeforeTime_1) BOOST_AUTO_TEST_CASE(test_entity_BeforeTime_2) { BOOST_REQUIRE_EQUAL(entity.size(), 5); - addResults(query::entity::BeforeTime{ query::QueryTarget::WMAndLTM, 3500, 2}); + addResults(query::entity::BeforeTime({query::QueryTarget::WM, query::QueryTarget::LTM}, 3500, 2)); BOOST_REQUIRE_EQUAL(results.size(), 2); for (const auto& result : results) @@ -343,7 +343,7 @@ BOOST_AUTO_TEST_CASE(test_entity_BeforeTime_2) BOOST_AUTO_TEST_CASE(test_entity_BeforeOrAtTime_before) { BOOST_REQUIRE_EQUAL(entity.size(), 5); - addResults(query::entity::BeforeOrAtTime{ query::QueryTarget::WMAndLTM, 3500 }); + addResults(query::entity::BeforeOrAtTime({query::QueryTarget::WM, query::QueryTarget::LTM}, 3500)); BOOST_REQUIRE_EQUAL(results.size(), 2); for (const auto& result : results) @@ -358,7 +358,7 @@ BOOST_AUTO_TEST_CASE(test_entity_BeforeOrAtTime_before) BOOST_AUTO_TEST_CASE(test_entity_BeforeOrAtTime_at) { BOOST_REQUIRE_EQUAL(entity.size(), 5); - addResults(query::entity::BeforeOrAtTime{ query::QueryTarget::WMAndLTM, 3000 }); + addResults(query::entity::BeforeOrAtTime({query::QueryTarget::WM, query::QueryTarget::LTM}, 3000)); BOOST_REQUIRE_EQUAL(results.size(), 2); for (const auto& result : results) @@ -373,7 +373,7 @@ BOOST_AUTO_TEST_CASE(test_entity_BeforeOrAtTime_at) BOOST_AUTO_TEST_CASE(test_entity_BeforeOrAtTime_lookup_past) { BOOST_REQUIRE_EQUAL(entity.size(), 5); - addResults(query::entity::BeforeOrAtTime{ query::QueryTarget::WMAndLTM, 1 }); + addResults(query::entity::BeforeOrAtTime({query::QueryTarget::WM, query::QueryTarget::LTM}, 1)); BOOST_REQUIRE_EQUAL(results.size(), 2); for (const auto& result : results) @@ -393,7 +393,7 @@ BOOST_AUTO_TEST_CASE(test_entity_BeforeOrAtTime_lookup_past) BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_no_limit) { BOOST_REQUIRE_EQUAL(entity.size(), 5); - addResults(query::entity::TimeApprox{ query::QueryTarget::WMAndLTM, 3500, -1}); + addResults(query::entity::TimeApprox({query::QueryTarget::WM, query::QueryTarget::LTM}, 3500, -1)); BOOST_REQUIRE_EQUAL(results.size(), 2); for (const auto& result : results) @@ -419,7 +419,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_no_limit) BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_limit_600) { BOOST_REQUIRE_EQUAL(entity.size(), 5); - addResults(query::entity::TimeApprox{ query::QueryTarget::WMAndLTM, 3500, 600}); + addResults(query::entity::TimeApprox({query::QueryTarget::WM, query::QueryTarget::LTM}, 3500, 600)); BOOST_REQUIRE_EQUAL(results.size(), 2); for (const auto& result : results) @@ -445,7 +445,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_limit_600) BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_limit_too_small) { BOOST_REQUIRE_EQUAL(entity.size(), 5); - addResults(query::entity::TimeApprox{ query::QueryTarget::WMAndLTM, 3500, 100}); + addResults(query::entity::TimeApprox({query::QueryTarget::WM, query::QueryTarget::LTM}, 3500, 100)); BOOST_REQUIRE_EQUAL(results.size(), 2); for (const auto& result : results) @@ -464,7 +464,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_limit_too_small) BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_limit_only_next) { BOOST_REQUIRE_EQUAL(entity.size(), 5); - addResults(query::entity::TimeApprox{ query::QueryTarget::WMAndLTM, 3700, 400}); + addResults(query::entity::TimeApprox({query::QueryTarget::WM, query::QueryTarget::LTM}, 3700, 400)); BOOST_REQUIRE_EQUAL(results.size(), 2); for (const auto& result : results) @@ -489,7 +489,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_limit_only_next) BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_limit_only_previous) { BOOST_REQUIRE_EQUAL(entity.size(), 5); - addResults(query::entity::TimeApprox{ query::QueryTarget::WMAndLTM, 3300, 400}); + addResults(query::entity::TimeApprox({query::QueryTarget::WM, query::QueryTarget::LTM}, 3300, 400)); BOOST_REQUIRE_EQUAL(results.size(), 2); for (const auto& result : results) @@ -514,7 +514,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_limit_only_previous) BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_perfect_match) { BOOST_REQUIRE_EQUAL(entity.size(), 5); - addResults(query::entity::TimeApprox{ query::QueryTarget::WMAndLTM, 3000, -1}); + addResults(query::entity::TimeApprox({query::QueryTarget::WM, query::QueryTarget::LTM}, 3000, -1)); BOOST_REQUIRE_EQUAL(results.size(), 2); for (const auto& result : results) @@ -539,7 +539,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_perfect_match) BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_lookup_past) { BOOST_REQUIRE_EQUAL(entity.size(), 5); - addResults(query::entity::TimeApprox{ query::QueryTarget::WMAndLTM, 1, 1}); + addResults(query::entity::TimeApprox({query::QueryTarget::WM, query::QueryTarget::LTM}, 1, 1)); BOOST_REQUIRE_EQUAL(results.size(), 2); for (const auto& result : results) @@ -557,7 +557,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_lookup_past) BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_lookup_future) { BOOST_REQUIRE_EQUAL(entity.size(), 5); - addResults(query::entity::TimeApprox{ query::QueryTarget::WMAndLTM, 10'000, 1}); + addResults(query::entity::TimeApprox({query::QueryTarget::WM, query::QueryTarget::LTM}, 10'000, 1)); BOOST_REQUIRE_EQUAL(results.size(), 2); for (const auto& result : results) @@ -575,7 +575,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_lookup_future) BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_lookup_future_valid) { BOOST_REQUIRE_EQUAL(entity.size(), 5); - addResults(query::entity::TimeApprox{ query::QueryTarget::WMAndLTM, 10'000, -1}); + addResults(query::entity::TimeApprox({query::QueryTarget::WM, query::QueryTarget::LTM}, 10'000, -1)); BOOST_REQUIRE_EQUAL(results.size(), 2); for (const auto& result : results) @@ -594,7 +594,7 @@ BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_lookup_future_valid) BOOST_AUTO_TEST_CASE(test_entity_TimeApprox_lookup_invalid_timestamp) { - BOOST_REQUIRE_THROW(addResults(query::entity::TimeApprox{ query::QueryTarget::WMAndLTM, -1, 1}), ::armarx::LocalException); + BOOST_REQUIRE_THROW(addResults(query::entity::TimeApprox({query::QueryTarget::WM, query::QueryTarget::LTM}, -1, 1)), ::armarx::LocalException); } @@ -634,7 +634,7 @@ BOOST_AUTO_TEST_CASE(test_negative_index_semantics) BOOST_AUTO_TEST_CASE(test_entity_IndexRange_all_default) { addResults(query::entity::IndexRange()); - addResults(query::entity::IndexRange(query::QueryTarget::WMAndLTM, 0, -1)); + addResults(query::entity::IndexRange({query::QueryTarget::WM, query::QueryTarget::LTM}, 0, -1)); BOOST_REQUIRE_GT(results.size(), 0); for (const armem::wm::Entity& result : results) @@ -654,10 +654,10 @@ BOOST_AUTO_TEST_CASE(test_entity_IndexRange_all_default) BOOST_AUTO_TEST_CASE(test_entity_IndexRange_slice) { BOOST_REQUIRE_EQUAL(entity.size(), 5); - addResults(query::entity::IndexRange{ query::QueryTarget::WMAndLTM, 1, 3 }); // => [1, 2, 3] - addResults(query::entity::IndexRange{ query::QueryTarget::WMAndLTM, 1, -2 }); // 5 - 2 = 3 - addResults(query::entity::IndexRange{ query::QueryTarget::WMAndLTM, -4, 3 }); // 5 - 4 = 1 - addResults(query::entity::IndexRange{ query::QueryTarget::WMAndLTM, -4, -2 }); + addResults(query::entity::IndexRange({query::QueryTarget::WM, query::QueryTarget::LTM}, 1, 3)); // => [1, 2, 3] + addResults(query::entity::IndexRange({query::QueryTarget::WM, query::QueryTarget::LTM}, 1, -2)); // 5 - 2 = 3 + addResults(query::entity::IndexRange({query::QueryTarget::WM, query::QueryTarget::LTM}, -4, 3)); // 5 - 4 = 1 + addResults(query::entity::IndexRange({query::QueryTarget::WM, query::QueryTarget::LTM}, -4, -2)); BOOST_REQUIRE_GT(results.size(), 0); for (const armem::wm::Entity& result : results) @@ -679,12 +679,12 @@ BOOST_AUTO_TEST_CASE(test_entity_IndexRange_slice) BOOST_AUTO_TEST_CASE(test_entity_IndexRange_empty_range) { BOOST_REQUIRE_EQUAL(entity.size(), 5); - addResults(query::entity::IndexRange{ query::QueryTarget::WMAndLTM, 1, 0 }); - addResults(query::entity::IndexRange{ query::QueryTarget::WMAndLTM, 2, 1 }); - addResults(query::entity::IndexRange{ query::QueryTarget::WMAndLTM, 5, 3 }); - addResults(query::entity::IndexRange{ query::QueryTarget::WMAndLTM, 4, -3 }); // 5-3 = 2 - addResults(query::entity::IndexRange{ query::QueryTarget::WMAndLTM, 3, -3 }); - addResults(query::entity::IndexRange{ query::QueryTarget::WMAndLTM, 1, -5 }); + addResults(query::entity::IndexRange({query::QueryTarget::WM, query::QueryTarget::LTM}, 1, 0)); + addResults(query::entity::IndexRange({query::QueryTarget::WM, query::QueryTarget::LTM}, 2, 1)); + addResults(query::entity::IndexRange({query::QueryTarget::WM, query::QueryTarget::LTM}, 5, 3)); + addResults(query::entity::IndexRange({query::QueryTarget::WM, query::QueryTarget::LTM}, 4, -3)); // 5-3 = 2 + addResults(query::entity::IndexRange({query::QueryTarget::WM, query::QueryTarget::LTM}, 3, -3)); + addResults(query::entity::IndexRange({query::QueryTarget::WM, query::QueryTarget::LTM}, 1, -5)); BOOST_REQUIRE_GT(results.size(), 0); @@ -701,12 +701,12 @@ BOOST_AUTO_TEST_CASE(test_entity_IndexRange_empty_entity) { entity.clear(); BOOST_REQUIRE_EQUAL(entity.size(), 0); - addResults(query::entity::IndexRange{ query::QueryTarget::WMAndLTM, 0, 0 }); - addResults(query::entity::IndexRange{ query::QueryTarget::WMAndLTM, 0, 10 }); - addResults(query::entity::IndexRange{query::QueryTarget::WMAndLTM, -10, -1 }); - addResults(query::entity::IndexRange{ query::QueryTarget::WMAndLTM, 2, 5 }); - addResults(query::entity::IndexRange{ query::QueryTarget::WMAndLTM, 3, -3 }); - addResults(query::entity::IndexRange{ query::QueryTarget::WMAndLTM, -1, 10 }); + addResults(query::entity::IndexRange({query::QueryTarget::WM, query::QueryTarget::LTM}, 0, 0)); + addResults(query::entity::IndexRange({query::QueryTarget::WM, query::QueryTarget::LTM}, 0, 10)); + addResults(query::entity::IndexRange({query::QueryTarget::WM, query::QueryTarget::LTM}, -10, -1)); + addResults(query::entity::IndexRange({query::QueryTarget::WM, query::QueryTarget::LTM}, 2, 5)); + addResults(query::entity::IndexRange({query::QueryTarget::WM, query::QueryTarget::LTM}, 3, -3)); + addResults(query::entity::IndexRange({query::QueryTarget::WM, query::QueryTarget::LTM}, -1, 10)); BOOST_REQUIRE_GT(results.size(), 0); diff --git a/source/RobotAPI/libraries/armem_gui/MemoryControlWidget.cpp b/source/RobotAPI/libraries/armem_gui/MemoryControlWidget.cpp index c68673377563e83019640755699187ebee39a418..5016db50bf5da8dc10d0fac5b5c004b9178ddc40 100644 --- a/source/RobotAPI/libraries/armem_gui/MemoryControlWidget.cpp +++ b/source/RobotAPI/libraries/armem_gui/MemoryControlWidget.cpp @@ -15,26 +15,31 @@ namespace armarx::armem::gui { setSizePolicy(QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Fixed); - QLayout* layout = new QHBoxLayout(); - this->setLayout(layout); + auto vlayout = new QVBoxLayout(); + auto hlayout = new QHBoxLayout(); const int margin = 0; - layout->setContentsMargins(margin, margin, margin, margin); + vlayout->setContentsMargins(margin, margin, margin, margin); _lineEdit = new QLineEdit("/tmp/MemoryExport", this); - _exportHereButton = new QPushButton("Export here", this); + _lineEdit->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred); + _lineEdit->setMinimumWidth(400); - _storeButton = new QPushButton("Store in LTM", this); + _storeOnDiskButton = new QPushButton("Store current result on local Disk", this); - layout->addWidget(_lineEdit); - layout->addWidget(_exportHereButton); - layout->addWidget(_storeButton); + _storeInLTMButton = new QPushButton("Store current result in LTM", this); + vlayout->addWidget(_lineEdit); + hlayout->addWidget(_storeOnDiskButton); + hlayout->addWidget(_storeInLTMButton); + vlayout->addItem(hlayout); + + this->setLayout(vlayout); // Private connections. // Public connections. - connect(_storeButton, &QPushButton::pressed, this, &This::store); - connect(_exportHereButton, &QPushButton::pressed, this, &This::exportHere); + connect(_storeInLTMButton, &QPushButton::pressed, this, &This::storeInLTM); + connect(_storeOnDiskButton, &QPushButton::pressed, this, &This::storeOnDisk); } QLineEdit* MemoryControlWidget::pathInputBox() @@ -47,14 +52,14 @@ namespace armarx::armem::gui return _lineEdit->text(); } - QPushButton* MemoryControlWidget::storeButton() + QPushButton* MemoryControlWidget::storeInLTMButton() { - return _storeButton; + return _storeInLTMButton; } - QPushButton* MemoryControlWidget::exportHereButton() + QPushButton* MemoryControlWidget::storeOnDiskButton() { - return _exportHereButton; + return _storeOnDiskButton; } } diff --git a/source/RobotAPI/libraries/armem_gui/MemoryControlWidget.h b/source/RobotAPI/libraries/armem_gui/MemoryControlWidget.h index 4f8acc62ac9c8918f887703d9188e76cfc9f8584..19831694acc7b9251c7d372b8381f755df1bc292 100644 --- a/source/RobotAPI/libraries/armem_gui/MemoryControlWidget.h +++ b/source/RobotAPI/libraries/armem_gui/MemoryControlWidget.h @@ -20,17 +20,15 @@ namespace armarx::armem::gui QLineEdit* pathInputBox(); QString getEnteredPath(); - QPushButton* storeButton(); - QPushButton* loadButton(); - QPushButton* exportHereButton(); + QPushButton* storeInLTMButton(); + QPushButton* storeOnDiskButton(); public slots: signals: - void store(); - void load(); - void exportHere(); + void storeInLTM(); + void storeOnDisk(); private slots: @@ -42,9 +40,8 @@ namespace armarx::armem::gui QLineEdit* _lineEdit; - QPushButton* _storeButton; - QPushButton* _loadButton; - QPushButton* _exportHereButton; + QPushButton* _storeInLTMButton; + QPushButton* _storeOnDiskButton; }; diff --git a/source/RobotAPI/libraries/armem_gui/MemoryViewer.cpp b/source/RobotAPI/libraries/armem_gui/MemoryViewer.cpp index 6d711ac1dfee696b069a0408a001f5d98a08f2cd..5037bad396c0e7a83b7704b4895a25225ae8106f 100644 --- a/source/RobotAPI/libraries/armem_gui/MemoryViewer.cpp +++ b/source/RobotAPI/libraries/armem_gui/MemoryViewer.cpp @@ -5,6 +5,9 @@ #include <RobotAPI/libraries/armem/core/diskmemory/Memory.h> +#include <RobotAPI/libraries/armem/server/query_proc/diskmemory/MemoryQueryProcessor.h> +#include <RobotAPI/libraries/armem/server/query_proc/workingmemory/MemoryQueryProcessor.h> + #include <ArmarXGui/libraries/SimpleConfigDialog/SimpleConfigDialog.h> #include <ArmarXCore/core/ManagedIceObject.h> @@ -24,7 +27,6 @@ #include <filesystem> - namespace armarx::armem::gui { MemoryViewer::MemoryViewer( @@ -79,8 +81,8 @@ namespace armarx::armem::gui // Connections //connect(this, &This::connected, this, &This::updateMemory); - connect(memoryControlWidget, &armem::gui::MemoryControlWidget::exportHere, this, &This::exportHere); - connect(memoryControlWidget, &armem::gui::MemoryControlWidget::store, this, &This::store); + connect(memoryControlWidget, &armem::gui::MemoryControlWidget::storeOnDisk, this, &This::storeOnDisk); + connect(memoryControlWidget, &armem::gui::MemoryControlWidget::storeInLTM, this, &This::storeInLTM); connect(this, &This::connected, this, &This::updateMemories); connect(updateWidget, &armem::gui::PeriodicUpdateWidget::update, this, &This::updateMemories); @@ -151,17 +153,18 @@ namespace armarx::armem::gui statusLabel->setText(QString::fromStdString(ss.str())); return nullptr; } - else if (not it->second.has_value()) + /*else if (not it->second.has_value()) { return nullptr; - } + }*/ else { - return &it->second.value(); + //return &it->second.value(); + return &it->second; } } - void MemoryViewer::store() + void MemoryViewer::storeInLTM() { TIMING_START(MemoryStore); @@ -175,32 +178,37 @@ namespace armarx::armem::gui TIMING_END_STREAM(MemoryStore, ARMARX_VERBOSE); } - void MemoryViewer::exportHere() + void MemoryViewer::storeOnDisk() { TIMING_START(MemoryExport); QString qs = memoryControlWidget->getEnteredPath(); std::string utf8_text = qs.toUtf8().constData(); - ARMARX_IMPORTANT << "Exporting all memories at '" << utf8_text << "'."; - - std::filesystem::path p(utf8_text); - if (std::filesystem::is_regular_file(p)) + if (not utf8_text.empty()) { - ARMARX_WARNING << "Could not export a memory at '" << utf8_text << "'. Skipping export."; - return; - } + ARMARX_IMPORTANT << "Exporting all memories at '" << utf8_text << "'."; - std::filesystem::create_directories(p); - for (auto& [name, reader] : memoryReaders) + std::filesystem::path p(utf8_text); + if (std::filesystem::is_regular_file(p)) + { + ARMARX_WARNING << "Could not export a memory at '" << utf8_text << "'. Skipping export."; + return; + } + + std::filesystem::create_directories(p); + for (auto& [name, reader] : memoryReaders) + { + armem::client::QueryInput input = memoryGroup->queryWidget()->queryInput(); + armem::client::QueryResult result = reader.query(input); + + armem::d_ltm::Memory dMem(name); + dMem.reload(p / name); + dMem.append(result.memory); + } + } + else { - armem::client::QueryInput input = memoryGroup->queryWidget()->queryInput(); - armem::client::QueryResult result = reader.query(input); - - armem::d_ltm::Memory dMem(name); - ARMARX_IMPORTANT << "RELOAD"; - dMem.reload(p / name); - ARMARX_IMPORTANT << "APPEND"; - dMem.append(result.memory); + ARMARX_WARNING << "The path is empty. Could not export the memory in nirvana."; } TIMING_END_STREAM(MemoryExport, ARMARX_VERBOSE); @@ -215,18 +223,77 @@ namespace armarx::armem::gui bool dataChanged = false; + QString qs = memoryControlWidget->getEnteredPath(); + std::string utf8_text = qs.toUtf8().constData(); + + std::filesystem::path p(utf8_text); + + // first check if the local file system should be queried + if (memoryGroup->queryWidget()->alsoQueryLocalDisk()) + { + if (std::filesystem::is_directory(p)) + { + for (const auto& d : std::filesystem::directory_iterator(p)) + { + if (d.is_directory()) + { + std::string k = d.path().filename(); + armem::d_ltm::Memory dMem(k); + dMem.reload(p / k); + + armem::client::QueryInput input = memoryGroup->queryWidget()->queryInput(); + input.addQueryTargetToAll(armem::query::data::QueryTarget::Disk); + + armem::d_ltm::query_proc::MemoryQueryProcessor d_ltm_processor; + dMem = d_ltm_processor.process(input.toIce(), dMem, /* execute if: */ { query::data::QueryTarget::Disk }); + + wm::Memory converted = dMem.convert(); + memoryData[k] = std::move(converted); + dataChanged = true; + } + } + } + else + { + ARMARX_WARNING << "Could not import a memory from '" << utf8_text << "'. Skipping import."; + } + } + + armem::client::QueryInput input = memoryGroup->queryWidget()->queryInput(); for (auto& [name, reader] : memoryReaders) { TIMING_START(MemoryQuery); { - armem::client::QueryInput input = memoryGroup->queryWidget()->queryInput(); armem::client::QueryResult result = reader.query(input); if (result) { - memoryData[name] = std::move(result.memory); + if (result.memory.hasData()) + { + if (const auto& it = memoryData.find(name); it != memoryData.end()) + { + result.memory.append(it->second); + + // requery (e.g. to get only the last n values instead of the last n from disk and the last n from wm) + armem::wm::query_proc::MemoryQueryProcessor wm_processor; + result.memory = wm_processor.process(input.toIce(), result.memory, /* execute if: */ { query::data::QueryTarget::WM }); + + if (!result.memory.hasData()) + { + ARMARX_ERROR << "A memory which had data before lost data. This indicates that there is something wrong."; + } + } + + dataChanged = true; + memoryData[name] = std::move(result.memory); + } + else + { + ARMARX_INFO << "The memory " << name << " has no data after querying."; + } } else { + ARMARX_WARNING << "A query for memory '" + name + "' produced an error: " << result.errorMessage; if (statusLabel) { statusLabel->setText(QString::fromStdString(result.errorMessage)); @@ -239,24 +306,19 @@ namespace armarx::armem::gui { debugObserver->setDebugDatafield(Logging::tag.tagName, "Memory Query [ms]", new Variant(MemoryQuery.toMilliSecondsDouble())); } - - if (memoryData[name]) - { - dataChanged = true; - } - else - { - if (statusLabel) - { - statusLabel->setText("No query result."); - } - } } if (dataChanged) { emit memoryDataChanged(); } + else + { + if (statusLabel) + { + statusLabel->setText("No query result."); + } + } } @@ -382,10 +444,11 @@ namespace armarx::armem::gui std::map<std::string, const armem::wm::Memory*> convMap; for (auto& [name, data] : memoryData) { - if (data.has_value()) + /*if (data.has_value()) { convMap[name] = &data.value(); - } + }*/ + convMap[name] = &data; } if (convMap.empty()) diff --git a/source/RobotAPI/libraries/armem_gui/MemoryViewer.h b/source/RobotAPI/libraries/armem_gui/MemoryViewer.h index 22455503637f55114516bf6e93c6772cd18c179e..71870bdd565b0b8a585808f5f0e9f0f43c93d315 100644 --- a/source/RobotAPI/libraries/armem_gui/MemoryViewer.h +++ b/source/RobotAPI/libraries/armem_gui/MemoryViewer.h @@ -71,8 +71,8 @@ namespace armarx::armem::gui void resolveMemoryID(const MemoryID& id); // LTMControlWidget - void store(); - void exportHere(); + void storeInLTM(); + void storeOnDisk(); signals: @@ -109,7 +109,7 @@ namespace armarx::armem::gui armem::client::MemoryNameSystem mns; std::map<std::string, armem::client::Reader> memoryReaders; - std::map<std::string, std::optional<armem::wm::Memory>> memoryData; + std::map<std::string, armem::wm::Memory> memoryData; QLayout* updateWidgetLayout = nullptr; armem::gui::PeriodicUpdateWidget* updateWidget = nullptr; diff --git a/source/RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.cpp b/source/RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.cpp index ae9af3c213fbbea4d4a44852e8e02d0af15b8de9..dbb3d3fcabfa2ccf0034d1ba72027664bebe6ebc 100644 --- a/source/RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.cpp +++ b/source/RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.cpp @@ -41,14 +41,18 @@ namespace armarx::armem::gui : armem::DataMode::NoData; } + bool QueryWidget::alsoQueryLocalDisk() const + { + return _snapshotSelectorWidget->queryTargetContainsLocalDisk(); + } + armem::client::QueryInput QueryWidget::queryInput() { armem::client::query::Builder qb(dataMode()); - qb - .queryTarget(_snapshotSelectorWidget->queryTarget()) - .coreSegments().all() - .providerSegments().all() - .entities().all() + qb.queryTargets(_snapshotSelectorWidget->queryTargets()) + .coreSegments().all().queryTargets(_snapshotSelectorWidget->queryTargets()) + .providerSegments().all().queryTargets(_snapshotSelectorWidget->queryTargets()) + .entities().all().queryTargets(_snapshotSelectorWidget->queryTargets()) .snapshots(_snapshotSelectorWidget->selector()); return qb.buildQueryInput(); diff --git a/source/RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.h b/source/RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.h index 37e5fca58b80d54592d4eb6443e8e624bd0a613d..d2c3fecd6198ad2ad5c3f37077eb07f4f365dea9 100644 --- a/source/RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.h +++ b/source/RobotAPI/libraries/armem_gui/query_widgets/QueryWidget.h @@ -21,6 +21,7 @@ namespace armarx::armem::gui armem::DataMode dataMode() const; + bool alsoQueryLocalDisk() const; armem::client::QueryInput queryInput(); diff --git a/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotForm.cpp b/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotForm.cpp index 8d60c2252d4e9d6593a228cad75075cc41a21e5c..1d6c0cff39fd69da5e7f29844c64fabc1843f9a4 100644 --- a/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotForm.cpp +++ b/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotForm.cpp @@ -20,9 +20,9 @@ namespace armarx::armem::gui { - client::query::SnapshotSelector SnapshotForm::makeEntitySelector() + client::query::SnapshotSelector SnapshotForm::makeEntitySelector(const armem::query::data::QueryTargets& targets) { - client::query::SnapshotSelector s; + client::query::SnapshotSelector s(targets); fillEntitySelector(s); return s; } diff --git a/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotForm.h b/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotForm.h index 0ca9950b33a0585c97a8157bf17ad3c272fc8abc..f2f9ba1940d268d06f3383374d01893ea2d3dea4 100644 --- a/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotForm.h +++ b/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotForm.h @@ -19,7 +19,7 @@ namespace armarx::armem::gui Q_OBJECT public: - virtual client::query::SnapshotSelector makeEntitySelector(); + virtual client::query::SnapshotSelector makeEntitySelector(const armem::query::data::QueryTargets& targets); signals: @@ -30,10 +30,6 @@ namespace armarx::armem::gui virtual void fillEntitySelector(client::query::SnapshotSelector& selector) = 0; void setDateTimeDisplayFormat(QDateTimeEdit* dt); - - public: - client::query::SnapshotSelector selector; - }; diff --git a/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotSelectorWidget.cpp b/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotSelectorWidget.cpp index 87d94376e673492d07a7fe2f0206359259ea327a..e41bed15cecbc599c7c97b4266a04e0e9a70e47e 100644 --- a/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotSelectorWidget.cpp +++ b/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotSelectorWidget.cpp @@ -10,25 +10,39 @@ namespace armarx::armem::gui { - client::query::SnapshotSelector& SnapshotSelectorWidget::selector() + client::query::SnapshotSelector SnapshotSelectorWidget::selector() { - return _selector; + return _queryForms.at(_queryComboBox->currentText())->makeEntitySelector(queryTargets()); } - query::data::QueryTarget SnapshotSelectorWidget::queryTarget() const + query::data::QueryTargets SnapshotSelectorWidget::queryTargets() const { - return _queryTarget; + query::data::QueryTargets targets; + if (_WMQueryTargetCheckBox->isChecked()) + { + targets.push_back(query::data::QueryTarget::WM); + } + if (_LTMQueryTargetCheckBox->isChecked()) + { + targets.push_back(query::data::QueryTarget::LTM); + } + if (_DiskMemoryQueryTargetCheckBox->isChecked()) + { + targets.push_back(query::data::QueryTarget::Disk); + } + return targets; } + bool SnapshotSelectorWidget::queryTargetContainsLocalDisk() const + { + return _LocalDiskMemoryQueryTargetCheckBox->isChecked(); + } SnapshotSelectorWidget::SnapshotSelectorWidget() { _pageLayout = new QVBoxLayout(); setLayout(_pageLayout); - connect(this, &This::queryOutdated, this, &This::updateSelector); - connect(this, &This::queryTargetOutdated, this, &This::updateQueryTarget); - { QHBoxLayout* typeLayout = new QHBoxLayout(); @@ -40,16 +54,23 @@ namespace armarx::armem::gui typeLayout->addWidget(_queryComboBox); connect(_queryComboBox, &QComboBox::currentTextChanged, this, &This::showSelectedFormForQuery); - connect(_queryComboBox, &QComboBox::currentTextChanged, this, &This::queryOutdated); + connect(_queryComboBox, &QComboBox::currentTextChanged, this, &This::queryChanged); // query type select box - _queryTargetComboBox = new QComboBox(); - _queryTargetComboBox->addItems({"WM", "WM & LTM", "LTM (debug only)"}); - _queryTargetComboBox->setCurrentIndex(0); + auto queryTargetLayout = new QHBoxLayout(); + _WMQueryTargetCheckBox = new QCheckBox("WM"); + _LTMQueryTargetCheckBox = new QCheckBox("LTM (MongoDB)"); + _DiskMemoryQueryTargetCheckBox = new QCheckBox("LTM (Disk)"); + _LocalDiskMemoryQueryTargetCheckBox = new QCheckBox("Local Disk"); - typeLayout->addWidget(_queryTargetComboBox); + queryTargetLayout->addWidget(_WMQueryTargetCheckBox); + queryTargetLayout->addWidget(_LTMQueryTargetCheckBox); + queryTargetLayout->addWidget(_DiskMemoryQueryTargetCheckBox); + queryTargetLayout->addWidget(_LocalDiskMemoryQueryTargetCheckBox); - connect(_queryTargetComboBox, &QComboBox::currentTextChanged, this, &This::queryTargetOutdated); + _WMQueryTargetCheckBox->setChecked(true); + + typeLayout->addLayout(queryTargetLayout); _pageLayout->addLayout(typeLayout); } @@ -61,26 +82,7 @@ namespace armarx::armem::gui addForm("Time Range", new SnapshotFormTimeRange()); addForm("Index Range", new SnapshotFormIndexRange()); - // Add query targets - _queryTargets.insert({"WM", query::data::QueryTarget::WM}); - _queryTargets.insert({"WM & LTM", query::data::QueryTarget::WMAndLTM}); - _queryTargets.insert({"LTM (debug only)", query::data::QueryTarget::LTM}); - showSelectedFormForQuery(_queryComboBox->currentText()); - updateSelector(); - updateQueryTarget(); - } - - void SnapshotSelectorWidget::updateSelector() - { - this->_selector = _queryForms.at(_queryComboBox->currentText())->makeEntitySelector(); - emit queryChanged(); - } - - void SnapshotSelectorWidget::updateQueryTarget() - { - this->_queryTarget = _queryTargets.at(_queryTargetComboBox->currentText()); - emit queryTargetChanged(); } void SnapshotSelectorWidget::showSelectedFormForQuery(QString selected) @@ -95,7 +97,7 @@ namespace armarx::armem::gui { auto r = _queryForms.emplace(key, form); _pageLayout->addWidget(r.first->second); - connect(r.first->second, &SnapshotForm::queryChanged, this, &This::updateSelector); + //connect(r.first->second, &SnapshotForm::queryChanged, this, &This::updateSelector); } void SnapshotSelectorWidget::hideAllForms() diff --git a/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotSelectorWidget.h b/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotSelectorWidget.h index 92db5fbb13c74b011ca0f36a64fbf82a58536717..6f6422c3cdbc7fd0e1899bce47efbaaa32589062 100644 --- a/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotSelectorWidget.h +++ b/source/RobotAPI/libraries/armem_gui/query_widgets/SnapshotSelectorWidget.h @@ -35,31 +35,27 @@ namespace armarx::armem::gui armem::DataMode dataMode() const; - client::query::SnapshotSelector& selector(); - query::data::QueryTarget queryTarget() const; + client::query::SnapshotSelector selector(); + query::data::QueryTargets queryTargets() const; + bool queryTargetContainsLocalDisk() const; public slots: signals: - void queryChanged(); - void queryTargetChanged(); private slots: - void updateSelector(); - void updateQueryTarget(); + //void updateSelector(); void hideAllForms(); void showSelectedFormForQuery(QString selected); signals: - void queryOutdated(); - void queryTargetOutdated(); private: @@ -68,16 +64,14 @@ namespace armarx::armem::gui public: - - client::query::SnapshotSelector _selector; - query::data::QueryTarget _queryTarget; - QVBoxLayout* _pageLayout; QComboBox* _queryComboBox; - QComboBox* _queryTargetComboBox; + QCheckBox* _WMQueryTargetCheckBox; + QCheckBox* _LTMQueryTargetCheckBox; + QCheckBox* _DiskMemoryQueryTargetCheckBox; + QCheckBox* _LocalDiskMemoryQueryTargetCheckBox; /// The forms for the different query types. Hidden when not selected. std::map<QString, SnapshotForm*> _queryForms; - std::map<QString, query::data::QueryTarget> _queryTargets; }; diff --git a/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Reader.cpp b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Reader.cpp index 944f755f4ffdac48ae204903c0047a39c45e828f..d37479515ef8b7d1d2a1397d5ae5c5d1b563cb99 100644 --- a/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Reader.cpp +++ b/source/RobotAPI/libraries/aron/core/codegenerator/typeReader/xml/Reader.cpp @@ -182,6 +182,13 @@ namespace armarx::aron::xmltypereader Data::EnforceTagName(node, Data::INCLUDE_TAG); const std::string xmlinclude = Data::GetAttribute(node, Data::INCLUDE_ATTRIBUTE_NAME); + // add logic to allow relative paths: + std::string xml_path = xmlinclude; + if (simox::alg::starts_with(xmlinclude, "Package: ")) + { + // TODO CMakePackageFinder: + } + // parse parent xml file and add objects to alreday known Reader anotherReader; anotherReader.parseFile(xmlinclude); diff --git a/source/RobotAPI/libraries/aron/core/io/dataIO/reader/nlohmannJSON/NlohmannJSONReader.cpp b/source/RobotAPI/libraries/aron/core/io/dataIO/reader/nlohmannJSON/NlohmannJSONReader.cpp index 5d614b7025a52239be1ecc9933202c5a5aa3d26f..a17cc3ed151006531771e31e4639db4a972d34d5 100644 --- a/source/RobotAPI/libraries/aron/core/io/dataIO/reader/nlohmannJSON/NlohmannJSONReader.cpp +++ b/source/RobotAPI/libraries/aron/core/io/dataIO/reader/nlohmannJSON/NlohmannJSONReader.cpp @@ -43,7 +43,7 @@ namespace armarx::aron::dataIO::reader { if (!n.is_object()) { - throw error::AronException("NlohmannJSONReader", "NlohmannJSONReader", "Allowed are only objects in reader"); + throw error::AronException("NlohmannJSONReader", "NlohmannJSONReader", "Allowed are only objects in reader. Got as json: " + n.dump(2)); } if (n.at(io::Data::READER_WRITER_TYPE_SLUG) != io::Data::READER_WRITER_DICT_TYPENAME_SLUG)