Belle II Software development
GearboxModule.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/modules/gearbox/GearboxModule.h>
10#include <framework/gearbox/Gearbox.h>
11#include <framework/datastore/StoreObjPtr.h>
12#include <framework/dataobjects/EventMetaData.h>
13// needed for complex module parameter
14#include <framework/core/ModuleParam.templateDetails.h>
15
16using namespace std;
17using namespace Belle2;
18
19//-----------------------------------------------------------------
20// Register the Module
21//-----------------------------------------------------------------
23
24//-----------------------------------------------------------------
25// Implementation
26//-----------------------------------------------------------------
27
28GearboxModule::GearboxModule() : Module()
29{
30 //Set module properties
31 setDescription("Loads the Belle II detector parameters from an XML document.");
32 setPropertyFlags(c_ParallelProcessingCertified);
33
34
35 m_backends.emplace_back("file:");
36
37 //Parameter definition
38 addParam("backends", m_backends, "The backends to use when looking for xml "
39 "data. A backend can also contain a search path after ':'. (If none "
40 "is given, '/data' will be used.)", m_backends);
41 addParam("fileName", m_fileName, "The filename of the main xml file",
42 string("geometry/Belle2.xml"));
43 addParam("override", m_unitOverrides, "Override single values from the XML "
44 "file. This should be a list of tuples containing an xpath "
45 "expression, a value and a unit (which can be empty). The xpath "
46 "expression must resolve to exactly one node in the XML tree which "
47 "does not contain any children except text. The supplied value and "
48 "unit will be set for this node. See "
49 "framework/examples/gearbox_override.py", m_unitOverrides);
50 addParam("overrideMultiple", m_multipleOverrides, "Same as override but the "
51 "xpath expression may evaluate to more than one node in which case "
52 "all occurances are set to the supplied value and unit",
53 m_multipleOverrides);
54 addParam("overridePrefix", m_overridePrefix, "Common prefix which is "
55 "prepended to all overrides. Beware that '//' has a special meaning "
56 "meaning in xpath so be careful with leading and trailing slashes "
57 "in the overrides and the prefix respectively", std::string("/Detector"));
58}
59
61{
62 //gearbox might need exp/run numbers
64
65 Gearbox& gearbox = Gearbox::getInstance();
66 for (auto& unit : m_unitOverrides) {
67 Gearbox::PathOverride poverride;
68 poverride.path = m_overridePrefix + std::get<0>(unit);
69 poverride.value = std::get<1>(unit);
70 poverride.unit = std::get<2>(unit);
71 gearbox.addOverride(poverride);
72 }
73 for (auto& multiple : m_multipleOverrides) {
74 Gearbox::PathOverride poverride;
75 poverride.path = m_overridePrefix + std::get<0>(multiple);
76 poverride.value = std::get<1>(multiple);
77 poverride.unit = std::get<2>(multiple);
78 poverride.multiple = true;
79 gearbox.addOverride(poverride);
80 }
81
82 gearbox.setBackends(m_backends);
83 gearbox.open(m_fileName);
84}
85
87{
88 //if only file backend is used, we don't want to reread the data in every run
89 if (m_backends.size() == 1 && m_backends[0] == "file:")
90 return;
91
92 Gearbox& gearbox = Gearbox::getInstance();
93 gearbox.close();
94 gearbox.open(m_fileName);
95}
void initialize() override
Define backends.
std::vector< std::tuple< std::string, std::string, std::string > > m_multipleOverrides
overrides to override the value and unit of many parameters
Definition: GearboxModule.h:73
std::string m_fileName
The toplevel filename for the parameters.
Definition: GearboxModule.h:66
std::vector< std::tuple< std::string, std::string, std::string > > m_unitOverrides
overrides to override the value and unit of a parameter
Definition: GearboxModule.h:71
void beginRun() override
Load the (possibly rundependent) parameters from the chosen backends.
std::string m_overridePrefix
common prefix for all value overrides
Definition: GearboxModule.h:69
std::vector< std::string > m_backends
The backend specifier.
Definition: GearboxModule.h:65
Singleton class responsible for loading detector parameters from an XML file.
Definition: Gearbox.h:34
Base class for Modules.
Definition: Module.h:72
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
static Gearbox & getInstance()
Return reference to the Gearbox instance.
Definition: Gearbox.cc:81
#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.
STL namespace.
Struct to override a path in the XML file with a custom value.
Definition: Gearbox.h:51
std::string unit
new Unit
Definition: Gearbox.h:57
bool multiple
if true, override all nodes when more than one node matches the XPath expression, bail otherwise
Definition: Gearbox.h:60
std::string path
XPath expression of the path to override.
Definition: Gearbox.h:53
std::string value
New value.
Definition: Gearbox.h:55