119 std::string input_file;
120 bool verbose =
false;
121 CLI::App app{
"tapipe"};
124 app.add_option(
"-i", input_file,
"Input TPStream file path")->required();
125 app.add_flag(
"-v", verbose);
126 CLI11_PARSE(app, argc, argv);
128 fmt::print(
"TPStream file: {}\n", input_file);
131 std::unique_ptr<hdf5libs::HDF5RawDataFile> tpstream_file;
134 tpstream_file = std::make_unique<hdf5libs::HDF5RawDataFile>(input_file);
135 }
catch(
const hdf5libs::FileOpenFailed& e) {
136 std::cout <<
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ERROR <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
137 std::cerr << e.what() <<
'\n';
141 fmt::print(
"{} opened\n", input_file);
144 fmt::print(
" File type: {}\n", tpstream_file->get_record_type());
147 auto records = tpstream_file->get_all_record_ids();
148 std::set<daqdataformats::SourceID> source_ids;
150 for(
const auto& rid : records ) {
151 const auto& [id, slice] = rid;
152 auto sids = tpstream_file->get_source_ids(rid);
153 source_ids.merge(sids);
155 fmt::print(
"TR {}:{} [{}]\n",
id, slice, fmt::join(sids,
", "));
157 fmt::print(
"Source IDs [{}]\n", fmt::join(source_ids,
", "));
160 std::map<daqdataformats::SourceID, hdf5libs::HDF5RawDataFile::record_id_set> m;
161 for(
const auto& sid: source_ids ) {
162 for(
const auto& rid : records ) {
163 auto rec_sids = tpstream_file->get_source_ids(rid);
164 if (rec_sids.find(sid) != rec_sids.end()) {
169 fmt::print(
"Record IDs for {} : [{}]\n", sid, fmt::join(m[sid],
", "));
173 fmt::print(
" Number of time slices in file: {}\n", records.size());
179 auto tp_records = m[tp_writer_sid];
182 std::vector<trgdataformats::TriggerPrimitive> tp_buffer;
184 auto a_slice_id = *tp_records.begin();
185 fmt::print(
"Processing tp time slice {}\n", a_slice_id);
188 auto tsl_hdr = tpstream_file->get_tsh_ptr(a_slice_id);
191 fmt::print(
" Run number: {}\n", tsl_hdr->run_number);
192 fmt::print(
" TSL number: {}\n", tsl_hdr->timeslice_number);
194 auto frag = tpstream_file->get_frag_ptr(a_slice_id, tp_writer_sid);
196 fmt::print(
" Fragment id: {} [{}]\n", frag->get_element_id().to_string(), daqdataformats::fragment_type_to_string(frag->get_fragment_type()));
199 fmt::print(
"TP fragment size: {}\n", frag->get_data_size());
200 fmt::print(
"Num TPs: {}\n", n_tps);
205 tp_buffer.resize(tp_buffer.size()+n_tps);
207 uint64_t last_ts = 0;
208 for(
size_t i(0); i<n_tps; ++i) {
209 auto& tp = tp_array[i];
210 if (tp.time_start <= last_ts) {
211 fmt::print(
"ERROR: {} {} ", +tp.time_start, last_ts );
213 tp_buffer.push_back(tp);
218 fmt::print(
"TS gap: {} {} ms\n", d_ts, d_ts*16.0/1'000'000);
225 std::vector<triggeralgs::TriggerActivity> ta_buffer;
228 const nlohmann::json config = {};
232 for(
const auto& tp : tp_buffer ) {
237 fmt::print(
"ta_buffer.size() = {}\n", ta_buffer.size());
239 size_t payload_size(0);
240 for (
const auto& ta : ta_buffer ) {
246 fmt::print(
"ta_buffer in bytes = {}\n", payload_size);
248 char* payload =
static_cast<char*
>(malloc(payload_size));
252 for (
const auto& ta : ta_buffer ) {
259 free(
static_cast<void*
>(payload));