8 #include <RobotAPI/libraries/armem/aron/MemoryLink.aron.generated.h>
20 #include <Ice/LocalException.h>
26 server::PredictingMemoryInterfacePrx predictingMemory) :
27 readingPrx(readingMemory), predictionPrx(predictingMemory)
39 armem::query::data::Result
42 armem::query::data::Result result;
46 "Reading interface proxy must be set to perform a query.");
53 catch (const ::Ice::ConnectionRefusedException& e)
59 catch (
const Ice::LocalException& e)
61 std::stringstream sstream;
62 sstream <<
"Memory query failed.\nReason: " << e.what();
63 result.errorMessage = sstream.str();
73 return this->
query(armem::query::data::MemoryQuerySeq{
query}, dataMode);
80 input.memoryQueries = queries;
81 input.dataMode = dataMode;
82 return this->
query(input);
94 int recursionDepth)
const
102 int recursionDepth)
const
107 "Reading interface proxy must be set to perform a query.");
110 armem::query::data::Result result;
117 { resolveMemoryLinks(instance, bObj.
memory, mns, recursionDepth); });
118 result = bObj.
toIce();
120 catch (
const Ice::LocalException& e)
122 std::stringstream sstream;
123 sstream <<
"Memory query failed.\nReason: " << e.what();
124 result.errorMessage = sstream.str();
128 std::stringstream sstream;
129 sstream <<
"Encountered malformed MemoryLink: " << e.what();
130 result.errorMessage = sstream.str();
139 int recursionDepth)
const
141 return this->
query(armem::query::data::MemoryQuerySeq{
query}, mns, recursionDepth);
147 int recursionDepth)
const
150 input.memoryQueries = queries;
151 return this->
query(input, mns, recursionDepth);
157 int recursionDepth)
const
173 std::optional<std::pair<MemoryID, aron::data::VariantPtr>>
178 static const aron::Path memoryLinkIDPath{{
"memoryID"}};
179 static const aron::Path memoryLinkDataPath{{
"data"}};
183 dto.fromAron(memoryIDDict);
184 auto memoryID = aron::fromAron<armem::MemoryID>(dto);
199 if (!nextDataAndType)
202 <<
" not available in memory containing that MemoryID.";
205 auto [nextData, nextType] = nextDataAndType.value();
208 std::string nextObjectName = nextType->getObjectNameWithTemplateInstantiations();
209 if (nextType->getObjectName() != linkTemplate)
212 << nextType->getObjectName() <<
", but the link requires the type "
219 nextData->toAronDTO(),
220 linkData->getPath().withElement(memoryLinkDataPath.toString()))}};
229 static const aron::Path memoryLinkDataPath{{
"data"}};
232 static const std::string linkType =
233 arondto::MemoryLink<arondto::MemoryID>::ToAronType()->getFullName();
235 std::set<armem::MemoryID> seenIDs{instance.
id()};
236 std::vector<aron::Path> currentPaths{{{
""}}};
237 std::vector<aron::Path> nextPaths;
243 ARMARX_INFO <<
"Instance '" << instance.
id().
str() <<
"' does not have a defined type.";
246 auto [instanceData, instanceType] = dataAndType.value();
247 while (!currentPaths.empty() && (recursionDepth == -1 || depth < recursionDepth))
249 for (
const auto& path : currentPaths)
251 aron::SubObjectFinder finder(linkType);
252 if (path.getFirstElement().empty())
259 instanceData->navigateAbsolute(path),
260 instanceType->navigateAbsolute(path));
263 for (
auto& [linkPathStr, linkDataAndType] : finder.getFoundObjects())
265 auto [linkData, linkType] = linkDataAndType;
269 auto [
memoryID, dataToAppend] = result.value();
270 if (seenIDs.find(
memoryID) != seenIDs.end())
277 memoryLinkDataPath.toString(), dataToAppend);
279 linkData->getPath().withElement(memoryLinkDataPath.toString()));
283 currentPaths = std::move(nextPaths);
292 using namespace client::query_fns;
299 if (
id.hasTimestamp())
315 std::vector<MemoryID> snapshotIDs = _snapshotIDs;
321 for (
const MemoryID& snapshotID : snapshotIDs)
336 ARMARX_INFO <<
"Error querying " << snapshotIDs.size() <<
" STT snapshots:\n"
345 using namespace client::query_fns;
346 if (!
id.isWellDefined())
353 id.hasCoreSegmentName()
357 id.hasProviderSegmentName()
375 std::optional<wm::EntitySnapshot>
latest = std::nullopt;
378 if (not entity.
empty())
380 const wm::EntitySnapshot& snapshot = entity.getLatestSnapshot();
381 if (not latest.has_value() or latest->time() < snapshot.time())
392 ARMARX_INFO <<
"Error querying latest snapshot in " << id;
400 using namespace client::query_fns;
405 return this->
query(qb);
411 using namespace client::query_fns;
416 return this->
query(qb);
419 server::dto::DirectlyStoreResult
422 server::RecordingMemoryInterfacePrx storingMemoryPrx = server::RecordingMemoryInterfacePrx::checkedCast(
readingPrx);
423 if (storingMemoryPrx)
425 return storingMemoryPrx->directlyStore(
input);
429 ARMARX_WARNING <<
"Could not store a query into the LTM. It seems like the Memory does not implement the StoringMemoryInterface.";
436 server::RecordingMemoryInterfacePrx storingMemoryPrx = server::RecordingMemoryInterfacePrx::checkedCast(
readingPrx);
437 if (storingMemoryPrx)
439 server::dto::StartRecordInput i;
440 i.executionTime = armarx::core::time::dto::DateTime();
441 i.startTime = armarx::core::time::dto::DateTime();
443 i.configuration.clear();
445 storingMemoryPrx->startRecord(i);
450 ARMARX_WARNING <<
"Could not store a query into the LTM. It seems like the Memory does not implement the StoringMemoryInterface.";
456 server::RecordingMemoryInterfacePrx storingMemoryPrx = server::RecordingMemoryInterfacePrx::checkedCast(
readingPrx);
457 if (storingMemoryPrx)
459 storingMemoryPrx->stopRecord();
464 ARMARX_WARNING <<
"Could not store a query into the LTM. It seems like the Memory does not implement the StoringMemoryInterface.";
481 std::vector<PredictionResult>
487 "PredictingMemoryInterfacePrx",
488 "Prediction interface proxy must be set to request a prediction.");
491 armem::prediction::data::PredictionRequestSeq iceRequests;
492 for (
const auto& request : requests)
494 iceRequests.push_back(request.toIce());
497 armem::prediction::data::PredictionResultSeq results;
502 catch (
const Ice::LocalException& e)
504 armem::prediction::data::PredictionResult
failure;
506 std::stringstream sstream;
507 sstream <<
"Prediction request failed. Reason: " << e.what();
508 failure.errorMessage = sstream.str();
510 for (
size_t i = 0; i < requests.size(); ++i)
516 std::vector<PredictionResult> boResults;
517 for (
const auto& result : results)
525 std::map<MemoryID, std::vector<PredictionEngine>>
531 "PredictingMemoryInterfacePrx",
532 "Prediction interface proxy must be set to request a prediction.");
535 armem::prediction::data::EngineSupportMap engines;
540 catch (
const Ice::LocalException& e)
545 std::map<MemoryID, std::vector<PredictionEngine>> boMap;