DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
copy_tpstream.cxx File Reference
#include "CLI/App.hpp"
#include "CLI/Config.hpp"
#include "CLI/Formatter.hpp"
#include <fmt/core.h>
#include <fmt/format.h>
#include "hdf5libs/HDF5RawDataFile.hpp"
Include dependency graph for copy_tpstream.cxx:

Go to the source code of this file.

Functions

int main (int argc, char const *argv[])

Function Documentation

◆ main()

int main ( int argc,
char const * argv[] )

Definition at line 13 of file copy_tpstream.cxx.

14{
15
16 CLI::App app{ "tapipe" };
17 // argv = app.ensure_utf8(argv);
18
19 std::string input_file_path;
20 app.add_option("-i", input_file_path, "Input TPStream file path")->required();
21 std::string output_file_path;
22 app.add_option("-o", output_file_path, "Output TPStream file path")->required();
23 bool verbose = false;
24 app.add_flag("-v", verbose);
25 CLI11_PARSE(app, argc, argv);
26
27 fmt::print("TPStream file: {}\n", input_file_path);
28
29 // Pointer to DD hdf5 file
30 std::unique_ptr<hdf5libs::HDF5RawDataFile> input_file, output_file;
31
32 try {
33 input_file = std::make_unique<hdf5libs::HDF5RawDataFile>(input_file_path);
34 } catch (const hdf5libs::FileOpenFailed& e) {
35 fmt::print("ERROR: failed to open input file '{}'\n", input_file_path);
36 std::cerr << e.what() << '\n';
37 exit(-1);
38 }
39
40 if (!input_file->is_timeslice_type()) {
41 fmt::print("ERROR: input file '{}' not of type 'TimeSlice'\n", input_file_path);
42 exit(-1);
43 }
44
45 auto run_number = input_file->get_attribute<daqdataformats::run_number_t>("run_number");
46 auto file_index = input_file->get_attribute<size_t>("file_index");
47 // auto creation_timestamp = input_file->get_attribute("creation_timestamp");
48 auto application_name = input_file->get_attribute<std::string>("application_name");
49
50 fmt::print("Run Number: {}\nFile Index: {}\nApp name: '{}'\n", run_number, file_index, application_name);
51
52 try {
53 output_file =
54 std::make_unique<hdf5libs::HDF5RawDataFile>(output_file_path,
55 input_file->get_attribute<daqdataformats::run_number_t>("run_number"),
56 input_file->get_attribute<size_t>("file_index"),
57 input_file->get_attribute<std::string>("application_name"),
58 input_file->get_file_layout().get_file_layout_params(),
59 input_file->get_srcid_geoid_map());
60
61 } catch (const hdf5libs::FileOpenFailed& e) {
62 std::cout << "ERROR: failed to open output file" << std::endl;
63 std::cerr << e.what() << '\n';
64 exit(-1);
65 }
66
67 auto records = input_file->get_all_record_ids();
68
69 for (const auto& rid : records) {
70 auto tsl = input_file->get_timeslice(rid);
71 output_file->write(tsl);
72 // Just 1, for testing
73 // break;
74 }
75
76 /* code */
77 return 0;
78}