Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

VldTimeStamp.h

Go to the documentation of this file.
00001 
00049 #ifndef VLDTIMESTAMP_H
00050 #define VLDTIMESTAMP_H
00051 
00052 #ifndef ROOT_Rtypes
00053 #if !defined(__CINT__) || defined(__MAKECINT__)
00054 #include "Rtypes.h"
00055 #endif
00056 #endif
00057 #ifndef ROOT_Riosfwd
00058 #include "Riosfwd.h"
00059 #endif
00060 
00061 #include <time.h>
00062 #if !defined(__CINT__) && defined(R__MACOSX)
00063 #include <sys/time.h>
00064 #endif
00065 #if defined(MACOSX)
00066  #include "TTimeStamp.h"
00067 #else                                        // start of MACOSX opt-out section
00068  #if defined(__CINT__) || defined(R__WIN32) || \
00069     (defined(R__LINUX) && defined(R__KCC) && !defined(__timespec_defined))
00070 // explicit definition of timespec  'cause "rootcint" won't look in 
00071 // appropriate <time.h>. time_t appears to be defined as "typedef long time_t;"
00072 // in CINT version of <time.h>.  This isn't required by the standard:
00073 // to be compatible w/ std functions it must be at least 32-bits long,
00074 // but it might be longer to avoid the year-2037 cutoff.
00075 struct timespec 
00076 {
00077    time_t   tv_sec;   /* seconds */
00078    long     tv_nsec;  /* nanoseconds */
00079 };
00080  #endif
00081  #if defined(__CINT__)
00082 struct tm
00083 {
00084   int tm_sec;                   /* Seconds.     [0-60] (1 leap second) */
00085   int tm_min;                   /* Minutes.     [0-59]   */
00086   int tm_hour;                  /* Hours.       [0-23]   */
00087   int tm_mday;                  /* Day.         [1-31]   */
00088   int tm_mon;                   /* Month.       [0-11]   */
00089   int tm_year;                  /* Year - 1900.          */
00090   int tm_wday;                  /* Day of week. [0-6]    */
00091   int tm_yday;                  /* Days in year.[0-365]  */
00092   int tm_isdst;                 /* DST.         [-1/0/1] */
00093 };
00094  #endif
00095 
00096 // define this typedef so that CINT doesn't barf at using these
00097 // for function return values
00098 typedef struct timespec timespec_t;
00099 typedef struct tm       tm_t;
00100 #endif                                         // end of MACOSX opt-out section
00101 
00102 // make the VldTimeStamp cout'able
00103 #include <iosfwd>
00104 
00105 class VldTimeStamp;
00106 std::ostream& operator<<(std::ostream& os, const VldTimeStamp& vldts);
00107 
00108 class VldTimeStamp {
00109 
00110    friend Bool_t operator==(const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00111    friend Bool_t operator!=(const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00112    friend Bool_t operator< (const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00113    friend Bool_t operator<=(const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00114    friend Bool_t operator> (const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00115    friend Bool_t operator>=(const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00116 
00117    friend VldTimeStamp operator- (const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00118 
00119  public:
00120 
00122    static VldTimeStamp GetBOT();
00123 
00127    static VldTimeStamp GetEOT();
00128 
00130    VldTimeStamp();
00131 
00133    VldTimeStamp(const VldTimeStamp &source)
00134       { fSec = source.fSec; fNanoSec = source.fNanoSec; }
00136    VldTimeStamp& operator=(const VldTimeStamp &source)
00137       { if (this != &source) {fSec = source.fSec; fNanoSec = source.fNanoSec;}
00138       return *this; }
00139 
00141    VldTimeStamp(const timespec_t &ts)
00142       { fSec = ts.tv_sec; fNanoSec = ts.tv_nsec; NormalizeNanoSec(); }
00143 
00145    VldTimeStamp(const time_t &t, const Int_t nsec)
00146       { fSec = t; fNanoSec = 0; fNanoSec = nsec; NormalizeNanoSec(); }
00147 
00160    VldTimeStamp(UInt_t year, UInt_t month,
00161                 UInt_t day,  UInt_t hour,
00162                 UInt_t min,  UInt_t sec,
00163                 UInt_t nsec=0, 
00164                 Bool_t isUTC=kTRUE, Int_t secOffset=0);
00165 
00168    VldTimeStamp(UInt_t date, UInt_t time, UInt_t nsec, 
00169                 Bool_t isUTC=kTRUE, Int_t secOffset=0);
00170 
00178    VldTimeStamp(Double_t seconds)
00179     { fSec = (Int_t)seconds; fNanoSec = (Int_t)((seconds-fSec)*1.0e9); 
00180     NormalizeNanoSec();}
00181 
00182 
00183    virtual ~VldTimeStamp();
00184 
00192    operator double() const { return fSec + 1.0e-9 * fNanoSec; }
00193 
00194 
00196    timespec_t     GetTimeSpec() const
00197       { timespec_t value = {fSec,fNanoSec}; return value; }
00198 
00200    time_t         GetSec(void) const { return fSec;}
00202    Int_t          GetNanoSec(void) const { return fNanoSec; }
00203    
00205    Double_t GetSeconds(void) const { return fSec+(fNanoSec/1.0e9); }
00206     
00239    const char    *AsString(Option_t *option="") const;
00240    void           Copy(VldTimeStamp &vldts) const;
00241 
00244    Int_t          GetDate(Bool_t inUTC=kTRUE, Int_t secOffset=0,
00245                           UInt_t *year=0, UInt_t *month=0,
00246                           UInt_t *day=0) const;
00247 
00250    Int_t          GetTime(Bool_t inUTC=kTRUE, Int_t secOffset=0,
00251                           UInt_t* hour=0, UInt_t* min=0, 
00252                           UInt_t* sec=0) const;
00253 
00254    void           Add(const VldTimeStamp& offset);
00255    void           Add(Double_t seconds);
00256 
00257    void           Print(Option_t *option="") const;
00258 
00259    // Utility functions
00260 
00263    static Int_t   GetZoneOffset();
00275    static time_t  MktimeFromUTC(tm_t* tmstruct);
00277    static Bool_t  IsLeapYear(Int_t year);
00279    static void    DumpTMStruct(const tm_t& tmstruct);
00280 
00281  private:
00282 
00283    void           Set();
00284    void           Set(Int_t year, Int_t month, Int_t day,
00285                       Int_t hour, Int_t min, Int_t sec, 
00286                       Int_t nsec, Bool_t isUTC, Int_t secOffset);
00287    void           Set(Int_t date, Int_t time, Int_t nsec,
00288                       Bool_t isUTC, Int_t secOffset);
00289    void           NormalizeNanoSec();
00290 
00291    // Data members:
00292    // similar fields to struct timespec
00293    // use ROOT versions to "know" that they are platform consistent
00294    // 32-bit integers to avoid IO confusion.
00295    Int_t  fSec;
00296    Int_t  fNanoSec;
00297 
00298    ClassDef(VldTimeStamp,2)
00299 };
00300 
00301 #ifndef __CINT__
00302 //=============================================================================
00303 // Implementation details -- inlines need to be hidden from CINT
00304 //=============================================================================
00305 
00306 inline Bool_t operator==(const VldTimeStamp &lhs, const VldTimeStamp &rhs)
00307    { return lhs.fSec  == rhs.fSec && 
00308             lhs.fNanoSec == rhs.fNanoSec; }
00309 
00310 inline Bool_t operator!=(const VldTimeStamp &lhs, const VldTimeStamp &rhs)
00311    { return lhs.fSec  != rhs.fSec ||
00312             lhs.fNanoSec != rhs.fNanoSec; }
00313 
00314 inline Bool_t operator<(const VldTimeStamp &lhs, const VldTimeStamp &rhs)
00315    { return lhs.fSec  < rhs.fSec ||
00316              ( lhs.fSec  == rhs.fSec &&
00317                lhs.fNanoSec <  rhs.fNanoSec   ); }
00318 
00319 inline Bool_t operator<=(const VldTimeStamp &lhs, const VldTimeStamp &rhs)
00320    { return lhs.fSec  < rhs.fSec ||
00321              ( lhs.fSec  == rhs.fSec &&
00322                lhs.fNanoSec <= rhs.fNanoSec   ); }
00323 
00324 inline Bool_t operator>(const VldTimeStamp &lhs, const VldTimeStamp &rhs)
00325    { return lhs.fSec  > rhs.fSec ||
00326              ( lhs.fSec  == rhs.fSec &&
00327                lhs.fNanoSec >  rhs.fNanoSec   ); }
00328 
00329 inline Bool_t operator>=(const VldTimeStamp &lhs, const VldTimeStamp &rhs)
00330    { return lhs.fSec  > rhs.fSec ||
00331              ( lhs.fSec  == rhs.fSec &&
00332                lhs.fNanoSec >= rhs.fNanoSec   ); }
00333 
00334 inline VldTimeStamp operator-(const VldTimeStamp& lhs, const VldTimeStamp& rhs)
00335 {
00336     return VldTimeStamp(lhs.GetSec()     - rhs.GetSec(),
00337                         lhs.GetNanoSec() - rhs.GetNanoSec());
00338 }
00339 
00340 #endif /* __CINT__ */
00341 #endif // VLDTIMESTAMP_H

Generated on Thu Nov 1 15:54:05 2007 for loon by  doxygen 1.3.9.1