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
9
12const constexpr std::size_t kDAPHNEEthStreamNumFrames = 1;
13const constexpr std::size_t kDAPHNEEthStreamSize =
15
17{
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
32 { // NOLINT(build/unsigned)
33 return reinterpret_cast<const FrameType*>(&data)->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->set_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 {
54 for (unsigned int i = 0; i < get_num_frames(); ++i) {
55 auto df = reinterpret_cast<FrameType*>((reinterpret_cast<uint8_t*>(&data)) + i * get_frame_size());
56 df->daq_header.crate_id = crate_id;
57 df->daq_header.slot_id = slot_id;
58 df->daq_header.stream_id = stream_id;
59 }
60 }
61
62 void fake_adc_pattern(int channel)
63 {
64 // Set the ADC for the first sample to the 14-bit max value
65 auto frame = reinterpret_cast<FrameType*>(&data); // NOLINT
66 frame->set_adc(0, channel, 0x3FFF);
67 }
68
69 void fake_frame_errors(std::vector<uint16_t>* /*fake_errors*/) // NOLINT
70 {
71 // Set frame error bits in header
72 }
73
75 {
76 return reinterpret_cast<FrameType*>(&data[0]); // NOLINT
77 }
78
80 {
81 return reinterpret_cast<FrameType*>(data + kDAPHNEEthStreamSize); // NOLINT
82 }
83
84 constexpr size_t get_payload_size() const { return kDAPHNEEthStreamSize; }
85
86 constexpr size_t get_num_frames() const { return kDAPHNEEthStreamNumFrames; }
87
88 constexpr size_t get_frame_size() const { return sizeof(dunedaq::fddetdataformats::DAPHNEEthStreamFrame); }
89
93 static const constexpr uint64_t expected_tick_difference = 280; // NOLINT(build/unsigned)
94};
95
96static_assert(sizeof(struct DAPHNEEthStreamTypeAdapter) == kDAPHNEEthStreamSize,
97 "Check your assumptions on DAPHNEEthStreamTypeAdapter");
98
99} // namespace dunedaq::fdreadoutlibs::types
100
101#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 set_timestamp(const uint64_t new_timestamp)
Set the starting 64-bit timestamp of the frame.
void set_adc(int i_adc, int i_channel, uint16_t val)
Set the i_adc-th ADC value of i_channel-th channel in the frame to val.
uint64_t get_timestamp() const
Get the starting 64-bit timestamp of the frame.
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