![]() |
Belle II Software development
|
Singleton class responsible for loading detector parameters from an XML file. More...
#include <Gearbox.h>
Classes | |
struct | PathOverride |
Struct to override a path in the XML file with a custom value. More... | |
struct | PathValue |
Struct for caching results from the xml file. More... | |
Public Types | |
enum | { c_DefaultCacheSize = 200 } |
Default cache size (in entries) for the Gearbox. More... | |
Public Member Functions | |
~Gearbox () | |
Free structures on destruction. | |
void | setBackends (const std::vector< std::string > &backends) |
Select the backends to use to find resources. | |
void | clearBackends () |
Clear list of backends. | |
void | addOverride (const PathOverride &poverride) |
Add an override for a given XPath expression. | |
void | clearOverrides () |
Clear all existing overrides. | |
void | open (const std::string &name="Belle2.xml", size_t cacheSize=c_DefaultCacheSize) |
Open connection to backend and parse tree. | |
void | close () |
Free internal structures of previously parsed tree and clear cache. | |
bool | isOpen () const |
Return the state of the Gearbox. | |
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::string | getString (const std::string &path, const std::string &defaultValue) const |
Get the parameter path as a string. | |
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. | |
virtual const TObject * | getTObject (const std::string &path) const noexcept(false) override |
Get the parameter path as a TObject. | |
GearDir | getDetectorComponent (const std::string &component) |
Return GearDir representing a given DetectorComponent. | |
bool | exists (const std::string &path="") const |
Check if a given parameter path exists. | |
operator bool () const | |
Convert to bool to simplify checking of existence. | |
std::vector< GearDir > | getNodes (const std::string &path="") const |
Get vector of GearDirs which point to all the nodes the given path evaluates to. | |
std::string | getPath () const |
Return path of the current interface. | |
double | getDouble (const std::string &path="") const noexcept(false) |
Get the parameter path as a double. | |
double | getDouble (const std::string &path, double defaultValue) const noexcept(false) |
Get the parameter path as a double. | |
int | getInt (const std::string &path="") const noexcept(false) |
Get the parameter path as a int. | |
int | getInt (const std::string &path, int defaultValue) const noexcept(false) |
Get the parameter path as a int. | |
bool | getBool (const std::string &path="") const noexcept(false) |
Get the parameter path as a bool. | |
bool | getBool (const std::string &path, bool defaultValue) const |
Get the parameter path as a bool. | |
double | getWithUnit (const std::string &path) const noexcept(false) |
Get the parameter path as a double converted to the standard unit. | |
double | getWithUnit (const std::string &path, double defaultValue) const noexcept(false) |
Get the parameter path as a double converted to the standard unit. | |
std::vector< double > | getArray (const std::string &path) const noexcept(false) |
Get the parameter path as a list of double values converted to the standard unit. | |
std::vector< double > | getArray (const std::string &path, const std::vector< double > &defaultValue) const noexcept(false) |
Get the parameter path as a list of double values converted to the standard unit. | |
double | getLength (const std::string &path="") const noexcept(false) |
Get the parameter path as a double converted to the standard length unit. | |
double | getLength (const std::string &path, double defaultValue) const noexcept(false) |
Get the parameter path as a double converted to the standard length unit. | |
double | getAngle (const std::string &path="") const noexcept(false) |
Get the parameter path as a double converted to the standard angle unit. | |
double | getAngle (const std::string &path, double defaultValue) const noexcept(false) |
Get the parameter path as a double converted to the standard angle unit. | |
double | getEnergy (const std::string &path="") const noexcept(false) |
Get the parameter path as a double converted to the standard energy unit. | |
double | getEnergy (const std::string &path, double defaultValue) const noexcept(false) |
Get the parameter path as a double converted to the standard energy unit. | |
double | getDensity (const std::string &path="") const noexcept(false) |
Get the parameter path as a double converted to the standard density unit. | |
double | getDensity (const std::string &path, double defaultValue) const noexcept(false) |
Get the parameter path as a double converted to the standard density unit. | |
double | getTime (const std::string &path="") const noexcept(false) |
Get the parameter path as a double converted to the standard time unit. | |
double | getTime (const std::string &path, double defaultValue) const noexcept(false) |
Get the parameter path as a double converted to the standard time unit. | |
double | getFrequency (const std::string &path="") const noexcept(false) |
Get the parameter path as a double converted to the standard frequency unit. | |
double | getFrequency (const std::string &path, double defaultValue) const noexcept(false) |
Get the parameter path as a double converted to the standard frequency unit. | |
Static Public Member Functions | |
static Gearbox & | getInstance () |
Return reference to the Gearbox instance. | |
static void | registerInputHandler (const std::string &prefix, gearbox::InputHandler::Factory *factory) |
Register a new input handler. | |
Protected Member Functions | |
std::string | ensureNode (const std::string &path) const |
make sure the path really corresponds to an XPath node expression by removing trailing slashes | |
std::string | ensurePath (const std::string &path) const |
make sure the path really corresponds to a path by appending a trailing slash if neccessary | |
std::string | addIndex (const std::string &path, int index) const |
add [index] to the path (after stripping trailing slashes) | |
std::string | joinPath (const std::string &path, const std::string &subpath) const |
joind to paths, inserting a slash if neccessary | |
Protected Attributes | |
std::string | m_path |
path of the current interface | |
Private Member Functions | |
Gearbox () | |
Singleton: private constructor. | |
Gearbox (const Gearbox &)=delete | |
Singleton: private copy constructor. | |
Gearbox & | operator= (const Gearbox &)=delete |
Also no assignment operator. | |
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. | |
PathValue | getPathValue (const std::string &path) const |
Return the (cached) value of a given path. | |
Private Attributes | |
xmlDocPtr | m_xmlDocument |
Pointer to the libxml Document structure. | |
xmlXPathContextPtr | m_xpathContext |
Pointer to the libxml XPath context. | |
MRUCache< std::string, PathValue > * | m_parameterCache |
Cache for already queried paths. | |
std::map< std::string, TObject * > | m_ownedObjects |
Map of queried objects (path -> TObject*). | |
std::vector< gearbox::InputHandler * > | m_handlers |
List of input handlers which will be used to find resources. | |
std::map< std::string, gearbox::InputHandler::Factory * > | m_registeredHandlers |
Map of registered InputHandlers. | |
std::vector< PathOverride > | m_overrides |
the existing overrides | |
Friends | |
void * | gearbox::openXmlUri (const char *) |
friend to internal c-like function to interface libxml2 callback | |
Singleton class responsible for loading detector parameters from an XML file.
anonymous enum |
|
protectedinherited |
add [index] to the path (after stripping trailing slashes)
Definition at line 166 of file Interface.cc.
|
inline |
Add an override for a given XPath expression.
Definition at line 81 of file Gearbox.h.
|
inline |
Clear all existing overrides.
|
protectedinherited |
make sure the path really corresponds to an XPath node expression by removing trailing slashes
Definition at line 156 of file Interface.cc.
|
protectedinherited |
make sure the path really corresponds to a path by appending a trailing slash if neccessary
Definition at line 161 of file Interface.cc.
|
inlineinherited |
Check if a given parameter path exists.
Definition at line 54 of file Interface.h.
|
inlineinherited |
Get the parameter path as a double converted to the standard angle unit.
Gearbox will try to determine the unit with which the parameter was saved and convert it to the default system. If no unit can be determinded, it will be assumed that the parameter does not need to be converted.
If the parameter is empty or does not exist, the defaultValue will be returned.
gearbox::PathEmptyError | if path is empty or does not exist |
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
defaultValue | Value to return if the Path es empty or does not exist |
Definition at line 321 of file Interface.h.
|
inlineinherited |
Get the parameter path as a double converted to the standard angle unit.
Gearbox will try to determine the unit with which the parameter was saved and convert it to the default system. If no unit can be determinded, it will be assumed that the parameter does not need to be converted.
gearbox::PathEmptyError | if path is empty or does not exist |
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
Definition at line 299 of file Interface.h.
|
inherited |
Get the parameter path as a list of double values converted to the standard unit.
The content of the parameter will be split at whitespace, comma and semi-colon and returned as a vector of numbers
Gearbox will try to determine the unit with which the parameter was saved and convert it to the default system. If no unit can be determinded, it will be assumed that the parameter does not need to be converted.
gearbox::PathEmptyError | if path is empty or does not exist |
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
Definition at line 123 of file Interface.cc.
|
inherited |
Get the parameter path as a list of double values converted to the standard unit.
The content of the parameter will be split at whitespace, comma and semi-colon and returned as a vector of numbers
Gearbox will try to determine the unit with which the parameter was saved and convert it to the default system. If no unit can be determinded, it will be assumed that the parameter does not need to be converted.
If the parameter is empty or does not exist, the defaultValue will be returned.
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
defaultValue | Value to return if the Path es empty or does not exist |
Definition at line 146 of file Interface.cc.
|
inherited |
Get the parameter path as a bool.
If the parameter is empty or does not exist, the defaultValue will be returned.
path | Path of the parameter to get |
defaultValue | Value to return if the Path es empty or does not exist |
Definition at line 88 of file Interface.cc.
|
inherited |
Get the parameter path as a bool.
gearbox::PathEmptyError | if path is empty or does not exist |
path | Path of the parameter to get |
Definition at line 80 of file Interface.cc.
|
inlineinherited |
Get the parameter path as a double converted to the standard density unit.
Gearbox will try to determine the unit with which the parameter was saved and convert it to the default system. If no unit can be determinded, it will be assumed that the parameter does not need to be converted.
If the parameter is empty or does not exist, the defaultValue will be returned.
gearbox::PathEmptyError | if path is empty or does not exist |
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
defaultValue | Value to return if the Path es empty or does not exist |
Definition at line 401 of file Interface.h.
|
inlineinherited |
Get the parameter path as a double converted to the standard density unit.
Gearbox will try to determine the unit with which the parameter was saved and convert it to the default system. If no unit can be determinded, it will be assumed that the parameter does not need to be converted.
gearbox::PathEmptyError | if path is empty or does not exist |
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
Definition at line 379 of file Interface.h.
|
inherited |
Get the parameter path as a double.
If the parameter is empty or does not exist, the defaultValue will be returned.
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
defaultValue | Value to return if the Path es empty or does not exist |
Definition at line 51 of file Interface.cc.
|
inherited |
Get the parameter path as a double.
gearbox::PathEmptyError | if path is empty or does not exist |
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
Definition at line 41 of file Interface.cc.
|
inlineinherited |
Get the parameter path as a double converted to the standard energy unit.
Gearbox will try to determine the unit with which the parameter was saved and convert it to the default system. If no unit can be determinded, it will be assumed that the parameter does not need to be converted.
If the parameter is empty or does not exist, the defaultValue will be returned.
gearbox::PathEmptyError | if path is empty or does not exist |
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
defaultValue | Value to return if the Path es empty or does not exist |
Definition at line 361 of file Interface.h.
|
inlineinherited |
Get the parameter path as a double converted to the standard energy unit.
Gearbox will try to determine the unit with which the parameter was saved and convert it to the default system. If no unit can be determinded, it will be assumed that the parameter does not need to be converted.
gearbox::PathEmptyError | if path is empty or does not exist |
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
Definition at line 339 of file Interface.h.
|
inlineinherited |
Get the parameter path as a double converted to the standard frequency unit.
Gearbox will try to determine the unit with which the parameter was saved and convert it to the default system. If no unit can be determinded, it will be assumed that the parameter does not need to be converted.
If the parameter is empty or does not exist, the defaultValue will be returned.
gearbox::PathEmptyError | if path is empty or does not exist |
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
defaultValue | Value to return if the Path es empty or does not exist |
Definition at line 481 of file Interface.h.
|
inlineinherited |
Get the parameter path as a double converted to the standard frequency unit.
Gearbox will try to determine the unit with which the parameter was saved and convert it to the default system. If no unit can be determinded, it will be assumed that the parameter does not need to be converted.
gearbox::PathEmptyError | if path is empty or does not exist |
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
Definition at line 459 of file Interface.h.
|
inherited |
Get the parameter path as a int.
If the parameter is empty or does not exist, the defaultValue will be returned.
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
defaultValue | Value to return if the Path es empty or does not exist |
Definition at line 71 of file Interface.cc.
|
inherited |
Get the parameter path as a int.
gearbox::PathEmptyError | if path is empty or does not exist |
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
Definition at line 60 of file Interface.cc.
|
inlineinherited |
Get the parameter path as a double converted to the standard length unit.
Gearbox will try to determine the unit with which the parameter was saved and convert it to the default system. If no unit can be determinded, it will be assumed that the parameter does not need to be converted.
If the parameter is empty or does not exist, the defaultValue will be returned.
gearbox::PathEmptyError | if path is empty or does not exist |
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
defaultValue | Value to return if the Path es empty or does not exist |
Definition at line 281 of file Interface.h.
|
inlineinherited |
Get the parameter path as a double converted to the standard length unit.
Gearbox will try to determine the unit with which the parameter was saved and convert it to the default system. If no unit can be determinded, it will be assumed that the parameter does not need to be converted.
gearbox::PathEmptyError | if path is empty or does not exist |
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
Definition at line 259 of file Interface.h.
|
inherited |
Get vector of GearDirs which point to all the nodes the given path evaluates to.
path | Path of the parameters to get |
Definition at line 21 of file Interface.cc.
|
inlineoverridevirtual |
Return the number of nodes a given path will expand to.
Implements Interface.
Definition at line 112 of file Gearbox.h.
|
inlineinherited |
Return path of the current interface.
Definition at line 70 of file Interface.h.
|
inline |
Get the parameter path as a string.
if the parameter is empty or does not exist, defaultValue will be returned.
path | path of the parameter to get |
defaultValue | value to return if the path es empty or does not exist |
|
inlineoverridevirtual |
Get the parameter path as a string.
gearbox::PathEmptyError | if path is empty or does not exist |
path | Path of the parameter to get |
Implements Interface.
Definition at line 123 of file Gearbox.h.
|
inlineoverridevirtual |
Get the parameter path as string and also return the unit it was defined with.
If no unit was defined, an empty string will be returned for the unit. No parsing of the unit is performed, this funtion is primarily used by getWithUnit.
gearbox::PathEmptyError | if path is empty or does not exist |
path | Path of the parameter to get |
Implements Interface.
Definition at line 154 of file Gearbox.h.
|
inlineinherited |
Get the parameter path as a double converted to the standard time unit.
Gearbox will try to determine the unit with which the parameter was saved and convert it to the default system. If no unit can be determinded, it will be assumed that the parameter does not need to be converted.
If the parameter is empty or does not exist, the defaultValue will be returned.
gearbox::PathEmptyError | if path is empty or does not exist |
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
defaultValue | Value to return if the Path es empty or does not exist |
Definition at line 441 of file Interface.h.
|
inlineinherited |
Get the parameter path as a double converted to the standard time unit.
Gearbox will try to determine the unit with which the parameter was saved and convert it to the default system. If no unit can be determinded, it will be assumed that the parameter does not need to be converted.
gearbox::PathEmptyError | if path is empty or does not exist |
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
Definition at line 419 of file Interface.h.
|
inherited |
Get the parameter path as a double converted to the standard unit.
Gearbox will try to determine the unit with which the parameter was saved and convert it to the default system. If no unit can be determinded, it will be assumed that the parameter does not need to be converted
gearbox::PathEmptyError | if path is empty or does not exist |
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
Definition at line 97 of file Interface.cc.
|
inherited |
Get the parameter path as a double converted to the standard unit.
Gearbox will try to determine the unit with which the parameter was saved and convert it to the default system. If no unit can be determinded, it will be assumed that the parameter does not need to be converted.
If the parameter is empty or does not exist, the defaultValue will be returned.
gearbox::ConversionError | if the value could not converted to a numerical type |
path | Path of the parameter to get |
defaultValue | Value to return if the Path es empty or does not exist |
Definition at line 114 of file Interface.cc.
|
inline |
Return the state of the Gearbox.
Definition at line 106 of file Gearbox.h.
|
protectedinherited |
joind to paths, inserting a slash if neccessary
Definition at line 172 of file Interface.cc.
|
inlineinherited |
Convert to bool to simplify checking of existence.
Definition at line 60 of file Interface.h.
|
inlinestatic |
Register a new input handler.
prefix | prefix signaling which handler to use for a given backend uri. The prefix is everything up to the first colon in the backend uri |
factory | Pointer to the factory function which will return an instance of the handler |
Definition at line 187 of file Gearbox.h.
|
friend |
friend to internal c-like function to interface libxml2 callback
This function is declared as friend since it needs access to Gearbox::openXmlUri, a function which should only be called by libxml2 and thus is declared private.
|
private |
|
private |
|
mutableprivate |
|
protectedinherited |
path of the current interface
Definition at line 498 of file Interface.h.
|
private |
|
private |
|
private |