| The Gaudi Framework v29r1 (5cd95fa2)

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

- File List
- File Members

Time.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_TIME_H
2 #define GAUDIKERNEL_TIME_H 1
3
4 // Include files
5 // for the architecture independent int64 definition (longlong)
6 #include "GaudiKernel/GaudiException.h"
7 #include "GaudiKernel/Kernel.h"
8 #include "GaudiKernel/StreamBuffer.h"
9
20 struct GAUDI_API TimeException : GaudiException {
21 // Standard constructor
22 TimeException( std::string Message = "unspecified exception", std::string Tag = "*Gaudi::Time*",
23 StatusCode Code = StatusCode::FAILURE )
24 : GaudiException( std::move( Message ), std::move( Tag ), std::move( Code ) )
25 {
26 }
27 };
28
29 struct tm;
30 #ifdef WIN32
31 typedef struct _FILETIME FILETIME;
32 #endif
33
34 namespace Gaudi
35 {
36
37 class Time;
38 class TimeSpan;
39
55 class GAUDI_API TimeSpan
56 {
57 friend class Time;
58
59 public:
60 typedef longlong ValueType;
61
63 TimeSpan() = default;
64
65 TimeSpan( Time t );
66 TimeSpan( ValueType nsecs );
67 TimeSpan( ValueType secs, int nsecs );
68 TimeSpan( int days, int hours, int mins, int secs, int nsecs );
69
70 int days() const;
71 int hours() const;
72 int minutes() const;
73 ValueType seconds() const;
74
75 int lastHours() const;
76 int lastMinutes() const;
77 int lastSeconds() const;
78 int lastNSeconds() const;
79
80 TimeSpan& operator+=( const TimeSpan& x );
81 TimeSpan& operator-=( const TimeSpan& x );
82 TimeSpan& operator*=( const TimeSpan& n );
83 TimeSpan& operator/=( const TimeSpan& n );
84 TimeSpan& operator%=( const TimeSpan& n );
85
86 ValueType ns() const;
87
88 friend bool operator==( const Gaudi::TimeSpan& t1, const Gaudi::TimeSpan& t2 ) { return t1.ns() == t2.ns(); }
89
90 friend bool operator!=( const Gaudi::TimeSpan& t1, const Gaudi::TimeSpan& t2 ) { return t1.ns() != t2.ns(); }
91
92 friend bool operator<( const Gaudi::TimeSpan& t1, const Gaudi::TimeSpan& t2 ) { return t1.ns() < t2.ns(); }
93
94 friend bool operator<=( const Gaudi::TimeSpan& t1, const Gaudi::TimeSpan& t2 ) { return t1.ns() <= t2.ns(); }
95
96 friend bool operator>( const Gaudi::TimeSpan& t1, const Gaudi::TimeSpan& t2 ) { return t1.ns() > t2.ns(); }
97
98 friend bool operator>=( const Gaudi::TimeSpan& t1, const Gaudi::TimeSpan& t2 ) { return t1.ns() >= t2.ns(); }
99
100 friend Gaudi::TimeSpan operator+( const Gaudi::TimeSpan& ts1, const Gaudi::TimeSpan& ts2 )
101 {
102 return Gaudi::TimeSpan( ts1.ns() + ts2.ns() );
103 }
104
105 friend Gaudi::TimeSpan operator-( const Gaudi::TimeSpan& ts1, const Gaudi::TimeSpan& ts2 )
106 {
107 return Gaudi::TimeSpan( ts1.ns() - ts2.ns() );
108 }
109
110 private:
111 ValueType m_nsecs = 0; //< The span length.
112 };
113
237 class GAUDI_API Time
238 {
239 friend class TimeSpan;
240
241 public:
242 typedef longlong ValueType;
243
245 enum Months {
246 January = 0,
247 February = 1,
248 March = 2,
249 April = 3,
250 May = 4,
251 June = 5,
252 July = 6,
253 August = 7,
254 September = 8,
255 October = 9,
256 November = 10,
257 December = 11
258 };
259
261 static const int SECS_PER_DAY = 86400;
262
264 static const int SECS_PER_HOUR = 3600;
265
267 static const ValueType SEC_NSECS = 1000000000;
268
270 Time() = default;
271
272 Time( TimeSpan ts );
273 Time( ValueType nsecs );
274 Time( ValueType secs, int nsecs );
275 Time( int year, int month, int day, int hour, int min, int sec, ValueType nsecs, bool local = true );
276 // implicit copy constructor
277 // implicit assignment operator
278 // implicit destructor
279
281 static Time epoch();
283 static Time max();
285 static Time current();
286 #ifdef WIN32
287 static Time from( const FILETIME* systime );
288 #endif
289 static Time build( bool local, const tm& base, TimeSpan diff = 0 );
290
291 tm split( bool local, int* nsecpart = 0 ) const;
292 tm utc( int* nsecpart = 0 ) const;
293 tm local( int* nsecpart = 0 ) const;
294
295 int year( bool local ) const;
296 int month( bool local ) const;
297 int day( bool local ) const;
298 int hour( bool local ) const;
299 int minute( bool local ) const;
300 int second( bool local ) const;
301 int nsecond() const;
302 int weekday( bool local ) const;
303 bool isdst( bool local ) const;
304
305 ValueType utcoffset( int* daylight = 0 ) const;
306 const char* timezone( int* daylight = 0 ) const;
307
308 Time& operator+=( const TimeSpan& x );
309 Time& operator-=( const TimeSpan& x );
310
311 ValueType ns() const;
312
313 std::string format( bool local, std::string spec = "%c" ) const;
314 std::string nanoformat( size_t minwidth = 1, size_t maxwidth = 9 ) const;
315
316 static bool isLeap( int year );
317
318 // Conversion helpers
319 static unsigned toDosDate( Time time );
320 static Time fromDosDate( unsigned dosDate );
321
322 friend bool operator==( const Gaudi::Time& t1, const Gaudi::Time& t2 ) { return t1.ns() == t2.ns(); }
323
324 friend bool operator!=( const Gaudi::Time& t1, const Gaudi::Time& t2 ) { return t1.ns() != t2.ns(); }
325
326 friend bool operator<( const Gaudi::Time& t1, const Gaudi::Time& t2 ) { return t1.ns() < t2.ns(); }
327
328 friend bool operator<=( const Gaudi::Time& t1, const Gaudi::Time& t2 ) { return t1.ns() <= t2.ns(); }
329
330 friend bool operator>( const Gaudi::Time& t1, const Gaudi::Time& t2 ) { return t1.ns() > t2.ns(); }
331
332 friend bool operator>=( const Gaudi::Time& t1, const Gaudi::Time& t2 ) { return t1.ns() >= t2.ns(); }
333
334 private:
335 ValueType m_nsecs = 0; //< Time value as nsecs from #epoch().
336
337 inline void TimeAssert( bool cond, const std::string& msg = "time assertion failed" ) const
338 {
339 if ( !cond ) throw TimeException( msg );
340 }
341 };
342 }
343
344 #include "GaudiKernel/Time.icpp"
345
346 #endif // GAUDIKERNEL_TIME_H
Gaudi::Time::ValueType
longlong ValueType
Definition: Time.h:242
Gaudi::Time::operator==
friend bool operator==(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.h:322
Kernel.h
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:22
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:120
StatusCode::FAILURE
Definition: StatusCode.h:31
Gaudi::Time::operator<
friend bool operator<(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.h:326
Gaudi::TimeSpan::ValueType
longlong ValueType
Definition: Time.h:60
Gaudi::TimeSpan::operator==
friend bool operator==(const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2)
Definition: Time.h:88
Gaudi::TimeSpan::operator!=
friend bool operator!=(const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2)
Definition: Time.h:90
plotSpeedupsPyRoot.time
time
Definition: plotSpeedupsPyRoot.py:154
std
STL namespace.
Gaudi::Time::TimeAssert
void TimeAssert(bool cond, const std::string &msg="time assertion failed") const
Definition: Time.h:337
Gaudi::TimeSpan::operator<=
friend bool operator<=(const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2)
Definition: Time.h:94
Gaudi::TimeSpan::operator+
friend Gaudi::TimeSpan operator+(const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2)
Definition: Time.h:100
StreamBuffer.h
Gaudi::Units::second
constexpr double second
Definition: SystemOfUnits.h:123
std::string
STL class.
Gaudi::Time::Months
Months
Symbolic names for months.
Definition: Time.h:245
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:228
compareRootHistos.ts
tuple ts
Definition: compareRootHistos.py:416
Gaudi::TimeSpan::ns
ValueType ns() const
Return the time span as nanoseconds.
Definition: Time.icpp:113
__longlong
Definition: Kernel.h:56
Gaudi::Time
Based on seal::Time.
Definition: Time.h:237
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
GaudiException.h
Gaudi::TimeSpan::operator>
friend bool operator>(const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2)
Definition: Time.h:96
TimeException
Exception thrown by Gaudi::Time.
Definition: Time.h:20
Gaudi::Time::operator>=
friend bool operator>=(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.h:332
Gaudi::Time::operator<=
friend bool operator<=(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.h:328
Gaudi::Time::operator>
friend bool operator>(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.h:330
Message
The Message class.
Definition: Message.h:15
TimeException::TimeException
TimeException(std::string Message="unspecified exception", std::string Tag="*Gaudi::Time*", StatusCode Code=StatusCode::FAILURE)
Definition: Time.h:22
Time.icpp
GaudiMP.FdsRegistry.msg
msg
Definition: FdsRegistry.py:8
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
Gaudi::TimeSpan::operator-
friend Gaudi::TimeSpan operator-(const Gaudi::TimeSpan &ts1, const Gaudi::TimeSpan &ts2)
Definition: Time.h:105
Gaudi::Time::operator!=
friend bool operator!=(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.h:324
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:110
Gaudi::TimeSpan::operator<
friend bool operator<(const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2)
Definition: Time.h:92
Gaudi::TimeSpan::operator>=
friend bool operator>=(const Gaudi::TimeSpan &t1, const Gaudi::TimeSpan &t2)
Definition: Time.h:98
Gaudi::TimeSpan
Based on seal::TimeSpan.
Definition: Time.h:55
Gaudi::Units::ns
constexpr double ns
Definition: SystemOfUnits.h:134
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1