11#include "data_types.hpp"
12#include "int_arith.hpp"
13#include "int_types.hpp"
14#include "introspect.hpp"
16#include "npint_ops.hpp"
17#include "processor.hpp"
18#include "read_integers.hpp"
19#include "time_tagged_events.hpp"
66 [[nodiscard]]
constexpr auto channel() const noexcept ->
u8np {
73 [[nodiscard]]
constexpr auto dtime() const noexcept ->
u16np {
81 [[nodiscard]]
constexpr auto nsync() const noexcept ->
u16np {
88 [[nodiscard]]
constexpr auto is_special() const noexcept ->
bool {
143 throw std::invalid_argument(
144 "pqt3_picoharp300_event channel must be in the range 0-14");
155 return make_from_fields(15_u8np, 0_u16np, 0_u16np);
169 if (marker_bits == 0_u8np)
170 throw std::invalid_argument(
171 "pqt3_picoharp300_event marker_bits must not be zero");
172 return make_from_fields(15_u8np,
u16np(marker_bits & 0x0f_u8np),
185 return stream <<
"pqt3_picoharp(channel="
186 << unsigned(event.channel().value())
187 <<
", dtime=" <<
event.dtime()
188 <<
", nsync=" <<
event.nsync() <<
")";
239 [[nodiscard]]
constexpr auto dtime() const noexcept ->
u16np {
243 return lo6 | (mid8 << 6) | (hi1 << 14);
250 [[nodiscard]]
constexpr auto nsync() const noexcept ->
u16np {
257 [[nodiscard]]
constexpr auto is_special() const noexcept ->
bool {
274 if (IsNSyncOverflowAlwaysSingle)
324 not IsNSyncOverflowAlwaysSingle,
325 "multiple nsync overflow is not available in HydraHarp V1 format");
326 return make_from_fields(
true, 63_u8np, 0_u16np,
count);
335 return make_from_fields(
true, 63_u8np, 0_u16np, 1_u16np);
349 return make_from_fields(
true, marker_bits, 0_u16np,
nsync);
360 static constexpr auto version = IsNSyncOverflowAlwaysSingle ? 1 : 2;
361 return stream <<
"pqt3_hydraharpv" << version
362 <<
"(special=" <<
event.is_special()
363 <<
", channel=" << unsigned(event.channel().value())
364 <<
", dtime=" <<
event.dtime()
365 <<
", nsync=" <<
event.nsync() <<
")";
369 static constexpr auto make_from_fields(
bool special,
u8np channel,
377 std::byte(((
u8np(
u8(special)) << 7) |
408template <
typename DataTypes,
typename PQT3Event,
typename Downstream>
416 static_assert(
sizeof(
typename DataTypes::abstime_type) >= 4);
417 static_assert(std::in_range<typename DataTypes::channel_type>(63));
418 static_assert(std::in_range<typename DataTypes::difftime_type>(32767));
420 using abstime_type =
typename DataTypes::abstime_type;
422 abstime_type nsync_base = 0;
424 Downstream downstream;
426 LIBTCSPC_NOINLINE
void issue_warning(
char const *message) {
431 explicit decode_pqt3(Downstream downstream)
432 : downstream(std::move(downstream)) {}
439 return downstream.introspect_graph().push_entry_point(
this);
442 template <
typename Event>
443 requires std::convertible_to<std::remove_cvref_t<Event>, PQT3Event>
444 void handle(Event &&event) {
445 if (event.is_nsync_overflow()) {
446 nsync_base += abstime_type(PQT3Event::nsync_overflow_period) *
447 event.nsync_overflow_count().value();
448 return downstream.handle(
452 abstime_type
const nsync = nsync_base +
event.nsync().value();
454 if (not event.is_special()) {
456 nsync,
event.channel().value(),
event.dtime().value()});
457 }
else if (event.is_external_marker()) {
458 for_each_set_bit(
u32np(event.external_marker_bits()), [&](
int b) {
459 downstream.handle(marker_event<DataTypes>{nsync, b});
462 issue_warning(
"invalid special event encountered");
466 template <
typename Event>
468 not std::convertible_to<std::remove_cvref_t<Event>, PQT3Event> and
470 void handle(Event &&event) {
471 downstream.handle(std::forward<Event>(event));
474 void flush() { downstream.flush(); }
501template <
typename DataTypes = default_data_types,
typename Downstream>
504 Downstream>(std::move(downstream));
530template <
typename DataTypes = default_data_types,
typename Downstream>
533 Downstream>(std::move(downstream));
560template <
typename DataTypes = default_data_types,
typename Downstream>
562 return internal::decode_pqt3<DataTypes, pqt3_generic_event, Downstream>(
563 std::move(downstream));
Value type representing a directed acyclic graph of processors.
Definition introspect.hpp:198
Value type representing metadata of a processor.
Definition introspect.hpp:58
Concept that is satisfied when a processor handles the given event types.
Definition processor.hpp:118
Concept that is satisfied when a processor handles the given event types and flush.
Definition processor.hpp:143
basic_pqt3_event< true > pqt3_hydraharpv1_event
Binary record interpretation for HydraHarp V1 T3 format.
Definition picoquant_t3.hpp:392
basic_pqt3_event< false > pqt3_generic_event
Binary record interpretation for HydraHarp V2, MultiHarp, TimeHarp 260, and PicoHarp 330 "Generic" T3...
Definition picoquant_t3.hpp:402
npint< u32 > u32np
Non-promoted unsigned 32-bit integer.
Definition npint.hpp:306
constexpr auto read_u8_at(std::span< T, N > bytes) noexcept -> u8np
Read an 8-bit unsigned integer from bytes at offset.
Definition read_integers.hpp:77
npint< u8 > u8np
Non-promoted unsigned 8-bit integer.
Definition npint.hpp:292
npint< u16 > u16np
Non-promoted unsigned 16-bit integer.
Definition npint.hpp:299
constexpr auto read_u16le_at(std::span< T, N > bytes) noexcept -> u16np
Read a little-endian 16-bit unsigned integer from bytes at offset.
Definition read_integers.hpp:90
auto decode_pqt3_picoharp300(Downstream downstream)
Create a processor that decodes PicoQuant PicoHarp 300 T3 events.
Definition picoquant_t3.hpp:502
auto decode_pqt3_generic(Downstream downstream)
Create a processor that decodes PicoQuant HydraHarp V2, MultiHarp, TimeHarp 260, and PicoHarp 330 "Ge...
Definition picoquant_t3.hpp:561
auto decode_pqt3_hydraharpv1(Downstream downstream)
Create a processor that decodes PicoQuant HydraHarp V1 T3 events.
Definition picoquant_t3.hpp:531
auto count(access_tracker< count_access > &&tracker, Downstream downstream)
Create a processor that counts events of a given type.
Definition count.hpp:313
std::int32_t i32
Short name for int32_t.
Definition int_types.hpp:42
std::uint8_t u8
Short name for uint8_t.
Definition int_types.hpp:24
libtcspc namespace.
Definition acquire.hpp:29
Implementation for binary record interpretation for HydraHarp, MultiHarp, TimeHarp 260,...
Definition picoquant_t3.hpp:218
static constexpr auto make_external_marker(u16np nsync, u8np marker_bits) -> basic_pqt3_event
Make an event representing an external marker.
Definition picoquant_t3.hpp:347
static constexpr auto make_nsync_overflow() noexcept -> basic_pqt3_event
Make an event representing a single nsync overflow.
Definition picoquant_t3.hpp:334
friend auto operator==(basic_pqt3_event const &lhs, basic_pqt3_event const &rhs) noexcept -> bool=default
Equality comparison operator.
constexpr auto dtime() const noexcept -> u16np
Read the difference time if this event is a non-special event.
Definition picoquant_t3.hpp:239
constexpr auto is_special() const noexcept -> bool
Determine if this event is a special event.
Definition picoquant_t3.hpp:257
std::array< std::byte, 4 > bytes
Definition picoquant_t3.hpp:222
constexpr auto is_nsync_overflow() const noexcept -> bool
Determine if this event represents an nsync overflow.
Definition picoquant_t3.hpp:264
constexpr auto nsync_overflow_count() const noexcept -> u16np
Read the nsync overflow count if this event represents an nsync overflow.
Definition picoquant_t3.hpp:272
constexpr auto external_marker_bits() const noexcept -> u8np
Read the marker bits (mask) if this event represents external markers.
Definition picoquant_t3.hpp:290
static constexpr auto make_nonspecial(u16np nsync, u8np channel, u16np dtime) -> basic_pqt3_event
Make an event representing a non-special (photon) event.
Definition picoquant_t3.hpp:306
constexpr auto nsync() const noexcept -> u16np
Read the nsync counter value if this event is a non-special event or an external marker event.
Definition picoquant_t3.hpp:250
friend auto operator<<(std::ostream &stream, basic_pqt3_event const &event) -> std::ostream &
Stream insertion operator.
Definition picoquant_t3.hpp:358
constexpr auto channel() const noexcept -> u8np
Read the channel if this event is a non-special event.
Definition picoquant_t3.hpp:232
static constexpr i32 nsync_overflow_period
Definition picoquant_t3.hpp:227
static constexpr auto make_nsync_overflow(u16np count) -> basic_pqt3_event
Make an event representing an nsync overflow.
Definition picoquant_t3.hpp:321
constexpr auto is_external_marker() const noexcept -> bool
Determine if this event represents external markers.
Definition picoquant_t3.hpp:282
Event indicating a timing marker.
Definition time_tagged_events.hpp:320
Binary record interpretation for PicoHarp 300 T3 Format.
Definition picoquant_t3.hpp:52
static constexpr auto make_nonspecial(u16np nsync, u8np channel, u16np dtime) -> pqt3_picoharp300_event
Make an event representing a non-special (photon) event.
Definition picoquant_t3.hpp:139
constexpr auto external_marker_bits() const noexcept -> u16np
Read the marker bits (mask) if this event represents external markers.
Definition picoquant_t3.hpp:123
constexpr auto channel() const noexcept -> u8np
Read the channel if this event is a non-special event.
Definition picoquant_t3.hpp:66
constexpr auto dtime() const noexcept -> u16np
Read the difference time if this event is a non-special event.
Definition picoquant_t3.hpp:73
constexpr auto nsync() const noexcept -> u16np
Read the nsync counter value if this event is a non-special event or an external marker event.
Definition picoquant_t3.hpp:81
constexpr auto is_external_marker() const noexcept -> bool
Determine if this event represents external markers.
Definition picoquant_t3.hpp:111
std::array< std::byte, 4 > bytes
Bytes of the 32-bit raw device event.
Definition picoquant_t3.hpp:56
constexpr auto is_nsync_overflow() const noexcept -> bool
Determine if this event represents an nsync overflow.
Definition picoquant_t3.hpp:95
static constexpr auto nsync_overflow_count() noexcept -> u16np
Read the nsync overflow count if this event represents an nsync overflow.
Definition picoquant_t3.hpp:103
friend auto operator==(pqt3_picoharp300_event const &lhs, pqt3_picoharp300_event const &rhs) noexcept -> bool=default
Equality comparison operator.
friend auto operator<<(std::ostream &stream, pqt3_picoharp300_event const &event) -> std::ostream &
Stream insertion operator.
Definition picoquant_t3.hpp:182
static constexpr auto make_external_marker(u16np nsync, u8np marker_bits) -> pqt3_picoharp300_event
Make an event representing an external marker.
Definition picoquant_t3.hpp:167
static constexpr i32 nsync_overflow_period
The nsync overflow period of this event type.
Definition picoquant_t3.hpp:61
static constexpr auto make_nsync_overflow() noexcept -> pqt3_picoharp300_event
Make an event representing an nsync overflow.
Definition picoquant_t3.hpp:153
constexpr auto is_special() const noexcept -> bool
Determine if this event is a special event.
Definition picoquant_t3.hpp:88
Event indicating latest abstime reached.
Definition time_tagged_events.hpp:41
An event type indicating a warning.
Definition core.hpp:31