source: trunk/MagicSoft/Mars/mbase/MTime.h@ 3077

Last change on this file since 3077 was 2728, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 4.7 KB
Line 
1#ifndef MARS_MTime
2#define MARS_MTime
3
4/////////////////////////////////////////////////////////////////////////////
5// //
6// MTime //
7// //
8// A generalized MARS time stamp //
9// //
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef MARS_MParContainer
13#include "MParContainer.h"
14#endif
15
16#ifndef _CPP_IOSFWD
17#include <iosfwd>
18#endif
19
20#ifndef ROOT_TTime
21#include <TTime.h>
22#endif
23
24struct timeval;
25
26class MTime : public MParContainer
27{
28public:
29 static const UInt_t kHour; // [ms] one hour
30 static const UInt_t kDay; // [ms] one day
31
32private:
33 UInt_t fMjd; // [d] Day in the century (Day of sun rise)
34 TTime fTime; // [ms] Time of Day (-11h<=x<13h)
35 UInt_t fNanoSec; // [ns] NanoSec part of TimeOfDay (<1000000)
36
37 ULong_t GetTime24() const
38 {
39 return (Long_t)fTime<0 ? (Long_t)fTime+kDay : (ULong_t)fTime;
40 }
41 void Init(const char *name, const char *title)
42 {
43 fName = name ? name : "MTime";
44 fTitle = title ? title : "Generalized time stamp";
45 }
46
47public:
48 MTime(const char *name=NULL, const char *title=NULL)
49 {
50 Init(name, title);
51 Reset();
52 }
53 MTime(const struct timeval &tm)
54 {
55 Init(NULL, NULL);
56 Set(tm);
57 }
58 MTime(const MTime& t) : fMjd(t.fMjd), fTime(t.fTime), fNanoSec(t.fNanoSec)
59 {
60 Init(NULL, NULL);
61 }
62
63 void operator=(const MTime &t)
64 {
65 fMjd = t.fMjd;
66 fTime = t.fTime;
67 fNanoSec = t.fNanoSec;
68 }
69
70 void Reset() { fMjd=0; fTime=0; fNanoSec=0; }
71
72 void Print(Option_t *t=NULL) const;
73
74 void Now();
75
76 Bool_t Set(UInt_t mjd, ULong_t ms, UInt_t ns=0);
77 Bool_t Set(UShort_t y, Byte_t m, Byte_t d, Byte_t h=13, Byte_t min=0, Byte_t s=0, UShort_t ms=0, UInt_t ns=0);
78 void Set(const struct timeval &tv);
79 void SetCT1Time(UInt_t mjd, UInt_t t1, UInt_t t0);
80 Bool_t UpdMagicTime(Byte_t h, Byte_t m, Byte_t s, UShort_t ms);
81 void SetMjd(Double_t m);
82 Double_t GetMjd() const;
83 TString GetString() const;
84 TString GetFileName() const;
85 void GetDate(UShort_t &y, Byte_t &m, Byte_t &d) const;
86 TTime GetRootTime() const;
87 Double_t GetAxisTime() const;
88 Long_t GetTime() const { return (Long_t)fTime; } // [ms] Time of Day returned in the range [-11h, 13h)
89 void GetTime(Byte_t &h, Byte_t &m, Byte_t &s, UShort_t &ms) const;
90 void GetTime(Byte_t &h, Byte_t &m, Byte_t &s) const
91 {
92 UShort_t ms;
93 GetTime(h, m, s, ms);
94 }
95
96 UInt_t Year() const { UShort_t y; Byte_t m, d; GetDate(y,m,d); return y; }
97 UInt_t Month() const { UShort_t y; Byte_t m, d; GetDate(y,m,d); return m; }
98 UInt_t Day() const { UShort_t y; Byte_t m, d; GetDate(y,m,d); return d; }
99 UInt_t Hour() const { Byte_t h, m, s; GetTime(h,m,s); return h; }
100 UInt_t Min() const { Byte_t h, m, s; GetTime(h,m,s); return m; }
101 UInt_t Sec() const { Byte_t h, m, s; GetTime(h,m,s); return s; }
102
103 istream &ReadBinary(istream &fin);
104
105 operator double() const //[s]
106 {
107 return ((Double_t)fMjd*kDay+(Long_t)fTime+fNanoSec/1e6)/1000;
108 }
109 double operator()() const //[s]
110 {
111 return operator double();
112 }
113
114 bool operator<(const MTime &t) const
115 {
116 if (fMjd<t.fMjd)
117 return true;
118 if (fMjd==t.fMjd && fTime<t.fTime)
119 return true;
120 if (fMjd==t.fMjd && fTime==t.fTime && fNanoSec<t.fNanoSec)
121 return true;
122 return false;
123 }
124 bool operator>(const MTime &t) const
125 {
126 if (fMjd>t.fMjd)
127 return true;
128 if (fMjd==t.fMjd && fTime>t.fTime)
129 return true;
130 if (fMjd==t.fMjd && fTime==t.fTime && fNanoSec>t.fNanoSec)
131 return true;
132 return false;
133 }
134
135 bool operator<=(const MTime &t) const
136 {
137 return !operator>(t);
138 }
139
140 bool operator>=(const MTime &t) const
141 {
142 return !operator<(t);
143 }
144
145 bool operator==(const MTime &t) const
146 {
147 return fNanoSec==t.fNanoSec && fTime==t.fTime && fMjd==t.fMjd;
148 }
149
150 bool operator!=(const MTime &t) const
151 {
152 return fNanoSec!=t.fNanoSec || fTime!=t.fTime || fMjd!=t.fMjd;
153 }
154
155 bool operator!() const
156 {
157 return fNanoSec==0 && (ULong_t)fTime==0 && fMjd==0;
158 }
159
160 ClassDef(MTime, 3) //A generalized MARS time stamp
161};
162
163inline ostream &operator<<(ostream &out, const MTime &t)
164{
165 out << t.GetString();
166 return out;
167}
168
169#endif
Note: See TracBrowser for help on using the repository browser.