Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:03

0001 #ifndef DataFormats_Provenance_Timestamp_h
0002 #define DataFormats_Provenance_Timestamp_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     DataFormats/Provenance
0006 // Class:      Timestamp
0007 //
0008 /**\class Timestamp Timestamp.h DataFormats/Provenance/interface/Timestamp.h
0009 
0010  Description: Defines an instance in time from the Online system
0011 
0012 */
0013 //
0014 // Author:      Chris Jones
0015 // Created:     Thu Mar 24 16:23:05 EST 2005
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     /// Time in seconds since January 1, 1970.
0033     unsigned int unixTime() const { return timeHigh_; }
0034 
0035     /// Microseconds offset within second
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     // ---------- const member functions ---------------------
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     // ---------- static member functions --------------------
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     // ---------- member data --------------------------------
0081     // ROOT does not support ULL
0082     //TimeValue_t time_;
0083     unsigned int timeLow_;
0084     unsigned int timeHigh_;
0085   };
0086 
0087 }  // namespace edm
0088 #endif