4#include <ArmarXCore/interface/core/UserException.h>
17 std::vector<std::unique_ptr<processor::SnapshotFilter>>
18 Processors::buildSnapshotFilters(
const nlohmann::json& config)
20 std::vector<std::unique_ptr<processor::SnapshotFilter>> filters;
24 auto f = std::make_unique<processor::filter::SnapshotFrequencyFilter>();
26 filters.push_back(std::move(f));
31 auto f = std::make_unique<processor::filter::SnapshotSimilarityFilter>();
33 filters.push_back(std::move(f));
38 auto f = std::make_unique<processor::filter::SnapshotImportanceFilter>();
40 filters.push_back(std::move(f));
53 if (config.contains(
"storeSegments"))
55 std::set<std::string> whitelist;
56 for (
const auto& entry : config[
"storeSegments"])
58 whitelist.insert(entry.get<std::string>());
60 ARMARX_IMPORTANT <<
"LTM storeSegments whitelist active with " << whitelist.size()
67 if (config.contains(
"segments"))
69 for (
const auto& [segmentPath, segmentConfig] : config[
"segments"].items())
78 auto f = std::make_unique<processor::filter::SnapshotEqualityFilter>();
87 auto f = std::make_unique<processor::converter::data::image::PngConverter>();
94 auto f = std::make_unique<processor::converter::data::image::ExrConverter>();
107 Processors::isSegmentWhitelisted(
const std::string& coreSegmentName,
108 const std::string& providerSegmentName)
const
118 if (whitelist.count(coreSegmentName) > 0)
122 if (!providerSegmentName.empty() &&
123 whitelist.count(coreSegmentName +
"/" + providerSegmentName) > 0)
132 const std::string& providerSegmentName,
134 bool simulatedVersion)
137 if (!isSegmentWhitelisted(coreSegmentName, providerSegmentName))
144 const std::string providerPath = coreSegmentName +
"/" + providerSegmentName;
158 if (!filter->accept(snapshot, simulatedVersion))
166 std::map<std::string, processor::SnapshotFilter::FilterStatistics>
169 std::map<std::string, processor::SnapshotFilter::FilterStatistics> stats;
170 bool recordedOverall =
false;
173 auto collect = [&](
const std::string& keyPrefix,
174 const std::vector<std::unique_ptr<processor::SnapshotFilter>>&
filters)
176 for (
const auto& filter_ptr :
filters)
178 auto statistics = filter_ptr->getFilterStatistics();
179 auto recorded = statistics.accepted + statistics.rejected;
180 stats[keyPrefix + filter_ptr->getName()] = statistics;
183 recordedOverall =
true;
192 collect(segmentPath +
":",
filters);
195 ARMARX_INFO <<
"Number of active filters: " << numFilters;
199 if (numFilters > 0 && !recordedOverall)
201 throw InvalidArgumentException(
202 "NoFilters recorded any data being accepted or rejected, "
203 "cant store empty statistics");
214 filter_ptr->resetStatisticsForNewEpisode();
218 for (
const auto& filter_ptr :
filters)
220 filter_ptr->resetStatisticsForNewEpisode();
std::vector< std::unique_ptr< processor::SnapshotFilter > > snapFilters
std::optional< std::set< std::string > > storeSegments
Optional whitelist of segments to store.
void configure(const nlohmann::json &config)
std::vector< std::unique_ptr< processor::DataConverter > > converters
bool acceptSnapshotForSegment(const std::string &coreSegmentName, const std::string &providerSegmentName, const armem::wm::EntitySnapshot &snapshot, bool simulatedVersion=false)
Decide whether a snapshot of the given segment should be stored to LTM.
std::map< std::string, std::vector< std::unique_ptr< processor::SnapshotFilter > > > segmentSnapFilters
Per-segment snapshot filter overrides, keyed by "CoreSegment" or "CoreSegment/ProviderSegment".
std::map< std::string, processor::SnapshotFilter::FilterStatistics > getSnapshotFilterStatistics()
bool hasSegmentSelection() const
Whether any segment-based selection or per-segment filtering is configured.
void resetFilterStatisticsForNewEpisode()
resetFilterStatisticsForNewEpisode runs resetFilterStatisticsForNewEpisode on all snapshot filters
static const constexpr char * NAME
static const constexpr char * NAME
static const constexpr char * NAME
static const constexpr char * NAME
static const constexpr char * NAME
static const constexpr char * NAME
Client-side working memory entity snapshot.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.