8 unsigned len_done = 0, len_bit = 1;
9 while(len > 0 && len_bit > 0)
18 throw std::exception(
"incomplete frame in buffer");
27 std::string error_message;
29 throw std::runtime_error(error_message);
79 std::ostringstream oss;
82 oss <<
"marker0=0x" << std::hex << head->
marker0 << std::dec <<
". ";
86 oss <<
"marker1=0x" << std::hex << head->
marker1 << std::dec <<
". ";
90 oss <<
"end run header: num_events=" << head->
num_events <<
" (!= 0). ";
98 oss <<
"header size: " << head->
info.
header_length <<
" is not an even number of 32bit words. ";
102 oss <<
"marker1=0x" << std::hex << head->
marker1 << std::dec <<
" (Dummy). ";
104 error_message = oss.str();
113 std::string error_message;
122 if (
checkEventHeader(reinterpret_cast<const DAEEventHeader*>(buffer+i), error_message) == 0)
143 if (n + frame_len > len)
159 throw std::exception(
"short frame - no header");
165 if ( frame_len > len )
167 throw std::exception(
"short frame - not enough events");
196 if (FileTimeToSystemTime(&filetime, &systime) == 0)
198 memset(&systime, 0,
sizeof(systime));
205 if (SystemTimeToFileTime(&systime, &filetime) != 0)
211 memset(&daetime, 0,
sizeof(daetime));
217 ULARGE_INTEGER ularge;
218 ularge.LowPart = daetime.
low;
219 ularge.HighPart = daetime.
high;
220 ularge.QuadPart /= 5;
221 filetime.dwLowDateTime = ularge.LowPart;
222 filetime.dwHighDateTime = ularge.HighPart;
225 template <
typename T>
230 Poco::Timestamp base_timestamp = Poco::Timestamp::fromEpochTime(base);
231 Poco::DateTime dae_dt(systime.wYear, systime.wMonth, systime.wDay, systime.wHour, systime.wMinute, systime.wSecond, systime.wMilliseconds);
232 offset =
static_cast<T
>(dae_dt.timestamp() - base_timestamp) / static_cast<T>(1000000);
240 Poco::Timestamp base_timestamp = Poco::Timestamp::fromEpochTime(base);
241 base_timestamp +=
static_cast<int64_t
>(offset * 1.0e6);
242 Poco::DateTime dae_dt(base_timestamp);
244 systime.wYear =
static_cast<WORD
>(dae_dt.year());
245 systime.wMonth =
static_cast<WORD
>(dae_dt.month());
246 systime.wDay =
static_cast<WORD
>(dae_dt.day());
247 systime.wHour =
static_cast<WORD
>(dae_dt.hour());
248 systime.wMinute =
static_cast<WORD
>(dae_dt.minute());
249 systime.wSecond =
static_cast<WORD
>(dae_dt.second());
250 systime.wMilliseconds =
static_cast<WORD
>(dae_dt.millisecond());
257 ULARGE_INTEGER ularge;
258 ularge.LowPart = filetime.dwLowDateTime;
259 ularge.HighPart = filetime.dwHighDateTime;
260 ularge.QuadPart *= 5;
261 daetime.
low = ularge.LowPart;
262 daetime.
high = ularge.HighPart;
271 Poco::format(s1,
"%04u-%02u-%02u",
272 static_cast<unsigned>(systime.wYear), static_cast<unsigned>(systime.wMonth), static_cast<unsigned>(systime.wDay));
273 Poco::format(s2,
"%sT%02u:%02u:%02u.%u", s1, static_cast<unsigned>(systime.wHour),
274 static_cast<unsigned>(systime.wMinute), static_cast<unsigned>(systime.wSecond),
275 static_cast<unsigned>(systime.wMilliseconds));
284 os <<
"Frame header invalid: " << err_str <<
"\n";
287 os <<
"Num events " << head->
num_events <<
"\n";
293 for(
int i=0; i<n; ++i)
295 os <<
"time channel " << events[i].
time_channel <<
" spectrum " << events[i].
spectrum << std::endl;
static int checkEventHeaderImpl(const DAEEventHeader *head)
return 0x20 if dummy header present
static void printEventHeader(const DAEEventHeader *head, std::ostream &os)
static const int DAEEventHeaderFixedMarker
static void OffsetToDAETime(time_t base, double offset, DAEEventHeader::DAETime &daetime)
static void getEventHeaderErrorMessage(const DAEEventHeader *head, unsigned code, std::string &error_message)
static void DAETimeToFILETIME(const DAEEventHeader::DAETime &daetime, FILETIME &filetime)
static void DAETimeToSystemTime(const DAEEventHeader::DAETime &daetime, SYSTEMTIME &systime)
static uint32_t getCompleteFramesLen(const isisU32_t *buffer, uint32_t len, DAEstatus &status)
static void SystemTimeToDAETime(const SYSTEMTIME &systime, DAEEventHeader::DAETime &daetime)
static int findValidEventHeaderOffset(const isisU32_t *buffer, uint32_t len, DAEstatus &status)
returns index of start of a valid event header, -1 on error
static void printDetectorEvents(const DetectorEvent32 *events, int n, std::ostream &os)
static void DAETimeToOffset(const DAEEventHeader::DAETime &daetime, time_t base, T &offset)
static std::string DAETimeAsString(const DAEEventHeader::DAETime &daetime)
return as ISO8601 format string
static const unsigned DAE_EVENT_HEADER_WORDS
static void FILETIMEToDAETime(const FILETIME &filetime, DAEEventHeader::DAETime &daetime)
static bool isEndRunHeader(const DAEEventHeader *head, DAEstatus &status)
check whether an event frame header is a special enf of frame header
static void checkEvents(const isisU32_t *buffer, uint32_t maxlen, DAEstatus &status)
checks that buffer corresponds to a copmplete set of event frames
static uint32_t checkEventsFrame(const isisU32_t *buffer, uint32_t maxlen, DAEstatus &status)
static void checkEventHeader(const DAEEventHeader *head)