Belle II Software  release-08-01-10
GearDir Class Reference

GearDir is the basic class used for accessing the parameter store. More...

#include <GearDir.h>

Inheritance diagram for GearDir:
Collaboration diagram for GearDir:

Public Member Functions

 GearDir (const gearbox::Interface &start, const std::string &path, int index=0)
 Create a GearDir starting at a given base path and appending some subpath and optionally an index.
 
 GearDir (const std::string &path="", int index=0)
 Create a GearDir with an absolute path and optionally appending an index.
 
 GearDir (const GearDir &other)
 Copy constructor.
 
void append (const std::string &path)
 Append something to the current path, modifying the GearDir in place.
 
virtual int getNumberNodes (const std::string &path="") const override
 Return the number of nodes a given path will expand to. More...
 
virtual std::string getString (const std::string &path="") const noexcept(false) override
 Get the parameter path as a string. More...
 
std::string getString (const std::string &path, const std::string &defaultValue) const
 Get the parameter path as a string. More...
 
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. More...
 
virtual const TObject * getTObject (const std::string &path) const noexcept(false) override
 Get the parameter path as a TObject. More...
 
bool exists (const std::string &path="") const
 Check if a given parameter path exists. More...
 
 operator bool () const
 Convert to bool to simplify checking of existence. More...
 
std::vector< GearDirgetNodes (const std::string &path="") const
 Get vector of GearDirs which point to all the nodes the given path evaluates to. More...
 
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. More...
 
double getDouble (const std::string &path, double defaultValue) const noexcept(false)
 Get the parameter path as a double. More...
 
int getInt (const std::string &path="") const noexcept(false)
 Get the parameter path as a int. More...
 
int getInt (const std::string &path, int defaultValue) const noexcept(false)
 Get the parameter path as a int. More...
 
bool getBool (const std::string &path="") const noexcept(false)
 Get the parameter path as a bool. More...
 
bool getBool (const std::string &path, bool defaultValue) const
 Get the parameter path as a bool. More...
 
double getWithUnit (const std::string &path) const noexcept(false)
 Get the parameter path as a double converted to the standard unit. More...
 
double getWithUnit (const std::string &path, double defaultValue) const noexcept(false)
 Get the parameter path as a double converted to the standard unit. More...
 
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. More...
 
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. More...
 
double getLength (const std::string &path="") const noexcept(false)
 Get the parameter path as a double converted to the standard length unit. More...
 
double getLength (const std::string &path, double defaultValue) const noexcept(false)
 Get the parameter path as a double converted to the standard length unit. More...
 
double getAngle (const std::string &path="") const noexcept(false)
 Get the parameter path as a double converted to the standard angle unit. More...
 
double getAngle (const std::string &path, double defaultValue) const noexcept(false)
 Get the parameter path as a double converted to the standard angle unit. More...
 
double getEnergy (const std::string &path="") const noexcept(false)
 Get the parameter path as a double converted to the standard energy unit. More...
 
double getEnergy (const std::string &path, double defaultValue) const noexcept(false)
 Get the parameter path as a double converted to the standard energy unit. More...
 
double getDensity (const std::string &path="") const noexcept(false)
 Get the parameter path as a double converted to the standard density unit. More...
 
double getDensity (const std::string &path, double defaultValue) const noexcept(false)
 Get the parameter path as a double converted to the standard density unit. More...
 
double getTime (const std::string &path="") const noexcept(false)
 Get the parameter path as a double converted to the standard time unit. More...
 
double getTime (const std::string &path, double defaultValue) const noexcept(false)
 Get the parameter path as a double converted to the standard time unit. More...
 
double getFrequency (const std::string &path="") const noexcept(false)
 Get the parameter path as a double converted to the standard frequency unit. More...
 
double getFrequency (const std::string &path, double defaultValue) const noexcept(false)
 Get the parameter path as a double converted to the standard frequency unit. More...
 

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
 

Detailed Description

GearDir is the basic class used for accessing the parameter store.

To access parameters, just create a GearDir with the correct path and use the getter functions defined by gearbox::Interface to retrieve any parameter in the given path

GearDir parameters("/test/"); int foo = parameters.getInt("bar");

will return an integer value of the parameter /test/bar

Definition at line 31 of file GearDir.h.

Member Function Documentation

◆ 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.

◆ getAngle() [1/2]

double getAngle ( const std::string &  path,
double  defaultValue 
) const
inlinenoexceptinherited

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.

◆ getAngle() [2/2]

double getAngle ( const std::string &  path = "") const
inlinenoexceptinherited

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.

◆ getArray() [1/2]

std::vector< double > getArray ( const std::string &  path) const
noexceptinherited

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.

◆ getArray() [2/2]

std::vector< double > getArray ( const std::string &  path,
const std::vector< double > &  defaultValue 
) const
noexceptinherited

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.

◆ 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.

◆ getBool() [2/2]

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

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.

◆ getDensity() [1/2]

double getDensity ( const std::string &  path,
double  defaultValue 
) const
inlinenoexceptinherited

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.

◆ getDensity() [2/2]

double getDensity ( const std::string &  path = "") const
inlinenoexceptinherited

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.

◆ getDouble() [1/2]

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

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.

◆ getDouble() [2/2]

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

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.

◆ getEnergy() [1/2]

double getEnergy ( const std::string &  path,
double  defaultValue 
) const
inlinenoexceptinherited

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.

◆ getEnergy() [2/2]

double getEnergy ( const std::string &  path = "") const
inlinenoexceptinherited

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.

◆ getFrequency() [1/2]

double getFrequency ( const std::string &  path,
double  defaultValue 
) const
inlinenoexceptinherited

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.

◆ getFrequency() [2/2]

double getFrequency ( const std::string &  path = "") const
inlinenoexceptinherited

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.

◆ getInt() [1/2]

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

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.

◆ getInt() [2/2]

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

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.

◆ getLength() [1/2]

double getLength ( const std::string &  path,
double  defaultValue 
) const
inlinenoexceptinherited

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.

◆ getLength() [2/2]

double getLength ( const std::string &  path = "") const
inlinenoexceptinherited

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.

◆ 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.

◆ 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 58 of file GearDir.h.

59  {
61  }
virtual int getNumberNodes(const std::string &path="") const override
Return the number of nodes a given path will expand to.
Definition: Gearbox.h:112
std::string m_path
path of the current interface
Definition: Interface.h:498
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
static Gearbox & getInstance()
Return reference to the Gearbox instance.
Definition: Gearbox.cc:81

◆ 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, 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 82 of file GearDir.h.

◆ getString() [2/2]

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

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 69 of file GearDir.h.

◆ getStringWithUnit()

virtual std::pair<std::string, std::string> getStringWithUnit ( const std::string &  path = "") const
inlineoverridevirtualnoexcept

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 98 of file GearDir.h.

◆ getTime() [1/2]

double getTime ( const std::string &  path,
double  defaultValue 
) const
inlinenoexceptinherited

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.

◆ getTime() [2/2]

double getTime ( const std::string &  path = "") const
inlinenoexceptinherited

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.

◆ getTObject()

virtual const TObject* getTObject ( const std::string &  path) const
inlineoverridevirtualnoexcept

Get the parameter path as a TObject.

Exceptions
gearbox::PathEmptyErrorif path is empty or does not exist
gearbox::TObjectConversionErrorif the value could not be deserialized
Parameters
pathPath of the parameter to get
Returns
pointer to object, owned and managed by gearbox. Object will be deleted once it is no longer valid (e.g. after the current run if it belongs to this run)

Implements Interface.

Definition at line 112 of file GearDir.h.

◆ getWithUnit() [1/2]

double getWithUnit ( const std::string &  path) const
noexceptinherited

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.

◆ getWithUnit() [2/2]

double getWithUnit ( const std::string &  path,
double  defaultValue 
) const
noexceptinherited

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.

◆ 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.


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