Belle II Software development
SwitchDataStoreModule.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/SwitchDataStoreModule.h>
10#include <framework/datastore/DataStore.h>
11
12
13using namespace Belle2;
14
15//REG_MODLUE needed for --execute-path functionality
16//Note: should not appear in module list since we're not in the right directory
17REG_MODULE(SwitchDataStore);
18
20{
21 setDescription("Internal module used by Path.add_independent_path(). This shouldn't appear in 'basf2 -m' output. If it does, check REG_MODULE() handling.");
22
23 addParam("toID", m_to, "active DataStore id after this module", std::string(""));
24 addParam("doCopy", m_doCopy,
25 "should data be copied to DataStore 'toID'? This should be true only when toID refers to a _new_ DataStore ID", false);
26 addParam("mergeBack", m_mergeBack, "if given, copy the given objects/arrays over even if doCopy is fals.", std::vector<std::string> {});
27}
28
29SwitchDataStoreModule::~SwitchDataStoreModule() = default;
30void SwitchDataStoreModule::init(const std::string& to, bool doCopy, const std::vector<std::string>& mergeBack)
31{
32 m_to = to;
33 m_doCopy = doCopy;
34 m_mergeBack = mergeBack;
35}
36
38{
40 if (m_from == m_to)
41 B2FATAL("identical from/to parameter value " << m_from);
42 if (m_doCopy and m_to == "")
43 B2FATAL("doCopy is set for default DataStore ID! This would likely cause corruption.");
44 if (not m_doCopy and m_from == "")
45 B2FATAL("doCopy is not set ?");
46
47 if (m_doCopy) {
48 //create DataStore ID that doesn't exist yet (copying contents)
50 } else if (!m_mergeBack.empty()) {
51 //if m_mergeBack is set, we need to register the objects/arrays there, too!
53 //then copy
55 }
56
57 //switch
59}
61{
62 if (not m_doCopy) {
63 //copy contents over
65 }
66 //nothing merged back. this is not really consistent anyway.
67
68 //terminate() is called in reverse order.
70}
71
73{
74 event();
75}
77{
78 event();
79}
81{
82 if (m_doCopy) {
83 //copy contents over
85 } else if (!m_mergeBack.empty()) {
87 }
88
90}
void createNewDataStoreID(const std::string &id)
creates new datastore with given id, copying the registered objects/arrays from the current one.
Definition: DataStore.cc:779
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 copyContentsTo(const std::string &id, const std::vector< std::string > &entrylist_event={})
copy contents (actual array / object contents) of current DataStore to the DataStore with given ID.
Definition: DataStore.cc:810
std::string currentID() const
returns ID of current DataStore.
Definition: DataStore.cc:789
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
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.
bool m_doCopy
should data be copied to m_to?
virtual void endRun() override
This method is called if the current run ends.
virtual void terminate() override
This method is called at the end of the event processing.
virtual void beginRun() override
Called when entering a new run.
std::vector< std::string > m_mergeBack
list of obj/arrays (of event durability) that should be copied to m_to regardless of m_doCopy.
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.
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.