9#include <framework/modules/core/PruneDataStoreModule.h>
10#include <framework/datastore/DataStore.h>
11#include <framework/logging/Logger.h>
22 Clears the content of the DataStore while it keeps entries listed in the matchEntries option.
23 The EventMetaData object will always be kept, as it is required by the framework to properly
24 work with the DataStore.
26 This logic can be inverted to remove only the entries matched by the regex
27 in the matchEntries parameter by setting the parameter to
28 keepMatchedEntries to False.
31 Also all Relations will be cleared if they are not matched by one entry
32 in the matchEntries list. You have to ensure the objects referenced by
33 kept relations are also matched by one entry in the keepEntries list so
34 a relation does not point to nirvana.
37 "name of all DataStore entries (with regular expression syntax) to match. "
38 "For example, you can use 'Raw.*' to match all Raw-Objects.",
41 "If true, all entries matched by the regular expression are kept. "
42 "If false, matched entries will be removed.",
63 return std::regex(regexString);
64 }
catch (
const std::regex_error& e) {
65 B2FATAL(
"Regex '" << regexString <<
"' cannot be compiled: " << e.what());
76 for (
auto& datastore_item : storemap) {
77 std::string
const& datastore_key = datastore_item.first;
82 if (std::regex_match(datastore_key, regx)) {
89 if (std::regex_match(datastore_key, regx)) {
97 "StoreArray entry " << datastore_key <<
" will be not pruned from the datastore");
100 "StoreArray entry " << datastore_key <<
" will be pruned from the datastore");
105 datastore_item.second.invalidate();
StoreEntryMap & getStoreEntryMap(EDurability durability)
Get a reference to the object/array map.
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
static DataStore & Instance()
Instance of singleton Store.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
void initialize() override
Prepare regex checks.
void event() override
Prune datastore.
std::vector< std::string > m_keepEntriesImplicit
Branches to always keep because the are required by the framework to properly work with the datastore...
std::vector< std::regex > m_compiled_regex_implicit
Caching the regex expression for the keep check.
bool m_keepMatchedEntries
If true, all entries matched by the RegEx expression are kept.
PruneDataStoreModule()
Constructor.
std::vector< std::regex > m_compiled_regex
Caching the regex expression for the keep check.
std::vector< std::string > m_matchEntries
Storing the option of branches to keep.
std::regex compileAndCatch(std::string ®exString) const
Compile a regex expression and catch the exception if the regex string is not valid.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.