BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Calibration/facilities/include/facilities/Timestamp.h
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/facilities/facilities/Timestamp.h,v 1.1.1.1 2005/10/17
2// 06:11:40 maqm Exp $
3#ifndef FACILITIES_TIMESTAMP_H
4#define FACILITIES_TIMESTAMP_H
5
6#include <string>
7
8namespace facilities {
9
10 /** Exception class, used to complain about bad arguments to
11 constructors, incompatible arguments for comparisons or
12 arithmetic, or out of range results.
13 */
15 public:
16 BadTimeInput( std::string msg ) : complaint( msg ){};
18 std::string complaint;
19
20 BadTimeInput( const BadTimeInput& other ) { complaint = other.complaint; };
21 };
22
23 /** Timestamp class, valid for dates from 1970 through 2037
24
25 Supports comparisons
26
27 Input to constructors may be
28 Julian date
29 seconds since start of 1970, Jan. 1 with optional
30 nanosecond field
31 individual fields (year, month, etc.)
32 string format
33
34 yyyy-mm-dd hh:mm:ss
35 1969 < yyyy < 2038
36 where 0 < mm < 13
37 0 < dd < 32
38 -1 < hh < 24
39 -1 < mm < 60
40 -1 < ss < 60
41
42 o only the first three fields are required. Omitted trailing
43 fields will be interpreted as equal to 0.
44 o by default : will be used to delimit fields, but user
45 may specify an alternative in most circumstances
46 o leading zeros are optional
47
48 */
49 class Timestamp {
50 public:
51 /// Default constructor builds object representing current time,
52 /// expressed in GMT
53 Timestamp();
54
55 /// Count seconds from the creation-according-to-unix, start of 1970
56 /// Optional third argument is offset in seconds from GMT
57 /// (e.g., PST is +28800)
58 Timestamp( long int seconds, int nano = 0, int tzOffset = 0 );
59
60 /// Constructor for Julian date. Must be GMT
61 Timestamp( double julian );
62
63 /** Create a timestamp from an ascii string of standard form
64 yyyy-mm-dd hh:mm:ss
65 where only the first three fields are required.
66
67 If the string is invalid, object will represent unix creation time.
68 If the string represents a time in a timezone other than GMT,
69 tzOffset should represent time zone offset relative to GMT in
70 seconds so if local time is, for example, PST, tzOffset should
71 be 28800
72 */
73 Timestamp( const std::string& str, int tzOffset = 0 );
74
75 /// Construct absolute time with specified fields
76 Timestamp( int year, int month, int day, int hour = 0, int minute = 0, int second = 0,
77 int nano = 0 );
78
79 /// Return string representation of time, not including nanoseconds;
80 std::string getString() const;
81
82 /// Return julian date
83 double getJulian() const;
84
85 double getNano() const { return m_nano; }
86 long int getClibTime() const { return m_time; }
87
88 bool operator<( const Timestamp& other ) const {
89 return ( ( m_time < other.m_time ) ||
90 ( ( m_time == other.m_time ) && ( m_nano < other.m_nano ) ) );
91 }
92
93 bool operator>( const Timestamp& other ) const { return ( other < ( *this ) ); }
94
95 bool operator<=( const Timestamp& other ) const { return ( !( other < ( *this ) ) ); }
96
97 bool operator>=( const Timestamp& other ) const { return ( !( ( *this ) < other ) ); }
98
99 Timestamp& operator=( const Timestamp& other ) {
100 m_time = other.m_time;
101 m_nano = other.m_nano;
102 return *this;
103 }
104
105 bool operator==( const Timestamp& other ) const {
106 return ( ( m_time == other.m_time ) && ( m_nano == other.m_nano ) );
107 }
108
109 bool operator!=( const Timestamp& other ) const { return ( !( *this == other ) ); }
110
111 // << (for debugging)
112 private:
113 // See the U.S. Naval Observatory site,
114 // http://aa.usno.navy.mil/data/docs/JulianDate.html,
115 // used to compute Julian date for Jan 1, 1970
116 static const double julian1970;
117 static const int secPerDay;
118 static const double inverseNano;
119 static const int inverseNanoInt;
120 static const long int maxInt;
121
122 /// Representation of nominal start of time -- Jan 1, 1970 --
123 /// will change between Visual Studio V6 and V7. Time zone
124 /// also has to be discovered dynamically, but only once.
125 /// Do the computation in the constructor of a private class.
126 class TZOffset {
127 public:
128 TZOffset();
129 long int m_tzseconds; // 0 for GMT, 28800 for PDT, etc.
130 int m_isDst; // Not yet sure if we need it
131 };
132 static TZOffset s_tz;
133
134 /// Return "standard" binary time: count in seconds since 1 jan 1970
135 static time_t toBinary( const std::string& strTime );
136
137 /// Assemble string rep. from count of seconds
138 static void toString( time_t bin, std::string& strTime );
139
140 protected:
141 /// internal binary rep of time; count seconds from Jan 1, 1970
142 time_t m_time;
143
144 /// Save fractional seconds separately (associated with m_time)
146 };
147
148} // namespace facilities
149
150#endif
string toString(const T &t)
*******INTEGER m_nBinMax INTEGER m_NdiMax !No of bins in histogram for cell exploration division $ !Last vertex $ !Last active cell $ !Last cell in buffer $ !No of sampling when dividing cell $ !No of function total $ !Flag for random ceel for $ !Flag for type of for WtMax $ !Flag which decides whether vertices are included in the sampling $ entire domain is hyp !Maximum effective eevents per bin
Definition FoamA.h:85
std::string getString() const
Return string representation of time, not including nanoseconds;.
Definition Timestamp.cxx:87
double getJulian() const
Return julian date.
Definition Timestamp.cxx:94
int m_nano
Save fractional seconds separately (associated with m_time).
time_t m_time
internal binary rep of time; count seconds from Jan 1, 1970