DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DAPHNEUnpacker.cpp
Go to the documentation of this file.
1
8
12
13#include <cstdint>
14#include <pybind11/numpy.h>
15
16namespace py = pybind11;
18
22uint32_t
27
31uint32_t
36
41
42py::array_t<uint8_t>
43np_array_channels_stream_data(void* data, int nframes)
44{
45
46 const auto channels_per_daphne = fddetdataformats::DAPHNEStreamFrame::s_channels_per_frame;
47 py::array_t<uint8_t> channels(channels_per_daphne * nframes);
48 auto ptr = static_cast<uint8_t*>(channels.request().ptr);
49
50 for (size_t i = 0; i < (size_t)nframes; ++i) {
51 auto fr = reinterpret_cast<fddetdataformats::DAPHNEStreamFrame*>(static_cast<char*>(data) +
53
54 ptr[i * channels_per_daphne + 0] = fr->get_channel0();
55 ptr[i * channels_per_daphne + 1] = fr->get_channel1();
56 ptr[i * channels_per_daphne + 2] = fr->get_channel2();
57 ptr[i * channels_per_daphne + 3] = fr->get_channel3();
58 }
59 channels.resize({ nframes, channels_per_daphne });
60
61 return channels;
62}
63
68py::array_t<uint8_t>
69np_array_channels_data(void* data, int nframes)
70{
71
72 py::array_t<uint8_t> channels(nframes);
73 auto ptr = static_cast<uint8_t*>(channels.request().ptr);
74
75 for (size_t i = 0; i < (size_t)nframes; ++i) {
76 auto fr = reinterpret_cast<fddetdataformats::DAPHNEFrame*>(static_cast<char*>(data) +
78 ptr[i] = fr->get_channel();
79 }
80
81 return channels;
82}
83
86py::array_t<uint8_t>
93
97py::array_t<uint8_t>
104
110py::array_t<uint16_t>
111np_array_adc_data(void* data, int nframes)
112{
113
114 const auto adcs_per_channel = fddetdataformats::DAPHNEFrame::s_num_adcs;
115
116 py::array_t<uint16_t> ret(nframes * adcs_per_channel);
117 auto ptr = static_cast<uint16_t*>(ret.request().ptr);
118 for (size_t i = 0; i < (size_t)nframes; ++i) {
119 auto fr = reinterpret_cast<fddetdataformats::DAPHNEFrame*>(static_cast<char*>(data) +
121 // auto fr = reinterpret_cast<fddetdataformats::DAPHNEFrame*>(static_cast<char*>(data) + i *
122 // sizeof(fddetdataformats::DAPHNEFrame));
123 for (size_t j = 0; j < adcs_per_channel; ++j) {
124 ptr[i * adcs_per_channel + j] = fr->get_adc(j);
125 }
126 // for (size_t j=0; j<channels_per_daphne; ++j)
127 }
128 ret.resize({ nframes, adcs_per_channel });
129
130 return ret;
131}
132
138py::array_t<uint16_t>
139np_array_adc_stream_data(void* data, int nframes)
140{
141
142 const auto channels_per_daphne = fddetdataformats::DAPHNEStreamFrame::s_channels_per_frame;
144
145 py::array_t<uint16_t> ret(channels_per_daphne * nframes * adcs_per_channel);
146 auto ptr = static_cast<uint16_t*>(ret.request().ptr);
147 for (size_t i = 0; i < (size_t)nframes; ++i) {
148 auto fr = reinterpret_cast<fddetdataformats::DAPHNEStreamFrame*>(static_cast<char*>(data) +
150 for (size_t j = 0; j < adcs_per_channel; ++j)
151 for (size_t k = 0; k < channels_per_daphne; ++k)
152 ptr[channels_per_daphne * (adcs_per_channel * i + j) + k] = fr->get_adc(j, k);
153 }
154 ret.resize({ nframes * adcs_per_channel, channels_per_daphne });
155
156 return ret;
157}
158
164
165py::array_t<uint64_t>
166np_array_timestamp_data(void* data, int nframes)
167{
168
169 py::array_t<uint64_t> ret(nframes);
170 auto ptr = static_cast<uint64_t*>(ret.request().ptr);
171 for (size_t i = 0; i < (size_t)nframes; ++i) {
172 auto fr = reinterpret_cast<fddetdataformats::DAPHNEFrame*>(static_cast<char*>(data) +
174 ptr[i] = fr->get_timestamp();
175 }
176
177 return ret;
178}
179
185py::array_t<uint64_t>
186np_array_timestamp_stream_data(void* data, int nframes)
187{
188
190 const size_t ticks_per_adc = 1;
191
192 py::array_t<uint64_t> ret(nframes * adcs_per_channel);
193
194 auto ptr = static_cast<uint64_t*>(ret.request().ptr);
195 for (size_t i = 0; i < (size_t)nframes; ++i) {
196 auto fr = reinterpret_cast<fddetdataformats::DAPHNEStreamFrame*>(static_cast<char*>(data) +
198 for (size_t j = 0; j < adcs_per_channel; ++j)
199 ptr[i * adcs_per_channel + j] = fr->get_timestamp() + j * ticks_per_adc;
200 }
201
202 return ret;
203}
204
209py::array_t<uint16_t>
216
221py::array_t<uint16_t>
228
233py::array_t<uint64_t>
240
245py::array_t<uint64_t>
252
253} // namespace dunedaq::rawdatautils::daphne // NOLINT
C++ Representation of a DUNE Fragment, wrapping the flat byte array that is the Fragment's "actual" f...
Definition Fragment.hpp:38
void * get_data() const
Get a pointer to the data payload in the Fragmnet.
Definition Fragment.hpp:153
fragment_size_t get_size() const
Get the total size of the Fragment in bytes, including header and all payload pieces.
Definition Fragment.hpp:147
py::array_t< uint16_t > np_array_adc_stream(daqdataformats::Fragment &frag)
Unpacks a Fragment containing DAPHNEStreamFrames into a numpy array with the ADC values and dimension...
py::array_t< uint8_t > np_array_channels_stream(daqdataformats::Fragment &frag)
Unpacks channel numbers for Fragment that contains DAPHNEStreamFrames into a numpy array with dimensi...
py::array_t< uint64_t > np_array_timestamp_stream_data(void *data, int nframes)
Unpacks data containing DAPHNEStreamFrames into a numpy array with the timestamps with dimension (num...
py::array_t< uint16_t > np_array_adc_stream_data(void *data, int nframes)
Unpacks data containing DAPHNEStreamFrames into a numpy array with the ADC values and dimension (numb...
py::array_t< uint64_t > np_array_timestamp_stream(daqdataformats::Fragment &frag)
Unpacks the timestamps in a Fragment containing DAPHNEStreamFrames into a numpy array with dimension ...
uint32_t get_n_frames(daqdataformats::Fragment const &frag)
Gets number of DAPHNEFrames in a fragment.
py::array_t< uint8_t > np_array_channels_data(void *data, int nframes)
Unpacks channel numbers for DAPHNEFrames into a numpy array with dimensions (nframes).
uint32_t get_n_frames_stream(daqdataformats::Fragment const &frag)
Gets number of DAPHNEStreamFrames in a fragment.
py::array_t< uint8_t > np_array_channels_stream_data(void *data, int nframes)
Unpacks channel numbers for DAPHNEStreamFrames into a numpy array with dimensions (nframes,...
py::array_t< uint8_t > np_array_channels(daqdataformats::Fragment &frag)
Unpacks channel numbers for Fragment that contains DAPHNEFrames into a numpy array with dimensions.
py::array_t< uint64_t > np_array_timestamp_data(void *data, int nframes)
Unpacks data containing DAPHNEFrames into a numpy array with the timestamps with dimension (number of...
py::array_t< uint64_t > np_array_timestamp(daqdataformats::Fragment &frag)
Unpacks the timestamps in a Fragment containing WIBFrames into a numpy array with dimension (number o...
py::array_t< uint16_t > np_array_adc(daqdataformats::Fragment &frag)
Unpacks a Fragment containing DAPHNEFrames into a numpy array with the ADC values and dimension (numb...
py::array_t< uint16_t > np_array_adc_data(void *data, int nframes)
Unpacks data containing DAPHNEFrames into a numpy array with the ADC values and dimension (number of ...
The header for a DUNE Fragment.
uint64_t get_timestamp() const
Get the 64-bit timestamp of the frame.
uint16_t get_adc(int i_adc, int i_channel) const
Get the i ADC value of chn in the frame.