DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
WIBtoWIBEth.hpp
Go to the documentation of this file.
1
9#ifndef RAWDATAUTILS_INCLUDE_WIBTOWIBETH_HPP_
10#define RAWDATAUTILS_INCLUDE_WIBTOWIBETH_HPP_
11
12#include <cstdint>
13#include <iostream>
14#include <fstream>
15#include <filesystem>
18
19namespace dunedaq {
20namespace rawdatautils {
21
22fddetdataformats::WIBEthFrame
23wibtowibeth(fddetdataformats::WIBFrame* fr, uint64_t timestamp=0, int starting_channel=0) {
25 for (int j = 0; j < 64; ++j) {
26 for (int i = 0; i < 64; ++i) {
27 res.set_adc(i, j, (fr + j)->get_channel(starting_channel + i));
28 }
29 }
30 auto header = fr->get_wib_header();
31 res.daq_header.version = header->version; //Warning, in WIBFrames version has 5 bits and here it has 4
32 res.daq_header.crate_id = header->crate_no;
33 res.daq_header.slot_id = header->slot_no;
34 res.daq_header.stream_id = header->fiber_no;
35 res.set_channel(starting_channel);
36 res.set_timestamp(timestamp);
37 res.header.extra_data = 0xdeadbeef0badface;
38 return res;
39}
40
41void
42wib_binary_to_wibeth_binary(std::string& filename, std::string& output) {
43 std::ifstream file(filename.c_str(), std::ios::binary);
44 std::cout << "Transforming " << filename << " to " << output << '\n';
45 auto size = std::filesystem::file_size(filename);
46 std::vector<char> v(size);
47 file.read(v.data(), size);
48 file.close();
49 std::cout << "Number of frames found: "<< size / sizeof(fddetdataformats::WIBFrame) << '\n';
50
51 std::ofstream out(output.c_str(), std::ios::binary);
52 std::vector<int> starting_channel {0, 64, 128, 192};
53 for (auto& sc : starting_channel) {
54 auto ptr = reinterpret_cast<fddetdataformats::WIBFrame*>(v.data());
55 uint64_t timestamp = ptr->get_timestamp();
56 int num_frames = size / sizeof(fddetdataformats::WIBFrame);
57 while(num_frames >= 64){
58 auto wibethfr = wibtowibeth(ptr, timestamp, sc);
59 timestamp += 32 * 64;
60 ptr += 64;
61 num_frames -= 64;
62 out.write(reinterpret_cast<char*>(&wibethfr), sizeof(wibethfr));
63 }
64 out.close();
65 }
66
67}
68
69void
70wib_hdf5_to_wibeth_binary(std::string& /*filename*/, std::string& /*output*/) {
71}
72
73
74} // namespace dunedaq::rawdatautils
75}
76
77#endif // RAWDATAUTILS_INCLUDE_WIBTOWIBETH_HPP_
Class for accessing raw WIB eth frames, as used in ProtoDUNE-II.
void set_channel(const uint8_t new_channel)
Set the channel identifier of the frame.
void set_adc(int i, int sample, uint16_t val)
Set the ith ADC value in the frame to val.
detdataformats::DAQEthHeader daq_header
void set_timestamp(const uint64_t new_timestamp)
Set the starting 64-bit timestamp of the frame.
const WIBHeader * get_wib_header() const
Definition WIBFrame.hpp:360
void wib_hdf5_to_wibeth_binary(std::string &, std::string &)
fddetdataformats::WIBEthFrame wibtowibeth(fddetdataformats::WIBFrame *fr, uint64_t timestamp=0, int starting_channel=0)
void wib_binary_to_wibeth_binary(std::string &filename, std::string &output)
Including Qt Headers.
FELIX Initialization std::string initerror FELIX queue timed out
FELIX Initialization std::string initerror FELIX queue timed std::string queuename Unexpected chunk size