Belle II Software development
MergeDataStoreModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <framework/core/MergeDataStoreModule.h>
10#include <framework/datastore/DataStore.h>
11
12#include <framework/core/Environment.h>
13#include <framework/core/InputController.h>
14
15
16using namespace Belle2;
17
18//REG_MODLUE needed for --execute-path functionality
19//Note: should not appear in module list since we're not in the right directory
20REG_MODULE(MergeDataStore);
21
23{
24 setDescription("Internal module used by Path.add_independent_merge_path(). This shouldn't appear in 'basf2 -m' output. If it does, check REG_MODULE() handling.");
25
26 addParam("toID", m_to, "active DataStore id after this module", std::string(""));
27 addParam("createNew", m_createNew,
28 "do you want to create a new (empty) DataStore 'toID'? This should be true only when toID refers to a _new_ DataStore ID", false);
29 addParam("mergeBack", m_mergeBack, "copy the given objects/arrays over even if createNew is false.",
30 std::vector<std::string> {"EventMetaData"});
31}
32
33MergeDataStoreModule::~MergeDataStoreModule() = default;
34
35void MergeDataStoreModule::init(const std::string& to, bool createNew, const std::vector<std::string>& mergeBack)
36{
37 m_to = to;
38 m_createNew = createNew;
39 m_mergeBack = mergeBack;
40}
41
43{
45 if (m_from == m_to)
46 B2FATAL("identical from/to parameter value " << m_from);
47 if (m_createNew and m_to == "")
48 B2FATAL("createNew is set for default DataStore ID! This would likely cause corruption.");
49 if (not m_createNew and m_from == "")
50 B2FATAL("createNew is not set ?");
51
52 if (m_createNew) {
53 //create DataStore ID that doesn't exist yet (copying contents)
55 } else if (!m_mergeBack.empty()) {
56 //if m_mergeBack is set, we need to register the objects/arrays there, too (if they are not registered yet)
58 }
59
60 //switch
62}
63
65{
66 //terminate() is called in reverse order.
68}
69
71{
72 if (m_createNew) {
73 // don't do anything
74 } else if (!m_mergeBack.empty()) {
76 }
77
79}
void createEmptyDataStoreID(const std::string &id)
creates empty datastore with given id.
Definition: DataStore.cc:784
void copyEntriesTo(const std::string &id, const std::vector< std::string > &entrylist_event={}, bool mergeEntries=false)
copy entries (not contents) of current DataStore to the DataStore with given ID.
Definition: DataStore.cc:805
void switchID(const std::string &id)
switch to DataStore with given ID.
Definition: DataStore.cc:794
void mergeContentsTo(const std::string &id, const std::vector< std::string > &entrylist_event={})
merge contents (actual array / object contents) of current DataStore to the DataStore with given ID.
Definition: DataStore.cc:815
std::string currentID() const
returns ID of current DataStore.
Definition: DataStore.cc:789
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
std::string m_from
active DataStore ID before this module.
virtual void initialize() override
Initialize the Module.
virtual void event() override
This method is the core of the module.
virtual void terminate() override
This method is called at the end of the event processing.
std::vector< std::string > m_mergeBack
list of obj/arrays (of event durability) that should be merged with m_to.
std::string m_to
active DataStore ID after this module.
void init(const std::string &to, bool doCopy, const std::vector< std::string > &mergeBack)
setter for Path.
bool m_createNew
create new DataStore
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.