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 {
33 return reinterpret_cast<const FrameType*>(&data)->daq_header.get_timestamp(); // NOLINT
34 }
35
36 void set_timestamp(uint64_t ts) // NOLINT(build/unsigned)
37 {
38 auto frame = reinterpret_cast<FrameType*>(&data); // NOLINT
39 frame->set_timestamp(ts);
40 }
41
42 void fake_timestamps(uint64_t first_timestamp, uint64_t offset = 280) // NOLINT(build/unsigned)
43 {
44 uint64_t ts_next = first_timestamp; // NOLINT(build/unsigned)
45 for (unsigned int i = 0; i < get_num_frames(); ++i) {
46 auto df = reinterpret_cast<FrameType*>((reinterpret_cast<uint8_t*>(&data)) + i * get_frame_size());
47 df->daq_header.timestamp = ts_next;
48 ts_next += offset;
49 }
50 }
51
52 void fake_geoid(uint16_t crate_id, uint16_t slot_id, uint16_t stream_id) {
53 for (unsigned int i = 0; i < get_num_frames(); ++i) {
54 auto df = reinterpret_cast<FrameType*>((reinterpret_cast<uint8_t*>(&data)) + i * get_frame_size());
55 df->daq_header.crate_id = crate_id;
56 df->daq_header.slot_id = slot_id;
57 df->daq_header.stream_id = stream_id;
58 }
59 }
60
61 void fake_adc_pattern(int channel) {
62 // Set the ADC for the first sample to the 14-bit max value
63 auto frame = reinterpret_cast<FrameType*>(&data); // NOLINT
64 frame->set_adc(channel, 0, 0x3FFF);
65 }
66
67
68 void fake_frame_errors(std::vector<uint16_t>* /*fake_errors*/) // NOLINT
69 {
70 // Set frame error bits in header
71 }
72
74 {
75 return reinterpret_cast<FrameType*>(&data[0]); // NOLINT
76 }
77
79 {
80 return reinterpret_cast<FrameType*>(data + kDAPHNEEthStreamSize); // NOLINT
81 }
82
83 constexpr size_t get_payload_size() const { return kDAPHNEEthStreamSize; }
84
85 constexpr size_t get_num_frames() const { return kDAPHNEEthStreamNumFrames; }
86
87 constexpr size_t get_frame_size() const { return sizeof(dunedaq::fddetdataformats::DAPHNEEthStreamFrame); }
88
91 static const constexpr uint64_t expected_tick_difference = 280; // NOLINT(build/unsigned)
92 };
93
94 static_assert(sizeof(struct DAPHNEEthStreamTypeAdapter) == kDAPHNEEthStreamSize,
95 "Check your assumptions on DAPHNEEthStreamTypeAdapter");
96
97
98} // namespace dunedaq::fdreadoutlibs::types
99
100
101#endif // FDREADOUTLIBS_INCLUDE_FDREADOUTLIBS_DAPHNEETHSTREAMTYPEADAPTER_
Class for accessing raw DAPHNE eth stream frames, as used in ProtoDUNE-II.
void set_timestamp(const uint64_t new_timestamp)
Set the starting 64-bit timestamp of the frame.
void set_adc(uint chn, uint i, uint16_t val)
Set the i ADC value of chn in the frame to val.
uint64_t get_timestamp() const
Get the starting 64-bit timestamp of the frame.
double offset
FragmentType
This enumeration should list 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:43
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)
static const constexpr daqdataformats::SourceID::Subsystem subsystem
bool operator<(const DAPHNEEthStreamTypeAdapter &other) const
static const constexpr daqdataformats::FragmentType fragment_type