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 MTime : public MParContainer
|
---|
17 | {
|
---|
18 | private:
|
---|
19 | UInt_t fTimeStamp[2]; // type of raw event which should be processed by this task
|
---|
20 | UInt_t fDuration; // time of validity
|
---|
21 |
|
---|
22 | Byte_t fHour;
|
---|
23 | Byte_t fMin;
|
---|
24 | Byte_t fSec;
|
---|
25 | UInt_t fNanoSec;
|
---|
26 |
|
---|
27 | public:
|
---|
28 | MTime(const char *name=NULL, const char *title=NULL)
|
---|
29 | {
|
---|
30 | fName = name ? name : ClassName();
|
---|
31 | fTitle = title;
|
---|
32 |
|
---|
33 | SetTime(0, 0);
|
---|
34 | }
|
---|
35 |
|
---|
36 | MTime(UInt_t t1, UInt_t t0)
|
---|
37 | {
|
---|
38 | SetTime(t1, t0);
|
---|
39 | }
|
---|
40 |
|
---|
41 | MTime(MTime& t)
|
---|
42 | {
|
---|
43 | fTimeStamp[0] = t.fTimeStamp[0];
|
---|
44 | fTimeStamp[1] = t.fTimeStamp[1];
|
---|
45 | fDuration = t.fDuration;
|
---|
46 | }
|
---|
47 |
|
---|
48 | void operator=(MTime &t)
|
---|
49 | {
|
---|
50 | fTimeStamp[0] = t.fTimeStamp[0];
|
---|
51 | fTimeStamp[1] = t.fTimeStamp[1];
|
---|
52 | fDuration = t.fDuration;
|
---|
53 | }
|
---|
54 |
|
---|
55 | ~MTime() {}
|
---|
56 |
|
---|
57 | void Print(Option_t *t=NULL) const;
|
---|
58 |
|
---|
59 | void SetTime(UInt_t t1, UInt_t t0)
|
---|
60 | {
|
---|
61 | fTimeStamp[0] = t1;
|
---|
62 | fTimeStamp[1] = t0;
|
---|
63 | }
|
---|
64 |
|
---|
65 | void SetCT1Time(UInt_t t1, UInt_t t0)
|
---|
66 | {
|
---|
67 | // int isecs_since_midday; // seconds passed since midday before sunset (JD of run start)
|
---|
68 | // int isecfrac_200ns; // fractional part of isecs_since_midday
|
---|
69 | // fTime->SetTime(isecfrac_200ns, isecs_since_midday);
|
---|
70 | fNanoSec = 200*t1;
|
---|
71 | fSec = t0%60;
|
---|
72 | t0 /= 60;
|
---|
73 | fMin = t0%60;
|
---|
74 | t0 /= 60;
|
---|
75 | fHour = (t0+12)%24;
|
---|
76 | }
|
---|
77 |
|
---|
78 | void SetTime(ULong_t t)
|
---|
79 | {
|
---|
80 | // t [millisec]
|
---|
81 | fNanoSec = (t*1000000)%1000;
|
---|
82 | t /= 1000;
|
---|
83 | fSec = t%60;
|
---|
84 | t /= 60;
|
---|
85 | fMin = t%60;
|
---|
86 | t /= 60;
|
---|
87 | fHour = t%24;
|
---|
88 | }
|
---|
89 |
|
---|
90 | void SetTime(Double_t t)
|
---|
91 | {
|
---|
92 | // t [s]
|
---|
93 | fNanoSec = (UInt_t)(fmod(t, 1)*1e9);
|
---|
94 | fSec = (Byte_t)fmod(t, 60);
|
---|
95 | t /= 60;
|
---|
96 | fMin = (Byte_t)fmod(t, 60);
|
---|
97 | t /= 60;
|
---|
98 | fHour = (Byte_t)fmod(t, 24);
|
---|
99 | }
|
---|
100 |
|
---|
101 | void SetTime(Byte_t h, Byte_t m, Byte_t s, UShort_t ns)
|
---|
102 | {
|
---|
103 | fHour = h;
|
---|
104 | fMin = m;
|
---|
105 | fSec = s;
|
---|
106 | fNanoSec = ns;
|
---|
107 | }
|
---|
108 |
|
---|
109 | void SetDuration(UInt_t t)
|
---|
110 | {
|
---|
111 | fDuration = t;
|
---|
112 | }
|
---|
113 |
|
---|
114 | MTime *GetTime()
|
---|
115 | {
|
---|
116 | return this;
|
---|
117 | }
|
---|
118 |
|
---|
119 | UInt_t GetTimeLo()
|
---|
120 | {
|
---|
121 | return fTimeStamp[0];
|
---|
122 | }
|
---|
123 | UInt_t GetTimeHi()
|
---|
124 | {
|
---|
125 | return fTimeStamp[1];
|
---|
126 | }
|
---|
127 |
|
---|
128 | UInt_t GetDuration()
|
---|
129 | {
|
---|
130 | return fDuration;
|
---|
131 | }
|
---|
132 |
|
---|
133 | operator double() const //[s]
|
---|
134 | {
|
---|
135 | return fNanoSec/1e9+(fHour*24*60*60+fMin*60+fSec);
|
---|
136 | }
|
---|
137 | double operator()() const //[s]
|
---|
138 | {
|
---|
139 | return operator double();
|
---|
140 | }
|
---|
141 |
|
---|
142 | ClassDef(MTime, 1) //A generalized MARS time stamp
|
---|
143 | };
|
---|
144 |
|
---|
145 | inline Double_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 | inline Bool_t operator<=(MTime &t1, MTime &t2)
|
---|
161 | {
|
---|
162 | return t1<=t2();
|
---|
163 | }
|
---|
164 |
|
---|
165 | inline Bool_t operator>=(MTime &t1, MTime &t2)
|
---|
166 | {
|
---|
167 | return t1()>=t2();
|
---|
168 | }
|
---|
169 |
|
---|
170 | inline Bool_t operator==(MTime &t1, MTime &t2)
|
---|
171 | {
|
---|
172 | return t1()==t2();
|
---|
173 | }
|
---|
174 |
|
---|
175 | #endif
|
---|