DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TDEUnpacker.cpp
Go to the documentation of this file.
1
11
12#include <cstdint>
13#include <pybind11/numpy.h>
14
15namespace py = pybind11;
17
23}
24
30py::array_t<uint16_t> np_array_adc_data(void* data, uint32_t n_frames){
31
34
35 py::array_t<uint16_t> result(n_ch * n_smpl * n_frames);
36
37 py::buffer_info buf_res = result.request();
38
39 auto ptr_res = static_cast<uint16_t*>(buf_res.ptr);
40
41 for (size_t i=0; i<n_frames; ++i) {
42
43 auto fr = reinterpret_cast<fddetdataformats::TDEEthFrame*>(
44 static_cast<char*>(data) + i * sizeof(fddetdataformats::TDEEthFrame)
45 );
46
47 for (size_t j=0; j<n_smpl; ++j){
48 for (size_t k=0; k<n_ch; ++k){
49 ptr_res[(n_smpl*n_ch) * i + n_ch*j + k] = fr->get_adc(k, j);
50 }
51 }
52 }
53 result.resize({n_frames*n_smpl, n_ch});
54
55 return result;
56}
57
63py::array_t<long double> np_array_timestamp_data(void* data, uint32_t n_frames){
64
66
67 py::array_t<long double> result(n_smpl*n_frames);
68
69 auto ptr = static_cast<long double*>(result.request().ptr);
70
71 for (size_t i=0; i<n_frames; ++i) {
72 auto fr = reinterpret_cast<fddetdataformats::TDEEthFrame*>(
73 static_cast<char*>(data) + i * sizeof(fddetdataformats::TDEEthFrame)
74 );
75 long double ts_0 = fr->get_timestamp();
76 for(size_t j=0; j<n_smpl; ++j )
77 ptr[i*n_smpl+j] = ts_0+31.25*j;
78 }
79
80 return result;
81}
82
87py::array_t<uint16_t> np_array_adc(daqdataformats::Fragment const& frag){
88 return np_array_adc_data(frag.get_data(), get_n_frames(frag));
89}
90
95py::array_t<long double> np_array_timestamp(daqdataformats::Fragment const& frag){
96 return np_array_timestamp_data(frag.get_data(), get_n_frames(frag));
97}
98
99} // namespace dunedaq::rawdatautils::tde // 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:254
fragment_size_t get_size() const
Get the total size of the Fragment.
Definition Fragment.hpp:242
Class for accessing raw WIB eth frames, as used in ProtoDUNE-II.
static constexpr int s_time_samples_per_frame
uint64_t get_timestamp() const
Get the starting 64-bit timestamp of the frame.
py::array_t< uint16_t > np_array_adc(daqdataformats::Fragment const &frag)
Unpacks a Fragment containing TDEEthFrames into a numpy array with the ADC values and dimension (numb...
py::array_t< long double > np_array_timestamp(daqdataformats::Fragment const &frag)
Unpacks the timestamps in a Fragment containing TDEEthFrames into a numpy array with dimension (numbe...
py::array_t< long double > np_array_timestamp_data(void *data, uint32_t n_frames)
Unpacks data containing TDEEthFrames into a numpy array with the timestamps with dimension (number of...
uint32_t get_n_frames(daqdataformats::Fragment const &frag)
Gets number of TDEEthFrames in a fragment.
py::array_t< uint16_t > np_array_adc_data(void *data, uint32_t n_frames)
Unpacks data containing TDEEthFrames into a numpy array with the ADC values and dimension (number of ...
The header for a DUNE Fragment.