DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DAPHNEEthStreamTypeAdapter.hpp
Go to the documentation of this file.
1#ifndef FDREADOUTLIBS_INCLUDE_FDREADOUTLIBS_DAPHNEETHSTREAMTYPEADAPTER_
2#define FDREADOUTLIBS_INCLUDE_FDREADOUTLIBS_DAPHNEETHSTREAMTYPEADAPTER_
3
7
8
9
11
14 const constexpr std::size_t kDAPHNEEthStreamNumFrames = 1;
16
18
20
22
23 // comparable based on first timestamp
24 bool operator<(const DAPHNEEthStreamTypeAdapter& other) const
25 {
26 auto thisptr = reinterpret_cast<const FrameType*>(&data); // NOLINT
27 auto otherptr = reinterpret_cast<const FrameType*>(&other.data); // NOLINT
28 return thisptr->get_timestamp() < otherptr->get_timestamp() ? true : false;
29 }
30
31 uint64_t get_timestamp() const { // NOLINT(build/unsigned)
32 return reinterpret_cast<const FrameType*>(&data)->get_timestamp(); // NOLINT
33 }
34
35 void set_timestamp(uint64_t ts) // NOLINT(build/unsigned)
36 {
37 auto frame = reinterpret_cast<FrameType*>(&data); // NOLINT
38 frame->set_timestamp(ts);
39 }
40
41 void fake_timestamps(uint64_t first_timestamp, uint64_t offset = 280) // NOLINT(build/unsigned)
42 {
43 uint64_t ts_next = first_timestamp; // NOLINT(build/unsigned)
44 for (unsigned int i = 0; i < get_num_frames(); ++i) {
45 auto df = reinterpret_cast<FrameType*>((reinterpret_cast<uint8_t*>(&data)) + i * get_frame_size());
46 df->set_timestamp(ts_next);
47 ts_next += offset;
48 }
49 }
50
51 void fake_geoid(uint16_t crate_id, uint16_t slot_id, uint16_t stream_id) {
52 for (unsigned int i = 0; i < get_num_frames(); ++i) {
53 auto df = reinterpret_cast<FrameType*>((reinterpret_cast<uint8_t*>(&data)) + i * get_frame_size());
54 df->daq_header.crate_id = crate_id;
55 df->daq_header.slot_id = slot_id;
56 df->daq_header.stream_id = stream_id;
57 }
58 }
59
60 void fake_adc_pattern(int channel) {
61 // Set the ADC for the first sample to the 14-bit max value
62 auto frame = reinterpret_cast<FrameType*>(&data); // NOLINT
63 frame->set_adc(0, channel, 0x3FFF);
64 }
65
66
67 void fake_frame_errors(std::vector<uint16_t>* /*fake_errors*/) // NOLINT
68 {
69 // Set frame error bits in header
70 }
71
73 {
74 return reinterpret_cast<FrameType*>(&data[0]); // NOLINT
75 }
76
78 {
79 return reinterpret_cast<FrameType*>(data + kDAPHNEEthStreamSize); // NOLINT
80 }
81
82 constexpr size_t get_payload_size() const { return kDAPHNEEthStreamSize; }
83
84 constexpr size_t get_num_frames() const { return kDAPHNEEthStreamNumFrames; }
85
86 constexpr size_t get_frame_size() const { return sizeof(dunedaq::fddetdataformats::DAPHNEEthStreamFrame); }
87
90 static const constexpr uint64_t expected_tick_difference = 280; // NOLINT(build/unsigned)
91 };
92
93 static_assert(sizeof(struct DAPHNEEthStreamTypeAdapter) == kDAPHNEEthStreamSize,
94 "Check your assumptions on DAPHNEEthStreamTypeAdapter");
95
96
97} // namespace dunedaq::fdreadoutlibs::types
98
99
100#endif // FDREADOUTLIBS_INCLUDE_FDREADOUTLIBS_DAPHNEETHSTREAMTYPEADAPTER_
double offset
FragmentType
All defined Fragment types.
const constexpr std::size_t kDAPHNEEthStreamNumFrames
const constexpr std::size_t kDAPHNEEthStreamSize
Subsystem
The Subsystem enum describes the kind of source we're dealing with.
Definition SourceID.hpp:40
Struct for accessing raw DAPHNE eth stream frames.
void fake_geoid(uint16_t crate_id, uint16_t slot_id, uint16_t stream_id)
void fake_timestamps(uint64_t first_timestamp, uint64_t offset=280)
dunedaq::fddetdataformats::DAPHNEEthStreamFrame FrameType
static const constexpr daqdataformats::SourceID::Subsystem subsystem
bool operator<(const DAPHNEEthStreamTypeAdapter &other) const
static const constexpr daqdataformats::FragmentType fragment_type