| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Time.icpp
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_TIME_ICPP
2 #define GAUDIKERNEL_TIME_ICPP 1
3
4 // Implementation of inline function for classes Gaudi::Time and Gaudi::TimeSpan
5
6 namespace Gaudi {
7
9 inline Time::Time (void): m_nsecs(0) {}
10
13 inline Time::Time (ValueType nsecs): m_nsecs(nsecs) {
14 TimeAssert( m_nsecs >= 0, "cannot create a negative time");
15 }
16
19 inline Time::Time (TimeSpan ts) : m_nsecs(ts.m_nsecs) {
20 TimeAssert( m_nsecs >= 0, "cannot create a negative time");
21 }
22
25 inline Time::Time (ValueType secs, int nsecs)
26 : m_nsecs(secs * Time::SEC_NSECS + nsecs) {
27 TimeAssert( m_nsecs >= 0, "cannot create a negative time");
28 }
29
32 inline Time::ValueType Time::ns (void) const {
33 return m_nsecs;
34 }
35
38 inline Time &Time::operator+= (const TimeSpan &x) {
39 TimeAssert( m_nsecs >= -x.m_nsecs, "time operation lead to negative time");
40 m_nsecs += x.m_nsecs;
41 return *this;
42 }
43
46 inline Time &Time::operator-= (const TimeSpan &x) {
47 TimeAssert( m_nsecs >= x.m_nsecs, "time operation lead to negative time");
48 m_nsecs -= x.m_nsecs;
49 return *this;
50 }
51
53 inline Time Time::epoch (void) {
54 return 0LL;
55 }
56
58 inline Time Time::max (void) {
59 return 0x7fffffffffffffffLL;
60 }
61
63 inline bool Time::isLeap (int year) {
64 return ((year % 4) == 0
65 && ((year % 100) != 0
66 || (year % 400) == 0));
67 }
68
72
73 inline TimeSpan::TimeSpan (void): m_nsecs(0) {}
74
76 inline TimeSpan::TimeSpan (Time t): m_nsecs (t.m_nsecs) {}
77
79 inline TimeSpan::TimeSpan (ValueType nsecs): m_nsecs (nsecs) {}
80
89 inline TimeSpan::TimeSpan (ValueType secs, int nsecs)
90 : m_nsecs(secs * Time::SEC_NSECS + nsecs) {}
91
103 inline TimeSpan::TimeSpan (int days, int hours, int mins, int secs, int nsecs) {
104 m_nsecs = (secs + 60 * (mins + 60 * (hours + 24*days)))*Time::SEC_NSECS + nsecs;
105 }
106
108 inline int TimeSpan::days (void) const {
109 return int(m_nsecs / Time::SEC_NSECS / Time::SECS_PER_DAY);
110 }
111
113 inline int TimeSpan::hours (void) const {
114 return int(m_nsecs / Time::SEC_NSECS / Time::SECS_PER_HOUR);
115 }
116
118 inline int TimeSpan::minutes (void) const {
119 return int(m_nsecs / Time::SEC_NSECS / 60);
120 }
121
123 inline TimeSpan::ValueType TimeSpan::seconds (void) const {
124 return m_nsecs / Time::SEC_NSECS;
125 }
126
128 inline TimeSpan::ValueType TimeSpan::ns (void) const {
129 return m_nsecs;
130 }
131
134 inline int TimeSpan::lastHours (void) const {
135 return hours () - days () * 24;
136 }
137
140 inline int TimeSpan::lastMinutes (void) const {
141 return minutes () - hours () * 60;
142 }
143
146 inline int TimeSpan::lastSeconds (void) const {
147 return int(seconds() - ( (ValueType)minutes() * (ValueType)60 ));
148 }
149
152 inline int TimeSpan::lastNSeconds (void) const {
153 return int(m_nsecs % Time::SEC_NSECS);
154 }
155
157 inline TimeSpan &TimeSpan::operator+= (const TimeSpan &x) {
158 m_nsecs += x.m_nsecs;
159 return *this;
160 }
161
163 inline TimeSpan & TimeSpan::operator-= (const TimeSpan &x) {
164 m_nsecs -= x.m_nsecs;
165 return *this;
166 }
167
169 inline TimeSpan & TimeSpan::operator*= (const TimeSpan &x) {
170 m_nsecs *= x.m_nsecs;
171 return *this;
172 }
173
175 inline TimeSpan & TimeSpan::operator/= (const TimeSpan &x) {
176 m_nsecs /= x.m_nsecs; return *this;
177 }
178
180 inline TimeSpan & TimeSpan::operator%= (const TimeSpan &x) {
181 m_nsecs %= x.m_nsecs; return *this;
182 }
183
185 inline std::ostream& operator<< (std::ostream &out, const Gaudi::Time &time) {
186 return out << Gaudi::TimeSpan(time).seconds() << '.' << time.nanoformat();
187 }
188
190 inline std::ostream& operator<< (std::ostream &out, const Gaudi::TimeSpan &time) {
191 return out << time.seconds() << '.' << Gaudi::Time(time).nanoformat();
192 }
193 }
194
195 //<<<<<< INLINE PUBLIC FUNCTIONS >>>>>>
196 inline Gaudi::Time operator+ (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
197 return Gaudi::Time (t.ns() + ts.ns());
198 }
199
200 inline Gaudi::Time operator+ (const Gaudi::TimeSpan &ts, const Gaudi::Time &t) {
201 return Gaudi::Time (t.ns() + ts.ns());
202 }
203
204 inline Gaudi::TimeSpan operator- (const Gaudi::Time &t1, const Gaudi::Time &t2) {
205 return Gaudi::TimeSpan (t1.ns() - t2.ns());
206 }
207
208 inline Gaudi::Time operator- (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
209 return Gaudi::Time (t.ns() - ts.ns());
210 }
211
212 //inline Gaudi::TimeSpan operator* (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
213 // return Gaudi::TimeSpan (t.ns() * ts.ns());
214 //}
215
216 //inline Gaudi::TimeSpan operator/ (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
217 // return Gaudi::TimeSpan (t.ns() / ts.ns());
218 //}
219
220 //inline Gaudi::TimeSpan operator% (const Gaudi::Time &t, const Gaudi::TimeSpan &ts) {
221 // return Gaudi::TimeSpan (t.ns() % ts.ns());
222 //}
223
224 inline bool operator== (const Gaudi::Time &t1, const Gaudi::Time &t2) {
225 return t1.ns() == t2.ns();
226 }
227
228 inline bool operator!= (const Gaudi::Time &t1, const Gaudi::Time &t2) {
229 return t1.ns() != t2.ns();
230 }
231
232 inline bool operator< (const Gaudi::Time &t1, const Gaudi::Time &t2) {
233 return t1.ns() < t2.ns();
234 }
235
236 inline bool operator<= (const Gaudi::Time &t1, const Gaudi::Time &t2) {
237 return t1.ns() <= t2.ns();
238 }
239
240 inline bool operator> (const Gaudi::Time &t1, const Gaudi::Time &t2) {
241 return t1.ns() > t2.ns();
242 }
243
244 inline bool operator>= (const Gaudi::Time &t1, const Gaudi::Time &t2) {
245 return t1.ns() >= t2.ns();
246 }
247
248 inline bool operator! (const Gaudi::Time &t) {
249 return ! t.ns();
250 }
251
255
256 inline Gaudi::TimeSpan operator+ (const Gaudi::TimeSpan &ts) {
257 return ts;
258 }
259
260 inline Gaudi::TimeSpan operator- (const Gaudi::TimeSpan &ts) {
261 return Gaudi::TimeSpan (-ts.ns());
262 }
263
264 inline Gaudi::TimeSpan operator+ (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
265 return Gaudi::TimeSpan (ts1.ns() + ts2.ns());
266 }
267
268 inline Gaudi::TimeSpan operator- (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
269 return Gaudi::TimeSpan (ts1.ns() - ts2.ns());
270 }
271
272 //inline Gaudi::TimeSpan operator* (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
273 // return Gaudi::TimeSpan (ts1.ns() * ts2.ns());
274 //}
275
276 //inline Gaudi::TimeSpan operator/ (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
277 // return Gaudi::TimeSpan (ts1.ns() / ts2.ns());
278 //}
279
280 //inline Gaudi::TimeSpan operator% (const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2) {
281 // return Gaudi::TimeSpan (ts1.ns() % ts2.ns());
282 //}
283
284 inline bool operator== (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
285 return t1.ns() == t2.ns();
286 }
287
288 inline bool operator!= (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
289 return t1.ns() != t2.ns();
290 }
291
292 inline bool operator< (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
293 return t1.ns() < t2.ns();
294 }
295
296 inline bool operator<= (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
297 return t1.ns() <= t2.ns();
298 }
299
300 inline bool operator> (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
301 return t1.ns() > t2.ns();
302 }
303
304 inline bool operator>= (const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2) {
305 return t1.ns() >= t2.ns();
306 }
307
308 inline bool operator! (const Gaudi::TimeSpan &ts) {
309 return ! ts.ns();
310 }
311
312 // --- operators for serialization ---
313
314 // Output serialization
315 inline StreamBuffer& operator<<(StreamBuffer &s, const Gaudi::Time &t) {
316 return s << t.ns();
317 }
318 // Input serialization
319 inline StreamBuffer& operator>>(StreamBuffer &s, Gaudi::Time &t) {
320 Gaudi::Time::ValueType tmp;
321 s >> tmp;
322 t = Gaudi::Time(tmp);
323 return s;
324 }
325
326 #endif
Gaudi::Time::ValueType
longlong ValueType
Definition: Time.h:216
Gaudi::TimeSpan::seconds
ValueType seconds(void) const
Get the number of complete seconds in the span.
Definition: Time.icpp:123
Gaudi::TimeSpan::ns
ValueType ns(void) const
Return the time span as nanoseconds.
Definition: Time.icpp:128
Gaudi::operator<<
GAUDI_API std::ostream & operator<<(std::ostream &o, const Gaudi::Histo1DDef &histo)
the streamer operator for class Gaudi::Histo1DDef
Definition: HistoDef.cpp:109
Gaudi::operator!=
bool operator!=(const T &v, const Property< TP, V, H > &p)
delegate (value != property) to property operator!=
Definition: Property.h:645
Gaudi::Time::SECS_PER_HOUR
static const int SECS_PER_HOUR
Seconds in one hour hour.
Definition: Time.h:238
Gaudi::operator==
bool operator==(const T &v, const Property< TP, V, H > &p)
delegate (value == property) to property operator==
Definition: Property.h:638
operator!
bool operator!(const Gaudi::Time &t)
Definition: Time.icpp:248
Gaudi::TimeSpan::operator/=
TimeSpan & operator/=(const TimeSpan &n)
Divide a time span.
Definition: Time.icpp:175
StreamBuffer
The stream buffer is a small object collecting object data.
Definition: StreamBuffer.h:41
Gaudi::TimeSpan::days
int days(void) const
Get the number of complete days in the span.
Definition: Time.icpp:108
Gaudi::TimeSpan::m_nsecs
ValueType m_nsecs
Definition: Time.h:86
operator<=
bool operator<=(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:236
Gaudi::TimeSpan::lastMinutes
int lastMinutes(void) const
Get the number of complete minutes in the last incomplete hour of the span.
Definition: Time.icpp:140
plotSpeedupsPyRoot.time
time
Definition: plotSpeedupsPyRoot.py:146
operator>=
bool operator>=(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:244
Gaudi::TimeSpan::lastNSeconds
int lastNSeconds(void) const
Get the number of nanoseconds in the last incomplete second of the span.
Definition: Time.icpp:152
operator-
Gaudi::TimeSpan operator-(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:204
Gaudi::Time::TimeAssert
void TimeAssert(bool cond, const std::string &msg="time assertion failed") const
Definition: Time.h:298
Gaudi::TimeSpan::operator*=
TimeSpan & operator*=(const TimeSpan &n)
Multiply a time span.
Definition: Time.icpp:169
Gaudi::TimeSpan::lastSeconds
int lastSeconds(void) const
Get the number of complete seconds in the last incomplete minute of the span.
Definition: Time.icpp:146
Gaudi::Time::ns
ValueType ns(void) const
Return the time as nanoseconds since 00:00:00 on January 1, 1970 in UTC.
Definition: Time.icpp:32
Gaudi::TimeSpan::operator+=
TimeSpan & operator+=(const TimeSpan &x)
Add to a time span.
Definition: Time.icpp:157
Gaudi::Time::SEC_NSECS
static const ValueType SEC_NSECS
Nanoseconds in one second.
Definition: Time.h:241
compareRootHistos.ts
tuple ts
Definition: compareRootHistos.py:342
__longlong
Definition: Kernel.h:56
Gaudi::Time
Based on seal::Time.
Definition: Time.h:213
Gaudi::TimeSpan::operator-=
TimeSpan & operator-=(const TimeSpan &x)
Subtract from a time span.
Definition: Time.icpp:163
operator>
bool operator>(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:240
Gaudi::TimeSpan::minutes
int minutes(void) const
Get the number of complete minutes in the span.
Definition: Time.icpp:118
Gaudi::Time::nanoformat
std::string nanoformat(size_t minwidth=1, size_t maxwidth=9) const
Format the nanosecond fractional part of the time as a string.
Definition: Time.cpp:322
Gaudi::TimeSpan::operator%=
TimeSpan & operator%=(const TimeSpan &n)
Compute a modulo of a time span.
Definition: Time.icpp:180
Gaudi::Time::operator+=
Time & operator+=(const TimeSpan &x)
Add the specified amount to the time.
Definition: Time.icpp:38
Gaudi::Time::isLeap
static bool isLeap(int year)
Check if the year is a leap-year.
Definition: Time.icpp:63
Gaudi::Time::epoch
static Time epoch(void)
Returns the minimum time.
Definition: Time.icpp:53
Gaudi::Time::m_nsecs
ValueType m_nsecs
Definition: Time.h:296
Gaudi::TimeSpan::lastHours
int lastHours(void) const
Get the number of complete hours in the last incomplete day of the span.
Definition: Time.icpp:134
gaudirun.s
string s
Definition: gaudirun.py:245
Gaudi::Time::SECS_PER_DAY
static const int SECS_PER_DAY
Seconds in 24 hours.
Definition: Time.h:235
Gaudi::Time::Time
Time(void)
Initialize an empty (zero) time value.
Definition: Time.icpp:9
Gaudi::TimeSpan::TimeSpan
TimeSpan(void)
Initialize an empty (zero) time difference.
Definition: Time.icpp:73
operator>>
StreamBuffer & operator>>(StreamBuffer &s, Gaudi::Time &t)
Definition: Time.icpp:319
operator<
bool operator<(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:232
Gaudi::Time::operator-=
Time & operator-=(const TimeSpan &x)
Subtract the specified amount from the time.
Definition: Time.icpp:46
Gaudi::Time::year
int year(bool local) const
Get the year.
Definition: Time.cpp:175
Gaudi::TimeSpan
Based on seal::TimeSpan.
Definition: Time.h:56
std::ostream
STL class.
Gaudi::Time::max
static Time max(void)
Returns the maximum time.
Definition: Time.icpp:58
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
Gaudi::operator+
decltype(std::declval< TP >()+std::declval< T >()) operator+(const T &v, const Property< TP, V, H > &p)
implemantation of (value + property)
Definition: Property.h:652
Gaudi::TimeSpan::hours
int hours(void) const
Get the number of complete hours in the span.
Definition: Time.icpp:113