diff --git a/CMakeLists.txt b/CMakeLists.txt index 4df28ad..ab8eb51 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,8 +18,6 @@ daq_add_library (WIBFragmentDecoder.cpp LINK_LIBRARIES) ############################################################################## daq_add_python_bindings(*.cpp LINK_LIBRARIES daqdataformats::daqdataformats detdataformats::detdataformats fddetdataformats::fddetdataformats fmt::fmt) -daq_add_unit_test(WIBtoWIB2_test LINK_LIBRARIES detdataformats::detdataformats fddetdataformats::fddetdataformats) - ############################################################################## # Applications # daq_add_application(hdf5_demo_tpc_decoder demo_tpc_decoder.cpp LINK_LIBRARIES ${PROJECT_NAME}) diff --git a/include/rawdatautils/WIBtoTDE.hpp b/include/rawdatautils/WIBtoTDE.hpp deleted file mode 100644 index 369e59c..0000000 --- a/include/rawdatautils/WIBtoTDE.hpp +++ /dev/null @@ -1,77 +0,0 @@ -/** - * @file WIBtoTDE16.hpp Implementation of functions to convert files from the old WIB format to TDE16 - * - * This is part of the DUNE DAQ , copyright 2020. - * Licensing/copyright details are in the COPYING file that you should have - * received with this code. - */ - -#ifndef RAWDATAUTILS_INCLUDE_WIBTOTDE16_HPP_ -#define RAWDATAUTILS_INCLUDE_WIBTOTDE16_HPP_ - -#include -#include -#include -#include -#include "detdataformats/DetID.hpp" -#include "fddetdataformats/WIBFrame.hpp" -#include "fddetdataformats/TDE16Frame.hpp" - -namespace dunedaq { -namespace rawdatautils { - -fddetdataformats::TDE16Frame -wibtotde(fddetdataformats::WIBFrame* fr, uint64_t timestamp, uint16_t ch) { - fddetdataformats::TDE16Frame res; - // leave ADCs empty for now - for (auto i=0; i < dunedaq::fddetdataformats::tot_adc16_samples; i++) { - res.set_adc_sample(ch,i); - } - - auto header = fr->get_wib_header(); - res.get_daq_header()->version = header->version; - res.get_daq_header()->det_id = 11; - res.get_daq_header()->crate_id = header->crate_no; - res.get_daq_header()->slot_id = header->slot_no; - res.get_daq_header()->stream_id = header->fiber_no; - res.set_channel(ch); - res.set_timestamp(timestamp); - std::cout << " Generated frame with TS " << res.get_timestamp() << " for channel " << res.get_channel() << std::endl; - return res; -} - -void -wib_binary_to_tde_binary(std::string& filename, std::string& output) { - //FIXME: this is temporary.... we take 1 WIB frame and invent TDE frames from it... ADC values not set - std::ifstream file(filename.c_str(), std::ios::binary); - std::ofstream out(output.c_str(), std::ios::binary); - std::cout << "Transforming " << filename << " to " << output << '\n'; - auto size = std::filesystem::file_size(filename); - std::vector v(size); - file.read(v.data(), size); - file.close(); - int num_frames = size / sizeof(fddetdataformats::WIBFrame); - if (num_frames > 10 ) num_frames = 10; - std::cout << "Number of frames found: "<< num_frames << '\n'; - auto ptr = reinterpret_cast(v.data()); - uint64_t timestamp = ptr->get_timestamp(); - while(num_frames--){ - for (uint16_t i = 0; i < dunedaq::fddetdataformats::n_channels_per_amc; i++) { - auto tdefr = wibtotde(ptr, timestamp, i); - out.write(reinterpret_cast(&tdefr), sizeof(tdefr)); - } - timestamp += (dunedaq::fddetdataformats::tot_adc16_samples * dunedaq::fddetdataformats::ticks_between_adc_samples); - ptr++; - } - out.close(); -} - -void -wib_hdf5_to_tde_binary(std::string& /*filename*/, std::string& /*output*/) { -} - - -} // namespace dunedaq::rawdatautils -} - -#endif // RAWDATAUTILS_INCLUDE_WIBTOTDE16_HPP_ diff --git a/include/rawdatautils/WIBtoWIB2.hpp b/include/rawdatautils/WIBtoWIB2.hpp deleted file mode 100644 index be946c5..0000000 --- a/include/rawdatautils/WIBtoWIB2.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/** - * @file WIBtoWIB2.hpp Implementation of functions to convert files from the old WIB format to WIB2 - * - * This is part of the DUNE DAQ , copyright 2020. - * Licensing/copyright details are in the COPYING file that you should have - * received with this code. - */ - -#ifndef RAWDATAUTILS_INCLUDE_WIBTOWIB2_HPP_ -#define RAWDATAUTILS_INCLUDE_WIBTOWIB2_HPP_ - -#include -#include -#include -#include -#include "fddetdataformats/WIBFrame.hpp" -#include "fddetdataformats/WIB2Frame.hpp" - -namespace dunedaq { -namespace rawdatautils { - -fddetdataformats::WIB2Frame -wibtowib2(fddetdataformats::WIBFrame* fr, uint64_t timestamp=0) { - fddetdataformats::WIB2Frame res; - for (int i = 0; i < 256; ++i) { - res.set_adc(i, fr->get_channel(i)); - } - auto header = fr->get_wib_header(); - res.header.version = header->version; - res.header.crate = header->crate_no; - res.header.slot = header->slot_no; - res.header.link = header->fiber_no; - res.set_timestamp(timestamp); - return res; -} - -void -wib_binary_to_wib2_binary(std::string& filename, std::string& output) { - std::ifstream file(filename.c_str(), std::ios::binary); - std::ofstream out(output.c_str(), std::ios::binary); - std::cout << "Transforming " << filename << " to " << output << '\n'; - auto size = std::filesystem::file_size(filename); - std::vector v(size); - file.read(v.data(), size); - file.close(); - int num_frames = size / sizeof(fddetdataformats::WIBFrame); - std::cout << "Number of frames found: "<< num_frames << '\n'; - auto ptr = reinterpret_cast(v.data()); - uint64_t timestamp = ptr->get_timestamp(); - while(num_frames--){ - auto wib2fr = wibtowib2(ptr, timestamp); - timestamp += 32; - ptr++; - out.write(reinterpret_cast(&wib2fr), sizeof(wib2fr)); - } - out.close(); -} - -void -wib_hdf5_to_wib2_binary(std::string& /*filename*/, std::string& /*output*/) { -} - - -} // namespace dunedaq::rawdatautils -} - -#endif // RAWDATAUTILS_INCLUDE_WIBTOWIB2_HPP_ diff --git a/include/rawdatautils/WIBtoWIBEth.hpp b/include/rawdatautils/WIBtoWIBEth.hpp deleted file mode 100644 index fe62176..0000000 --- a/include/rawdatautils/WIBtoWIBEth.hpp +++ /dev/null @@ -1,77 +0,0 @@ -/** - * @file WIBtoWIBEth.hpp Implementation of functions to convert files from the old WIB format to WIBEth - * - * This is part of the DUNE DAQ , copyright 2020. - * Licensing/copyright details are in the COPYING file that you should have - * received with this code. - */ - -#ifndef RAWDATAUTILS_INCLUDE_WIBTOWIBETH_HPP_ -#define RAWDATAUTILS_INCLUDE_WIBTOWIBETH_HPP_ - -#include -#include -#include -#include -#include "fddetdataformats/WIBFrame.hpp" -#include "fddetdataformats/WIBEthFrame.hpp" - -namespace dunedaq { -namespace rawdatautils { - -fddetdataformats::WIBEthFrame -wibtowibeth(fddetdataformats::WIBFrame* fr, uint64_t timestamp=0, int starting_channel=0) { - fddetdataformats::WIBEthFrame res; - for (int j = 0; j < 64; ++j) { - for (int i = 0; i < 64; ++i) { - res.set_adc(i, j, (fr + j)->get_channel(starting_channel + i)); - } - } - auto header = fr->get_wib_header(); - res.daq_header.version = header->version; //Warning, in WIBFrames version has 5 bits and here it has 4 - res.daq_header.crate_id = header->crate_no; - res.daq_header.slot_id = header->slot_no; - res.daq_header.stream_id = header->fiber_no; - res.set_channel(starting_channel); - res.set_timestamp(timestamp); - res.header.extra_data = 0xdeadbeef0badface; - return res; -} - -void -wib_binary_to_wibeth_binary(std::string& filename, std::string& output) { - std::ifstream file(filename.c_str(), std::ios::binary); - std::cout << "Transforming " << filename << " to " << output << '\n'; - auto size = std::filesystem::file_size(filename); - std::vector v(size); - file.read(v.data(), size); - file.close(); - std::cout << "Number of frames found: "<< size / sizeof(fddetdataformats::WIBFrame) << '\n'; - - std::ofstream out(output.c_str(), std::ios::binary); - std::vector starting_channel {0, 64, 128, 192}; - for (auto& sc : starting_channel) { - auto ptr = reinterpret_cast(v.data()); - uint64_t timestamp = ptr->get_timestamp(); - int num_frames = size / sizeof(fddetdataformats::WIBFrame); - while(num_frames >= 64){ - auto wibethfr = wibtowibeth(ptr, timestamp, sc); - timestamp += 32 * 64; - ptr += 64; - num_frames -= 64; - out.write(reinterpret_cast(&wibethfr), sizeof(wibethfr)); - } - out.close(); - } - -} - -void -wib_hdf5_to_wibeth_binary(std::string& /*filename*/, std::string& /*output*/) { -} - - -} // namespace dunedaq::rawdatautils -} - -#endif // RAWDATAUTILS_INCLUDE_WIBTOWIBETH_HPP_ diff --git a/pybindsrc/WIB2Unpacker.cpp b/pybindsrc/WIB2Unpacker.cpp deleted file mode 100644 index 938f3f9..0000000 --- a/pybindsrc/WIB2Unpacker.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/** - * @file WIB2Unpacker.cc Fast C++ -> numpy WIB2 format unpacker - * - * This is part of the DUNE DAQ , copyright 2020. - * Licensing/copyright details are in the COPYING file that you should have - * received with this code. - */ - -#include "fddetdataformats/WIB2Frame.hpp" -#include "daqdataformats/Fragment.hpp" - -#include -#include - -namespace py = pybind11; -namespace dunedaq::rawdatautils::wib2 { - -/** - * @brief Gets number of WIB2Frames in a fragment - */ -uint32_t get_n_frames(daqdataformats::Fragment const& frag){ - return (frag.get_size() - sizeof(daqdataformats::FragmentHeader)) / sizeof(fddetdataformats::WIB2Frame); -} - -/** - * @brief Unpacks data containing WIB2Frames into a numpy array with the ADC - * values and dimension (number of WIB2Frames, 256) - * Warning: It doesn't check that nframes is a sensible value (can read out of bounds) - */ -py::array_t np_array_adc_data(void* data, int nframes){ - py::array_t ret(256 * nframes); - auto ptr = static_cast(ret.request().ptr); - for (size_t i=0; i<(size_t)nframes; ++i) { - auto fr = reinterpret_cast(static_cast(data) + i * sizeof(fddetdataformats::WIB2Frame)); - for (size_t j=0; j<256; ++j) - ptr[256 * i + j] = fr->get_adc(j); - } - ret.resize({nframes, 256}); - - return ret; -} - -/** - * @brief Unpacks data containing WIB2Frames into a numpy array with the - * timestamps with dimension (number of WIB2Frames) - * Warning: It doesn't check that nframes is a sensible value (can read out of bounds) - */ -py::array_t np_array_timestamp_data(void* data, int nframes){ - py::array_t ret(nframes); - auto ptr = static_cast(ret.request().ptr); - for (size_t i=0; i<(size_t)nframes; ++i) { - auto fr = reinterpret_cast(static_cast(data) + i * sizeof(fddetdataformats::WIB2Frame)); - ptr[i] = fr->get_timestamp(); - } - - return ret; -} - -/** - * @brief Unpacks a Fragment containing WIB2Frames into a numpy array with the - * ADC values and dimension (number of WIB2Frames in the Fragment, 256) - */ -py::array_t np_array_adc(daqdataformats::Fragment const& frag){ - return np_array_adc_data(frag.get_data(), get_n_frames(frag)); -} - -/** - * @brief Unpacks the timestamps in a Fragment containing WIBFrames into a numpy - * array with dimension (number of WIB2Frames in the Fragment) - */ -py::array_t np_array_timestamp(daqdataformats::Fragment const& frag){ - return np_array_timestamp_data(frag.get_data(), get_n_frames(frag)); -} - - -} // namespace dunedaq::rawdatautils::wib2 // NOLINT diff --git a/pybindsrc/WIBUnpacker.cpp b/pybindsrc/WIBUnpacker.cpp deleted file mode 100644 index 059f8dc..0000000 --- a/pybindsrc/WIBUnpacker.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/** - * @file WIBUnpacker.cc Fast C++ -> numpy WIB format decoder - * - * This is part of the DUNE DAQ , copyright 2020. - * Licensing/copyright details are in the COPYING file that you should have - * received with this code. - */ - -#include "fddetdataformats/WIBFrame.hpp" -#include "daqdataformats/Fragment.hpp" - -#include -#include - -namespace py = pybind11; -namespace dunedaq::rawdatautils::wib { - -/** - * @brief Unpacks data containing WIBFrames into a numpy array with the ADC - * values and dimension (number of WIBFrames, 256) - * Warning: It doesn't check that nframes is a sensible value (can read out of bounds) - */ -py::array_t np_array_adc_data(void* data, int nframes){ - py::array_t ret(256 * nframes); - auto ptr = static_cast(ret.request().ptr); - for (size_t i=0; i<(size_t)nframes; ++i) { - auto fr = reinterpret_cast(static_cast(data) + i * sizeof(fddetdataformats::WIBFrame)); - for (size_t j=0; j<256; ++j) - ptr[256 * i + j] = fr->get_channel(j); - } - ret.resize({nframes, 256}); - - return ret; -} - -/** - * @brief Unpacks data containing WIBFrames into a numpy array with the - * timestamps with dimension (number of WIBFrames) - * Warning: It doesn't check that nframes is a sensible value (can read out of bounds) - */ -py::array_t np_array_timestamp_data(void* data, int nframes){ - py::array_t ret(nframes); - auto ptr = static_cast(ret.request().ptr); - for (size_t i=0; i<(size_t)nframes; ++i) { - auto fr = reinterpret_cast(static_cast(data) + i * sizeof(fddetdataformats::WIBFrame)); - ptr[i] = fr->get_timestamp(); - } - - return ret; -} - -/** - * @brief Unpacks a Fragment containing WIBFrames into a numpy array with the - * ADC values and dimension (number of WIBFrames in the Fragment, 256) - */ -py::array_t np_array_adc(daqdataformats::Fragment& frag){ - return np_array_adc_data(frag.get_data(), (frag.get_size() - sizeof(daqdataformats::FragmentHeader)) / sizeof(fddetdataformats::WIBFrame)); -} - -/** - * @brief Unpacks the timestamps in a Fragment containing WIBFrames into a numpy - * array with dimension (number of WIBFrames in the Fragment) - */ -py::array_t np_array_timestamp(daqdataformats::Fragment& frag){ - return np_array_timestamp_data(frag.get_data(), (frag.get_size() - sizeof(daqdataformats::FragmentHeader)) / sizeof(fddetdataformats::WIBFrame)); -} - - -} // namespace dunedaq::rawdatautils::wib // NOLINT diff --git a/pybindsrc/file_conversion.cpp b/pybindsrc/file_conversion.cpp deleted file mode 100644 index 1e50ce3..0000000 --- a/pybindsrc/file_conversion.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/** - * @file file_conversion.cpp Python bindings for file conversions between formats - * - * This is part of the DUNE DAQ Software Suite, copyright 2020. - * Licensing/copyright details are in the COPYING file that you should have - * received with this code. - */ - -#include "rawdatautils/WIBtoWIB2.hpp" -#include "rawdatautils/WIBtoWIBEth.hpp" -#include "rawdatautils/WIBtoTDE.hpp" - - -#include -#include -#include - -namespace py = pybind11; - -namespace dunedaq { -namespace rawdatautils { - -namespace fc { -namespace python { - -void -register_file_conversion(py::module& m) -{ - m.def("wib_hdf5_to_wib2_binary", &wib_hdf5_to_wib2_binary); - m.def("wib_binary_to_wib2_binary", &wib_binary_to_wib2_binary); - m.def("wib_hdf5_to_wibeth_binary", &wib_hdf5_to_wibeth_binary); - m.def("wib_binary_to_wibeth_binary", &wib_binary_to_wibeth_binary); - m.def("wib_hdf5_to_tde_binary", &wib_hdf5_to_tde_binary); - m.def("wib_binary_to_tde_binary", &wib_binary_to_tde_binary); -} - -} // namespace python -} // namespace file_conversion -} // namespace rawdatautils -} // namespace dunedaq diff --git a/pybindsrc/unpack.cpp b/pybindsrc/unpack.cpp index dde4786..511ece7 100644 --- a/pybindsrc/unpack.cpp +++ b/pybindsrc/unpack.cpp @@ -6,8 +6,6 @@ * received with this code. */ -#include "fddetdataformats/WIBFrame.hpp" -#include "fddetdataformats/WIB2Frame.hpp" #include "fddetdataformats/DAPHNEFrame.hpp" #include "fddetdataformats/DAPHNEEthFrame.hpp" #include "fddetdataformats/DAPHNEEthStreamFrame.hpp" @@ -36,22 +34,6 @@ void print_hex_fragment(daqdataformats::Fragment const& frag) { } - -namespace wib { - extern py::array_t np_array_adc(daqdataformats::Fragment& frag); - extern py::array_t np_array_adc_data(void* data, int nframes); - extern py::array_t np_array_timestamp(daqdataformats::Fragment& frag); - extern py::array_t np_array_timestamp_data(void* data, int nframes); -} - -namespace wib2 { - extern uint32_t get_n_frames(daqdataformats::Fragment const& frag); - extern py::array_t np_array_adc(daqdataformats::Fragment const& frag); - extern py::array_t np_array_adc_data(void* data, int nframes); - extern py::array_t np_array_timestamp(daqdataformats::Fragment const& frag); - extern py::array_t np_array_timestamp_data(void* data, int nframes); -} - namespace wibeth { extern uint32_t get_n_frames(daqdataformats::Fragment const& frag); extern py::array_t np_array_adc(daqdataformats::Fragment const& frag); @@ -116,19 +98,6 @@ register_unpack(py::module& m) { m.def("print_hex_fragment", &print_hex_fragment); - py::module_ wib_module = m.def_submodule("wib"); - wib_module.def("np_array_adc", &wib::np_array_adc); - wib_module.def("np_array_timestamp", &wib::np_array_timestamp); - wib_module.def("np_array_adc_data", &wib::np_array_adc_data); - wib_module.def("np_array_timestamp_data", &wib::np_array_timestamp_data); - - py::module_ wib2_module = m.def_submodule("wib2"); - wib2_module.def("get_n_frames", &wib2::get_n_frames); - wib2_module.def("np_array_adc", &wib2::np_array_adc); - wib2_module.def("np_array_timestamp", &wib2::np_array_timestamp); - wib2_module.def("np_array_adc_data", &wib2::np_array_adc_data); - wib2_module.def("np_array_timestamp_data", &wib2::np_array_timestamp_data); - py::module_ wibeth_module = m.def_submodule("wibeth"); wibeth_module.def("get_n_frames", &wibeth::get_n_frames); wibeth_module.def("np_array_adc", &wibeth::np_array_adc); diff --git a/scripts/hdf5_wib2_to_binary.py b/scripts/hdf5_wib2_to_binary.py deleted file mode 100755 index e7737c1..0000000 --- a/scripts/hdf5_wib2_to_binary.py +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env python3 -""" -Created on: 21/02/2023 15:28 - -Author: Shyam Bhuller - -Description: Python script to write WIB2 frames from DUNE-DAQ HDF5 files to binary files. -""" - -import argparse - -from hdf5libs import HDF5RawDataFile -import daqdataformats -import fddetdataformats - -from rich import print - - -def Debug(x): - """ print if we are in debug mode - - Args: - x (any): thing to prints - """ - if debug: - print(x) - - -def main(args): - h5file = HDF5RawDataFile(args.file_name) - - total_records = len(h5file.get_all_record_ids()) - if args.n_records == -1: - args.n_records = total_records - if args.n_records > total_records: - raise Exception(f"Number of specified records is greater than the total {total}") - - n_links = len([f for f in h5file.get_fragment_dataset_paths(1) if f.split("_")[-1] == "WIB"]) # exclude other fragments in the record that are not WIB frames - if args.link >= n_links: - raise Exception(f"Link number out of range.") - - out_name = f"wib_link_{args.link}.bin" - with open(out_name, "wb") as bf: - total_frames = 0 - # loop over all triggers - for i in range(args.n_records): - header = h5file.get_record_header_dataset_path(i+1) # trigger number starts at 1 - Debug(header) - - fragments = h5file.get_fragment_dataset_paths(i+1) - fragments = [f for f in fragments if f.split("_")[-1] == "WIB"] # exclude other fragments in the record that are not WIB frames - - Debug(f"loading fragment: {fragments[args.link]}") - f = h5file.get_frag(fragments[args.link]) - - WIB2Frame_size = fddetdataformats.WIB2Frame.sizeof() - - n_frames = (f.get_size() - f.get_header().sizeof()) // WIB2Frame_size # calculate the number of wib frames per fragment - for j in range(n_frames): - Debug(f.get_fragment_type()) - Debug(f.get_element_id()) - - data = fddetdataformats.WIB2Frame(f.get_data(j * WIB2Frame_size)) # unpack fragment to WIB2Frame - - Debug(f"{data.sizeof()=}") - - bf.write(bytearray(data.get_bytes())) # write binary data to the file - total_frames += j - print(f"writing {total_frames} WIB2 frames to binary file.", "\r") - print(f"wrote {args.n_records} fragments from wib link {args.link} to file {out_name}.") - return - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description = 'Python script to write WIB2 frames from DUNE-DAQ HDF5 files to binary files.') - parser.add_argument(dest = "file_name", help = 'path to HDF5 file') - parser.add_argument("-l", "--link", dest = "link", type = int, help = "link number to conver to binary", required = True) - parser.add_argument('-n', '--num-of-records', dest = "n_records", type = int, help = 'specify number of records to be parsed, -1 will parse all records', default = 0, required = True) - parser.add_argument("--debug", dest = "debug", action = "store_true", help = "Debugging information") - args = parser.parse_args() - debug = args.debug - Debug(vars(args)) - main(args) diff --git a/scripts/wibdecoder.py b/scripts/wibdecoder.py deleted file mode 100755 index dc64e82..0000000 --- a/scripts/wibdecoder.py +++ /dev/null @@ -1,185 +0,0 @@ -#!/usr/bin/env python3 - -from hdf5libs import HDF5RawDataFile - -import daqdataformats -import detdataformats -import fddetdataformats -import rawdatautils.unpack.wibeth as wibeth_unpack -import rawdatautils.unpack.wib2 as wib2_unpack -import rawdatautils.utilities.wib2 as wib2_utils -import rawdatautils.utilities.wibeth as wibeth_utils -import detchannelmaps - -import click -import time -import numpy as np - - -@click.command() -@click.argument('filenames', nargs=-1, type=click.Path(exists=True)) -@click.option('--nrecords', '-n', default=-1, help='How many Trigger Records to process (default: all)') -@click.option('--nskip', default=0, help='How many Trigger Records to skip (default: 0)') -@click.option('--channel-map', default=None, help="Channel map to load (default: None)") -@click.option('--print-headers', is_flag=True, help="Print WIB2Frame headers") -@click.option('--print-adc-stats', is_flag=True, help="Print ADC Pedestals/RMS") -@click.option('--check-timestamps', is_flag=True, help="Check WIB2 Frame Timestamps") -@click.option('--det', default='HD_TPC', help='Subdetector string (default: HD_TPC)') -@click.option('--quiet', is_flag=True, help="Print only final summary information") - -def main(filenames, nrecords, nskip, channel_map, print_headers, print_adc_stats, check_timestamps, det, quiet): - - for filename in filenames: - - h5_file = HDF5RawDataFile(filename) - - records = h5_file.get_all_record_ids() - - if nskip > len(records): - print(f'Requested records to skip {nskip} is greater than number of records {len(records)}. Exiting...') - return - if nrecords>0: - if (nskip+nrecords)>len(records): - nrecords=-1 - else: - nrecords=nskip+nrecords - - records_to_process = [] - if nrecords==-1: - records_to_process = records[nskip:] - else: - records_to_process = records[nskip:nrecords] - print(f'Will process {len(records_to_process)} of {len(records)} records.') - - #have channel numbers per geoid in here - ch_map = None - if channel_map is not None: - ch_map = detchannelmaps.make_tpc_map(channel_map) - offline_ch_num_dict = {} - offline_ch_plane_dict = {} - - for r in records_to_process: - - if not quiet: - print(f'Processing (Record Number,Sequence Number)=({r[0],r[1]})') - - wib_geo_ids = h5_file.get_geo_ids_for_subdetector(r,detdataformats.DetID.string_to_subdetector(det)) - - timestamps_frame0 = [] - for gid in wib_geo_ids: - #geo_info = detchannelmaps.HardwareMapService.parse_geo_id(gid) - det_link = 0xffff & (gid >> 48); - det_slot = 0xffff & (gid >> 32); - det_crate = 0xffff & (gid >> 16); - det_id = 0xffff & gid; - subdet = detdataformats.DetID.Subdetector(det_id) - det_name = detdataformats.DetID.subdetector_to_string(subdet) - - if not quiet: - print(f'\tProcessing subdetector {det_name}, crate {det_crate}, slot {det_slot}, link {det_link}') - - frag = h5_file.get_frag(r,gid) - frag_hdr = frag.get_header() - frag_type = frag.get_fragment_type() - frag_type_name = "Unknown" - frag_ts = frag.get_trigger_timestamp() - - unpacker = None - utils = None - FrameType = None - if(frag_type==daqdataformats.FragmentType.kWIB): - frag_type_name="WIB" - unpacker = wib2_unpack - utils = wib2_utils - FrameType = fddetdataformats.WIB2Frame - elif(frag_type==daqdataformats.FragmentType.kWIBEth): - frag_type_name="WIBEth" - unpacker = wibeth_unpack - utils = wibeth_utils - FrameType = fddetdataformats.WIBEthFrame - - if not quiet: - print(f'\tFragment type is {frag_type} ({frag_type_name})') - print(f'\tTrigger timestamp for fragment is {frag_ts}') - - if unpacker is None: - print('\tUnrecognized WIB fragment type. Continue.') - continue - - n_frames = unpacker.get_n_frames(frag) - if not quiet: - print(f'\tFound {n_frames} {frag_type_name} frames.') - - wf = FrameType(frag.get_data()) - - #print header info - if print_headers: - print('\n\t==== WIB HEADER (First Frame) ====') - utils.print_header(wf,"\t\t") - - #fill channel map info if needed - if(offline_ch_num_dict.get(gid) is None): - if channel_map is None: - offline_ch_num_dict[gid] = np.arange(64) - offline_ch_plane_dict[gid] = np.full(64,9999) - else: - crate, slot, stream, nchans = None, None, None, None - if frag_type==daqdataformats.FragmentType.kWIBEth: - dh = wf.get_daqheader() - offline_ch_num_dict[gid] = np.array([ch_map.get_offline_channel_from_det_crate_slot_stream_chan(dh.det_id, dh.crate_id, dh.slot_id, dh.stream_id, c) for c in range(64)]) - else: - wh = wf.get_header() - offline_ch_num_dict[gid] = np.array([ch_map.get_offline_channel_from_det_crate_slot_stream_chan(wh.detector_id, wh.crate, wh.slot, wh.link, c) for c in range(256)]) - offline_ch_plane_dict[gid] = np.array([ ch_map.get_plane_from_offline_channel(uc) for uc in offline_ch_num_dict[gid] ]) - - - #unpack timestamps into numpy array of uin64 - if check_timestamps: - timestamps = unpacker.np_array_timestamp(frag) - timestamps_diff = np.diff(timestamps) - timestamps_diff_vals, timestamps_diff_counts = np.unique(timestamps_diff, return_counts=True) - - if(n_frames>0): - timestamps_frame0.append(timestamps[0]) - if not quiet or len(timestamps_diff_counts)>1: - print('\n\t==== TIMESTAMP CHECK ====') - print(f'\t\tTimestamps (First, Last, Min, Max): ({timestamps[0]},{timestamps[-1]},{np.min(timestamps)},{np.max(timestamps)})') - print(f'\t\tTimestamp diffs: {timestamps_diff_vals}') - print(f'\t\tTimestamp diff counts: {timestamps_diff_counts}') - print(f'\t\tAverage diff: {np.mean(timestamps_diff)}') - else: - timestamps_frame0.append(0) - - - - if print_adc_stats: - - #unpack adcs into a n_frames x 256 numpy array of uint16 - adcs = unpacker.np_array_adc(frag) - adcs_rms = np.std(adcs,axis=0) - adcs_ped = np.mean(adcs,axis=0) - - print('\n\t====WIB DATA====') - - for ch,rms in enumerate(adcs_rms): - print(f'\t\tch {offline_ch_num_dict[gid][ch]} (plane {offline_ch_plane_dict[gid][ch]}): ped = {adcs_ped[ch]:.2f}, rms = {adcs_rms[ch]:.4f}') - - #print("\n") - #end gid loop - - if check_timestamps: - timestamps_frame0 = np.array(timestamps_frame0) - timestamps_frame0_diff = timestamps_frame0 - timestamps_frame0[0] - - if not quiet or np.any(timestamps_frame0_diff): - print('\n\t==== TIMESTAMP ACROSS WIBS CHECK ====') - print(f'\t\tTimestamp diff relative to first WIB',timestamps_frame0_diff) - - #end record loop - - #end file loop - print(f'Processed all requested records') - - -if __name__ == '__main__': - main() diff --git a/test/scripts/wibdecoder_BasicStats.py b/test/scripts/wibdecoder_BasicStats.py deleted file mode 100644 index 4920d78..0000000 --- a/test/scripts/wibdecoder_BasicStats.py +++ /dev/null @@ -1,70 +0,0 @@ -from hdf5libs import HDF5RawDataFile - -import daqdataformats -from rawdatautils.unpack.wib import * -import fddetdataformats -import detchannelmaps - -import click -import time -import numpy as np - -@click.command() -@click.argument('filename', type=click.Path(exists=True)) -@click.option('--tr-count', default=-1, help='How many Trigger Records to test') -@click.option('--channel-map', default=None, help="Channel map to load (default: None)") -def main(filename, tr_count, channel_map): - - h5_file = HDF5RawDataFile(filename) - - records = h5_file.get_all_record_ids() - records_to_process = records[0:tr_count] - print(f'Will process {len(records_to_process)} of {len(records)} records.') - - #have channel numbers per geoid in here - ch_map = None - if channel_map is not None: - ch_map = detchannelmaps.make_tpc_map(channel_map) - offline_ch_num_dict = {} - - for r in records_to_process: - print(f'Processing (Record Number,Sequence Number)=({r[0],r[1]})') - wib_geo_ids = h5_file.get_geo_ids(r,daqdataformats.GeoID.SystemType.kTPC) - for gid in wib_geo_ids: - print(f'\tProcessing geoid {gid}') - - frag = h5_file.get_frag(r,gid) - frag_hdr = frag.get_header() - frag_ts = frag.get_trigger_timestamp() - - print(f'\tTrigger timestamp for fragment is {frag_ts}') - - n_frames = (frag.get_size()-frag_hdr.sizeof())//fddetdataformats.WIBFrame.sizeof() - - if(offline_ch_num_dict.get(gid) is None): - if channel_map is None: - offline_ch_num_dict[gid] = range(256) - else: - wf = fddetdataformats.WIBFrame(frag.get_data()) - wh = wf.get_wib_header() - offline_ch_num_dict[gid] = [ch_map.get_offline_channel_from_crate_slot_fiber_chan(wh.crate_no, wh.slot_no, wh.fiber_no, c) for c in range(256)] - - - #unpack timestamps into numpy array of uin64 - #timestamps = np_array_timestamp(frag) - - #unpack adcs into a n_frames x 256 numpy array of uint16 - adcs = np_array_adc(frag) - - adcs_rms = np.std(adcs,axis=0) - - for ch,rms in enumerate(adcs_rms): - print(f'\t\tch {offline_ch_num_dict[gid][ch]}: rms = {rms}') - - #end gid loop - #end record loop - - print(f'Processed all requested records') - -if __name__ == '__main__': - main() diff --git a/test/scripts/wibdecoder_TimeTest.py b/test/scripts/wibdecoder_TimeTest.py deleted file mode 100644 index 87ed6e5..0000000 --- a/test/scripts/wibdecoder_TimeTest.py +++ /dev/null @@ -1,67 +0,0 @@ -from hdf5libs import HDF5RawDataFile -import daqdataformats -from rawdatautils.unpack.wib import * -import fddetdataformats -import click -import time -import numpy as np - -@click.command() -@click.argument('filename', type=click.Path(exists=True)) -@click.option('--tr-count', default=-1, help='How many Trigger Records to test') -def main(filename, tr_count): - """Test the python WIBFrame decoders on an HDF5 file containing WIBFrames, - for example np02_bde_coldbox_run011918_0001_20211029T122926.hdf5 - """ - - h5_file = HDF5RawDataFile(filename) - - records = h5_file.get_all_record_ids() - records_to_process = records[0:tr_count] - print(f'Will process {len(records_to_process)} of {len(records)} records.') - - for r in records_to_process: - print(f'Processing (Record Number,Sequence Number)=({r[0],r[1]})') - wib_geo_ids = h5_file.get_geo_ids(r,daqdataformats.GeoID.SystemType.kTPC) - for gid in wib_geo_ids: - print(f'Processing geoid {gid}') - frag = h5_file.get_frag(r,gid) - frag_hdr = frag.get_header() - - n_frames = (frag.get_size()-frag_hdr.sizeof())//fddetdataformats.WIBFrame.sizeof() - - wf = fddetdataformats.WIBFrame(frag.get_data()) - wh = wf.get_wib_header() - - ts = np.zeros(n_frames,dtype='uint64') - adcs = np.zeros((n_frames,256),dtype='uint16') - - t0 = time.time() - for iframe in range(n_frames): - wf = fddetdataformats.WIBFrame(frag.get_data(iframe*fddetdataformats.WIBFrame.sizeof())) - ts[iframe] = wf.get_timestamp() - adcs[iframe] = [ wf.get_channel(k) for k in range(256) ] - print(f'Time to decode with the python for loop {time.time() - t0:.3f} s') - - t0 = time.time() - timestamps = np_array_timestamp_data(frag.get_data(), n_frames) - ary = np_array_adc_data(frag.get_data(), n_frames) - print(f'Time to decode with the C++ -> numpy function {time.time() - t0:.3f} s') - - t0 = time.time() - timestamps = np_array_timestamp(frag) - ary = np_array_adc(frag) - print(f'Time to decode with the C++ -> numpy function (with a Fragment as input) {time.time() - t0:.3f} s') - - if (adcs == ary).all() and (ts == timestamps).all(): - print(f'The arrays obtained for TR {r} are the same for the python for loop and the C++ -> numpy functions') - else: - print('Test failed, the python for loop and the C++ -> numpy functions return different results') - - #end gid loop - #end record loop - - print(f'Processed all requested records') - -if __name__ == '__main__': - main() diff --git a/unittest/WIBtoWIB2_test.cxx b/unittest/WIBtoWIB2_test.cxx deleted file mode 100644 index 148c40e..0000000 --- a/unittest/WIBtoWIB2_test.cxx +++ /dev/null @@ -1,64 +0,0 @@ -/** - * @file WIBtoWIB2_test.cxx Unit Tests for the WIB -> WIB2 file converter - * - * This is part of the DUNE DAQ Application Framework, copyright 2020. - * Licensing/copyright details are in the COPYING file that you should have - * received with this code. - */ - -/** - * @brief Name of this test module - */ -#define BOOST_TEST_MODULE WIBtoWIB2_test // NOLINT - -#include "boost/test/unit_test.hpp" - -#include "rawdatautils/WIBtoWIB2.hpp" -#include "fddetdataformats/WIBFrame.hpp" - -#include - -namespace dunedaq{ -namespace rawdatautils{ - -BOOST_AUTO_TEST_SUITE(WIBtoWIB2_test) - -std::mt19937 mt(1000007); - -BOOST_AUTO_TEST_CASE(WIBtoWIB2_test1) -{ - - std::uniform_real_distribution dist(0, 4096); - - std::vector adcs; - for (int i = 0; i < 256; i++) { - int num = dist(mt); - adcs.push_back(num); - } - - fddetdataformats::WIBFrame fr; - for (int i = 0; i < 256; i++){ - fr.set_channel(i, adcs[i]); - } - auto header = fr.get_wib_header(); - header->version = 31; - header->crate_no = 31; - header->slot_no = 7; - header->fiber_no = 7; - fr.set_timestamp(1844674407370955161U); //2**48-1 - - auto wib2fr = wibtowib2(&fr, 1844674407370955161U); - for (int i = 0; i < 256; i++){ - BOOST_REQUIRE_EQUAL(adcs[i], wib2fr.get_adc(i)); - } - BOOST_REQUIRE_EQUAL(wib2fr.header.version, 31); - BOOST_REQUIRE_EQUAL(wib2fr.header.crate, 31); - BOOST_REQUIRE_EQUAL(wib2fr.header.slot, 7); - BOOST_REQUIRE_EQUAL(wib2fr.header.link, 7); - BOOST_REQUIRE_EQUAL(wib2fr.get_timestamp(), 1844674407370955161U); -} - -} // namespace dunedaq -} // namespace rawdatautils - -BOOST_AUTO_TEST_SUITE_END()