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