ATLAS Offline Software
Loading...
Searching...
No Matches
Units.h File Reference

Wrapper to avoid constant divisions when using units. More...

#include "GaudiKernel/SystemOfUnits.h"
#include "GaudiKernel/PhysicalConstants.h"
Include dependency graph for Units.h:

Go to the source code of this file.

Classes

class  Athena::Units::Unit< TAG >
 Wrapper to avoid constant divisions when using units. More...

Namespaces

namespace  Athena
 Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc.h and will be non-nullptr in case the GaudiSvc/AthenaKernel shared libraries have been loaded.
namespace  Athena::Units

Macros

#define UNIT(NAME)

Functions

template<int TAG>
constexpr double Athena::Units::operator/ (double x, const Unit< TAG > u)
template<int TAG>
constexpr float Athena::Units::operator/ (float x, const Unit< TAG > u)
 Athena::Units::UNIT (millimeter)
 Athena::Units::UNIT (millimeter2)
 Athena::Units::UNIT (millimeter3)
 Athena::Units::UNIT (centimeter)
 Athena::Units::UNIT (centimeter2)
 Athena::Units::UNIT (centimeter3)
 Athena::Units::UNIT (meter)
 Athena::Units::UNIT (meter2)
 Athena::Units::UNIT (meter3)
 Athena::Units::UNIT (micrometer)
 Athena::Units::UNIT (um)
 Athena::Units::UNIT (mm)
 Athena::Units::UNIT (mm2)
 Athena::Units::UNIT (mm3)
 Athena::Units::UNIT (cm)
 Athena::Units::UNIT (cm2)
 Athena::Units::UNIT (cm3)
 Athena::Units::UNIT (radian)
 Athena::Units::UNIT (degree)
 Athena::Units::UNIT (rad)
 Athena::Units::UNIT (deg)
 Athena::Units::UNIT (picosecond)
 Athena::Units::UNIT (nanosecond)
 Athena::Units::UNIT (microsecond)
 Athena::Units::UNIT (millisecond)
 Athena::Units::UNIT (second)
 Athena::Units::UNIT (ns)
 Athena::Units::UNIT (s)
 Athena::Units::UNIT (ms)
 Athena::Units::UNIT (keV)
 Athena::Units::UNIT (MeV)
 Athena::Units::UNIT (GeV)
 Athena::Units::UNIT (TeV)
 Athena::Units::UNIT (gram)
 Athena::Units::UNIT (g)
 Athena::Units::UNIT (mole)
 Athena::Units::UNIT (c_light)

Detailed Description

Wrapper to avoid constant divisions when using units.

Author
scott snyder snyde.nosp@m.r@bn.nosp@m.l.gov
Date
Jun, 2015

A typical use of the unit symbols is like

double pt_in_gev = pt / GeV;

However, writing it like this results in a division by a constant being generated. It would be faster to rewrite this as multiplication by the inverse, but the compiler won't do that by default as the results are not guaranteed to be the same.

Using the symbols defined here allow avoiding the divisions (in optimized builds) without having to write the above explicitly as

double pt_in_gev = pt * (1./GeV);

which is pretty ugly.

We do this by creating a static const object wrapping the value of the unit and overriding operator/ to change the division to multiplication by inverse.

Definition in file Units.h.

Macro Definition Documentation

◆ UNIT

#define UNIT ( NAME)
Value:
template <> class Unit<__LINE__> \
{ \
public: \
constexpr operator double() const { return Gaudi::Units::NAME; } \
}; \
constexpr static const Unit<__LINE__> NAME

Definition at line 74 of file Units.h.

74#define UNIT(NAME) \
75template <> class Unit<__LINE__> \
76{ \
77public: \
78 constexpr operator double() const { return Gaudi::Units::NAME; } \
79}; \
80constexpr static const Unit<__LINE__> NAME