Belle II Software light-2406-ragdoll
Gearbox Class Reference

Singleton class responsible for loading detector parameters from an XML file. More...

#include <Gearbox.h>

Inheritance diagram for Gearbox:
Collaboration diagram for Gearbox:

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< GearDirgetNodes (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 GearboxgetInstance ()
 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.
 
Gearboxoperator= (const Gearbox &)=delete
 Also no assignment operator.
 
gearbox::InputContextopenXmlUri (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< PathOverridem_overrides
 the existing overrides
 

Friends

void * gearbox::openXmlUri (const char *)
 friend to internal c-like function to interface libxml2 callback
 

Detailed Description

Singleton class responsible for loading detector parameters from an XML file.

See also
GearboxModule

Definition at line 34 of file Gearbox.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Default cache size (in entries) for the Gearbox.

Definition at line 37 of file Gearbox.h.

37{ c_DefaultCacheSize = 200 };

Member Function Documentation

◆ addIndex()

std::string addIndex ( const std::string &  path,
int  index 
) const
protectedinherited

add [index] to the path (after stripping trailing slashes)

Definition at line 166 of file Interface.cc.

167 {
168 static boost::format index_fmt("%1%[%2%]");
169 return (index_fmt % ensureNode(path) % index).str();
170 }
std::string ensureNode(const std::string &path) const
make sure the path really corresponds to an XPath node expression by removing trailing slashes
Definition: Interface.cc:156

◆ addOverride()

void addOverride ( const PathOverride poverride)
inline

Add an override for a given XPath expression.

Definition at line 81 of file Gearbox.h.

82 {
83 m_overrides.push_back(poverride);
84 }
std::vector< PathOverride > m_overrides
the existing overrides
Definition: Gearbox.h:223

◆ clearOverrides()

void clearOverrides ( )
inline

Clear all existing overrides.

Definition at line 87 of file Gearbox.h.

88 {
89 m_overrides.clear();
90 }

◆ ensureNode()

std::string ensureNode ( const std::string &  path) const
protectedinherited

make sure the path really corresponds to an XPath node expression by removing trailing slashes

Definition at line 156 of file Interface.cc.

157 {
158 return boost::trim_right_copy_if(path, boost::is_any_of("/"));
159 }

◆ ensurePath()

std::string ensurePath ( const std::string &  path) const
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.

162 {
163 return ensureNode(path) + '/';
164 }

◆ exists()

bool exists ( const std::string &  path = "") const
inlineinherited

Check if a given parameter path exists.

Returns
true if path exists, false otherwise

Definition at line 54 of file Interface.h.

54{ return getNumberNodes(path) > 0; }
virtual int getNumberNodes(const std::string &path="") const =0
Return the number of nodes a given path will expand to.

◆ getAngle() [1/2]

double getAngle ( const std::string &  path,
double  defaultValue 
) const
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.

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
defaultValueValue to return if the Path es empty or does not exist
Returns
value of the parameter

Definition at line 321 of file Interface.h.

322 {
323 return getWithUnit(path, defaultValue);
324 }
double getWithUnit(const std::string &path) const noexcept(false)
Get the parameter path as a double converted to the standard unit.
Definition: Interface.cc:97

◆ getAngle() [2/2]

double getAngle ( const std::string &  path = "") const
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.

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
Returns
value of the parameter

Definition at line 299 of file Interface.h.

300 {
301 return getWithUnit(path);
302 }

◆ getArray() [1/2]

std::vector< double > getArray ( const std::string &  path) const
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.

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
Returns
value of the parameter

Definition at line 123 of file Interface.cc.

124 {
125 using tokenizer = boost::tokenizer<boost::char_separator<char> >;
126 boost::char_separator<char> sep(",; \t\n\r");
127
128 std::pair<std::string, std::string> value = getStringWithUnit(path);
129 tokenizer tokens(value.first, sep);
130 std::vector<double> result;
131 double numValue(0);
132 for (const std::string& tok : tokens) {
133 try {
134 numValue = boost::lexical_cast<double>(tok);
135 } catch (boost::bad_lexical_cast&) {
136 throw (ConversionError() << path << value.first);
137 }
138 if (!value.second.empty()) {
139 numValue = Unit::convertValue(numValue, value.second);
140 }
141 result.push_back(numValue);
142 }
143 return result;
144 }
virtual std::pair< std::string, std::string > getStringWithUnit(const std::string &path) const noexcept(false)=0
Get the parameter path as string and also return the unit it was defined with.
static double convertValue(double value, const std::string &unitString)
Converts a floating point value to the standard framework unit.
Definition: UnitConst.cc:129

◆ getArray() [2/2]

std::vector< double > getArray ( const std::string &  path,
const std::vector< double > &  defaultValue 
) const
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.

Exceptions
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
defaultValueValue to return if the Path es empty or does not exist
Returns
value of the parameter

Definition at line 146 of file Interface.cc.

147 {
148 try {
149 return getArray(path);
150 } catch (PathEmptyError&) {
151 return defaultValue;
152 }
153 }
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.
Definition: Interface.cc:123

◆ getBool() [1/2]

bool getBool ( const std::string &  path,
bool  defaultValue 
) const
inherited

Get the parameter path as a bool.

If the parameter is empty or does not exist, the defaultValue will be returned.

Parameters
pathPath of the parameter to get
defaultValueValue to return if the Path es empty or does not exist
Returns
value of the parameter

Definition at line 88 of file Interface.cc.

89 {
90 try {
91 return getBool(path);
92 } catch (PathEmptyError&) {
93 return defaultValue;
94 }
95 }
bool getBool(const std::string &path="") const noexcept(false)
Get the parameter path as a bool.
Definition: Interface.cc:80

◆ getBool() [2/2]

bool getBool ( const std::string &  path = "") const
inherited

Get the parameter path as a bool.

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
Parameters
pathPath of the parameter to get
Returns
value of the parameter

Definition at line 80 of file Interface.cc.

81 {
82 std::string value = getString(path);
83 boost::to_lower(value);
84 if (value.empty() || value == "false" || value == "off" || value == "0") return false;
85 return true;
86 }
virtual std::string getString(const std::string &path="") const noexcept(false)=0
Get the parameter path as a string.

◆ getDensity() [1/2]

double getDensity ( const std::string &  path,
double  defaultValue 
) const
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.

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
defaultValueValue to return if the Path es empty or does not exist
Returns
value of the parameter

Definition at line 401 of file Interface.h.

402 {
403 return getWithUnit(path, defaultValue);
404 }

◆ getDensity() [2/2]

double getDensity ( const std::string &  path = "") const
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.

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
Returns
value of the parameter

Definition at line 379 of file Interface.h.

380 {
381 return getWithUnit(path);
382 }

◆ getDouble() [1/2]

double getDouble ( const std::string &  path,
double  defaultValue 
) const
inherited

Get the parameter path as a double.

If the parameter is empty or does not exist, the defaultValue will be returned.

Exceptions
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
defaultValueValue to return if the Path es empty or does not exist
Returns
value of the parameter

Definition at line 51 of file Interface.cc.

52 {
53 try {
54 return getDouble(path);
55 } catch (PathEmptyError&) {
56 return defaultValue;
57 }
58 }
double getDouble(const std::string &path="") const noexcept(false)
Get the parameter path as a double.
Definition: Interface.cc:41

◆ getDouble() [2/2]

double getDouble ( const std::string &  path = "") const
inherited

Get the parameter path as a double.

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
Returns
value of the parameter

Definition at line 41 of file Interface.cc.

42 {
43 std::string value = getString(path);
44 try {
45 return boost::lexical_cast<double>(value);
46 } catch (boost::bad_lexical_cast&) {
47 throw ConversionError() << path << value;
48 }
49 }

◆ getEnergy() [1/2]

double getEnergy ( const std::string &  path,
double  defaultValue 
) const
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.

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
defaultValueValue to return if the Path es empty or does not exist
Returns
value of the parameter

Definition at line 361 of file Interface.h.

362 {
363 return getWithUnit(path, defaultValue);
364 }

◆ getEnergy() [2/2]

double getEnergy ( const std::string &  path = "") const
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.

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
Returns
value of the parameter

Definition at line 339 of file Interface.h.

340 {
341 return getWithUnit(path);
342 }

◆ getFrequency() [1/2]

double getFrequency ( const std::string &  path,
double  defaultValue 
) const
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.

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
defaultValueValue to return if the Path es empty or does not exist
Returns
value of the parameter

Definition at line 481 of file Interface.h.

482 {
483 return getWithUnit(path, defaultValue);
484 }

◆ getFrequency() [2/2]

double getFrequency ( const std::string &  path = "") const
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.

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
Returns
value of the parameter

Definition at line 459 of file Interface.h.

460 {
461 return getWithUnit(path);
462 }

◆ getInt() [1/2]

int getInt ( const std::string &  path,
int  defaultValue 
) const
inherited

Get the parameter path as a int.

If the parameter is empty or does not exist, the defaultValue will be returned.

Exceptions
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
defaultValueValue to return if the Path es empty or does not exist
Returns
value of the parameter

Definition at line 71 of file Interface.cc.

72 {
73 try {
74 return getInt(path);
75 } catch (PathEmptyError&) {
76 return defaultValue;
77 }
78 }
int getInt(const std::string &path="") const noexcept(false)
Get the parameter path as a int.
Definition: Interface.cc:60

◆ getInt() [2/2]

int getInt ( const std::string &  path = "") const
inherited

Get the parameter path as a int.

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
Returns
value of the parameter

Definition at line 60 of file Interface.cc.

61 {
62 std::string value = getString(path);
63 try {
64 //hide spurious warning in boost
65 return boost::lexical_cast<int>(value);
66 } catch (boost::bad_lexical_cast&) {
67 throw ConversionError() << path << value;
68 }
69 }

◆ getLength() [1/2]

double getLength ( const std::string &  path,
double  defaultValue 
) const
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.

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
defaultValueValue to return if the Path es empty or does not exist
Returns
value of the parameter

Definition at line 281 of file Interface.h.

282 {
283 return getWithUnit(path, defaultValue);
284 }

◆ getLength() [2/2]

double getLength ( const std::string &  path = "") const
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.

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
Returns
value of the parameter

Definition at line 259 of file Interface.h.

260 {
261 return getWithUnit(path);
262 }

◆ getNodes()

std::vector< GearDir > getNodes ( const std::string &  path = "") const
inherited

Get vector of GearDirs which point to all the nodes the given path evaluates to.

Parameters
pathPath of the parameters to get

Definition at line 21 of file Interface.cc.

22 {
23 int size = getNumberNodes(path);
24 std::vector<GearDir> result;
25 result.reserve(size);
26 for (int i = 1; i <= size; ++i) {
27 result.emplace_back(*this, path, i);
28 }
29 return result;
30 }

◆ getNumberNodes()

virtual int getNumberNodes ( const std::string &  path = "") const
inlineoverridevirtual

Return the number of nodes a given path will expand to.

Returns
number of nodes, 0 if path does not exist

Implements Interface.

Definition at line 112 of file Gearbox.h.

113 {
114 return getPathValue(path).numNodes;
115 }
PathValue getPathValue(const std::string &path) const
Return the (cached) value of a given path.
Definition: Gearbox.cc:247
int numNodes
number of nodes corresponding to the path
Definition: Gearbox.h:43

◆ getPath()

std::string getPath ( ) const
inlineinherited

Return path of the current interface.

Definition at line 70 of file Interface.h.

70{ return m_path; }
std::string m_path
path of the current interface
Definition: Interface.h:498

◆ getString() [1/2]

std::string getString ( const std::string &  path,
const std::string &  defaultValue 
) const
inline

Get the parameter path as a string.

if the parameter is empty or does not exist, defaultValue will be returned.

Parameters
pathpath of the parameter to get
defaultValuevalue to return if the path es empty or does not exist
Returns
value of the parameter

Definition at line 138 of file Gearbox.h.

139 {
140 return gearbox::Interface::getString(path, defaultValue);
141 }

◆ getString() [2/2]

virtual std::string getString ( const std::string &  path = "") const
inlineoverridevirtual

Get the parameter path as a string.

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
Parameters
pathPath of the parameter to get
Returns
value of the parameter

Implements Interface.

Definition at line 123 of file Gearbox.h.

124 {
125 PathValue p = getPathValue(path);
126 if (p.numNodes == 0) throw gearbox::PathEmptyError() << path;
127 return p.value;
128 }

◆ getStringWithUnit()

virtual std::pair< std::string, std::string > getStringWithUnit ( const std::string &  path = "") const
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.

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
Parameters
pathPath of the parameter to get
Returns
value of the parameter

Implements Interface.

Definition at line 154 of file Gearbox.h.

155 {
156 PathValue p = getPathValue(path);
157 if (!p.numNodes) throw gearbox::PathEmptyError() << path;
158 return make_pair(p.value, p.unit);
159 }

◆ getTime() [1/2]

double getTime ( const std::string &  path,
double  defaultValue 
) const
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.

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
defaultValueValue to return if the Path es empty or does not exist
Returns
value of the parameter

Definition at line 441 of file Interface.h.

442 {
443 return getWithUnit(path, defaultValue);
444 }

◆ getTime() [2/2]

double getTime ( const std::string &  path = "") const
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.

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
Returns
value of the parameter

Definition at line 419 of file Interface.h.

420 {
421 return getWithUnit(path);
422 }

◆ getWithUnit() [1/2]

double getWithUnit ( const std::string &  path) const
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

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
Returns
value of the parameter

Definition at line 97 of file Interface.cc.

98 {
99 std::pair<std::string, std::string> value = getStringWithUnit(path);
100 double numValue(0);
101 try {
102 numValue = boost::lexical_cast<double>(value.first);
103 } catch (boost::bad_lexical_cast&) {
104 throw ConversionError() << path << value.first;
105 }
106 if (value.second.empty()) {
107 B2WARNING("Requested unit conversion for parameter '" << path << "' but no unit found");
108 } else {
109 numValue = Unit::convertValue(numValue, value.second);
110 }
111 return numValue;
112 }

◆ getWithUnit() [2/2]

double getWithUnit ( const std::string &  path,
double  defaultValue 
) const
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.

Exceptions
gearbox::ConversionErrorif the value could not converted to a numerical type
Parameters
pathPath of the parameter to get
defaultValueValue to return if the Path es empty or does not exist
Returns
value of the parameter

Definition at line 114 of file Interface.cc.

115 {
116 try {
117 return getWithUnit(path);
118 } catch (PathEmptyError&) {
119 return defaultValue;
120 }
121 }

◆ isOpen()

bool isOpen ( ) const
inline

Return the state of the Gearbox.

Returns
True if the Gearbox has an initialized backend and opened a document for reading.

Definition at line 106 of file Gearbox.h.

106{ return m_xmlDocument != 0; }
xmlDocPtr m_xmlDocument
Pointer to the libxml Document structure.
Definition: Gearbox.h:209

◆ joinPath()

std::string joinPath ( const std::string &  path,
const std::string &  subpath 
) const
protectedinherited

joind to paths, inserting a slash if neccessary

Definition at line 172 of file Interface.cc.

173 {
174 return ensurePath(path) + boost::trim_left_copy_if(subpath, boost::is_any_of("/"));
175 }
std::string ensurePath(const std::string &path) const
make sure the path really corresponds to a path by appending a trailing slash if neccessary
Definition: Interface.cc:161

◆ operator bool()

operator bool ( ) const
inlineinherited

Convert to bool to simplify checking of existence.

Returns
true if path exists, false otherwise

Definition at line 60 of file Interface.h.

60{ return exists(); }
bool exists(const std::string &path="") const
Check if a given parameter path exists.
Definition: Interface.h:54

◆ registerInputHandler()

static void registerInputHandler ( const std::string &  prefix,
gearbox::InputHandler::Factory factory 
)
inlinestatic

Register a new input handler.

Parameters
prefixprefix signaling which handler to use for a given backend uri. The prefix is everything up to the first colon in the backend uri
factoryPointer to the factory function which will return an instance of the handler

Definition at line 187 of file Gearbox.h.

188 {
189 getInstance().m_registeredHandlers[prefix] = factory;
190 }
std::map< std::string, gearbox::InputHandler::Factory * > m_registeredHandlers
Map of registered InputHandlers.
Definition: Gearbox.h:220
static Gearbox & getInstance()
Return reference to the Gearbox instance.
Definition: Gearbox.cc:81

Friends And Related Function Documentation

◆ gearbox::openXmlUri

void * gearbox::openXmlUri ( const char *  )
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.

Member Data Documentation

◆ m_handlers

std::vector<gearbox::InputHandler*> m_handlers
private

List of input handlers which will be used to find resources.

Definition at line 218 of file Gearbox.h.

◆ m_overrides

std::vector<PathOverride> m_overrides
private

the existing overrides

Definition at line 223 of file Gearbox.h.

◆ m_ownedObjects

std::map<std::string, TObject*> m_ownedObjects
mutableprivate

Map of queried objects (path -> TObject*).

Objects will be removed once they are no longer valid.

Definition at line 215 of file Gearbox.h.

◆ m_parameterCache

MRUCache<std::string, PathValue>* m_parameterCache
mutableprivate

Cache for already queried paths.

Definition at line 213 of file Gearbox.h.

◆ m_path

std::string m_path
protectedinherited

path of the current interface

Definition at line 498 of file Interface.h.

◆ m_registeredHandlers

std::map<std::string, gearbox::InputHandler::Factory*> m_registeredHandlers
private

Map of registered InputHandlers.

Definition at line 220 of file Gearbox.h.

◆ m_xmlDocument

xmlDocPtr m_xmlDocument
private

Pointer to the libxml Document structure.

Definition at line 209 of file Gearbox.h.

◆ m_xpathContext

xmlXPathContextPtr m_xpathContext
private

Pointer to the libxml XPath context.

Definition at line 211 of file Gearbox.h.


The documentation for this class was generated from the following files: