TkN 2.7.1
Toolkit for Nuclei
Loading...
Searching...
No Matches
tkstate_time.h
1#ifndef TKN_STATE_TIME_H
2#define TKN_STATE_TIME_H
3
4#include "tkmeasure.h"
5#include <cmath>
6#include <limits>
7
8namespace tkn { namespace detail {
9
10// The persisted "lifetime" measure is T1/2 (time) or Gamma (energy).
11// Only scalar accessors are exposed here: a generic tkmeasure of mean lifetime
12// would otherwise inherit the legacy T1/2 <-> Gamma conversion convention.
13inline double state_time_value(const shared_ptr<tkmeasure> &measure, bool stable,
14 tkunit_manager::units_keys unit, bool width)
15{
16 const auto expected = width ? tkunit_manager::kEnergy : tkunit_manager::kTime;
17 if (gunits->get_type(unit) != expected) return std::numeric_limits<double>::quiet_NaN();
18 if (stable) return width ? 0. : std::numeric_limits<double>::infinity();
19 if (!measure) return std::numeric_limits<double>::quiet_NaN();
20 // Do not mutate the shared property or reinterpret its uncertainty.
21 tkunit value(measure->get_value(), measure->get_unit_key());
22 return value.set_unit(unit) ? value.get_value() : std::numeric_limits<double>::quiet_NaN();
23}
24
25} } // namespace tkn::detail
26#endif
units_keys
units identifiers
Definition tkunit.h:48
A measured value associated to its unit.
Definition tkunit.h:144
double get_value() const
get the value in the current unit
Definition tkunit.h:158
bool set_unit(const tkstring &_unit)
set the unit from a string
Definition tkunit.cpp:109
double state_time_value(const shared_ptr< tkmeasure > &measure, bool stable, tkunit_manager::units_keys unit, bool width)
Definition tklog.cpp:16