Changeset 2607 for trunk/MagicSoft/Mars/mbase
- Timestamp:
- 12/05/03 16:06:34 (21 years ago)
- Location:
- trunk/MagicSoft/Mars/mbase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbase/MTime.cc
r2580 r2607 38 38 // - removed fTimeStamp[2] 39 39 // 40 // Version 3: 41 // ---------- 42 // - removed fDurtaion - we may put it back when it is needed 43 // - complete rewrite of the data members (old ones completely replaced) 44 // 40 45 ///////////////////////////////////////////////////////////////////////////// 41 46 #include "MTime.h" 42 47 43 48 #include <iomanip> 49 #include <sys/time.h> // struct timeval 44 50 45 51 #include <TTime.h> 46 52 47 53 #include "MLog.h" 54 #include "MAstro.h" 48 55 49 56 ClassImp(MTime); … … 51 58 using namespace std; 52 59 53 void MTime:: SetTime(const TTime &t)60 void MTime::GetDate(UShort_t &y, Byte_t &m, Byte_t &d) const 54 61 { 55 SetTime((ULong_t)t); 62 MAstro::Mjd2Ymd((Long_t)fTime<0?fMjd-1:fMjd, y, m, d); 63 } 64 65 Bool_t MTime::Set(UShort_t y, Byte_t m, Byte_t d, Byte_t h, Byte_t min, Byte_t s, UShort_t ms, UInt_t ns) 66 { 67 if (h>23 || min>59 || s>59 || ms>999 || ns>999999) 68 return kFALSE; 69 70 const Int_t mjd = MAstro::Ymd2Mjd(y, m, d); 71 if (mjd<0) 72 return kFALSE; 73 74 const ULong_t tm = ((((h*60+min)*60)+s)*1000)+ms; 75 76 return Set(mjd, tm, ns); 77 } 78 79 void MTime::SetSystemTimer(const struct timeval &tv) 80 { 81 const ULong_t hor = 3600000; // One Hour in milliseconds 82 83 const UInt_t mjd = tv.tv_sec/(60*60*24) + 40587; 84 const Long_t tm = (tv.tv_usec/1000)%(24*hor); 85 86 Set(mjd, tm, tv.tv_usec*1000); 87 } 88 89 void MTime::Now() 90 { 91 #ifdef __LINUX__ 92 struct timeval tv; 93 gettimeofday(&tv, NULL); 94 SetSystemTimer(tv); 95 #else 96 Reset(); 97 #endif 56 98 } 57 99 58 100 void MTime::Print(Option_t *) const 59 101 { 60 *fLog << GetDescriptor() << ": " << dec << setfill('0'); 61 *fLog << setw(2) << (int)fHour << ":"; 62 *fLog << setw(2) << (int)fMin << ":"; 63 *fLog << setw(2) << (int)fSec << "."; 64 *fLog << setw(9) << fNanoSec << endl; 102 UShort_t yea, ms; 103 Byte_t mon, day, h, m, s; 104 105 GetDate(yea, mon, day); 106 GetTime(h, m, s, ms); 107 108 *fLog << GetDescriptor() << ": "; 109 *fLog << Form("%4d/%02d/%02d %02d:%02d:%02d.%03d (+%dns)", 110 yea, mon, day, h, m, s, ms, fNanoSec) << endl; 65 111 } -
trunk/MagicSoft/Mars/mbase/MTime.h
r2580 r2607 14 14 #endif 15 15 16 class TTime; 16 #ifndef ROOT_TTime 17 #include <TTime.h> 18 #endif 19 20 struct timeval; 17 21 18 22 class MTime : public MParContainer 19 23 { 24 friend bool operator==(MTime &t1, MTime &t2); 25 friend bool operator!=(MTime &t1, MTime &t2); 26 friend bool operator< (MTime &t1, MTime &t2); 27 friend bool operator> (MTime &t1, MTime &t2); 28 //friend bool operator<=(MTime &t1, MTime &t2); 29 //friend bool operator>=(MTime &t1, MTime &t2); 30 20 31 private: 21 //UInt_t fTimeStamp[2]; // type of raw event which should be processed by this task 22 UInt_t fDuration; // time of validity 32 UInt_t fMjd; // [d] Day in the century (Day of sun rise) 33 TTime fTime; // [ms] Time of Day (-11h<=x<13h) 34 UInt_t fNanoSec; // [ns] NanoSec part of TimeOfDay (<1000000) 23 35 24 Byte_t fHour; 25 Byte_t fMin; 26 Byte_t fSec; 27 UInt_t fNanoSec; 28 29 /* 30 UInt_t fMjd; // Day in the century (Day of sun rise) 31 TTime fTime; // Time of Day (43,200,000<x<43,200,000) 32 UShort_t fNanoSec; // NanoSec part of TimeOfDay (<1000) 33 */ 36 ULong_t GetTime24() const 37 { 38 const ULong_t hor = 3600000; // One Hour in milliseconds 39 return (Long_t)fTime<0 ? (Long_t)fTime+24*hor : (ULong_t)fTime; 40 } 34 41 35 42 public: … … 39 46 fTitle = title; 40 47 41 SetTime((ULong_t)0);48 Reset(); 42 49 } 43 50 44 51 MTime(MTime& t) { *this = t; } 45 52 53 void Reset() { fMjd=0; fTime=0; fNanoSec=0; } 54 46 55 void operator=(MTime &t) 47 56 { 48 fDuration = t.fDuration; 49 fHour = t.fHour; 50 fMin = t.fMin; 51 fSec = t.fSec; 52 fNanoSec = t.fNanoSec; 57 fMjd = t.fMjd; 58 fTime = t.fTime; 59 fNanoSec = t.fNanoSec; 53 60 } 54 61 55 62 void Print(Option_t *t=NULL) const; 56 63 57 void SetCT1Time(UInt_t t1, UInt_t t0) 64 void Now(); 65 66 Double_t GetMjd() const 67 { 68 return fMjd+((Long_t)fTime+fNanoSec/1e6)/1000; 69 } 70 71 void SetSystemTimer(const struct timeval &tv); 72 73 Bool_t Set(UInt_t mjd, ULong_t ms, UInt_t ns=0) 74 { 75 const ULong_t hor = 3600000; // One Hour in milliseconds 76 if (ms>24*hor-1 || ns>999999) 77 return kFALSE; 78 79 const Bool_t am = ms < hor*13; 80 81 fMjd = am ? mjd : mjd + 1; 82 fTime = (Long_t)(am ? ms : ms - hor*24); 83 fNanoSec = ns%1000000; 84 85 return kTRUE; 86 } 87 88 Bool_t Set(UShort_t y, Byte_t m, Byte_t d, Byte_t h, Byte_t min, Byte_t s, UShort_t ms, UInt_t ns=0); 89 90 void SetCT1Time(UInt_t mjd, UInt_t t1, UInt_t t0) 58 91 { 59 92 // int isecs_since_midday; // seconds passed since midday before sunset (JD of run start) 60 93 // int isecfrac_200ns; // fractional part of isecs_since_midday 61 94 // fTime->SetTime(isecfrac_200ns, isecs_since_midday); 62 fNanoSec = 200*t1; 63 fSec = t0%60; 64 t0 /= 60; 65 fMin = t0%60; 66 t0 /= 60; 67 fHour = (t0+12)%24; 95 const ULong_t hor = 3600000; // One Hour in milliseconds 96 97 fNanoSec = (200*t1)%1000000; 98 const ULong_t ms = (200*t1)/1000000 + t0+12*hor; 99 100 fTime = (Long_t)(ms<13*hor ? ms : ms-24*hor); 101 102 fMjd = mjd+1; 68 103 } 69 70 void Set Time(ULong_t t)104 /* 105 void SetSystemTime(const TTime &tm) 71 106 { 72 // t [millisec] 73 fNanoSec = (t*1000000)%1000; 74 t /= 1000; 75 fSec = t%60; 76 t /= 60; 77 fMin = t%60; 78 t /= 60; 79 fHour = t%24; 107 fTime = (ULong_t)tm%(24*hor); 80 108 } 81 82 void SetTime(const TTime &t); 83 84 void SetTime(Double_t t) 85 { 86 // t [s] 87 fNanoSec = (UInt_t)(fmod(t, 1)*1e9); 88 fSec = (Byte_t)fmod(t, 60); 89 t /= 60; 90 fMin = (Byte_t)fmod(t, 60); 91 t /= 60; 92 fHour = (Byte_t)fmod(t, 24); 93 } 94 95 void SetTime(Byte_t h, Byte_t m, Byte_t s, UInt_t ns) 96 { 97 fHour = h; 98 fMin = m; 99 fSec = s; 100 fNanoSec = ns; 101 } 102 103 void SetDuration(UInt_t t) 104 { 105 fDuration = t; 106 } 107 108 UInt_t GetDuration() 109 { 110 return fDuration; 111 } 112 109 */ 113 110 operator double() const //[s] 114 111 { 115 return f NanoSec/1e9+(fHour*60*60+fMin*60+fSec);112 return fMjd*24*3600+((Long_t)fTime+fNanoSec*1e6)*1000; 116 113 } 117 114 double operator()() const //[s] … … 120 117 } 121 118 122 Byte_t GetHour() const { return fHour; } 123 Byte_t GetMin() const { return fMin; } 124 Byte_t GetSec() const { return fSec; } 125 UInt_t GetNanoSec() const { return fNanoSec; } 119 void GetDate(UShort_t &y, Byte_t &m, Byte_t &d) const; 120 void GetTime(Byte_t &h, Byte_t &m, Byte_t &s, UShort_t &ms) const // Time of Day returned in the range [0h, 24h) 121 { 122 Long_t tm = GetTime24(); 123 ms = tm%1000; 124 tm /= 1000; 125 s = tm%60; 126 tm /= 60; 127 m = tm%60; 128 tm /= 60; 129 h = tm; 130 } 131 Long_t GetTime() const // Time of Day returned in the range [-11h, 13h) 132 { return (Long_t)fTime; } 126 133 127 ClassDef(MTime, 2) //A generalized MARS time stamp 134 void GetTime(Byte_t &h, Byte_t &m, Byte_t &s) const 135 { 136 UShort_t ms; 137 GetTime(h, m, s, ms); 138 } 139 140 ClassDef(MTime, 3) //A generalized MARS time stamp 128 141 }; 129 142 130 inline Double_t operator-(MTime &t1, MTime &t2)143 inline bool operator<(MTime &t1, MTime &t2) 131 144 { 132 return t1()-t2(); 145 if (t1.fMjd<t2.fMjd) 146 return true; 147 if (t1.fMjd==t2.fMjd && t1.fTime<t2.fTime) 148 return true; 149 if (t1.fMjd==t2.fMjd && t1.fTime==t2.fTime && t1.fNanoSec<t2.fNanoSec) 150 return true; 151 return false; 133 152 } 134 135 inline Bool_t operator<(MTime &t1, MTime &t2) 153 inline bool operator>(MTime &t1, MTime &t2) 136 154 { 137 return t1()<t2(); 155 if (t1.fMjd>t2.fMjd) 156 return true; 157 if (t1.fMjd==t2.fMjd && t1.fTime>t2.fTime) 158 return true; 159 if (t1.fMjd==t2.fMjd && t1.fTime==t2.fTime && t1.fNanoSec>t2.fNanoSec) 160 return true; 161 return false; 138 162 } 139 140 inline Bool_t operator>(MTime &t1, MTime &t2) 163 inline bool operator<=(MTime &t1, MTime &t2) 141 164 { 142 return t1()>t2();165 return !(t1>t2); 143 166 } 144 145 inline Bool_t operator<=(MTime &t1, MTime &t2) 167 inline bool operator>=(MTime &t1, MTime &t2) 146 168 { 147 return t1<=t2();169 return !(t1<t2); 148 170 } 149 150 inline Bool_t operator>=(MTime &t1, MTime &t2) 171 inline bool operator==(MTime &t1, MTime &t2) 151 172 { 152 return t1 ()>=t2();173 return t1.fNanoSec==t2.fNanoSec && t1.fTime==t2.fTime && t1.fMjd==t2.fMjd; 153 174 } 154 155 inline Bool_t operator==(MTime &t1, MTime &t2) 175 inline bool operator!=(MTime &t1, MTime &t2) 156 176 { 157 return t1 ()==t2();177 return t1.fNanoSec!=t2.fNanoSec || t1.fTime!=t2.fTime || t1.fMjd!=t2.fMjd; 158 178 } 159 160 179 #endif
Note:
See TracChangeset
for help on using the changeset viewer.