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

VldTimeStamp.h

Go to the documentation of this file.
00001 
00049 #ifndef VLDTIMESTAMP_H
00050 #define VLDTIMESTAMP_H
00051 
00052 // TTimeStamp is the ROOT adopted version of this class
00053 // so it has all the necessary includes
00054 #include "TTimeStamp.h"
00055 
00056 // make the VldTimeStamp cout'able
00057 #include <iosfwd>
00058 
00059 class VldTimeStamp;
00060 std::ostream& operator<<(std::ostream& os, const VldTimeStamp& vldts);
00061 
00062 class VldTimeStamp {
00063 
00064    friend Bool_t operator==(const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00065    friend Bool_t operator!=(const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00066    friend Bool_t operator< (const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00067    friend Bool_t operator<=(const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00068    friend Bool_t operator> (const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00069    friend Bool_t operator>=(const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00070 
00071    friend VldTimeStamp operator- (const VldTimeStamp &lhs, const VldTimeStamp &rhs);
00072 
00073  public:
00074 
00076    static VldTimeStamp GetBOT();
00077 
00081    static VldTimeStamp GetEOT();
00082 
00085    static VldTimeStamp GetNBOT();
00086 
00088    VldTimeStamp();
00089 
00091    VldTimeStamp(const VldTimeStamp &source)
00092       { fSec = source.fSec; fNanoSec = source.fNanoSec; }
00094    VldTimeStamp& operator=(const VldTimeStamp &source)
00095       { if (this != &source) {fSec = source.fSec; fNanoSec = source.fNanoSec;}
00096       return *this; }
00097 
00099    VldTimeStamp(const timespec_t &ts)
00100       { fSec = ts.tv_sec; fNanoSec = ts.tv_nsec; NormalizeNanoSec(); }
00101 
00103    VldTimeStamp(const time_t &t, const Int_t nsec)
00104       { fSec = t; fNanoSec = 0; fNanoSec = nsec; NormalizeNanoSec(); }
00105 
00118    VldTimeStamp(UInt_t year, UInt_t month,
00119                 UInt_t day,  UInt_t hour,
00120                 UInt_t min,  UInt_t sec,
00121                 UInt_t nsec=0, 
00122                 Bool_t isUTC=kTRUE, Int_t secOffset=0);
00123 
00126    VldTimeStamp(UInt_t date, UInt_t time, UInt_t nsec, 
00127                 Bool_t isUTC=kTRUE, Int_t secOffset=0);
00128 
00136    VldTimeStamp(Double_t seconds)
00137     { fSec = (Int_t)seconds; fNanoSec = (Int_t)((seconds-fSec)*1.0e9); 
00138     NormalizeNanoSec();}
00139 
00140 
00141    virtual ~VldTimeStamp();
00142 
00150    operator double() const { return fSec + 1.0e-9 * fNanoSec; }
00151 
00152 
00154    timespec_t     GetTimeSpec() const
00155       { timespec_t value = {fSec,fNanoSec}; return value; }
00156 
00158    time_t         GetSec(void) const { return fSec;}
00160    Int_t          GetNanoSec(void) const { return fNanoSec; }
00161    
00163    Double_t GetSeconds(void) const { return fSec+(fNanoSec/1.0e9); }
00164     
00197    const char    *AsString(Option_t *option="") const;
00198    void           Copy(VldTimeStamp &vldts) const;
00199 
00202    Int_t          GetDate(Bool_t inUTC=kTRUE, Int_t secOffset=0,
00203                           UInt_t *year=0, UInt_t *month=0,
00204                           UInt_t *day=0) const;
00205 
00208    Int_t          GetTime(Bool_t inUTC=kTRUE, Int_t secOffset=0,
00209                           UInt_t* hour=0, UInt_t* min=0, 
00210                           UInt_t* sec=0) const;
00211 
00212    void           Add(const VldTimeStamp& offset);
00213    void           Add(Double_t seconds);
00214 
00215    void           Print(Option_t *option="") const;
00216 
00217    // Utility functions
00218 
00221    static Int_t   GetZoneOffset();
00233    static time_t  MktimeFromUTC(tm_t* tmstruct);
00235    static Bool_t  IsLeapYear(Int_t year);
00237    static void    DumpTMStruct(const tm_t& tmstruct);
00238 
00239  private:
00240 
00241    void           Set();
00242    void           Set(Int_t year, Int_t month, Int_t day,
00243                       Int_t hour, Int_t min, Int_t sec, 
00244                       Int_t nsec, Bool_t isUTC, Int_t secOffset);
00245    void           Set(Int_t date, Int_t time, Int_t nsec,
00246                       Bool_t isUTC, Int_t secOffset);
00247    void           NormalizeNanoSec();
00248 
00249    // Data members:
00250    // similar fields to struct timespec
00251    // use ROOT versions to "know" that they are platform consistent
00252    // 32-bit integers to avoid IO confusion.
00253    Int_t  fSec;
00254    Int_t  fNanoSec;
00255 
00256    ClassDef(VldTimeStamp,2)
00257 };
00258 
00259 #ifndef __CINT__
00260 //=============================================================================
00261 // Implementation details -- inlines need to be hidden from CINT
00262 //=============================================================================
00263 
00264 inline Bool_t operator==(const VldTimeStamp &lhs, const VldTimeStamp &rhs)
00265    { return lhs.fSec  == rhs.fSec && 
00266             lhs.fNanoSec == rhs.fNanoSec; }
00267 
00268 inline Bool_t operator!=(const VldTimeStamp &lhs, const VldTimeStamp &rhs)
00269    { return lhs.fSec  != rhs.fSec ||
00270             lhs.fNanoSec != rhs.fNanoSec; }
00271 
00272 inline Bool_t operator<(const VldTimeStamp &lhs, const VldTimeStamp &rhs)
00273    { return lhs.fSec  < rhs.fSec ||
00274              ( lhs.fSec  == rhs.fSec &&
00275                lhs.fNanoSec <  rhs.fNanoSec   ); }
00276 
00277 inline Bool_t operator<=(const VldTimeStamp &lhs, const VldTimeStamp &rhs)
00278    { return lhs.fSec  < rhs.fSec ||
00279              ( lhs.fSec  == rhs.fSec &&
00280                lhs.fNanoSec <= rhs.fNanoSec   ); }
00281 
00282 inline Bool_t operator>(const VldTimeStamp &lhs, const VldTimeStamp &rhs)
00283    { return lhs.fSec  > rhs.fSec ||
00284              ( lhs.fSec  == rhs.fSec &&
00285                lhs.fNanoSec >  rhs.fNanoSec   ); }
00286 
00287 inline Bool_t operator>=(const VldTimeStamp &lhs, const VldTimeStamp &rhs)
00288    { return lhs.fSec  > rhs.fSec ||
00289              ( lhs.fSec  == rhs.fSec &&
00290                lhs.fNanoSec >= rhs.fNanoSec   ); }
00291 
00292 inline VldTimeStamp operator-(const VldTimeStamp& lhs, const VldTimeStamp& rhs)
00293 {
00294     return VldTimeStamp(lhs.GetSec()     - rhs.GetSec(),
00295                         lhs.GetNanoSec() - rhs.GetNanoSec());
00296 }
00297 
00298 #endif /* __CINT__ */
00299 #endif // VLDTIMESTAMP_H

Generated on Fri Mar 28 15:41:53 2008 for loon by  doxygen 1.3.9.1