121 std::string input_file;
122 bool verbose =
false;
123 CLI::App app{
"tapipe" };
126 app.add_option(
"-i", input_file,
"Input TPStream file path")->required();
127 app.add_flag(
"-v", verbose);
128 CLI11_PARSE(app, argc, argv);
130 fmt::print(
"TPStream file: {}\n", input_file);
133 std::unique_ptr<hdf5libs::HDF5RawDataFile> tpstream_file;
136 tpstream_file = std::make_unique<hdf5libs::HDF5RawDataFile>(input_file);
137 }
catch (
const hdf5libs::FileOpenFailed& e) {
138 std::cout <<
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ERROR <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
139 std::cerr << e.what() <<
'\n';
143 fmt::print(
"{} opened\n", input_file);
146 fmt::print(
" File type: {}\n", tpstream_file->get_record_type());
149 auto records = tpstream_file->get_all_record_ids();
150 std::set<daqdataformats::SourceID> source_ids;
152 for (
const auto& rid : records) {
153 const auto& [id, slice] = rid;
154 auto sids = tpstream_file->get_source_ids(rid);
155 source_ids.merge(sids);
157 fmt::print(
"TR {}:{} [{}]\n",
id, slice, fmt::join(sids,
", "));
159 fmt::print(
"Source IDs [{}]\n", fmt::join(source_ids,
", "));
162 std::map<daqdataformats::SourceID, hdf5libs::HDF5RawDataFile::record_id_set> m;
163 for (
const auto& sid : source_ids) {
164 for (
const auto& rid : records) {
165 auto rec_sids = tpstream_file->get_source_ids(rid);
166 if (rec_sids.find(sid) != rec_sids.end()) {
171 fmt::print(
"Record IDs for {} : [{}]\n", sid, fmt::join(m[sid],
", "));
175 fmt::print(
" Number of time slices in file: {}\n", records.size());
180 auto tp_records = m[tp_writer_sid];
183 std::vector<trgdataformats::TriggerPrimitive> tp_buffer;
185 auto a_slice_id = *tp_records.begin();
186 fmt::print(
"Processing tp time slice {}\n", a_slice_id);
189 auto tsl_hdr = tpstream_file->get_tsh_ptr(a_slice_id);
192 fmt::print(
" Run number: {}\n", tsl_hdr->run_number);
193 fmt::print(
" TSL number: {}\n", tsl_hdr->timeslice_number);
195 auto frag = tpstream_file->get_frag_ptr(a_slice_id, tp_writer_sid);
197 fmt::print(
" Fragment id: {} [{}]\n",
198 frag->get_element_id().to_string(),
202 fmt::print(
"TP fragment size: {}\n", frag->get_data_size());
203 fmt::print(
"Num TPs: {}\n", n_tps);
208 tp_buffer.resize(tp_buffer.size() + n_tps);
210 uint64_t last_ts = 0;
211 for (
size_t i(0); i < n_tps; ++i) {
212 auto& tp = tp_array[i];
213 if (tp.time_start <= last_ts) {
214 fmt::print(
"ERROR: {} {} ", +tp.time_start, last_ts);
216 tp_buffer.push_back(tp);
221 fmt::print(
"TS gap: {} {} ms\n", d_ts, d_ts * 16.0 / 1'000'000);
228 std::vector<triggeralgs::TriggerActivity> ta_buffer;
231 const nlohmann::json
config = {};
235 for (
const auto& tp : tp_buffer) {
240 fmt::print(
"ta_buffer.size() = {}\n", ta_buffer.size());
242 size_t payload_size(0);
243 for (
const auto& ta : ta_buffer) {
248 fmt::print(
"ta_buffer in bytes = {}\n", payload_size);
250 char* payload =
static_cast<char*
>(malloc(payload_size));
253 for (
const auto& ta : ta_buffer) {
260 free(
static_cast<void*
>(payload));