Falaise  4.0.1
SuperNEMO Software Toolkit
Public Member Functions | List of all members
falaise::config::quantity Class Reference

Class representing a value and physical unit. More...

#include <falaise/config/quantity.h>

Inheritance diagram for falaise::config::quantity:
falaise::config::quantity_t< Dimension >

Public Member Functions

 quantity ()=default
 Default constructor. More...
 
 quantity (double value, std::string const &unit)
 Construct a quantity from a value and unit. More...
 
virtual ~quantity ()=default
 Destructor. More...
 
double operator() () const
 Convert quantity to double value in the CLHEP::Units numeric scaling system. More...
 
double value () const
 Return the value for the quantity in its units. More...
 
double value_in (std::string const &unit) const
 Return value for the quantity in given units. More...
 
std::string constunit () const
 Return datatools::units tag for the quantity's unit. More...
 
std::string constdimension () const
 Return datatools::unit tag for the quantity's dimension. More...
 

Detailed Description

Class representing a value and physical unit.

quantity is a simple holder for datatools::properties values that are marked with an explicit unit. In properties files, these are declared as

foo : real as length = 3.14 m

where length is the dimension, and m is the explicit unit. quantity composes this value, unit, and dimension into a single object allowing these to be queried and the value directly converted to the internal CLHEP::Units numeric representation. For example:

auto x = falaise::config::quantity{3.14, "m"}; // valid
auto y = falaise::config::quantity{4.13, "furlong"}; // throws, "furlong" not a known unit
double forCalc = x(); // value is 3.14*CLHEP::meter, so 3140.0

In general, you should not use quantity directly, but rather the typed System of Units concrete classes for the physical quantities you need (e.g. length_t for length parameters). quantity only validates that the unit is known to datatools::units, whereas the System of Units types provide strict dimensional correctness.

See also
System of Units
quantity_t

Constructor & Destructor Documentation

◆ quantity() [1/2]

falaise::config::quantity::quantity ( )
default

Default constructor.

Initializes as an effectively zero value dimensionless parameter

◆ quantity() [2/2]

falaise::config::quantity::quantity ( double  value,
std::string const unit 
)

Construct a quantity from a value and unit.

Parameters
[in]valueNumeric value in units of unit
[in]unitdatatools::units::unit tag
Exceptions
falaise::config::unknown_unit_errorif unit is not supported by datatools::units

◆ ~quantity()

virtual falaise::config::quantity::~quantity ( )
virtualdefault

Destructor.

Member Function Documentation

◆ dimension()

std::string const& falaise::config::quantity::dimension ( ) const
inline

Return datatools::unit tag for the quantity's dimension.

◆ operator()()

double falaise::config::quantity::operator() ( void  ) const
inline

Convert quantity to double value in the CLHEP::Units numeric scaling system.

For example:

double x = q();
std::cout << x << std::endl; // prints 3140.0
Returns
quantity's value multiplied by its unit's CLHEP::Units scaling factor

◆ unit()

std::string const& falaise::config::quantity::unit ( ) const
inline

Return datatools::units tag for the quantity's unit.

◆ value()

double falaise::config::quantity::value ( ) const
inline

Return the value for the quantity in its units.

For example:

std::cout << x.value() << std::endl; // prints 3.14

◆ value_in()

double falaise::config::quantity::value_in ( std::string const unit) const

Return value for the quantity in given units.


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