9#include <framework/modules/core/PruneDataStoreModule.h>
10#include <framework/datastore/DataStore.h>
11#include <framework/datastore/StoreEntry.h>
12#include <framework/logging/LogSystem.h>
13#include <framework/logging/Logger.h>
24 Clears the content of the DataStore while it keeps entries listed in the matchEntries option.
25 The EventMetaData object will always be kept, as it is required by the framework to properly
26 work with the DataStore.
28 This logic can be inverted to remove only the entries matched by the regex
29 in the matchEntries parameter by setting the parameter to
30 keepMatchedEntries to False.
33 Also all Relations will be cleared if they are not matched by one entry
34 in the matchEntries list. You have to ensure the objects referenced by
35 kept relations are also matched by one entry in the keepEntries list so
36 a relation does not point to nirvana.
39 "name of all DataStore entries (with regular expression syntax) to match. "
40 "For example, you can use 'Raw.*' to match all Raw-Objects.",
43 "If true, all entries matched by the regular expression are kept. "
44 "If false, matched entries will be removed.",
69 return std::regex(regexString);
70 }
catch (
const std::regex_error& e) {
71 B2FATAL(
"Regex '" << regexString <<
"' cannot be compiled: " << e.what());
83 for (
auto& datastore_item : storemap) {
84 std::string
const& datastore_key = datastore_item.first;
89 if (std::regex_match(datastore_key, regx)) {
96 if (std::regex_match(datastore_key, regx)) {
128 "StoreArray entry " << *datastore_key <<
" will be not pruned from the datastore");
132 "StoreArray entry " << entry->name <<
" will be pruned from the datastore");
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.
std::map< std::string, StoreEntry > StoreEntryMap
Map for StoreEntries.
@ c_Debug
Debug: for code development.
static LogSystem & Instance()
Static method to get a reference to the LogSystem instance.
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.
bool m_cacheValid
Whether the caches above have already been filled for this run.
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< const std::string * > m_entriesToKeep
Names of the DataStore entries which are kept, only used for debug output.
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.
void updateCache(DataStore::StoreEntryMap &storemap)
Evaluate the regular expressions for all entries of the given DataStore map and fill the m_entriesToP...
std::regex compileAndCatch(std::string ®exString) const
Compile a regex expression and catch the exception if the regex string is not valid.
std::vector< DataStore::StoreEntry * > m_entriesToPrune
DataStore entries which have to be pruned.
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.