#include <LtbTime.h>
Inheritance diagram for DybDaq::LtbTime:
Public Types | |
typedef std::pair< const char *, unsigned int > | OutputBuffer |
typedef std::vector< OutputBuffer > | OutputBufferList |
typedef std::vector< ByteInspector * > | Bytes |
typedef std::vector< BitsInspector * > | Bits |
Public Member Functions | |
LtbTime (const LtbTraits::LtbDateTime &dateTime, const unsigned int halfNanoseconds, const unsigned int accumulation, const LtbTraits &traits) | |
Create an instance of this class. | |
LtbTime (const ByteBuffer &byteBuffer, const LtbTraits &traits) | |
Create an instance of this class. | |
virtual | ~LtbTime () |
Destroy this instance of the class. | |
unsigned int | year () const |
Returns the year of the LTB trigger. | |
unsigned int | month () const |
Returns the month of the LTB trigger. | |
unsigned int | day () const |
Returns the day of the LTB trigger. | |
unsigned int | hour () const |
Returns the hour of the LTB trigger. | |
unsigned int | minutes () const |
Returns the minutes of the LTB trigger. | |
unsigned int | seconds () const |
Returns the seconds of the LTB trigger. | |
unsigned int | ticks () const |
Returns the 12.5 ns ticks of the LTB trigger. | |
time_t | unixTime () const |
Returns the time as millisecond since 1970-01-01T00:00:00Z. | |
unsigned int | halfNanoseconds () const |
Returns the 1/2 nanoseconds within the seconds of this object. | |
int | accumulation () const |
Returns the accumulated deviation of 1/2 nanosecond from the PPS. | |
virtual unsigned int | bufferSize () const |
Returns the size, in 4-bytes, of this object's contents in the buffer. | |
void | setDateTime (const LtbTraits::LtbDateTime &dateTime) |
Sets the date and time (to the second) of this object. | |
void | setDateTime (const time_t &dateTime) |
Sets the date and time (to the second) of this object. | |
void | setHalfNanoseconds (const unsigned int halfNanoseconds) |
Sets the 1/2 nanoseconds within the seconds of this object. | |
void | setAccumulation (const int accumulation) |
Sets the accumulated deviation of 1/2 nanosecond from the PPS. | |
const LtbTraits & | ltbTraits () const |
Returns the LtbTraits instance used to parse this object's buffer. | |
bool | hasDaqTraits () const |
virtual const DaqTraits & | daqTraits () const |
virtual unsigned int | gather (OutputBufferList &outputBuffers) const |
virtual unsigned int | inspect (DaqBuffer::Bytes &inspectors) const |
Static Public Attributes | |
static const unsigned int | kBytesInInt |
static const unsigned int | kUndefinedFormatComponent |
Protected Member Functions | |
LtbTime (const time_t &dateTime, const unsigned int halfNanoseconds, const unsigned int accumulation, const LtbTraits &traits) | |
Create an instance of this class. | |
virtual unsigned int | formatComponent () const |
Returns the component with the format of this buffer. | |
const char * | buffer () const |
char * | buffer () |
bool | hasByteBuffer () const |
const ByteBuffer & | byteBuffer () const |
unsigned int | fillInspectors (DaqBuffer::Bytes &inspectors, unsigned int component, unsigned int cursor) const |
virtual bool | readBool (const unsigned int field) const |
virtual int | readInt (const unsigned int field) const |
virtual unsigned char | readUnsignedChar (const unsigned int field) const |
virtual unsigned int | readUnsignedInt (const unsigned int field) const |
virtual void | writeField (const bool value, const unsigned int field) |
virtual void | writeField (const int value, const unsigned int field) |
virtual void | writeField (const unsigned int value, const unsigned int field) |
Private Member Functions | |
LtbTime (LtbTime &rhs) | |
Suppress default. | |
LtbTime & | operator= (LtbTime &rhs) |
Suppress default. | |
Friends | |
class | LtbFrame |
class | LtbTraits |
Definition at line 24 of file LtbTime.h.
LtbTime::LtbTime | ( | const LtbTraits::LtbDateTime & | dateTime, | |
const unsigned int | halfNanoseconds, | |||
const unsigned int | accumulation, | |||
const LtbTraits & | traits | |||
) |
Create an instance of this class.
Definition at line 37 of file LtbTime.cc.
00040 : 00041 LtbBuffer(new char[traits.timeSize() * kBytesInInt], 00042 traits) { 00043 traits.initializeTime(buffer()); 00044 setDateTime(dateTime); 00045 setHalfNanoseconds(halfNanoseconds); 00046 setAccumulation(accumulation); 00047 }
LtbTime::LtbTime | ( | const ByteBuffer & | byteBuffer, | |
const LtbTraits & | traits | |||
) |
Create an instance of this class.
Definition at line 49 of file LtbTime.cc.
00050 : 00051 LtbBuffer(byteBuffer, 00052 traits) { 00053 }
LtbTime::~LtbTime | ( | ) | [virtual] |
LtbTime::LtbTime | ( | const time_t & | dateTime, | |
const unsigned int | halfNanoseconds, | |||
const unsigned int | accumulation, | |||
const LtbTraits & | traits | |||
) | [protected] |
Create an instance of this class.
Definition at line 25 of file LtbTime.cc.
00028 : 00029 LtbBuffer(new char[traits.timeSize() * kBytesInInt], 00030 traits) { 00031 traits.initializeTime(buffer()); 00032 setDateTime(dateTime); 00033 setHalfNanoseconds(halfNanoseconds); 00034 setAccumulation(accumulation); 00035 }
DybDaq::LtbTime::LtbTime | ( | LtbTime & | rhs | ) | [private] |
Suppress default.
unsigned int LtbTime::year | ( | ) | const |
Returns the year of the LTB trigger.
Definition at line 62 of file LtbTime.cc.
00062 { 00063 if (4 > ltbTraits().majorVersion()) { 00064 unsigned int result = readUnsignedInt(LtbTraits::kYear); 00065 if (0 == result) { 00066 return kYearZero; 00067 } 00068 return result; 00069 } 00070 const time_t time = unixTime(); 00071 struct tm* tmStruct = gmtime(&time); 00072 return tmStruct->tm_year + kTmBaseYear; 00073 }
unsigned int LtbTime::month | ( | ) | const |
Returns the month of the LTB trigger.
Definition at line 75 of file LtbTime.cc.
00075 { 00076 if (4 > ltbTraits().majorVersion()) { 00077 return readUnsignedInt(LtbTraits::kMonth); 00078 } 00079 const time_t time = unixTime(); 00080 struct tm* tmStruct = gmtime(&time); 00081 return tmStruct->tm_mon + 1; 00082 }
unsigned int LtbTime::day | ( | ) | const |
Returns the day of the LTB trigger.
Definition at line 84 of file LtbTime.cc.
00084 { 00085 if (4 > ltbTraits().majorVersion()) { 00086 return readUnsignedInt(LtbTraits::kDay); 00087 } 00088 const time_t time = unixTime(); 00089 struct tm* tmStruct = gmtime(&time); 00090 return tmStruct->tm_mday; 00091 }
unsigned int LtbTime::hour | ( | ) | const |
Returns the hour of the LTB trigger.
Definition at line 93 of file LtbTime.cc.
00093 { 00094 if (4 > ltbTraits().majorVersion()) { 00095 return readUnsignedInt(LtbTraits::kHour); 00096 } 00097 const time_t time = unixTime(); 00098 struct tm* tmStruct = gmtime(&time); 00099 return tmStruct->tm_hour; 00100 }
unsigned int LtbTime::minutes | ( | ) | const |
Returns the minutes of the LTB trigger.
Definition at line 102 of file LtbTime.cc.
00102 { 00103 if (4 > ltbTraits().majorVersion()) { 00104 return readUnsignedInt(LtbTraits::kMinutes); 00105 } 00106 const time_t time = unixTime(); 00107 struct tm* tmStruct = gmtime(&time); 00108 return tmStruct->tm_min; 00109 }
unsigned int LtbTime::seconds | ( | ) | const |
Returns the seconds of the LTB trigger.
Definition at line 111 of file LtbTime.cc.
00111 { 00112 if (4 > ltbTraits().majorVersion()) { 00113 return readUnsignedInt(LtbTraits::kSeconds); 00114 } 00115 const time_t time = unixTime(); 00116 struct tm* tmStruct = gmtime(&time); 00117 return tmStruct->tm_sec; 00118 }
unsigned int LtbTime::ticks | ( | ) | const |
Returns the 12.5 ns ticks of the LTB trigger.
Definition at line 120 of file LtbTime.cc.
00120 { 00121 if (4 > ltbTraits().majorVersion()) { 00122 return readUnsignedInt(LtbTraits::kTicks); 00123 } 00124 return (halfNanoseconds() / 25U); 00125 }
time_t LtbTime::unixTime | ( | ) | const |
Returns the time as millisecond since 1970-01-01T00:00:00Z.
Definition at line 127 of file LtbTime.cc.
00127 { 00128 if (4 > ltbTraits().majorVersion()) { 00129 struct tm gmtAsLocal; 00130 gmtAsLocal.tm_sec = seconds(); 00131 gmtAsLocal.tm_min = minutes(); 00132 gmtAsLocal.tm_hour = hour(); 00133 gmtAsLocal.tm_mday = day(); 00134 gmtAsLocal.tm_mon = month() - 1; 00135 gmtAsLocal.tm_year = year() - kTmBaseYear; 00136 const time_t local = mktime(&gmtAsLocal); 00137 struct tm lcl = *localtime(&local); 00138 struct tm gmt = *gmtime(&local); 00139 gmt.tm_isdst = gmtAsLocal.tm_isdst; 00140 const time_t a = mktime(&lcl); 00141 const time_t b = mktime(&gmt); 00142 return local + (a - b); 00143 } 00144 const unsigned int highUnixTime = readUnsignedInt(LtbTraits::kHighUnixTime); 00145 const unsigned int lowUnixTime = readUnsignedInt(LtbTraits::kLowUnixTime); 00146 const TIME_T_BUILTIN_TYPE unixTime = (highUnixTime << 16U) | lowUnixTime; 00147 return *((const time_t*)(&unixTime)); 00148 }
unsigned int LtbTime::halfNanoseconds | ( | ) | const |
Returns the 1/2 nanoseconds within the seconds of this object.
Definition at line 150 of file LtbTime.cc.
00150 { 00151 if (4 > ltbTraits().majorVersion()) { 00152 return ticks() * 25U; 00153 } 00154 const unsigned int highNonaseconds = readUnsignedInt(LtbTraits::kHighNanoseconds); 00155 const unsigned int lowNanoseconds = readUnsignedInt(LtbTraits::kLowNanoseconds); 00156 return (highNonaseconds << 4U) | lowNanoseconds; 00157 }
int LtbTime::accumulation | ( | ) | const |
Returns the accumulated deviation of 1/2 nanosecond from the PPS.
Definition at line 159 of file LtbTime.cc.
00159 { 00160 if (4 > ltbTraits().majorVersion()) { 00161 return 0; 00162 } 00163 const unsigned int highAccumulation = readUnsignedInt(LtbTraits::kHighAccumulation); 00164 const unsigned int lowAccumulation = readUnsignedInt(LtbTraits::kLowAccumulation); 00165 return (highAccumulation << 4U) + lowAccumulation; 00166 }
unsigned int LtbTime::bufferSize | ( | ) | const [virtual] |
Returns the size, in 4-bytes, of this object's contents in the buffer.
Implements DybDaq::DaqBuffer.
Definition at line 168 of file LtbTime.cc.
void LtbTime::setDateTime | ( | const LtbTraits::LtbDateTime & | dateTime | ) |
Sets the date and time (to the second) of this object.
Definition at line 172 of file LtbTime.cc.
00172 { 00173 if (4 > ltbTraits().majorVersion()) { 00174 writeField(dateTime.year(), 00175 LtbTraits::kYear); 00176 writeField(dateTime.month(), 00177 LtbTraits::kMonth); 00178 writeField(dateTime.day(), 00179 LtbTraits::kDay); 00180 writeField(dateTime.hour(), 00181 LtbTraits::kHour); 00182 writeField(dateTime.minutes(), 00183 LtbTraits::kMinutes); 00184 writeField(dateTime.seconds(), 00185 LtbTraits::kSeconds); 00186 return; 00187 } 00188 const time_t timeToCopy = dateTime.unixTime(); 00189 const TIME_T_BUILTIN_TYPE time = *((TIME_T_BUILTIN_TYPE*)(&timeToCopy)); 00190 writeField((((unsigned int)time) >> 16U) & 0x0000ffffU, 00191 LtbTraits::kHighUnixTime); 00192 writeField(((unsigned int)time) & 0x0000ffffU, 00193 LtbTraits::kLowUnixTime); 00194 00195 }
void LtbTime::setDateTime | ( | const time_t & | dateTime | ) |
Sets the date and time (to the second) of this object.
Definition at line 197 of file LtbTime.cc.
00197 { 00198 if (4 > ltbTraits().majorVersion()) { 00199 const tm* time = gmtime(&dateTime); 00200 writeField(time->tm_year + kTmBaseYear, 00201 LtbTraits::kYear); 00202 writeField(time->tm_mon + 1, 00203 LtbTraits::kMonth); 00204 writeField(time->tm_mday, 00205 LtbTraits::kDay); 00206 writeField(time->tm_hour, 00207 LtbTraits::kHour); 00208 writeField(time->tm_min, 00209 LtbTraits::kMinutes); 00210 writeField(time->tm_sec, 00211 LtbTraits::kSeconds); 00212 return; 00213 } 00214 const TIME_T_BUILTIN_TYPE time = *((TIME_T_BUILTIN_TYPE*)(&dateTime)); 00215 writeField((((unsigned int)time) >> 16U) & 0x0000ffffU, 00216 LtbTraits::kHighUnixTime); 00217 writeField(((unsigned int)time) & 0x0000ffffU, 00218 LtbTraits::kLowUnixTime); 00219 00220 }
void LtbTime::setHalfNanoseconds | ( | const unsigned int | halfNanoseconds | ) |
Sets the 1/2 nanoseconds within the seconds of this object.
Definition at line 222 of file LtbTime.cc.
00222 { 00223 if (4 > ltbTraits().majorVersion()) { 00224 writeField(halfNanoseconds / 25U, 00225 LtbTraits::kTicks); 00226 return; 00227 } 00228 writeField((halfNanoseconds >> 4U) & 0x0fffffffU, 00229 LtbTraits::kHighNanoseconds); 00230 writeField(halfNanoseconds & 0x0000000fU, 00231 LtbTraits::kLowNanoseconds); 00232 }
void LtbTime::setAccumulation | ( | const int | accumulation | ) |
Sets the accumulated deviation of 1/2 nanosecond from the PPS.
Definition at line 234 of file LtbTime.cc.
00234 { 00235 if (4 > ltbTraits().majorVersion()) { 00236 return; 00237 } 00238 writeField((accumulation >> 4U) & 0x0fffffffU, 00239 LtbTraits::kHighAccumulation); 00240 writeField(accumulation & 0x0000000fU, 00241 LtbTraits::kLowAccumulation); 00242 }
unsigned int LtbTime::formatComponent | ( | ) | const [protected, virtual] |
Returns the component with the format of this buffer.
Reimplemented from DybDaq::DaqBuffer.
Definition at line 58 of file LtbTime.cc.
00058 { 00059 return LtbTraits::kUnixTime; 00060 }
const LtbTraits & LtbBuffer::ltbTraits | ( | ) | const [inherited] |
Returns the LtbTraits instance used to parse this object's buffer.
Definition at line 36 of file LtbBuffer.cc.
00036 { 00037 return dynamic_cast<const LtbTraits&>(daqTraits()); 00038 }