Belle II Software  release-05-02-19
SwitchDataStoreModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Christian Pulvermacher *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <framework/core/SwitchDataStoreModule.h>
12 #include <framework/datastore/DataStore.h>
13 
14 
15 using namespace Belle2;
16 
17 //REG_MODLUE needed for --execute-path functionality
18 //Note: should not appear in module list since we're not in the right directory
19 REG_MODULE(SwitchDataStore)
20 
22 {
23  setDescription("Internal module used by Path.add_independent_path(). This shouldn't appear in 'basf2 -m' output. If it does, check REG_MODULE() handling.");
24 
25  addParam("toID", m_to, "active DataStore id after this module", std::string(""));
26  addParam("doCopy", m_doCopy,
27  "should data be copied to DataStore 'toID'? This should be true only when toID refers to a _new_ DataStore ID", false);
28  addParam("mergeBack", m_mergeBack, "if given, copy the given objects/arrays over even if doCopy is fals.", std::vector<std::string> {});
29 }
30 
31 SwitchDataStoreModule::~SwitchDataStoreModule() = default;
32 void SwitchDataStoreModule::init(const std::string& to, bool doCopy, const std::vector<std::string>& mergeBack)
33 {
34  m_to = to;
35  m_doCopy = doCopy;
36  m_mergeBack = mergeBack;
37 }
38 
40 {
42  if (m_from == m_to)
43  B2FATAL("identical from/to parameter value " << m_from);
44  if (m_doCopy and m_to == "")
45  B2FATAL("doCopy is set for default DataStore ID! This would likely cause corruption.");
46  if (not m_doCopy and m_from == "")
47  B2FATAL("doCopy is not set ?");
48 
49  if (m_doCopy) {
50  //create DataStore ID that doesn't exist yet (copying contents)
52  } else if (!m_mergeBack.empty()) {
53  //if m_mergeBack is set, we need to register the objects/arrays there, too!
55  //then copy
57  }
58 
59  //switch
61 }
63 {
64  if (not m_doCopy) {
65  //copy contents over
67  }
68  //nothing merged back. this is not really consistent anyway.
69 
70  //terminate() is called in reverse order.
72 }
73 
75 {
76  event();
77 }
79 {
80  event();
81 }
83 {
84  if (m_doCopy) {
85  //copy contents over
87  } else if (!m_mergeBack.empty()) {
89  }
90 
92 }
Belle2::DataStore::currentID
std::string currentID() const
returns ID of current DataStore.
Definition: DataStore.cc:758
Belle2::DataStore::Instance
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::DataStore::createNewDataStoreID
void createNewDataStoreID(const std::string &id)
creates new datastore with given id, copying the registered objects/arrays from the current one.
Definition: DataStore.cc:753
Belle2::DataStore::copyEntriesTo
void copyEntriesTo(const std::string &id, const std::vector< std::string > &entrylist_event={})
copy entries (not contents) of current DataStore to the DataStore with given ID.
Definition: DataStore.cc:774
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::DataStore::copyContentsTo
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:779
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SwitchDataStoreModule::beginRun
virtual void beginRun() override
Called when entering a new run.
Definition: SwitchDataStoreModule.cc:74
Belle2::SwitchDataStoreModule::m_doCopy
bool m_doCopy
should data be copied to m_to?
Definition: SwitchDataStoreModule.h:52
Belle2::SwitchDataStoreModule::event
virtual void event() override
This method is the core of the module.
Definition: SwitchDataStoreModule.cc:82
Belle2::SwitchDataStoreModule::terminate
virtual void terminate() override
This method is called at the end of the event processing.
Definition: SwitchDataStoreModule.cc:62
Belle2::DataStore::switchID
void switchID(const std::string &id)
switch to DataStore with given ID.
Definition: DataStore.cc:763
Belle2::SwitchDataStoreModule::endRun
virtual void endRun() override
This method is called if the current run ends.
Definition: SwitchDataStoreModule.cc:78
Belle2::SwitchDataStoreModule
Internal module used by Path.add_independent_path().
Definition: SwitchDataStoreModule.h:29
Belle2::SwitchDataStoreModule::m_to
std::string m_to
active DataStore ID after this module.
Definition: SwitchDataStoreModule.h:51
Belle2::SwitchDataStoreModule::init
void init(const std::string &to, bool doCopy, const std::vector< std::string > &mergeBack)
setter for Path.
Definition: SwitchDataStoreModule.cc:32
Belle2::SwitchDataStoreModule::m_from
std::string m_from
active DataStore ID before this module.
Definition: SwitchDataStoreModule.h:50
Belle2::SwitchDataStoreModule::m_mergeBack
std::vector< std::string > m_mergeBack
list of obj/arrays (of event durability) that should be copied to m_to regardless of m_doCopy.
Definition: SwitchDataStoreModule.h:54
Belle2::SwitchDataStoreModule::initialize
virtual void initialize() override
Initialize the Module.
Definition: SwitchDataStoreModule.cc:39