153main(
int argc,
char const* argv[])
156 CLI::App app{
"tapipe" };
159 std::string input_file_path;
160 app.add_option(
"-i", input_file_path,
"Input TPStream file path")->required();
161 std::string output_file_path;
162 app.add_option(
"-o", output_file_path,
"Output TPStream file path");
163 std::string channel_map_name =
"VDColdboxTPCChannelMap";
164 app.add_option(
"-m", channel_map_name,
"Detector Channel Map");
165 std::string config_name;
166 app.add_option(
"-j", config_name,
"Trigger Activity and Candidate config JSON to use.")->required();
167 uint64_t skip_rec(0);
168 app.add_option(
"-s", skip_rec,
"Skip records");
170 app.add_option(
"-n", num_rec,
"Process records");
173 app.add_flag(
"--quiet", quiet,
"Quiet outputs.");
175 bool latencies =
false;
176 app.add_flag(
"--latencies", latencies,
"Saves latencies per TP into csv");
177 CLI11_PARSE(app, argc, argv);
180 fmt::print(
"TPStream file: {}\n", input_file_path);
187 auto channel_map = dunedaq::detchannelmaps::make_tpc_map(channel_map_name);
190 std::ifstream config_stream(config_name);
191 nlohmann::json
config = nlohmann::json::parse(config_stream);
194 nlohmann::json ta_algo =
config[
"trigger_activity_plugin"][0];
195 nlohmann::json ta_config =
config[
"trigger_activity_config"][0];
197 nlohmann::json tc_algo =
config[
"trigger_candidate_plugin"][0];
198 nlohmann::json tc_config =
config[
"trigger_candidate_config"][0];
201 std::unique_ptr<triggeralgs::TriggerActivityMaker> ta_maker =
203 ta_maker->configure(ta_config);
204 std::unique_ptr<trgtools::TAEmulationUnit> ta_emulator = std::make_unique<trgtools::TAEmulationUnit>();
205 ta_emulator->set_maker(ta_maker);
208 std::filesystem::path output_path(output_file_path);
209 ta_emulator->set_timing_file(
210 (output_path.parent_path() / (
"ta_timings_" + output_path.stem().string() +
".csv")).string());
211 ta_emulator->write_csv_header(
"TP Time Start,TP ADC Integral,Time Diffs,Is Last TP In TA");
215 std::unique_ptr<triggeralgs::TriggerCandidateMaker> tc_maker =
217 tc_maker->configure(tc_config);
218 std::unique_ptr<trgtools::TCEmulationUnit> tc_emulator = std::make_unique<trgtools::TCEmulationUnit>();
219 tc_emulator->set_maker(tc_maker);
222 std::filesystem::path output_path(output_file_path);
223 tc_emulator->set_timing_file(
224 (output_path.parent_path() / (
"tc_timings_" + output_path.stem().string() +
".csv")).string());
225 tc_emulator->write_csv_header(
"Time Diffs");
232 return (channel_map->get_plane_from_offline_channel(tp.channel) != 2);
235 tp_filter = z_plane_filter;
238 const std::vector<std::unique_ptr<daqdataformats::Fragment>>& frags = tsl.
get_fragments_ref();
239 const size_t num_frags = frags.size();
241 fmt::print(
"The number of fragments: {}\n", num_frags);
243 uint64_t average_ta_time = 0;
244 uint64_t average_tc_time = 0;
250 for (
size_t i = 0; i < num_frags; i++) {
251 const auto& frag = frags[i];
254 if (frag->get_element_id().subsystem != tp_subsystem_requirement) {
256 fmt::print(
" Warning, got non kTrigger SourceID {}\n", frag->get_element_id().to_string());
263 fmt::print(
" Error: FragmentType is: {}!\n", fragment_type_to_string(frag->get_fragment_type()));
269 fmt::print(
" Fragment id: {} [{}]\n",
270 frag->get_element_id().to_string(),
276 fmt::print(
" TP fragment size: {}\n", frag->get_data_size());
277 fmt::print(
" Num TPs: {}\n", n_tps);
281 std::vector<trgdataformats::TriggerPrimitive> tp_buffer;
283 tp_buffer.reserve(tp_buffer.size() + n_tps);
287 uint64_t last_ts = 0;
288 for (
size_t i(0); i < n_tps; ++i) {
289 auto& tp = tp_array[i];
290 if (tp.time_start <= last_ts && !quiet) {
291 fmt::print(
" ERROR: {} {} ", +tp.time_start, last_ts);
293 tp_buffer.push_back(tp);
299 fmt::print(
" TS gap: {} {} ms\n", d_ts, d_ts * 16.0 / 1'000'000);
305 const auto ta_start = std::chrono::steady_clock::now();
306 std::unique_ptr<daqdataformats::Fragment> ta_frag = ta_emulator->emulate_vector(tp_buffer);
307 const auto ta_end = std::chrono::steady_clock::now();
309 if (ta_frag ==
nullptr)
311 num_tas += ta_emulator->get_last_output_buffer().size();
314 const uint64_t ta_diff = std::chrono::nanoseconds(ta_end - ta_start).count();
315 average_ta_time += ta_diff;
317 fmt::print(
"\tTA Time Process: {} ns.\n", ta_diff);
326 ta_frag->set_header_fields(frag_hdr);
338 std::vector<triggeralgs::TriggerActivity> ta_buffer = ta_emulator->get_last_output_buffer();
339 const auto tc_start = std::chrono::steady_clock::now();
340 std::unique_ptr<daqdataformats::Fragment> tc_frag = tc_emulator->emulate_vector(ta_buffer);
341 const auto tc_end = std::chrono::steady_clock::now();
343 if (tc_frag ==
nullptr)
345 num_tcs += tc_emulator->get_last_output_buffer().size();
348 const uint64_t tc_diff = std::chrono::nanoseconds(tc_end - tc_start).count();
349 average_tc_time += tc_diff;
351 fmt::print(
"\tTC Time Process: {} ns.\n", tc_diff);
355 tc_frag->set_header_fields(frag_hdr);
365 average_ta_time /= num_tas;
369 average_tc_time /= num_tcs;
371 fmt::print(
"\t\tAverage TA Time Process ({} TAs): {} ns.\n", num_tas, average_ta_time);
372 fmt::print(
"\t\tAverage TC Time Process ({} TCs): {} ns.\n", num_tcs, average_tc_time);
376 rp.
loop(num_rec, skip_rec);
Unknown serialization type<< t,((char) t)) template< typename T > inline std::string datatype_to_string() { return "Unknown";} namespace serialization { template< typename T > struct is_serializable :std::false_type {};enum SerializationType { kMsgPack };inline SerializationType from_string(const std::string s) { if(s=="msgpack") return kMsgPack;throw UnknownSerializationTypeString(ERS_HERE, s);} constexpr uint8_t serialization_type_byte(SerializationType stype) { switch(stype) { case kMsgPack:return 'M';default:throw UnknownSerializationTypeEnum(ERS_HERE);} } constexpr SerializationType DEFAULT_SERIALIZATION_TYPE=kMsgPack;template< class T > std::vector< uint8_t > serialize(const T &obj, SerializationType stype=DEFAULT_SERIALIZATION_TYPE) { switch(stype) { case kMsgPack:{ msgpack::sbuffer buf;msgpack::pack(buf, obj);std::vector< uint8_t > ret(buf.size()+1);ret[0]=serialization_type_byte(stype);std::copy(buf.data(), buf.data()+buf.size(), ret.begin()+1);return ret;} default:throw UnknownSerializationTypeEnum(ERS_HERE);} } template< class T, typename CharType=unsigned char > T deserialize(const std::vector< CharType > &v) { switch(v[0]) { case serialization_type_byte(kMsgPack):{ try { msgpack::object_handle oh=msgpack::unpack(const_cast< char * >(reinterpret_cast< const char * >(v.data()+1)), v.size() - 1,[](msgpack::type::object_type, std::size_t, void *) -> bool