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((ULong_t)0);
|
---|
34 | }
|
---|
35 |
|
---|
36 | MTime(MTime& t) { *this = t; }
|
---|
37 |
|
---|
38 | void operator=(MTime &t)
|
---|
39 | {
|
---|
40 | fDuration = t.fDuration;
|
---|
41 | fHour = t.fHour;
|
---|
42 | fMin = t.fMin;
|
---|
43 | fSec = t.fSec;
|
---|
44 | fNanoSec = t.fNanoSec;
|
---|
45 | }
|
---|
46 |
|
---|
47 | void Print(Option_t *t=NULL) const;
|
---|
48 |
|
---|
49 | void SetCT1Time(UInt_t t1, UInt_t t0)
|
---|
50 | {
|
---|
51 | // int isecs_since_midday; // seconds passed since midday before sunset (JD of run start)
|
---|
52 | // int isecfrac_200ns; // fractional part of isecs_since_midday
|
---|
53 | // fTime->SetTime(isecfrac_200ns, isecs_since_midday);
|
---|
54 | fNanoSec = 200*t1;
|
---|
55 | fSec = t0%60;
|
---|
56 | t0 /= 60;
|
---|
57 | fMin = t0%60;
|
---|
58 | t0 /= 60;
|
---|
59 | fHour = (t0+12)%24;
|
---|
60 | }
|
---|
61 |
|
---|
62 | void SetTime(ULong_t t)
|
---|
63 | {
|
---|
64 | // t [millisec]
|
---|
65 | fNanoSec = (t*1000000)%1000;
|
---|
66 | t /= 1000;
|
---|
67 | fSec = t%60;
|
---|
68 | t /= 60;
|
---|
69 | fMin = t%60;
|
---|
70 | t /= 60;
|
---|
71 | fHour = t%24;
|
---|
72 | }
|
---|
73 |
|
---|
74 | void SetTime(Double_t t)
|
---|
75 | {
|
---|
76 | // t [s]
|
---|
77 | fNanoSec = (UInt_t)(fmod(t, 1)*1e9);
|
---|
78 | fSec = (Byte_t)fmod(t, 60);
|
---|
79 | t /= 60;
|
---|
80 | fMin = (Byte_t)fmod(t, 60);
|
---|
81 | t /= 60;
|
---|
82 | fHour = (Byte_t)fmod(t, 24);
|
---|
83 | }
|
---|
84 |
|
---|
85 | void SetTime(Byte_t h, Byte_t m, Byte_t s, UInt_t ns)
|
---|
86 | {
|
---|
87 | fHour = h;
|
---|
88 | fMin = m;
|
---|
89 | fSec = s;
|
---|
90 | fNanoSec = ns;
|
---|
91 | }
|
---|
92 |
|
---|
93 | void SetDuration(UInt_t t)
|
---|
94 | {
|
---|
95 | fDuration = t;
|
---|
96 | }
|
---|
97 |
|
---|
98 | MTime *GetTime()
|
---|
99 | {
|
---|
100 | return this;
|
---|
101 | }
|
---|
102 |
|
---|
103 | UInt_t GetDuration()
|
---|
104 | {
|
---|
105 | return fDuration;
|
---|
106 | }
|
---|
107 |
|
---|
108 | operator double() const //[s]
|
---|
109 | {
|
---|
110 | return fNanoSec/1e9+(fHour*24*60*60+fMin*60+fSec);
|
---|
111 | }
|
---|
112 | double operator()() const //[s]
|
---|
113 | {
|
---|
114 | return operator double();
|
---|
115 | }
|
---|
116 |
|
---|
117 | Byte_t GetHour() const { return fHour; }
|
---|
118 | Byte_t GetMin() const { return fMin; }
|
---|
119 | Byte_t GetSec() const { return fSec; }
|
---|
120 | UInt_t GetNanoSec() const { return fNanoSec; }
|
---|
121 |
|
---|
122 | ClassDef(MTime, 2) //A generalized MARS time stamp
|
---|
123 | };
|
---|
124 |
|
---|
125 | inline Double_t operator-(MTime &t1, MTime &t2)
|
---|
126 | {
|
---|
127 | return t1()-t2();
|
---|
128 | }
|
---|
129 |
|
---|
130 | inline Bool_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 | #endif
|
---|