| The Gaudi Framework v29r0 (ff2e7097)

- 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 {
8
11 inline Time::Time( ValueType nsecs ) : m_nsecs( nsecs )
12 {
13 TimeAssert( m_nsecs >= 0, "cannot create a negative time" );
14 }
15
18 inline Time::Time( TimeSpan ts ) : m_nsecs( ts.m_nsecs )
19 {
20 TimeAssert( m_nsecs >= 0, "cannot create a negative time" );
21 }
22
25 inline Time::Time( ValueType secs, int nsecs ) : m_nsecs( secs * Time::SEC_NSECS + nsecs )
26 {
27 TimeAssert( m_nsecs >= 0, "cannot create a negative time" );
28 }
29
32 inline Time::ValueType Time::ns() const { return m_nsecs; }
33
36 inline Time& Time::operator+=( const TimeSpan& x )
37 {
38 TimeAssert( m_nsecs >= -x.m_nsecs, "time operation lead to negative time" );
39 m_nsecs += x.m_nsecs;
40 return *this;
41 }
42
45 inline Time& Time::operator-=( const TimeSpan& x )
46 {
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() { return 0LL; }
54
56 inline Time Time::max() { return 0x7fffffffffffffffLL; }
57
59 inline bool Time::isLeap( int year )
60 {
61 return ( ( year % 4 ) == 0 && ( ( year % 100 ) != 0 || ( year % 400 ) == 0 ) );
62 }
63
67
69 inline TimeSpan::TimeSpan( Time t ) : m_nsecs( t.m_nsecs ) {}
70
72 inline TimeSpan::TimeSpan( ValueType nsecs ) : m_nsecs( nsecs ) {}
73
82 inline TimeSpan::TimeSpan( ValueType secs, int nsecs ) : m_nsecs( secs * Time::SEC_NSECS + nsecs ) {}
83
95 inline TimeSpan::TimeSpan( int days, int hours, int mins, int secs, int nsecs )
96 {
97 m_nsecs = ( secs + 60 * ( mins + 60 * ( hours + 24 * days ) ) ) * Time::SEC_NSECS + nsecs;
98 }
99
101 inline int TimeSpan::days() const { return int( m_nsecs / Time::SEC_NSECS / Time::SECS_PER_DAY ); }
102
104 inline int TimeSpan::hours() const { return int( m_nsecs / Time::SEC_NSECS / Time::SECS_PER_HOUR ); }
105
107 inline int TimeSpan::minutes() const { return int( m_nsecs / Time::SEC_NSECS / 60 ); }
108
110 inline TimeSpan::ValueType TimeSpan::seconds() const { return m_nsecs / Time::SEC_NSECS; }
111
113 inline TimeSpan::ValueType TimeSpan::ns() const { return m_nsecs; }
114
117 inline int TimeSpan::lastHours() const { return hours() - days() * 24; }
118
121 inline int TimeSpan::lastMinutes() const { return minutes() - hours() * 60; }
122
125 inline int TimeSpan::lastSeconds() const { return int( seconds() - ( (ValueType)minutes() * (ValueType)60 ) ); }
126
129 inline int TimeSpan::lastNSeconds() const { return int( m_nsecs % Time::SEC_NSECS ); }
130
132 inline TimeSpan& TimeSpan::operator+=( const TimeSpan& x )
133 {
134 m_nsecs += x.m_nsecs;
135 return *this;
136 }
137
139 inline TimeSpan& TimeSpan::operator-=( const TimeSpan& x )
140 {
141 m_nsecs -= x.m_nsecs;
142 return *this;
143 }
144
146 inline TimeSpan& TimeSpan::operator*=( const TimeSpan& x )
147 {
148 m_nsecs *= x.m_nsecs;
149 return *this;
150 }
151
153 inline TimeSpan& TimeSpan::operator/=( const TimeSpan& x )
154 {
155 m_nsecs /= x.m_nsecs;
156 return *this;
157 }
158
160 inline TimeSpan& TimeSpan::operator%=( const TimeSpan& x )
161 {
162 m_nsecs %= x.m_nsecs;
163 return *this;
164 }
165
167 inline std::ostream& operator<<( std::ostream& out, const Gaudi::Time& time )
168 {
169 return out << Gaudi::TimeSpan( time ).seconds() << '.' << time.nanoformat();
170 }
171
173 inline std::ostream& operator<<( std::ostream& out, const Gaudi::TimeSpan& time )
174 {
175 return out << time.seconds() << '.' << Gaudi::Time( time ).nanoformat();
176 }
177 }
178
179 //<<<<<< INLINE PUBLIC FUNCTIONS >>>>>>
180 inline Gaudi::Time operator+( const Gaudi::Time& t, const Gaudi::TimeSpan& ts )
181 {
182 return Gaudi::Time( t.ns() + ts.ns() );
183 }
184
185 inline Gaudi::Time operator+( const Gaudi::TimeSpan& ts, const Gaudi::Time& t )
186 {
187 return Gaudi::Time( t.ns() + ts.ns() );
188 }
189
190 inline Gaudi::TimeSpan operator-( const Gaudi::Time& t1, const Gaudi::Time& t2 )
191 {
192 return Gaudi::TimeSpan( t1.ns() - t2.ns() );
193 }
194
195 inline Gaudi::Time operator-( const Gaudi::Time& t, const Gaudi::TimeSpan& ts )
196 {
197 return Gaudi::Time( t.ns() - ts.ns() );
198 }
199
200 inline bool operator!( const Gaudi::Time& t ) { return !t.ns(); }
201
205
206 inline Gaudi::TimeSpan operator+( const Gaudi::TimeSpan& ts ) { return ts; }
207
208 inline Gaudi::TimeSpan operator-( const Gaudi::TimeSpan& ts ) { return Gaudi::TimeSpan( -ts.ns() ); }
209
210 inline bool operator!( const Gaudi::TimeSpan& ts ) { return !ts.ns(); }
211
212 // --- operators for serialization ---
213
214 // Output serialization
215 inline StreamBuffer& operator<<( StreamBuffer& s, const Gaudi::Time& t ) { return s << t.ns(); }
216 // Input serialization
217 inline StreamBuffer& operator>>( StreamBuffer& s, Gaudi::Time& t )
218 {
219 Gaudi::Time::ValueType tmp;
220 s >> tmp;
221 t = Gaudi::Time( tmp );
222 return s;
223 }
224
225 // make sure that "namespace Gaudi { using ::operator<; }" continues to compile...
226 // to be removed once all instances of the above have been removed from user code...
227 class backwards_compatibility_hack_time_timespan
228 {
229 backwards_compatibility_hack_time_timespan() = delete;
230 };
231 inline bool operator<( backwards_compatibility_hack_time_timespan, backwards_compatibility_hack_time_timespan )
232 {
233 return false;
234 }
235
236 #endif
Gaudi::Time::ValueType
longlong ValueType
Definition: Time.h:242
Gaudi::Time::Time
Time()=default
Initialize an empty (zero) time value.
Gaudi::operator<<
GAUDI_API std::ostream & operator<<(std::ostream &o, const Gaudi::Histo1DDef &histo)
the streamer operator for class Gaudi::Histo1DDef
Definition: HistoDef.cpp:94
Gaudi::Time::SECS_PER_HOUR
static const int SECS_PER_HOUR
Seconds in one hour hour.
Definition: Time.h:264
Gaudi::Time::max
static Time max()
Returns the maximum time.
Definition: Time.icpp:56
operator!
bool operator!(const Gaudi::Time &t)
Definition: Time.icpp:200
Gaudi::TimeSpan::operator/=
TimeSpan & operator/=(const TimeSpan &n)
Divide a time span.
Definition: Time.icpp:153
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:111
plotSpeedupsPyRoot.time
time
Definition: plotSpeedupsPyRoot.py:154
Gaudi::Time::TimeAssert
void TimeAssert(bool cond, const std::string &msg="time assertion failed") const
Definition: Time.h:337
Gaudi::TimeSpan::operator*=
TimeSpan & operator*=(const TimeSpan &n)
Multiply a time span.
Definition: Time.icpp:146
Gaudi::TimeSpan::operator+
friend Gaudi::TimeSpan operator+(const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2)
Definition: Time.h:100
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:132
Gaudi::TimeSpan::lastNSeconds
int lastNSeconds() const
Get the number of nanoseconds in the last incomplete second of the span.
Definition: Time.icpp:129
Gaudi::Time::SEC_NSECS
static const ValueType SEC_NSECS
Nanoseconds in one second.
Definition: Time.h:267
compareRootHistos.ts
tuple ts
Definition: compareRootHistos.py:414
Gaudi::TimeSpan::ns
ValueType ns() const
Return the time span as nanoseconds.
Definition: Time.icpp:113
backwards_compatibility_hack_time_timespan
Definition: Time.icpp:227
__longlong
Definition: Kernel.h:56
Gaudi::Time
Based on seal::Time.
Definition: Time.h:237
Gaudi::TimeSpan::days
int days() const
Get the number of complete days in the span.
Definition: Time.icpp:101
Gaudi::TimeSpan::operator-=
TimeSpan & operator-=(const TimeSpan &x)
Subtract from a time span.
Definition: Time.icpp:139
Gaudi::TimeSpan::lastMinutes
int lastMinutes() const
Get the number of complete minutes in the last incomplete hour of the span.
Definition: Time.icpp:121
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:303
Gaudi::TimeSpan::operator%=
TimeSpan & operator%=(const TimeSpan &n)
Compute a modulo of a time span.
Definition: Time.icpp:160
Gaudi::Time::operator+=
Time & operator+=(const TimeSpan &x)
Add the specified amount to the time.
Definition: Time.icpp:36
Gaudi::TimeSpan::hours
int hours() const
Get the number of complete hours in the span.
Definition: Time.icpp:104
Gaudi::Time::isLeap
static bool isLeap(int year)
Check if the year is a leap-year.
Definition: Time.icpp:59
Gaudi::TimeSpan::seconds
ValueType seconds() const
Get the number of complete seconds in the span.
Definition: Time.icpp:110
Gaudi::Time::m_nsecs
ValueType m_nsecs
Definition: Time.h:335
gaudirun.s
string s
Definition: gaudirun.py:253
Gaudi::Time::SECS_PER_DAY
static const int SECS_PER_DAY
Seconds in 24 hours.
Definition: Time.h:261
Gaudi::Time::epoch
static Time epoch()
Returns the minimum time.
Definition: Time.icpp:53
Gaudi::Time::ns
ValueType ns() const
Return the time as nanoseconds since 00:00:00 on January 1, 1970 in UTC.
Definition: Time.icpp:32
operator>>
StreamBuffer & operator>>(StreamBuffer &s, Gaudi::Time &t)
Definition: Time.icpp:217
Gaudi::TimeSpan::operator-
friend Gaudi::TimeSpan operator-(const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2)
Definition: Time.h:105
Gaudi::Time::operator-=
Time & operator-=(const TimeSpan &x)
Subtract the specified amount from the time.
Definition: Time.icpp:45
Gaudi::Time::year
int year(bool local) const
Get the year.
Definition: Time.cpp:172
Gaudi::TimeSpan::operator<
friend bool operator<(const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2)
Definition: Time.h:92
Gaudi::TimeSpan
Based on seal::TimeSpan.
Definition: Time.h:55
std::ostream
STL class.
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
Gaudi::TimeSpan::lastHours
int lastHours() const
Get the number of complete hours in the last incomplete day of the span.
Definition: Time.icpp:117
Gaudi::TimeSpan::lastSeconds
int lastSeconds() const
Get the number of complete seconds in the last incomplete minute of the span.
Definition: Time.icpp:125
Gaudi::TimeSpan::minutes
int minutes() const
Get the number of complete minutes in the span.
Definition: Time.icpp:107