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.
36 addParam("matchEntries", m_matchEntries,
37 "name of all DataStore entries (with regular expression syntax) to match. "
38 "For example, you can use 'Raw.*' to match all Raw-Objects.",
40 addParam(
"keepMatchedEntries", m_keepMatchedEntries,
41 "If true, all entries matched by the regular expression are kept. "
42 "If false, matched entries will be removed.",
43 m_keepMatchedEntries);
44 setPropertyFlags(c_ParallelProcessingCertified);
48 void PruneDataStoreModule::initialize()
51 for (
auto& kEntry : m_matchEntries) {
52 m_compiled_regex.push_back(compileAndCatch(kEntry));
55 for (
auto& kEntry : m_keepEntriesImplicit) {
56 m_compiled_regex_implicit.push_back(compileAndCatch(kEntry));
60 std::regex PruneDataStoreModule::compileAndCatch(std::string& regexString)
const
63 return std::regex(regexString);
64 }
catch (
const std::regex_error& e) {
65 B2FATAL(
"Regex '" << regexString <<
"' cannot be compiled: " << e.what());
71 void PruneDataStoreModule::event()
73 auto& storemap = DataStore::Instance().getStoreEntryMap(DataStore::c_Event);
76 for (
auto& datastore_item : storemap) {
77 std::string
const& datastore_key = datastore_item.first;
80 bool toKeep = !m_keepMatchedEntries;
81 for (
auto const& regx : m_compiled_regex) {
82 if (std::regex_match(datastore_key, regx)) {
83 toKeep = m_keepMatchedEntries;
88 for (
auto const& regx : m_compiled_regex_implicit) {
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();
Clears the content of the DataStore while it keeps entries matching the regex expression in the match...
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.