11#include <libxml/xpath.h>
13#include <framework/gearbox/Interface.h>
14#include <framework/gearbox/InputHandler.h>
26 void* openXmlUri(
const char*);
28 template <
class KEY,
class VALUE>
class MRUCache;
37 enum { c_DefaultCacheSize = 200 };
75 void setBackends(
const std::vector<std::string>& backends);
97 void open(
const std::string& name =
"Belle2.xml",
size_t cacheSize = c_DefaultCacheSize);
123 virtual std::string
getString(
const std::string& path =
"") const noexcept(false)
override
126 if (p.numNodes == 0)
throw gearbox::PathEmptyError() << path;
138 std::string
getString(
const std::string& path,
const std::string& defaultValue)
const
154 virtual std::pair<std::string, std::string>
getStringWithUnit(
const std::string& path =
"") const noexcept(false)
override
157 if (!p.numNodes)
throw gearbox::PathEmptyError() << path;
158 return make_pair(p.value, p.unit);
170 virtual const TObject*
getTObject(
const std::string& path)
const noexcept(
false)
override;
256#define B2_GEARBOX_REGISTER_INPUTHANDLER(classname,prefix)\
257 InputHandlerFactory<classname> Gearbox_InputHandlerFactory_##classname(prefix)
GearDir is the basic class used for accessing the parameter store.
Singleton class responsible for loading detector parameters from an XML file.
Gearbox & operator=(const Gearbox &)=delete
Also no assignment operator.
bool isOpen() const
Return the state of the Gearbox.
static void registerInputHandler(const std::string &prefix, gearbox::InputHandler::Factory *factory)
Register a new input handler.
void clearOverrides()
Clear all existing overrides.
std::map< std::string, TObject * > m_ownedObjects
Map of queried objects (path -> TObject*).
std::map< std::string, gearbox::InputHandler::Factory * > m_registeredHandlers
Map of registered InputHandlers.
std::string getString(const std::string &path, const std::string &defaultValue) const
Get the parameter path as a string.
Gearbox(const Gearbox &)=delete
Singleton: private copy constructor.
xmlDocPtr m_xmlDocument
Pointer to the libxml Document structure.
friend void * gearbox::openXmlUri(const char *)
friend to internal c-like function to interface libxml2 callback
MRUCache< std::string, PathValue > * m_parameterCache
Cache for already queried paths.
void addOverride(const PathOverride &poverride)
Add an override for a given XPath expression.
virtual int getNumberNodes(const std::string &path="") const override
Return the number of nodes a given path will expand to.
virtual std::string getString(const std::string &path="") const noexcept(false) override
Get the parameter path as a string.
std::vector< PathOverride > m_overrides
the existing overrides
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::vector< gearbox::InputHandler * > m_handlers
List of input handlers which will be used to find resources.
xmlXPathContextPtr m_xpathContext
Pointer to the libxml XPath context.
Class implementing a generic Most Recently Used cache.
Class representing a resource context for gearbox.
Exception to be thrown in case of an empty result.
virtual std::string getString(const std::string &path="") const noexcept(false)=0
Get the parameter path as a string.
static Gearbox & getInstance()
Return reference to the Gearbox instance.
virtual const TObject * getTObject(const std::string &path) const noexcept(false) override
Get the parameter path as a TObject.
~Gearbox()
Free structures on destruction.
Gearbox()
Singleton: private constructor.
void overridePathValue(const PathOverride &poverride)
Change the value of a given path expression.
PathValue getPathValue(const std::string &path) const
Return the (cached) value of a given path.
void clearBackends()
Clear list of backends.
void close()
Free internal structures of previously parsed tree and clear cache.
void setBackends(const std::vector< std::string > &backends)
Select the backends to use to find resources.
void open(const std::string &name="Belle2.xml", size_t cacheSize=c_DefaultCacheSize)
Open connection to backend and parse tree.
GearDir getDetectorComponent(const std::string &component)
Return GearDir representing a given DetectorComponent.
Abstract base class for different kinds of events.
Struct to override a path in the XML file with a custom value.
bool multiple
if true, override all nodes when more than one node matches the XPath expression, bail otherwise
std::string path
XPath expression of the path to override.
std::string value
New value.
Struct for caching results from the xml file.
std::string unit
unit attribute of the first node if present, otherwise ""
std::string value
value of the first node if present, otherwise ""
int numNodes
number of nodes corresponding to the path