| 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 | class TTime;
|
|---|
| 17 |
|
|---|
| 18 | class MTime : public MParContainer
|
|---|
| 19 | {
|
|---|
| 20 | private:
|
|---|
| 21 | //UInt_t fTimeStamp[2]; // type of raw event which should be processed by this task
|
|---|
| 22 | UInt_t fDuration; // time of validity
|
|---|
| 23 |
|
|---|
| 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 | */
|
|---|
| 34 |
|
|---|
| 35 | public:
|
|---|
| 36 | MTime(const char *name=NULL, const char *title=NULL)
|
|---|
| 37 | {
|
|---|
| 38 | fName = name ? name : ClassName();
|
|---|
| 39 | fTitle = title;
|
|---|
| 40 |
|
|---|
| 41 | SetTime((ULong_t)0);
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | MTime(MTime& t) { *this = t; }
|
|---|
| 45 |
|
|---|
| 46 | void operator=(MTime &t)
|
|---|
| 47 | {
|
|---|
| 48 | fDuration = t.fDuration;
|
|---|
| 49 | fHour = t.fHour;
|
|---|
| 50 | fMin = t.fMin;
|
|---|
| 51 | fSec = t.fSec;
|
|---|
| 52 | fNanoSec = t.fNanoSec;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | void Print(Option_t *t=NULL) const;
|
|---|
| 56 |
|
|---|
| 57 | void SetCT1Time(UInt_t t1, UInt_t t0)
|
|---|
| 58 | {
|
|---|
| 59 | // int isecs_since_midday; // seconds passed since midday before sunset (JD of run start)
|
|---|
| 60 | // int isecfrac_200ns; // fractional part of isecs_since_midday
|
|---|
| 61 | // 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;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | void SetTime(ULong_t t)
|
|---|
| 71 | {
|
|---|
| 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;
|
|---|
| 80 | }
|
|---|
| 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 |
|
|---|
| 113 | operator double() const //[s]
|
|---|
| 114 | {
|
|---|
| 115 | return fNanoSec/1e9+(fHour*60*60+fMin*60+fSec);
|
|---|
| 116 | }
|
|---|
| 117 | double operator()() const //[s]
|
|---|
| 118 | {
|
|---|
| 119 | return operator double();
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 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; }
|
|---|
| 126 |
|
|---|
| 127 | ClassDef(MTime, 2) //A generalized MARS time stamp
|
|---|
| 128 | };
|
|---|
| 129 |
|
|---|
| 130 | inline Double_t operator-(MTime &t1, MTime &t2)
|
|---|
| 131 | {
|
|---|
| 132 | return t1()-t2();
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | inline Bool_t operator<(MTime &t1, MTime &t2)
|
|---|
| 136 | {
|
|---|
| 137 | return t1()<t2();
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | inline Bool_t operator>(MTime &t1, MTime &t2)
|
|---|
| 141 | {
|
|---|
| 142 | return t1()>t2();
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | inline Bool_t operator<=(MTime &t1, MTime &t2)
|
|---|
| 146 | {
|
|---|
| 147 | return t1<=t2();
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | inline Bool_t operator>=(MTime &t1, MTime &t2)
|
|---|
| 151 | {
|
|---|
| 152 | return t1()>=t2();
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | inline Bool_t operator==(MTime &t1, MTime &t2)
|
|---|
| 156 | {
|
|---|
| 157 | return t1()==t2();
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | #endif
|
|---|