120{
121 std::string input_file;
122 bool verbose = false;
123 CLI::App
app{
"tapipe" };
124
125
126 app.add_option(
"-i", input_file,
"Input TPStream file path")->required();
127 app.add_flag(
"-v", verbose);
128 CLI11_PARSE(app, argc, argv);
129
130 fmt::print("TPStream file: {}\n", input_file);
131
132
133 std::unique_ptr<hdf5libs::HDF5RawDataFile> tpstream_file;
134
135 try {
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';
140 exit(-1);
141 }
142
143 fmt::print("{} opened\n", input_file);
144
145
146 fmt::print(" File type: {}\n", tpstream_file->get_record_type());
147
148
149 auto records = tpstream_file->get_all_record_ids();
150 std::set<daqdataformats::SourceID> source_ids;
151
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);
156 if (verbose)
157 fmt::print("TR {}:{} [{}]\n", id, slice, fmt::join(sids, ", "));
158 }
159 fmt::print("Source IDs [{}]\n", fmt::join(source_ids, ", "));
160
161
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()) {
168 }
169 }
170 if (verbose)
171 fmt::print("Record IDs for {} : [{}]\n", sid, fmt::join(m[sid], ", "));
172 }
173
174
175 fmt::print(" Number of time slices in file: {}\n", records.size());
176
177
178
179 daqdataformats::SourceID tp_writer_sid{ daqdataformats::SourceID::Subsystem::kTrigger, 0 };
180 auto tp_records =
m[tp_writer_sid];
181
182
183 std::vector<trgdataformats::TriggerPrimitive> tp_buffer;
184
185 auto a_slice_id = *tp_records.begin();
186 fmt::print("Processing tp time slice {}\n", a_slice_id);
187
188
189 auto tsl_hdr = tpstream_file->get_tsh_ptr(a_slice_id);
190
191
192 fmt::print(" Run number: {}\n", tsl_hdr->run_number);
193 fmt::print(" TSL number: {}\n", tsl_hdr->timeslice_number);
194
195 auto frag = tpstream_file->get_frag_ptr(a_slice_id, tp_writer_sid);
196
197 fmt::print(" Fragment id: {} [{}]\n",
198 frag->get_element_id().to_string(),
199 daqdataformats::fragment_type_to_string(frag->get_fragment_type()));
200
201 size_t n_tps = frag->get_data_size() / sizeof(trgdataformats::TriggerPrimitive);
202 fmt::print("TP fragment size: {}\n", frag->get_data_size());
203 fmt::print("Num TPs: {}\n", n_tps);
204
205 trgdataformats::TriggerPrimitive* tp_array = static_cast<trgdataformats::TriggerPrimitive*>(frag->get_data());
206
207
208 tp_buffer.resize(tp_buffer.size() + n_tps);
209
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);
215 }
216 tp_buffer.push_back(tp);
217 }
218
219
220 uint64_t d_ts = tp_array[n_tps - 1].time_start - tp_array[0].time_start;
221 fmt::print("TS gap: {} {} ms\n", d_ts, d_ts * 16.0 / 1'000'000);
222
223
224
226
227
228 std::vector<triggeralgs::TriggerActivity> ta_buffer;
229
230
231 const nlohmann::json
config = {};
233
234
235 for (const auto& tp : tp_buffer) {
236 hmta(tp, ta_buffer);
237 }
238
239
240 fmt::print("ta_buffer.size() = {}\n", ta_buffer.size());
241
242 size_t payload_size(0);
243 for (const auto& ta : ta_buffer) {
245 }
246
247
248 fmt::print("ta_buffer in bytes = {}\n", payload_size);
249
250 char*
payload =
static_cast<char*
>(malloc(payload_size));
251
253 for (const auto& ta : ta_buffer) {
256 }
257
258 daqdataformats::Fragment ta_frag(static_cast<void*>(payload), payload_size);
259
260 free(static_cast<void*>(payload));
261
262
263 return 0;
264}
void configure(const nlohmann::json &config)
void write_overlay(const Object &object, void *buffer)
size_t get_overlay_nbytes(const Object &object)