Changeset 4887 for trunk/MagicSoft/Mars/mbase
- Timestamp:
- 09/07/04 18:31:53 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/mbase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbase/MTime.cc
r4732 r4887 563 563 return fin; 564 564 } 565 566 void MTime::AddMilliSeconds(UInt_t ms) 567 { 568 fTime += ms; 569 570 fTime += 11*kHour; 571 fMjd += (Long_t)fTime/kDay; 572 fTime = (Long_t)fTime%kDay; 573 fTime -= 11*kHour; 574 } 575 /* 576 MTime MTime::operator-(const MTime &tm1) 577 { 578 const MTime &tm0 = *this; 579 580 MTime t0 = tm0>tm1 ? tm0 : tm1; 581 const MTime &t1 = tm0>tm1 ? tm1 : tm0; 582 583 if (t0.fNanoSec<t1.fNanoSec) 584 { 585 t0.fNanoSec += 1000000; 586 t0.fTime -= 1; 587 } 588 589 t0.fNanoSec -= t1.fNanoSec; 590 t0.fTime -= t1.fTime; 591 592 if ((Long_t)t0.fTime<-(Long_t)kHour*11) 593 { 594 t0.fTime += kDay; 595 t0.fMjd--; 596 } 597 598 t0.fMjd -= t1.fMjd; 599 600 return t0; 601 } 602 603 void MTime::operator-=(const MTime &t) 604 { 605 *this = *this-t; 606 } 607 608 MTime MTime::operator+(const MTime &t1) 609 { 610 MTime t0 = *this; 611 612 t0.fNanoSec += t1.fNanoSec; 613 614 if (t0.fNanoSec>999999) 615 { 616 t0.fNanoSec -= 1000000; 617 t0.fTime += kDay; 618 } 619 620 t0.fTime += t1.fTime; 621 622 if ((Long_t)t0.fTime>=(Long_t)kHour*13) 623 { 624 t0.fTime -= kDay; 625 t0.fMjd++; 626 } 627 628 t0.fMjd += t1.fMjd; 629 630 return t0; 631 } 632 633 void MTime::operator+=(const MTime &t) 634 { 635 *this = *this+t; 636 } 637 */ 638 639 void MTime::SetMean(const MTime &t0, const MTime &t1) 640 { 641 // This could be an operator+ 642 *this = t0; 643 644 fNanoSec += t1.fNanoSec; 645 646 if (fNanoSec>999999) 647 { 648 fNanoSec -= 1000000; 649 fTime += kDay; 650 } 651 652 fTime += t1.fTime; 653 654 if ((Long_t)fTime>=(Long_t)kHour*13) 655 { 656 fTime -= kDay; 657 fMjd++; 658 } 659 660 fMjd += t1.fMjd; 661 662 // This could be an operator/ 663 if ((Long_t)fTime<0) 664 { 665 fTime += kDay; 666 fMjd--; 667 } 668 669 Int_t reminder = fMjd%2; 670 fMjd /= 2; 671 672 fTime += reminder*kDay; 673 reminder = (Long_t)fTime%2; 674 fTime /= 2; 675 676 fNanoSec += reminder*1000000; 677 fNanoSec /= 2; 678 679 fTime += 11*kHour; 680 fMjd += (Long_t)fTime/kDay; 681 fTime = (Long_t)fTime%kDay; 682 fTime -= 11*kHour; 683 } 684 685 void MTime::SetMean(Double_t t0, Double_t t1) 686 { 687 const Double_t mean = (t0+t1)*(500./kDay); 688 SetMjd(mean); 689 } -
trunk/MagicSoft/Mars/mbase/MTime.h
r4627 r4887 35 35 UInt_t fNanoSec; // [ns] NanoSec part of TimeOfDay (<1000000) 36 36 37 37 38 ULong_t GetTime24() const 38 39 { … … 75 76 void Now(); 76 77 78 // Setter functions 77 79 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 80 void Set(const struct timeval &tv); … … 85 87 Bool_t SetMjd(UInt_t mjd, ULong_t ms, UInt_t ns=0); 86 88 void SetMjd(Double_t m); 89 90 // Getter functions 87 91 Double_t GetMjd() const; 88 92 Double_t GetGmst() const; … … 111 115 UInt_t Sec() const { Byte_t h, m, s; GetTime(h,m,s); return s; } 112 116 117 // I/O functions 113 118 istream &ReadBinary(istream &fin); 114 119 115 operator double() const //[s] 116 { 117 return ((Double_t)fMjd*kDay+(Long_t)fTime+fNanoSec/1e6)/1000; 118 } 119 double operator()() const //[s] 120 { 121 return operator double(); 122 } 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 bool operator>(const MTime &t) const 135 { 136 if (fMjd>t.fMjd) 137 return true; 138 if (fMjd==t.fMjd && fTime>t.fTime) 139 return true; 140 if (fMjd==t.fMjd && fTime==t.fTime && fNanoSec>t.fNanoSec) 141 return true; 142 return false; 143 } 144 145 bool operator<=(const MTime &t) const 146 { 147 return !operator>(t); 148 } 149 150 bool operator>=(const MTime &t) const 151 { 152 return !operator<(t); 153 } 154 155 bool operator==(const MTime &t) const 156 { 157 return fNanoSec==t.fNanoSec && fTime==t.fTime && fMjd==t.fMjd; 158 } 159 160 bool operator!=(const MTime &t) const 161 { 162 return fNanoSec!=t.fNanoSec || fTime!=t.fTime || fMjd!=t.fMjd; 163 } 164 165 bool operator!() const 166 { 167 return fNanoSec==0 && (ULong_t)fTime==0 && fMjd==0; 168 } 120 // Conversion functions 121 operator double() const; //[s] 122 double operator()() const; //[s] 123 124 // Calculation functions 125 void AddMilliSeconds(UInt_t ms); 126 void SetMean(const MTime &t0, const MTime &t1); 127 void SetMean(Double_t t0, Double_t t1); 128 /* 129 MTime operator-(const MTime &tm1); 130 void operator-=(const MTime &t); 131 MTime operator+(const MTime &t1); 132 void operator+=(const MTime &t); 133 */ 134 135 // Base comparison operators 136 bool operator<(const MTime &t) const; 137 bool operator>(const MTime &t) const; 138 139 // Derived comparison operators 140 bool operator<=(const MTime &t) const; 141 bool operator>=(const MTime &t) const; 142 bool operator==(const MTime &t) const; 143 bool operator!=(const MTime &t) const; 144 bool operator!() const; 169 145 170 146 ClassDef(MTime, 3) //A generalized MARS time stamp … … 186 162 } 187 163 188 #endif 164 inline MTime::operator double() const //[s] 165 { 166 return ((Double_t)fMjd*kDay+(Long_t)fTime+fNanoSec/1e6)/1000; 167 } 168 169 inline double MTime::operator()() const //[s] 170 { 171 return operator double(); 172 } 173 174 inline bool MTime::operator<(const MTime &t) const 175 { 176 if (fMjd<t.fMjd) 177 return true; 178 if (fMjd==t.fMjd && fTime<t.fTime) 179 return true; 180 if (fMjd==t.fMjd && fTime==t.fTime && fNanoSec<t.fNanoSec) 181 return true; 182 return false; 183 } 184 185 inline bool MTime::operator>(const MTime &t) const 186 { 187 if (fMjd>t.fMjd) 188 return true; 189 if (fMjd==t.fMjd && fTime>t.fTime) 190 return true; 191 if (fMjd==t.fMjd && fTime==t.fTime && fNanoSec>t.fNanoSec) 192 return true; 193 return false; 194 } 195 196 inline bool MTime::operator<=(const MTime &t) const 197 { 198 return !operator>(t); 199 } 200 201 inline bool MTime::operator>=(const MTime &t) const 202 { 203 return !operator<(t); 204 } 205 206 inline bool MTime::operator==(const MTime &t) const 207 { 208 return fNanoSec==t.fNanoSec && fTime==t.fTime && fMjd==t.fMjd; 209 } 210 211 inline bool MTime::operator!=(const MTime &t) const 212 { 213 return fNanoSec!=t.fNanoSec || fTime!=t.fTime || fMjd!=t.fMjd; 214 } 215 216 inline bool MTime::operator!() const 217 { 218 return fNanoSec==0 && (ULong_t)fTime==0 && fMjd==0; 219 } 220 221 #endif
Note:
See TracChangeset
for help on using the changeset viewer.