The Gaudi Framework  v28r3 (cc1cf868)
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 
10  inline Time::Time (ValueType nsecs): m_nsecs(nsecs) {
11  TimeAssert( m_nsecs >= 0, "cannot create a negative time");
12  }
13 
17  TimeAssert( m_nsecs >= 0, "cannot create a negative time");
18  }
19 
22  inline Time::Time (ValueType secs, int nsecs)
23  : m_nsecs(secs * Time::SEC_NSECS + nsecs) {
24  TimeAssert( m_nsecs >= 0, "cannot create a negative time");
25  }
26 
29  inline Time::ValueType Time::ns() const {
30  return m_nsecs;
31  }
32 
35  inline Time &Time::operator+= (const TimeSpan &x) {
36  TimeAssert( m_nsecs >= -x.m_nsecs, "time operation lead to negative time");
37  m_nsecs += x.m_nsecs;
38  return *this;
39  }
40 
43  inline Time &Time::operator-= (const TimeSpan &x) {
44  TimeAssert( m_nsecs >= x.m_nsecs, "time operation lead to negative time");
45  m_nsecs -= x.m_nsecs;
46  return *this;
47  }
48 
50  inline Time Time::epoch() {
51  return 0LL;
52  }
53 
55  inline Time Time::max() {
56  return 0x7fffffffffffffffLL;
57  }
58 
60  inline bool Time::isLeap (int year) {
61  return ((year % 4) == 0
62  && ((year % 100) != 0
63  || (year % 400) == 0));
64  }
65 
69 
72 
74  inline TimeSpan::TimeSpan (ValueType nsecs): m_nsecs (nsecs) {}
75 
84  inline TimeSpan::TimeSpan (ValueType secs, int nsecs)
85  : m_nsecs(secs * Time::SEC_NSECS + nsecs) {}
86 
98  inline TimeSpan::TimeSpan (int days, int hours, int mins, int secs, int nsecs) {
99  m_nsecs = (secs + 60 * (mins + 60 * (hours + 24*days)))*Time::SEC_NSECS + nsecs;
100  }
101 
103  inline int TimeSpan::days() const {
105  }
106 
108  inline int TimeSpan::hours() const {
110  }
111 
113  inline int TimeSpan::minutes() const {
114  return int(m_nsecs / Time::SEC_NSECS / 60);
115  }
116 
119  return m_nsecs / Time::SEC_NSECS;
120  }
121 
124  return m_nsecs;
125  }
126 
129  inline int TimeSpan::lastHours() const {
130  return hours () - days () * 24;
131  }
132 
135  inline int TimeSpan::lastMinutes() const {
136  return minutes () - hours () * 60;
137  }
138 
141  inline int TimeSpan::lastSeconds() const {
142  return int(seconds() - ( (ValueType)minutes() * (ValueType)60 ));
143  }
144 
147  inline int TimeSpan::lastNSeconds() const {
148  return int(m_nsecs % Time::SEC_NSECS);
149  }
150 
153  m_nsecs += x.m_nsecs;
154  return *this;
155  }
156 
159  m_nsecs -= x.m_nsecs;
160  return *this;
161  }
162 
165  m_nsecs *= x.m_nsecs;
166  return *this;
167  }
168 
171  m_nsecs /= x.m_nsecs; return *this;
172  }
173 
176  m_nsecs %= x.m_nsecs; return *this;
177  }
178 
181  return out << Gaudi::TimeSpan(time).seconds() << '.' << time.nanoformat();
182  }
183 
186  return out << time.seconds() << '.' << Gaudi::Time(time).nanoformat();
187  }
188 }
189 
190 //<<<<<< INLINE PUBLIC FUNCTIONS >>>>>>
192  return Gaudi::Time (t.ns() + ts.ns());
193 }
194 
196  return Gaudi::Time (t.ns() + ts.ns());
197 }
198 
199 inline Gaudi::TimeSpan operator- (const Gaudi::Time &t1, const Gaudi::Time &t2) {
200  return Gaudi::TimeSpan (t1.ns() - t2.ns());
201 }
202 
204  return Gaudi::Time (t.ns() - ts.ns());
205 }
206 
207 
208 inline bool operator! (const Gaudi::Time &t) {
209  return ! t.ns();
210 }
211 
215 
217  return ts;
218 }
219 
221  return Gaudi::TimeSpan (-ts.ns());
222 }
223 
224 inline bool operator! (const Gaudi::TimeSpan &ts) {
225  return ! ts.ns();
226 }
227 
228 // --- operators for serialization ---
229 
230 // Output serialization
232  return s << t.ns();
233 }
234 // Input serialization
237  s >> tmp;
238  t = Gaudi::Time(tmp);
239  return s;
240 }
241 
242 // make sure that "namespace Gaudi { using ::operator<; }" continues to compile...
243 // to be removed once all instances of the above have been removed from user code...
246  return false;
247 }
248 
249 #endif
longlong ValueType
Definition: Time.h:239
Time()=default
Initialize an empty (zero) time value.
GAUDI_API std::ostream & operator<<(std::ostream &o, const Gaudi::Histo1DDef &histo)
the streamer operator for class Gaudi::Histo1DDef
Definition: HistoDef.cpp:109
static const int SECS_PER_HOUR
Seconds in one hour hour.
Definition: Time.h:261
static Time max()
Returns the maximum time.
Definition: Time.icpp:55
bool operator!(const Gaudi::Time &t)
Definition: Time.icpp:208
TimeSpan & operator/=(const TimeSpan &n)
Divide a time span.
Definition: Time.icpp:170
The stream buffer is a small object collecting object data.
Definition: StreamBuffer.h:41
ValueType m_nsecs
Definition: Time.h:109
void TimeAssert(bool cond, const std::string &msg="time assertion failed") const
Definition: Time.h:341
TimeSpan & operator*=(const TimeSpan &n)
Multiply a time span.
Definition: Time.icpp:164
friend Gaudi::TimeSpan operator+(const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2)
Definition: Time.h:102
TimeSpan()=default
Initialize an empty (zero) time difference.
TimeSpan & operator+=(const TimeSpan &x)
Add to a time span.
Definition: Time.icpp:152
int lastNSeconds() const
Get the number of nanoseconds in the last incomplete second of the span.
Definition: Time.icpp:147
static const ValueType SEC_NSECS
Nanoseconds in one second.
Definition: Time.h:264
ValueType ns() const
Return the time span as nanoseconds.
Definition: Time.icpp:123
Based on seal::Time.
Definition: Time.h:236
int days() const
Get the number of complete days in the span.
Definition: Time.icpp:103
TimeSpan & operator-=(const TimeSpan &x)
Subtract from a time span.
Definition: Time.icpp:158
int lastMinutes() const
Get the number of complete minutes in the last incomplete hour of the span.
Definition: Time.icpp:135
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
TimeSpan & operator%=(const TimeSpan &n)
Compute a modulo of a time span.
Definition: Time.icpp:175
Time & operator+=(const TimeSpan &x)
Add the specified amount to the time.
Definition: Time.icpp:35
int hours() const
Get the number of complete hours in the span.
Definition: Time.icpp:108
static bool isLeap(int year)
Check if the year is a leap-year.
Definition: Time.icpp:60
ValueType seconds() const
Get the number of complete seconds in the span.
Definition: Time.icpp:118
ValueType m_nsecs
Definition: Time.h:339
string s
Definition: gaudirun.py:245
static const int SECS_PER_DAY
Seconds in 24 hours.
Definition: Time.h:258
static Time epoch()
Returns the minimum time.
Definition: Time.icpp:50
ValueType ns() const
Return the time as nanoseconds since 00:00:00 on January 1, 1970 in UTC.
Definition: Time.icpp:29
StreamBuffer & operator>>(StreamBuffer &s, Gaudi::Time &t)
Definition: Time.icpp:235
friend Gaudi::TimeSpan operator-(const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2)
Definition: Time.h:105
Time & operator-=(const TimeSpan &x)
Subtract the specified amount from the time.
Definition: Time.icpp:43
int year(bool local) const
Get the year.
Definition: Time.cpp:175
friend bool operator<(const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2)
Definition: Time.h:90
Based on seal::TimeSpan.
Definition: Time.h:53
STL class.
Helper functions to set/get the application return code.
Definition: __init__.py:1
int lastHours() const
Get the number of complete hours in the last incomplete day of the span.
Definition: Time.icpp:129
int lastSeconds() const
Get the number of complete seconds in the last incomplete minute of the span.
Definition: Time.icpp:141
int minutes() const
Get the number of complete minutes in the span.
Definition: Time.icpp:113