summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Blum2013-06-22 19:24:34 -0700
committerJosh Blum2013-06-22 19:24:34 -0700
commit1cebdcfb645ca6abefaa5e2d8feac8140e95e5ad (patch)
treea4c67de25d394cec0e839c73a9454c3673f82d9c
parent407a198a07dc1a333bda8b5c2e731ce0ee793ebf (diff)
downloadsandhi-1cebdcfb645ca6abefaa5e2d8feac8140e95e5ad.tar.gz
sandhi-1cebdcfb645ca6abefaa5e2d8feac8140e95e5ad.tar.bz2
sandhi-1cebdcfb645ca6abefaa5e2d8feac8140e95e5ad.zip
gras: various fixes for new time tag class
m---------grextras0
-rw-r--r--include/gras/time_tag.hpp6
-rw-r--r--lib/time_tag.cpp10
-rw-r--r--tests/time_tags_test.py4
4 files changed, 13 insertions, 7 deletions
diff --git a/grextras b/grextras
-Subproject 49beb736b878022785c80a42f6c566998cbbdc9
+Subproject ef9d5db728f1cc59f249e17eb35c1e52b27297d
diff --git a/include/gras/time_tag.hpp b/include/gras/time_tag.hpp
index 9459f9f..2476f41 100644
--- a/include/gras/time_tag.hpp
+++ b/include/gras/time_tag.hpp
@@ -35,13 +35,13 @@ struct GRAS_API TimeTag :
static TimeTag from_pmc(const PMCC &p);
//! Convert this time tag to ticks w/ default ticks per second
- time_ticks_t to_ticks(void);
+ time_ticks_t to_ticks(void) const;
//! Convert this time tag to ticks w/ specified ticks per second
- time_ticks_t to_ticks(const double rate);
+ time_ticks_t to_ticks(const double rate) const;
//! Convert this time tag to a PMC containing a PMCTuple<2>(uint64, double)
- PMCC to_pmc(void);
+ PMCC to_pmc(void) const;
//! Addition for additive interface
TimeTag &operator+=(const TimeTag &);
diff --git a/lib/time_tag.cpp b/lib/time_tag.cpp
index d438fc3..b2beadf 100644
--- a/lib/time_tag.cpp
+++ b/lib/time_tag.cpp
@@ -45,17 +45,19 @@ TimeTag TimeTag::from_pmc(const PMCC &p)
return normalize(t);
}
-time_ticks_t TimeTag::to_ticks(void)
+time_ticks_t TimeTag::to_ticks(void) const
{
return _fsecs*time_tps() + _ticks;
}
-time_ticks_t TimeTag::to_ticks(const double rate)
+time_ticks_t TimeTag::to_ticks(const double rate) const
{
- return _fsecs*time_tps() + boost::math::llround((_ticks*rate)/time_tps());
+ 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);
}
-PMCC TimeTag::to_pmc(void)
+PMCC TimeTag::to_pmc(void) const
{
PMCTuple<2> tuple;
tuple[0] = PMC_M<boost::uint64_t>(_fsecs);
diff --git a/tests/time_tags_test.py b/tests/time_tags_test.py
index 7d0221f..08a59d3 100644
--- a/tests/time_tags_test.py
+++ b/tests/time_tags_test.py
@@ -24,6 +24,10 @@ class TimeTagsTest(unittest.TestCase):
t3 = gras.TimeTag.from_ticks(time_ns_now, 1e9)
self.assertEqual(t3.to_ticks(1e9), time_ns_now)
+ time_us_now = long(time.time()*1e6)
+ t4 = gras.TimeTag.from_ticks(time_us_now, 1e6)
+ self.assertEqual(t4.to_ticks(1e6), time_us_now)
+
def test_time_tag_compare(self):
t0 = gras.TimeTag.from_ticks(42)
t1 = gras.TimeTag.from_ticks(-1000)