| The Gaudi Framework v32r1 (f65d50dc)

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
16 inline Time::Time( TimeSpan ts ) : m_nsecs( ts.m_nsecs ) {
17 TimeAssert( m_nsecs >= 0, "cannot create a negative time" );
18 }
19
22 inline Time::Time( ValueType secs, int nsecs ) : m_nsecs( secs * Time::SEC_NSECS + nsecs ) {
23 TimeAssert( m_nsecs >= 0, "cannot create a negative time" );
24 }
25
28 inline Time::ValueType Time::ns() const { return m_nsecs; }
29
32 inline Time& Time::operator+=( const TimeSpan& x ) {
33 TimeAssert( m_nsecs >= -x.m_nsecs, "time operation lead to negative time" );
34 m_nsecs += x.m_nsecs;
35 return *this;
36 }
37
40 inline Time& Time::operator-=( const TimeSpan& x ) {
41 TimeAssert( m_nsecs >= x.m_nsecs, "time operation lead to negative time" );
42 m_nsecs -= x.m_nsecs;
43 return *this;
44 }
45
47 inline Time Time::epoch() { return 0LL; }
48
50 inline Time Time::max() { return 0x7fffffffffffffffLL; }
51
53 inline bool Time::isLeap( int year ) {
54 return ( ( year % 4 ) == 0 && ( ( year % 100 ) != 0 || ( year % 400 ) == 0 ) );
55 }
56
60
62 inline TimeSpan::TimeSpan( Time t ) : m_nsecs( t.m_nsecs ) {}
63
65 inline TimeSpan::TimeSpan( ValueType nsecs ) : m_nsecs( nsecs ) {}
66
75 inline TimeSpan::TimeSpan( ValueType secs, int nsecs ) : m_nsecs( secs * Time::SEC_NSECS + nsecs ) {}
76
88 inline TimeSpan::TimeSpan( int days, int hours, int mins, int secs, int nsecs ) {
89 m_nsecs = ( secs + 60 * ( mins + 60 * ( hours + 24 * days ) ) ) * Time::SEC_NSECS + nsecs;
90 }
91
93 inline int TimeSpan::days() const { return int( m_nsecs / Time::SEC_NSECS / Time::SECS_PER_DAY ); }
94
96 inline int TimeSpan::hours() const { return int( m_nsecs / Time::SEC_NSECS / Time::SECS_PER_HOUR ); }
97
99 inline int TimeSpan::minutes() const { return int( m_nsecs / Time::SEC_NSECS / 60 ); }
100
102 inline TimeSpan::ValueType TimeSpan::seconds() const { return m_nsecs / Time::SEC_NSECS; }
103
105 inline TimeSpan::ValueType TimeSpan::ns() const { return m_nsecs; }
106
109 inline int TimeSpan::lastHours() const { return hours() - days() * 24; }
110
113 inline int TimeSpan::lastMinutes() const { return minutes() - hours() * 60; }
114
117 inline int TimeSpan::lastSeconds() const { return int( seconds() - ( (ValueType)minutes() * (ValueType)60 ) ); }
118
121 inline int TimeSpan::lastNSeconds() const { return int( m_nsecs % Time::SEC_NSECS ); }
122
124 inline TimeSpan& TimeSpan::operator+=( const TimeSpan& x ) {
125 m_nsecs += x.m_nsecs;
126 return *this;
127 }
128
130 inline TimeSpan& TimeSpan::operator-=( const TimeSpan& x ) {
131 m_nsecs -= x.m_nsecs;
132 return *this;
133 }
134
136 inline TimeSpan& TimeSpan::operator*=( const TimeSpan& x ) {
137 m_nsecs *= x.m_nsecs;
138 return *this;
139 }
140
142 inline TimeSpan& TimeSpan::operator/=( const TimeSpan& x ) {
143 m_nsecs /= x.m_nsecs;
144 return *this;
145 }
146
148 inline TimeSpan& TimeSpan::operator%=( const TimeSpan& x ) {
149 m_nsecs %= x.m_nsecs;
150 return *this;
151 }
152
154 inline std::ostream& operator<<( std::ostream& out, const Gaudi::Time& time ) {
155 return out << Gaudi::TimeSpan( time ).seconds() << '.' << time.nanoformat();
156 }
157
159 inline std::ostream& operator<<( std::ostream& out, const Gaudi::TimeSpan& time ) {
160 return out << time.seconds() << '.' << Gaudi::Time( time ).nanoformat();
161 }
162 } // namespace Gaudi
163
164 //<<<<<< INLINE PUBLIC FUNCTIONS >>>>>>
165 inline Gaudi::Time operator+( const Gaudi::Time& t, const Gaudi::TimeSpan& ts ) {
166 return Gaudi::Time( t.ns() + ts.ns() );
167 }
168
169 inline Gaudi::Time operator+( const Gaudi::TimeSpan& ts, const Gaudi::Time& t ) {
170 return Gaudi::Time( t.ns() + ts.ns() );
171 }
172
173 inline Gaudi::TimeSpan operator-( const Gaudi::Time& t1, const Gaudi::Time& t2 ) {
174 return Gaudi::TimeSpan( t1.ns() - t2.ns() );
175 }
176
177 inline Gaudi::Time operator-( const Gaudi::Time& t, const Gaudi::TimeSpan& ts ) {
178 return Gaudi::Time( t.ns() - ts.ns() );
179 }
180
181 inline bool operator!( const Gaudi::Time& t ) { return !t.ns(); }
182
186
187 inline Gaudi::TimeSpan operator+( const Gaudi::TimeSpan& ts ) { return ts; }
188
189 inline Gaudi::TimeSpan operator-( const Gaudi::TimeSpan& ts ) { return Gaudi::TimeSpan( -ts.ns() ); }
190
191 inline bool operator!( const Gaudi::TimeSpan& ts ) { return !ts.ns(); }
192
193 // --- operators for serialization ---
194
195 // Output serialization
196 inline StreamBuffer& operator<<( StreamBuffer& s, const Gaudi::Time& t ) { return s << t.ns(); }
197 // Input serialization
198 inline StreamBuffer& operator>>( StreamBuffer& s, Gaudi::Time& t ) {
199 Gaudi::Time::ValueType tmp;
200 s >> tmp;
201 t = Gaudi::Time( tmp );
202 return s;
203 }
204
205 // make sure that "namespace Gaudi { using ::operator<; }" continues to compile...
206 // to be removed once all instances of the above have been removed from user code...
207 class backwards_compatibility_hack_time_timespan {
208 backwards_compatibility_hack_time_timespan() = delete;
209 };
210 inline bool operator<( backwards_compatibility_hack_time_timespan, backwards_compatibility_hack_time_timespan ) {
211 return false;
212 }
213
214 #endif
plotSpeedupsPyRoot.time
def time
Definition: plotSpeedupsPyRoot.py:152
Gaudi::Time::year
int year(bool local) const
Get the year.
Definition: Time.cpp:166
Gaudi::Time::Time
Time()=default
Initialize an empty (zero) time value.
Gaudi::TimeSpan::lastSeconds
int lastSeconds() const
Get the number of complete seconds in the last incomplete minute of the span.
Definition: Time.icpp:117
Gaudi::Time::SECS_PER_HOUR
static const int SECS_PER_HOUR
Seconds in one hour hour.
Definition: Time.h:257
Gaudi::Time::max
static Time max()
Returns the maximum time.
Definition: Time.icpp:50
operator!
bool operator!(const Gaudi::Time &t)
Definition: Time.icpp:181
Gaudi::TimeSpan::operator/=
TimeSpan & operator/=(const TimeSpan &n)
Divide a time span.
Definition: Time.icpp:142
StreamBuffer
The stream buffer is a small object collecting object data.
Definition: StreamBuffer.h:41
Gaudi::TimeSpan::m_nsecs
ValueType m_nsecs
Definition: Time.h:105
operator+
Gaudi::Time operator+(const Gaudi::Time &t, const Gaudi::TimeSpan &ts)
Definition: Time.icpp:165
Gaudi::TimeSpan::seconds
ValueType seconds() const
Get the number of complete seconds in the span.
Definition: Time.icpp:102
operator-
Gaudi::TimeSpan operator-(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:173
Gaudi::TimeSpan::TimeSpan
TimeSpan()=default
Initialize an empty (zero) time difference.
Gaudi::TimeSpan::operator+=
TimeSpan & operator+=(const TimeSpan &x)
Add to a time span.
Definition: Time.icpp:124
Gaudi::Time::SEC_NSECS
static const ValueType SEC_NSECS
Nanoseconds in one second.
Definition: Time.h:260
compareRootHistos.ts
tuple ts
Definition: compareRootHistos.py:447
Gaudi::TimeSpan::days
int days() const
Get the number of complete days in the span.
Definition: Time.icpp:93
backwards_compatibility_hack_time_timespan
Definition: Time.icpp:207
Gaudi::Time
Based on seal::Time.
Definition: Time.h:231
Gaudi::TimeSpan::operator-=
TimeSpan & operator-=(const TimeSpan &x)
Subtract from a time span.
Definition: Time.icpp:130
Gaudi::TimeSpan::lastHours
int lastHours() const
Get the number of complete hours in the last incomplete day of the span.
Definition: Time.icpp:109
operator<
bool operator<(backwards_compatibility_hack_time_timespan, backwards_compatibility_hack_time_timespan)
Definition: Time.icpp:210
Gaudi::TimeSpan::minutes
int minutes() const
Get the number of complete minutes in the span.
Definition: Time.icpp:99
Gaudi::Time::ns
ValueType ns() const
Return the time as nanoseconds since 00:00:00 on January 1, 1970 in UTC.
Definition: Time.icpp:28
Gaudi::TimeSpan::hours
int hours() const
Get the number of complete hours in the span.
Definition: Time.icpp:96
Gaudi::TimeSpan::operator%=
TimeSpan & operator%=(const TimeSpan &n)
Compute a modulo of a time span.
Definition: Time.icpp:148
Gaudi::Time::operator+=
Time & operator+=(const TimeSpan &x)
Add the specified amount to the time.
Definition: Time.icpp:32
Gaudi::Time::isLeap
static bool isLeap(int year)
Check if the year is a leap-year.
Definition: Time.icpp:53
Gaudi::Time::m_nsecs
ValueType m_nsecs
Definition: Time.h:328
Gaudi::TimeSpan::lastMinutes
int lastMinutes() const
Get the number of complete minutes in the last incomplete hour of the span.
Definition: Time.icpp:113
gaudirun.s
string s
Definition: gaudirun.py:316
Gaudi::Time::SECS_PER_DAY
static const int SECS_PER_DAY
Seconds in 24 hours.
Definition: Time.h:254
backwards_compatibility_hack_time_timespan::backwards_compatibility_hack_time_timespan
backwards_compatibility_hack_time_timespan()=delete
Gaudi::TimeSpan::ns
ValueType ns() const
Return the time span as nanoseconds.
Definition: Time.icpp:105
Gaudi::Time::epoch
static Time epoch()
Returns the minimum time.
Definition: Time.icpp:47
Gaudi::TimeSpan::operator *=
TimeSpan & operator *=(const TimeSpan &n)
Multiply a time span.
Definition: Time.icpp:136
operator>>
StreamBuffer & operator>>(StreamBuffer &s, Gaudi::Time &t)
Definition: Time.icpp:198
operator<<
StreamBuffer & operator<<(StreamBuffer &s, const Gaudi::Time &t)
Definition: Time.icpp:196
Gaudi::Time::operator-=
Time & operator-=(const TimeSpan &x)
Subtract the specified amount from the time.
Definition: Time.icpp:40
Gaudi::TimeSpan
Based on seal::TimeSpan.
Definition: Time.h:52
std::ostream
STL class.
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
Gaudi::Time::ValueType
long long ValueType
Definition: Time.h:235
Gaudi::TimeSpan::lastNSeconds
int lastNSeconds() const
Get the number of nanoseconds in the last incomplete second of the span.
Definition: Time.icpp:121
Gaudi::TimeSpan::ValueType
long long ValueType
Definition: Time.h:56
Gaudi::Time::TimeAssert
void TimeAssert(bool cond, const std::string &msg="time assertion failed") const
Definition: Time.h:330
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:292
Gaudi::operator<<
std::ostream & operator<<(std::ostream &o, const Gaudi::StringKey &key)
printout of the object reply on the native printout for the string
Definition: StringKey.h:235