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 12 of file copy_tpstream.cxx.

13{
14
15 CLI::App app{"tapipe"};
16 // argv = app.ensure_utf8(argv);
17
18 std::string input_file_path;
19 app.add_option("-i", input_file_path, "Input TPStream file path")->required();
20 std::string output_file_path;
21 app.add_option("-o", output_file_path, "Output TPStream file path")->required();
22 bool verbose = false;
23 app.add_flag("-v", verbose);
24 CLI11_PARSE(app, argc, argv);
25
26 fmt::print("TPStream file: {}\n", input_file_path);
27
28 // Pointer to DD hdf5 file
29 std::unique_ptr<hdf5libs::HDF5RawDataFile> input_file, output_file;
30
31 try {
32 input_file = std::make_unique<hdf5libs::HDF5RawDataFile>(input_file_path);
33 } catch(const hdf5libs::FileOpenFailed& e) {
34 fmt::print("ERROR: failed to open input file '{}'\n", input_file_path);
35 std::cerr << e.what() << '\n';
36 exit(-1);
37 }
38
39 if (!input_file->is_timeslice_type()) {
40 fmt::print("ERROR: input file '{}' not of type 'TimeSlice'\n", input_file_path);
41 exit(-1);
42 }
43
44 auto run_number = input_file->get_attribute<daqdataformats::run_number_t>("run_number");
45 auto file_index = input_file->get_attribute<size_t>("file_index");
46 // auto creation_timestamp = input_file->get_attribute("creation_timestamp");
47 auto application_name = input_file->get_attribute<std::string>("application_name");
48
49 fmt::print("Run Number: {}\nFile Index: {}\nApp name: '{}'\n", run_number, file_index, application_name);
50
51 try {
52 output_file = std::make_unique<hdf5libs::HDF5RawDataFile>(
53 output_file_path,
54 input_file->get_attribute<daqdataformats::run_number_t>("run_number"),
55 input_file->get_attribute<size_t>("file_index"),
56 input_file->get_attribute<std::string>("application_name"),
57 input_file->get_file_layout().get_file_layout_params(),
58 input_file->get_srcid_geoid_map()
59 );
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
77 /* code */
78 return 0;
79}