15 const std::string& exportName,
17 const std::shared_ptr<Processors>&
filters,
18 const std::shared_ptr<persistence::MemoryPersistenceStrategy>& persistenceStrategy) :
19 CoreSegmentBase(exportName,
id,
filters), persistenceStrategy_(persistenceStrategy)
31 << (persistenceStrategy_ !=
33 ARMARX_DEBUG <<
"Strategy identifier=" << persistenceStrategy_->getIdentifier();
34 ARMARX_DEBUG <<
"Strategy export name=" << persistenceStrategy_->getExportName();
36 for (
auto& providerSegmentKey : persistenceStrategy_->getContainerKeys(
id()))
38 std::shared_ptr<persistence::MemoryPersistenceStrategy>
39 providerSegmentPersistenceStrategy(persistenceStrategy_);
42 id().withProviderSegmentName(providerSegmentKey),
44 providerSegmentPersistenceStrategy);
56 return persistenceStrategy_->containsContainer(
id(), providerSegmentName);
59 std::shared_ptr<ProviderSegment>
71 id().withProviderSegmentName(providerSegmentName),
73 persistenceStrategy_);
85 if (persistenceStrategy_->containsItem(
91 auto filecontent = persistenceStrategy_->retrieveItem(
93 auto aron = conv.convert(filecontent,
"");
96 catch (
const nlohmann::json::type_error& e)
98 ARMARX_WARNING <<
"You are trying to access aron data in a CoreSegment which is "
99 "not available, skipping...";
105 [&wmCoreSegment](
auto& ltmProviderSegment)
108 ltmProviderSegment.loadAllReferences(wmProviderSegment);
115 existingWmProviderSegment.
append(wmProviderSegment);
131 auto& conv =
processors->defaultTypeConverter;
135 if (persistenceStrategy_->containsItem(
138 auto& conv =
processors->defaultTypeConverter;
142 auto filecontent = persistenceStrategy_->retrieveItem(
144 auto aron = conv.convert(filecontent,
"");
147 catch (
const nlohmann::json::type_error& e)
150 <<
"You are trying to access aron data which is not available, skipping...";
158 [&wmCoreSegment, &n](
auto& ltmProviderSegment)
161 ltmProviderSegment.loadLatestNReferences(n, wmProviderSegment);
168 existingWmProviderSegment.
append(wmProviderSegment);
185 [&](
auto& wmProviderSegment)
187 std::shared_ptr<persistence::MemoryPersistenceStrategy>
188 providerSegmentPersistenceStrategy(persistenceStrategy_);
192 id().withProviderSegmentName(wmProviderSegment.id().providerSegmentName),
194 providerSegmentPersistenceStrategy);
196 ltmProviderSegment.
resolve(wmProviderSegment);
205 if (
id().coreSegmentName.empty())
208 <<
"During storage of segment '" << wmCoreSegment.
id().
str()
209 <<
"' I noticed that the corresponding LTM has no id set. "
210 <<
"I set the id of the LTM to the same name, however this should not happen!";
219 auto& conv =
processors->defaultTypeConverter;
221 auto [vec, modeSuffix] = conv.convert(wmCoreSegment.
aronType());
227 if (!persistenceStrategy_->containsItem(
id(), key))
229 persistenceStrategy_->storeItem(
id(), key, vec);
230 ARMARX_DEBUG <<
"Stored type information for CoreSegment "
236 ARMARX_DEBUG <<
"CoreSegment does not have aron type, so aron type information "
237 "cannot be exported";
242 [&](
const auto& wmProviderSegment)
244 std::shared_ptr<persistence::MemoryPersistenceStrategy>
245 providerSegmentPersistenceStrategy(persistenceStrategy_);
249 id().withProviderSegmentName(wmProviderSegment.id().providerSegmentName),
251 providerSegmentPersistenceStrategy);
253 ltmProviderSegment.
store(wmProviderSegment, simulatedVersion);
#define ARMARX_CHECK_EMPTY(c)
std::string coreSegmentName
MemoryID getCoreSegmentID() const
std::string str(bool escapeDelimiters=true) const
Get a string representation of this memory ID.
ProviderSegmentT & addProviderSegment(const std::string &name, aron::type::ObjectPtr providerSegmentType=nullptr, const std::vector< PredictionEngine > &predictionEngines={})
Add an empty provider segment with the given name, optional provider segment type and prediction engi...
bool hasProviderSegment(const std::string &name) const
bool forEachProviderSegment(ProviderSegmentFunctionT &&func)
ProviderSegmentT & getProviderSegment(const std::string &name)
void append(const OtherDerivedT &other)
aron::type::ObjectPtr & aronType()
CoreSegment(const std::string &exportName, const MemoryID &memoryId, const std::shared_ptr< Processors > &filters, const std::shared_ptr< persistence::MemoryPersistenceStrategy > &persistenceStrategy)
bool _implForEachProviderSegment(std::function< void(ProviderSegment &)> func) const override
bool _implHasProviderSegment(const std::string &name) const override
void _loadLatestNReferences(int n, armem::wm::CoreSegment &wmCoreSegment) override
std::shared_ptr< ProviderSegment > _implFindProviderSegment(const std::string &name) const override
void _resolve(armem::wm::CoreSegment &wmCoreSegment) override
void _store(const armem::wm::CoreSegment &wmCoreSegment, bool simulatedVersion) override
void _loadAllReferences(armem::wm::CoreSegment &wmCoreSegment) override
virtual std::string getExportName() const
std::shared_ptr< Processors > processors
void store(const armem::wm::ProviderSegment &provSeg, bool simulatedVersion)
encode the content of a wm::Memory and store
void resolve(armem::wm::ProviderSegment &provSeg)
convert the references of the input into a wm::Memory
static const constexpr char * TYPE_FILENAME
Client-side working memory core segment.
Client-side working memory provider segment.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.