BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
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 06:11:40 maqm Exp $
2#ifndef FACILITIES_TIMESTAMP_H
3#define FACILITIES_TIMESTAMP_H
4
5#include <string>
6
7namespace facilities {
8
9 /** Exception class, used to complain about bad arguments to
10 constructors, incompatible arguments for comparisons or
11 arithmetic, or out of range results.
12 */
14 public:
15 BadTimeInput(std::string msg) : complaint(msg) {};
17 std::string complaint;
18
19 BadTimeInput(const BadTimeInput &other) {complaint = other.complaint; };
20 };
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
64 /** Create a timestamp from an ascii string of standard form
65 yyyy-mm-dd hh:mm:ss
66 where only the first three fields are required.
67
68 If the string is invalid, object will represent unix creation time.
69 If the string represents a time in a timezone other than GMT,
70 tzOffset should represent time zone offset relative to GMT in
71 seconds so if local time is, for example, PST, tzOffset should
72 be 28800
73 */
74 Timestamp(const std::string& str, int tzOffset = 0);
75
76 /// Construct absolute time with specified fields
77 Timestamp(int year, int month, int day,
78 int hour = 0, int minute = 0,
79 int second = 0, int nano = 0);
80
81 /// Return string representation of time, not including nanoseconds;
82 std::string getString() const;
83
84 /// Return julian date
85 double getJulian() const;
86
87 double getNano() const {return m_nano;}
88 long int getClibTime() const {return m_time;}
89
90 bool operator<(const Timestamp& other) const {
91 return ((m_time < other.m_time) ||
92 ((m_time == other.m_time) && (m_nano < other.m_nano)));
93 }
94
95 bool operator>(const Timestamp& other) const {
96 return (other < (*this));
97
98 }
99
100 bool operator<=(const Timestamp& other) const {
101 return ( !(other < (*this)) );
102 }
103
104 bool operator>=(const Timestamp& other) const {
105 return ( !( (*this) < other ) );
106 }
107
108
110 m_time = other.m_time; m_nano = other.m_nano;
111 return *this;
112 }
113
114 bool operator==(const Timestamp& other) const{
115 return ((m_time == other.m_time) && (m_nano == other.m_nano));
116 }
117
118 bool operator!=(const Timestamp& other) const {
119 return (!(*this == other));
120 }
121
122 // << (for debugging)
123 private:
124 // See the U.S. Naval Observatory site,
125 // http://aa.usno.navy.mil/data/docs/JulianDate.html,
126 // used to compute Julian date for Jan 1, 1970
127 static const double julian1970;
128 static const int secPerDay;
129 static const double inverseNano;
130 static const int inverseNanoInt;
131 static const long int maxInt;
132
133 /// Representation of nominal start of time -- Jan 1, 1970 --
134 /// will change between Visual Studio V6 and V7. Time zone
135 /// also has to be discovered dynamically, but only once.
136 /// Do the computation in the constructor of a private class.
137 class TZOffset {
138 public:
139 TZOffset();
140 long int m_tzseconds; // 0 for GMT, 28800 for PDT, etc.
141 int m_isDst; // Not yet sure if we need it
142 };
143 static TZOffset s_tz;
144
145 /// Return "standard" binary time: count in seconds since 1 jan 1970
146 static time_t toBinary(const std::string& strTime);
147
148 /// Assemble string rep. from count of seconds
149 static void toString(time_t bin, std::string& strTime);
150
151 protected:
152 /// internal binary rep of time; count seconds from Jan 1, 1970
153 time_t m_time;
154
155 /// Save fractional seconds separately (associated with m_time)
157 };
158
159}
160
161#endif
*******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
BadTimeInput(const BadTimeInput &other)
Definition: Timestamp.h:19
std::string complaint
Definition: Timestamp.h:17
BadTimeInput(std::string msg)
Definition: Timestamp.h:15
std::string getString() const
Return string representation of time, not including nanoseconds;.
Definition: Timestamp.cxx:92
bool operator==(const Timestamp &other) const
Definition: Timestamp.h:114
bool operator!=(const Timestamp &other) const
Definition: Timestamp.h:118
bool operator>=(const Timestamp &other) const
Definition: Timestamp.h:104
bool operator<(const Timestamp &other) const
Definition: Timestamp.h:90
double getJulian() const
Return julian date.
Definition: Timestamp.cxx:99
long int getClibTime() const
Definition: Timestamp.h:88
Timestamp & operator=(const Timestamp &other)
Definition: Timestamp.h:109
bool operator>(const Timestamp &other) const
Definition: Timestamp.h:95
bool operator<=(const Timestamp &other) const
Definition: Timestamp.h:100
double getNano() const
Definition: Timestamp.h:87
int m_nano
Save fractional seconds separately (associated with m_time)
Definition: Timestamp.h:156
time_t m_time
internal binary rep of time; count seconds from Jan 1, 1970
Definition: Timestamp.h:153