diff options
Diffstat (limited to 'lib/time_tag.cpp')
-rw-r--r-- | lib/time_tag.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/time_tag.cpp b/lib/time_tag.cpp index b2beadf..b80e944 100644 --- a/lib/time_tag.cpp +++ b/lib/time_tag.cpp @@ -5,14 +5,16 @@ #include <boost/cstdint.hpp> //uint64 #include <boost/math/special_functions/round.hpp> +#define TIME_TAG_TPS time_ticks_t(1000000000UL) + using namespace gras; static TimeTag &normalize(TimeTag &t) { - int num = int(t._ticks/time_tps()); + int num = int(t._ticks/TIME_TAG_TPS); if (num < 0) num--; //stops negative ticks t._fsecs += num; - t._ticks -= num*time_tps(); + t._ticks -= num*TIME_TAG_TPS; return t; } @@ -32,7 +34,7 @@ TimeTag TimeTag::from_ticks(const time_ticks_t ticks, const double rate) TimeTag t; t._fsecs = time_ticks_t(ticks/rate); const double error = ticks - (t._fsecs*rate); - t._ticks = boost::math::llround((error*time_tps())/rate); + t._ticks = boost::math::llround((error*TIME_TAG_TPS)/rate); return normalize(t); } @@ -41,27 +43,27 @@ TimeTag TimeTag::from_pmc(const PMCC &p) TimeTag t; const PMCTuple<2> &tuple = p.as<PMCTuple<2> >(); t._fsecs = tuple[0].as<boost::uint64_t>(); - t._ticks = boost::math::llround(tuple[1].as<double>()*time_tps()); + t._ticks = boost::math::llround(tuple[1].as<double>()*TIME_TAG_TPS); return normalize(t); } time_ticks_t TimeTag::to_ticks(void) const { - return _fsecs*time_tps() + _ticks; + return _fsecs*TIME_TAG_TPS + _ticks; } time_ticks_t TimeTag::to_ticks(const double rate) const { const time_ticks_t full = time_ticks_t(_fsecs*rate); const double error = _fsecs - (full/rate); - return full + boost::math::llround(_ticks*rate/time_tps() + error*rate); + return full + boost::math::llround(_ticks*rate/TIME_TAG_TPS + error*rate); } PMCC TimeTag::to_pmc(void) const { PMCTuple<2> tuple; tuple[0] = PMC_M<boost::uint64_t>(_fsecs); - tuple[1] = PMC_M<double>(_ticks/double(time_tps())); + tuple[1] = PMC_M<double>(_ticks/double(TIME_TAG_TPS)); return PMC_M(tuple); } |