 |
Belle II Software
release-05-02-19
|
13 #include <libxml/xpath.h>
15 #include <framework/gearbox/Interface.h>
16 #include <framework/gearbox/InputHandler.h>
28 void* openXmlUri(
const char*);
30 template <
class KEY,
class VALUE>
class MRUCache;
36 class Gearbox:
public gearbox::Interface {
39 enum { c_DefaultCacheSize = 200 };
59 std::string
unit {
""};
77 void setBackends(
const std::vector<std::string>& backends);
99 void open(
const std::string& name =
"Belle2.xml",
size_t cacheSize = c_DefaultCacheSize);
114 virtual int getNumberNodes(
const std::string& path =
"")
const override
125 virtual std::string
getString(
const std::string& path =
"") const noexcept(false)
override
128 if (p.numNodes == 0)
throw gearbox::PathEmptyError() << path;
140 std::string
getString(
const std::string& path,
const std::string& defaultValue)
const
156 virtual std::pair<std::string, std::string>
getStringWithUnit(
const std::string& path =
"") const noexcept(false)
override
159 if (!p.numNodes)
throw gearbox::PathEmptyError() << path;
160 return make_pair(p.value, p.unit);
172 virtual const TObject*
getTObject(
const std::string& path)
const noexcept(
false)
override;
203 gearbox::InputContext*
openXmlUri(
const std::string& uri)
const;
220 std::vector<gearbox::InputHandler*>
m_handlers;
245 static gearbox::InputHandler*
factory(
const std::string& uri)
258 #define B2_GEARBOX_REGISTER_INPUTHANDLER(classname,prefix)\
259 InputHandlerFactory<classname> Gearbox_InputHandlerFactory_##classname(prefix)
GearDir getDetectorComponent(const std::string &component)
Return GearDir representing a given DetectorComponent.
std::vector< gearbox::InputHandler * > m_handlers
List of input handlers which will be used to find resources.
virtual std::pair< std::string, std::string > getStringWithUnit(const std::string &path="") const noexcept(false) override
Get the parameter path as string and also return the unit it was defined with.
std::string value
New value.
int numNodes
number of nodes corresponding to the path
void clearOverrides()
Clear all existing overrides.
virtual const TObject * getTObject(const std::string &path) const noexcept(false) override
Get the parameter path as a TObject.
static Gearbox & getInstance()
Return reference to the Gearbox instance.
void clearBackends()
Clear list of backends.
std::vector< PathOverride > m_overrides
the existing overrides
virtual int getNumberNodes(const std::string &path="") const override
Return the number of nodes a given path will expand to.
std::map< std::string, gearbox::InputHandler::Factory * > m_registeredHandlers
Map of registered InputHandlers.
virtual std::string getString(const std::string &path="") const noexcept(false)=0
Get the parameter path as a string.
bool multiple
if true, override all nodes when more than one node matches the XPath expression, bail otherwise
std::string unit
unit attribute of the first node if present, otherwise ""
friend void * gearbox::openXmlUri(const char *)
friend to internal c-like function to interface libxml2 callback
Struct to override a path in the XML file with a custom value.
void close()
Free internal structures of previously parsed tree and clear cache.
Gearbox & operator=(const Gearbox &)=delete
Also no assignment operator.
Abstract base class for different kinds of events.
Singleton class responsible for loading detector parameters from an XML file.
virtual std::string getString(const std::string &path="") const noexcept(false) override
Get the parameter path as a string.
void addOverride(const PathOverride &poverride)
Add an override for a given XPath expression.
xmlDocPtr m_xmlDocument
Pointer to the libxml Document structure.
std::map< std::string, TObject * > m_ownedObjects
Map of queried objects (path -> TObject*).
std::string value
value of the first node if present, otherwise ""
std::string path
XPath expression of the path to override.
xmlXPathContextPtr m_xpathContext
Pointer to the libxml XPath context.
Gearbox()
Singleton: private constructor.
MRUCache< std::string, PathValue > * m_parameterCache
Cache for already queried paths.
~Gearbox()
Free structures on destruction.
PathValue getPathValue(const std::string &path) const
Return the (cached) value of a given path.
static void registerInputHandler(const std::string &prefix, gearbox::InputHandler::Factory *factory)
Register a new input handler.
void open(const std::string &name="Belle2.xml", size_t cacheSize=c_DefaultCacheSize)
Open connection to backend and parse tree.
gearbox::InputContext * openXmlUri(const std::string &uri) const
Function to be called when libxml requests a new input uri to be opened.
void overridePathValue(const PathOverride &poverride)
Change the value of a given path expression.
void setBackends(const std::vector< std::string > &backends)
Select the backends to use to find resources.
bool isOpen() const
Return the state of the Gearbox.