6 #include <SimoxUtility/algorithm/string.h>
22 const std::shared_ptr<Processors>& filters,
23 const std::shared_ptr<persistence::MemoryPersistenceStrategy>& persistenceStrategy) :
24 EntityBase(exportName, memoryId, filters), persistenceStrategy_(persistenceStrategy) {}
39 for (
auto& entitySnapshotKey : persistenceStrategy_->getContainerKeys(
id()))
41 ARMARX_DEBUG <<
"Found entity snapshot=" << entitySnapshotKey;
43 std::shared_ptr<persistence::MemoryPersistenceStrategy> entitySnapshotPersistenceStrategy(persistenceStrategy_);
49 entitySnapshotPersistenceStrategy);
52 func(ltmEntitySnapshot);
69 if (first < 0 or last < 0)
72 unsigned long size = 0;
73 auto countFunc = [&](
EntitySnapshot& ltmEntitySnapshot) { size++; };
83 if (checked >= first && checked <= last)
85 func(ltmEntitySnapshot);
104 Time ts = ltmEntitySnapshot.id().timestamp;
105 if (ts >=
min && ts <=
max)
107 func(ltmEntitySnapshot);
124 Time ts = ltmEntitySnapshot.id().timestamp;
127 func(ltmEntitySnapshot);
143 Time ts = ltmEntitySnapshot.id().timestamp;
146 func(ltmEntitySnapshot);
165 return foundSnapshot;
168 std::shared_ptr<EntitySnapshot>
186 std::shared_ptr<EntitySnapshot>
196 Time ts = ltmEntitySnapshot.id().timestamp;
218 persistenceStrategy_);
221 std::shared_ptr<EntitySnapshot>
231 auto ts = e.id().timestamp;
232 if (ts < time && ts > bestMatch)
253 persistenceStrategy_);
256 std::shared_ptr<EntitySnapshot>
266 auto ts = e.id().timestamp;
267 if (ts <= time && ts > bestMatch)
286 persistenceStrategy_);
289 std::shared_ptr<EntitySnapshot>
299 auto ts = e.id().timestamp;
300 if (ts > time && ts < bestMatch)
317 id().withTimestamp(bestMatch),
319 persistenceStrategy_);
322 std::shared_ptr<EntitySnapshot>
332 auto ts = e.id().timestamp;
333 if (ts >= time && ts < bestMatch)
351 persistenceStrategy_);
364 [&wmEntity](
auto& ltmEntitySnapshot)
367 ltmEntitySnapshot.id()
370 armem::wm::EntitySnapshot s;
371 ltmEntitySnapshot.loadAllReferences(s);
372 wmEntity.addSnapshot(s);
397 [&wmEntity, &
n, ¤t, &count](
auto& ltmEntitySnapshot)
400 ltmEntitySnapshot.id()
403 if (current >= (count - n))
405 armem::wm::EntitySnapshot wmEntitySnapshot;
406 ltmEntitySnapshot.loadAllReferences(wmEntitySnapshot);
407 ltmEntitySnapshot.resolve(wmEntitySnapshot);
408 wmEntity.addSnapshot(wmEntitySnapshot);
412 ARMARX_DEBUG <<
"Skipping snapshot with timestamp " << ltmEntitySnapshot.id().timestamp;
422 std::lock_guard l(ltm_mutex);
426 ARMARX_DEBUG <<
"Resolve entity id=" << id().cleanID().str();
429 [&](
auto& wmEntitySnapshot)
432 id().clearTimestamp();
434 std::shared_ptr<persistence::MemoryPersistenceStrategy> entitySnapshotPersistenceStrategy(persistenceStrategy_);
438 id().withTimestamp(wmEntitySnapshot.id().timestamp),
440 entitySnapshotPersistenceStrategy);
441 ltmEntitySnapshot.
resolve(wmEntitySnapshot);
448 std::lock_guard l(ltm_mutex);
452 if (
id().entityName.empty())
455 <<
"During storage of segment '" << wmEntity.
id().
str()
456 <<
"' I noticed that the corresponding LTM has no id set. "
457 <<
"I set the id of the LTM to the same name, however this should not happen!";
473 [&](
const auto& wmEntitySnapshot)
476 id().clearTimestamp();
478 std::shared_ptr<persistence::MemoryPersistenceStrategy> entitySnapshotPersistenceStrategy(persistenceStrategy_);
481 id().withTimestamp(wmEntitySnapshot.id().timestamp),
483 entitySnapshotPersistenceStrategy);
486 if (hasSnapshot(wmEntitySnapshot.id().timestamp))
488 ARMARX_DEBUG <<
"Ignoring to put an EntitiySnapshot into the LTM because "
489 "the timestamp already existed (we assume snapshots are "
490 "const and do not change outside the ltm).";
494 for (
auto& filters : processors->snapFilters)
496 bool accepted = filters->accept(wmEntitySnapshot, simulatedVersion);
500 ARMARX_DEBUG <<
"Ignoring to put an EntitySnapshot into the LTM because it "
510 ltmEntitySnapshot.
store(wmEntitySnapshot);
511 statistics.recordedSnapshots++;