File indexing completed on 2024-04-06 12:05:03
0001 #ifndef DataFormats_Provenance_Timestamp_h
0002 #define DataFormats_Provenance_Timestamp_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include <limits>
0019
0020 namespace edm {
0021 typedef unsigned long long TimeValue_t;
0022
0023 class Timestamp {
0024 static const TimeValue_t kLowMask = 0xFFFFFFFF;
0025
0026 public:
0027 explicit Timestamp(TimeValue_t iValue)
0028 : timeLow_(static_cast<unsigned int>(kLowMask & iValue)), timeHigh_(static_cast<unsigned int>(iValue >> 32)) {}
0029
0030 Timestamp() : timeLow_(invalidTimestamp().timeLow_), timeHigh_(invalidTimestamp().timeHigh_) {}
0031
0032
0033 unsigned int unixTime() const { return timeHigh_; }
0034
0035
0036 unsigned int microsecondOffset() const { return timeLow_; }
0037
0038 TimeValue_t value() const {
0039 TimeValue_t returnValue = timeHigh_;
0040 returnValue = returnValue << 32;
0041 returnValue += timeLow_;
0042 return returnValue;
0043 }
0044
0045
0046 bool operator==(Timestamp const& iRHS) const { return timeHigh_ == iRHS.timeHigh_ && timeLow_ == iRHS.timeLow_; }
0047 bool operator!=(Timestamp const& iRHS) const { return !(*this == iRHS); }
0048
0049 bool operator<(Timestamp const& iRHS) const {
0050 if (timeHigh_ == iRHS.timeHigh_) {
0051 return timeLow_ < iRHS.timeLow_;
0052 }
0053 return timeHigh_ < iRHS.timeHigh_;
0054 }
0055 bool operator<=(Timestamp const& iRHS) const {
0056 if (timeHigh_ == iRHS.timeHigh_) {
0057 return timeLow_ <= iRHS.timeLow_;
0058 }
0059 return timeHigh_ <= iRHS.timeHigh_;
0060 }
0061 bool operator>(Timestamp const& iRHS) const {
0062 if (timeHigh_ == iRHS.timeHigh_) {
0063 return timeLow_ > iRHS.timeLow_;
0064 }
0065 return timeHigh_ > iRHS.timeHigh_;
0066 }
0067 bool operator>=(Timestamp const& iRHS) const {
0068 if (timeHigh_ == iRHS.timeHigh_) {
0069 return timeLow_ >= iRHS.timeLow_;
0070 }
0071 return timeHigh_ >= iRHS.timeHigh_;
0072 }
0073
0074
0075 static Timestamp invalidTimestamp() { return Timestamp(0); }
0076 static Timestamp endOfTime() { return Timestamp(std::numeric_limits<TimeValue_t>::max()); }
0077 static Timestamp beginOfTime() { return Timestamp(1); }
0078
0079 private:
0080
0081
0082
0083 unsigned int timeLow_;
0084 unsigned int timeHigh_;
0085 };
0086
0087 }
0088 #endif