10 #include <framework/modules/core/PruneDataStoreModule.h>
11 #include <framework/datastore/DataStore.h>
12 #include <framework/logging/Logger.h>
23 Clears the content of the DataStore while it keeps entries listed in the matchEntries option.
24 The EventMetaData object will always be kept, as it is required by the framework to properly
25 work with the DataStore.
27 This logic can be inverted to remove only the entries matched by the regex
28 in the matchEntries parameter by setting the parameter to
29 keepMatchedEntries to False.
32 Also all Relations will be cleared if they are not matched by one entry
33 in the matchEntries list. You have to ensure the objects referenced by
34 kept relations are also matched by one entry in the keepEntries list so
35 a relation does not point to nirvana.
37 addParam("matchEntries", m_matchEntries,
38 "name of all DataStore entries (with regular expression syntax) to match. "
39 "For example, you can use 'Raw.*' to match all Raw-Objects.",
41 addParam(
"keepMatchedEntries", m_keepMatchedEntries,
42 "If true, all entries matched by the regular expression are kept. "
43 "If false, matched entries will be removed.",
44 m_keepMatchedEntries);
45 setPropertyFlags(c_ParallelProcessingCertified);
49 void PruneDataStoreModule::initialize()
52 for (
auto& kEntry : m_matchEntries) {
53 m_compiled_regex.push_back(compileAndCatch(kEntry));
56 for (
auto& kEntry : m_keepEntriesImplicit) {
57 m_compiled_regex_implicit.push_back(compileAndCatch(kEntry));
61 std::regex PruneDataStoreModule::compileAndCatch(std::string& regexString)
const
64 return std::regex(regexString);
65 }
catch (
const std::regex_error& e) {
66 B2FATAL(
"Regex '" << regexString <<
"' cannot be compiled: " << e.what());
72 void PruneDataStoreModule::event()
74 auto& storemap = DataStore::Instance().getStoreEntryMap(DataStore::c_Event);
77 for (
auto& datastore_item : storemap) {
78 std::string
const& datastore_key = datastore_item.first;
81 bool toKeep = !m_keepMatchedEntries;
82 for (
auto const& regx : m_compiled_regex) {
83 if (std::regex_match(datastore_key, regx)) {
84 toKeep = m_keepMatchedEntries;
89 for (
auto const& regx : m_compiled_regex_implicit) {
90 if (std::regex_match(datastore_key, regx)) {
98 "StoreArray entry " << datastore_key <<
" will be not pruned from the datastore");
101 "StoreArray entry " << datastore_key <<
" will be pruned from the datastore");
106 datastore_item.second.invalidate();