// // File : TTimeInterval.hh // // Purpose: Declaration of the class TTimeInterval // // Author : T. Paul, D. Veberic // // $Id: TTimeInterval.hh 12265 2011-03-22 03:24:18Z mathes $ // /** @file TTimeInterval.hh * Declaration of the class TTimeInterval. * @author T. Paul, D. Veberic */ #ifndef _FdRoot_TTimeInterval_hh_ #define _FdRoot_TTimeInterval_hh_ #include namespace FdRoot { /** A TimeInterval is used to represent time elapsed between two events For information on how to use TimeInterval's together with TimeStamp's in your code, see the documentation in utl::TimeStamp. From a TimeInterval, one can extract the lower bound on the number of seconds in the interval (the seconds floor) as well as the number of nanoseconds past the seconds floor. When subracting TimeInvervals or TimeStamps to yield a TimeInterval, there are two cases to consider: Note that this class uses a double precision floating point to represent the elapsed time between two events. 52 bits are allocated for the mantissa of a double precision number, this interval is precise to about 1 part in 5.4e15. If for example 1 ns precision were required, one could use this class to describe intervals up to about 62 days. Basic arithmetic operations are defined for TimeInterval. See the documentation for utl::TimeStamp for some examples. * Note: This class is taken from the AUGER Offline code (utl/TimeInterval.h) * and is adopted for the needs of the FD-DAQ. */ class TTimeInterval { // class TTimeInterval : public SafeBoolCast { public: TTimeInterval(const double interval = 0.) : fInterval(interval) { } TTimeInterval(const TTimeInterval& ti) : fInterval(ti.fInterval) { } TTimeInterval& operator=(const TTimeInterval& ti) { fInterval = ti.fInterval; return *this; } /// [TTimeInterval] = double TTimeInterval& operator=(const double& d) { fInterval = d; return *this; } /// Get the seconds floor for the interval /*! This number is positive if the interval is positive, and negative if the interval is negative */ int GetSec() const; /// Get integer number of nanoseconds past seconds boundary. /*! This number is always positive */ unsigned int GetNanoSec() const; /// Get the time interval as a double (in Auger base units) double GetInterval() const { return fInterval; } /// [TTimeInterval] + [TTimeInterval] = [TTimeInterval] TTimeInterval operator+(const TTimeInterval& ti) const { return TTimeInterval(fInterval + ti.fInterval); } /// [TTimeInterval] - [TTimeInterval] = [TTimeInterval] TTimeInterval operator-(const TTimeInterval& ti) const { return TTimeInterval(fInterval - ti.fInterval); } /// [TTimeInterval] * [double] = [TTimeInterval] TTimeInterval operator*(const double& d) const { return TTimeInterval(fInterval * d); } /// [double] * [TTimeInterval] = [TTimeInterval] friend TTimeInterval operator*(const double& d, const TTimeInterval& ti); /// [TTimeInterval] / [TTimeInterval] = [double] double operator/(const TTimeInterval& ti) const { return fInterval / ti.fInterval; } /// [TTimeInterval] / [double] = [TTimeInterval] TTimeInterval operator/(const double& d) const { return TTimeInterval(fInterval / d); } /// [TTimeInterval] += [TTimeInterval] = [TTimeInterval] TTimeInterval operator+=(const TTimeInterval& ti) { fInterval += ti.fInterval; return *this; } /// [TTimeInterval] -= [TTimeInterval] = [TTimeInterval] TTimeInterval& operator-=(const TTimeInterval& ti) { fInterval -= ti.fInterval; return *this; } /// [TTimeInterval] *= [TTimeInterval] = [TTimeInterval] TTimeInterval& operator*=(const double& d) { fInterval *= d; return *this; } /// [TTimeInterval] /= [double] = [TTimeInterval] TTimeInterval& operator/=(const double& d) { fInterval /= d; return *this; } /// unary sign reversal TTimeInterval operator-() const { return TTimeInterval(-fInterval); } bool operator>(const TTimeInterval& ti) const { return (fInterval > ti.fInterval); } bool operator>=(const TTimeInterval& ti) const { return (fInterval >= ti.fInterval); } bool operator<(const TTimeInterval& ti) const { return (fInterval < ti.fInterval); } bool operator<=(const TTimeInterval& ti) const { return (fInterval <= ti.fInterval); } bool operator==(const TTimeInterval& ti) const { return (fInterval == ti.fInterval); } bool operator!=(const TTimeInterval& ti) const { return (fInterval != ti.fInterval); } // class TimeInterval : public SafeBoolCast //bool BoolCast() const { return fInterval; } // /// stream output // friend std::ostream& operator<<(std::ostream& os, const TTimeInterval& ti) // { return os << ti.fInterval; } static TTimeInterval Min() { return -4.294967296e9; } static TTimeInterval Max() { return 4.294967296e9; } private: double fInterval; // stored in nano seconds ClassDef(TTimeInterval,1) }; /// [double] * [TTimeInterval] = [TTimeInterval] inline TTimeInterval operator*(const double& d, const TTimeInterval& ti) { return TTimeInterval(d * ti.fInterval); } } // namespace FdRoot #endif // _FdRoot_TTimeInterval_hh_