diff --git a/include/trigger/TriggerDataHandlingModel.hpp b/include/trigger/TriggerDataHandlingModel.hpp new file mode 100644 index 00000000..edb6ad07 --- /dev/null +++ b/include/trigger/TriggerDataHandlingModel.hpp @@ -0,0 +1,46 @@ +/** + * @file TriggerDataHandlingModel.hpp Glue between data source, payload raw processor, + * latency buffer and request handler. + * + * This is part of the DUNE DAQ, copyright 2024. + * Licensing/copyright details are in the COPYING file that you should have + * received with this code. + */ +#ifndef TRIGGER_INCLUDE_TRIGGER_TRIGGERDATAHANDLINGMODEL_HPP_ +#define TRIGGER_INCLUDE_TRIGGER_TRIGGERDATAHANDLINGMODEL_HPP_ + +#include "datahandlinglibs/models/DataHandlingModel.hpp" +#include + +namespace dunedaq::trigger { + +template +class TriggerDataHandlingModel + : public datahandlinglibs:: + DataHandlingModel +{ +public: + using Base = datahandlinglibs:: + DataHandlingModel; + using RDT = typename Base::RDT; + using RHT = typename Base::RHT; + using LBT = typename Base::LBT; + using RPT = typename Base::RPT; + using IDT = typename Base::IDT; + + explicit TriggerDataHandlingModel(std::atomic& run_marker); + + // Transform input data type to readout + std::vector transform_payload(IDT& original) const override; +}; + +} // namespace dunedaq::trigger + +// Declarations +#include "detail/TriggerDataHandlingModel.hxx" + +#endif // TRIGGER_INCLUDE_TRIGGER_TRIGGERDATAHANDLINGMODEL_HPP_ diff --git a/include/trigger/detail/TriggerDataHandlingModel.hxx b/include/trigger/detail/TriggerDataHandlingModel.hxx new file mode 100644 index 00000000..7f7bf142 --- /dev/null +++ b/include/trigger/detail/TriggerDataHandlingModel.hxx @@ -0,0 +1,41 @@ +/** + * @file TriggerDataHandlingModel.hxx Glue between data source, payload raw processor, + * latency buffer and request handler. + * + * This is part of the DUNE DAQ, copyright 2024. + * Licensing/copyright details are in the COPYING file that you should have + * received with this code. + */ +#include "triggeralgs/TriggerActivity.hpp" +#include "triggeralgs/TriggerCandidate.hpp" + +namespace dunedaq::trigger { + +template +TriggerDataHandlingModel::TriggerDataHandlingModel(std::atomic& run_marker) + : Base(run_marker) +{ +} + +template +std::vector +TriggerDataHandlingModel::transform_payload(IDT& original) const +{ + if constexpr (std::is_same_v) { + std::vector transformed(original.objects.size()); + for (std::size_t i = 0; i < transformed.size(); ++i) { + transformed[i].tp = std::move(original.objects[i]); + } + return transformed; + } else if constexpr (std::is_same_v>) { + return std::move(original); + } else if constexpr (std::is_same_v || + std::is_same_v) { + return { RDT(std::move(original)) }; + + } else { + return Base::transform_payload(original); + } +} + +} // namespace dunedaq::trigger diff --git a/plugins/DataSubscriberModule.cpp b/plugins/DataSubscriberModule.cpp index c570b900..094d59f8 100644 --- a/plugins/DataSubscriberModule.cpp +++ b/plugins/DataSubscriberModule.cpp @@ -12,14 +12,13 @@ #include "datahandlinglibs/DataHandlingIssues.hpp" #include "datahandlinglibs/models/DataSubscriberModel.hpp" #include "trigger/HSISourceModel.hpp" -#include "trigger/TPSetSourceModel.hpp" -#include "trigger/TriggerSourceModel.hpp" #include "appmodel/DataSubscriberModule.hpp" #include "trigger/TriggerPrimitiveTypeAdapter.hpp" #include "trigger/TAWrapper.hpp" #include "trigger/TCWrapper.hpp" +#include "trigger/TPSet.hpp" #include "trgdataformats/TriggerPrimitive.hpp" #include "triggeralgs/TriggerActivity.hpp" #include "triggeralgs/TriggerCandidate.hpp" @@ -31,6 +30,7 @@ namespace dunedaq { //DUNE_DAQ_TYPESTRING(dunedaq::trigger::TPSet, "TPSet") DUNE_DAQ_TYPESTRING(dunedaq::trigger::TriggerPrimitiveTypeAdapter, "TriggerPrimitive") +DUNE_DAQ_TYPESTRING(std::vector, "TriggerPrimitiveVector") DUNE_DAQ_TYPESTRING(dunedaq::trigger::TAWrapper, "TriggerActivity") DUNE_DAQ_TYPESTRING(dunedaq::trigger::TCWrapper, "TriggerCandidate") @@ -81,21 +81,21 @@ DataSubscriberModule::create_data_subscriber(const confmodel::DaqModule* cfg) if (raw_dt == "TPSet") { TLOG_DEBUG(1) << "Creating trigger primitives subscriber"; auto source_model = - std::make_shared(); + std::make_shared>>(); return source_model; } if (raw_dt == "TriggerActivity") { TLOG_DEBUG(1) << "Creating trigger activities subscriber"; auto source_model = - std::make_shared>(); + std::make_shared>(); return source_model; } if (raw_dt == "TriggerCandidate") { TLOG_DEBUG(1) << "Creating trigger candidates subscriber"; auto source_model = - std::make_shared>(); + std::make_shared>(); return source_model; } diff --git a/plugins/TriggerDataHandlerModule.cpp b/plugins/TriggerDataHandlerModule.cpp index 407c08ea..f385faa8 100644 --- a/plugins/TriggerDataHandlerModule.cpp +++ b/plugins/TriggerDataHandlerModule.cpp @@ -17,6 +17,7 @@ #include "datahandlinglibs/models/DefaultSkipListRequestHandler.hpp" #include "trigger/TPRequestHandler.hpp" +#include "trigger/TriggerDataHandlingModel.hpp" #include "trigger/TriggerPrimitiveTypeAdapter.hpp" #include "trigger/TPProcessor.hpp" #include "trigger/TAProcessor.hpp" @@ -33,6 +34,7 @@ using namespace dunedaq::datahandlinglibs::logging; namespace dunedaq { DUNE_DAQ_TYPESTRING(dunedaq::trigger::TriggerPrimitiveTypeAdapter, "TriggerPrimitive") +DUNE_DAQ_TYPESTRING(std::vector, "TriggerPrimitiveVector") DUNE_DAQ_TYPESTRING(dunedaq::trigger::TAWrapper, "TriggerActivity") DUNE_DAQ_TYPESTRING(dunedaq::trigger::TCWrapper, "TriggerCandidate") @@ -69,10 +71,24 @@ TriggerDataHandlerModule::create_readout(const appmodel::DataHandlerModule* modc std::string raw_dt = modconf->get_module_configuration()->get_input_data_type(); TLOG() << "Choosing specializations for DataHandlingModel with data_type:" << raw_dt << ']'; + // IF TriggerPrimitiveVector (TP vector) + if (raw_dt.find("TriggerPrimitiveVector") != std::string::npos) { + TLOG(TLVL_WORK_STEPS) << "Creating readout for TriggerPrimitiveVector"; + auto readout_model = std::make_shared, + TPProcessor, + std::vector>>(run_marker); + register_node("TPProcessor", readout_model); + readout_model->init(modconf); + return readout_model; + } + // IF TriggerPrimitive (TP) if (raw_dt.find("TriggerPrimitive") != std::string::npos) { TLOG(TLVL_WORK_STEPS) << "Creating readout for TriggerPrimitive"; - auto readout_model = std::make_shared, @@ -85,11 +101,12 @@ TriggerDataHandlerModule::create_readout(const appmodel::DataHandlerModule* modc // IF TriggerActivity (TA) if (raw_dt.find("TriggerActivity") != std::string::npos) { TLOG(TLVL_WORK_STEPS) << "Creating readout for TriggerActivity"; - auto readout_model = std::make_shared, rol::SkipListLatencyBufferModel, - TAProcessor>>(run_marker); + TAProcessor, + triggeralgs::TriggerActivity>>(run_marker); register_node("TAProcessor", readout_model); readout_model->init(modconf); @@ -99,11 +116,12 @@ TriggerDataHandlerModule::create_readout(const appmodel::DataHandlerModule* modc // No processing, only buffering to respond to data requests if (raw_dt.find("TriggerCandidate") != std::string::npos) { TLOG(TLVL_WORK_STEPS) << "Creating readout for TriggerCandidate"; - auto readout_model = std::make_shared, rol::SkipListLatencyBufferModel, - TCProcessor>>(run_marker); + TCProcessor, + triggeralgs::TriggerCandidate>>(run_marker); register_node("TCProcessor", readout_model); readout_model->init(modconf); diff --git a/src/TPProcessor.cpp b/src/TPProcessor.cpp index a4b2b3eb..662fb80b 100644 --- a/src/TPProcessor.cpp +++ b/src/TPProcessor.cpp @@ -30,6 +30,7 @@ using dunedaq::datahandlinglibs::logging::TLVL_TAKE_NOTE; // THIS SHOULDN'T BE HERE!!!!! But it is necessary..... DUNE_DAQ_TYPESTRING(dunedaq::trigger::TriggerPrimitiveTypeAdapter, "TriggerPrimitive") +DUNE_DAQ_TYPESTRING(std::vector, "TriggerPrimitiveVector") namespace dunedaq { namespace trigger { diff --git a/src/trigger/TPSetSourceModel.hpp b/src/trigger/TPSetSourceModel.hpp deleted file mode 100644 index 40998d50..00000000 --- a/src/trigger/TPSetSourceModel.hpp +++ /dev/null @@ -1,105 +0,0 @@ -/** - * @file TPSetSourceModel.hpp - * - * This is part of the DUNE DAQ , copyright 2020. - * Licensing/copyright details are in the COPYING file that you should have - * received with this code. - */ -#ifndef TRIGGER_SRC_TRIGGER_TPSETSOURCEMODEL_HPP_ -#define TRIGGER_SRC_TRIGGER_TPSETSOURCEMODEL_HPP_ - -#include -#include "datahandlinglibs/concepts/SourceConcept.hpp" -#include "detdataformats/DetID.hpp" -#include "dfmessages/HSIEvent.hpp" -#include "triggeralgs/TriggerCandidate.hpp" -#include "trigger/TCWrapper.hpp" - - -#include "iomanager/IOManager.hpp" -#include "iomanager/Sender.hpp" -#include "iomanager/Receiver.hpp" -#include "logging/Logging.hpp" -#include "confmodel/DaqModule.hpp" -#include "appmodel/DataSubscriberModule.hpp" -#include "trigger/TPSet.hpp" -#include "trigger/TriggerPrimitiveTypeAdapter.hpp" - -//#include "appmodel/HSI2TCTranslatorConf.hpp" -//#include "appmodel/HSISignalWindow.hpp" - -namespace dunedaq::trigger { - - -class TPSetSourceModel : public datahandlinglibs::SourceConcept -{ -public: - using inherited = datahandlinglibs::SourceConcept; - - /** - * @brief SourceModel Constructor - * @param name Instance name for this SourceModel instance - */ - - TPSetSourceModel(): datahandlinglibs::SourceConcept() {} - ~TPSetSourceModel() {} - - void init(const confmodel::DaqModule* cfg) override { - if (cfg->get_outputs().size() != 1) { - throw datahandlinglibs::InitializationError(ERS_HERE, "Only 1 output supported for subscribers"); - } - m_data_sender = get_iom_sender(cfg->get_outputs()[0]->UID()); - - if (cfg->get_inputs().size() != 1) { - throw datahandlinglibs::InitializationError(ERS_HERE, "Only 1 input supported for subscribers"); - } - m_data_receiver = get_iom_receiver(cfg->get_inputs()[0]->UID()); -/* - auto data_reader = cfg->cast(); - if (data_reader == nullptr) { - throw datahandlinglibs::InitializationError(ERS_HERE, "DAQ module is not a DataReader"); - } - auto hsi_conf = data_reader->get_configuration()->cast(); - if (hsi_conf == nullptr) { - throw datahandlinglibs::InitializationError(ERS_HERE, "Missing HSI2TCTranslatorConf"); - } - for (auto win : hsi_conf->get_signals()) { - m_signals[win->get_signal_type()] = std::pair(win->get_time_before(), win->get_time_after()); - } - */ - } - - void start() { - m_data_receiver->add_callback(std::bind(&TPSetSourceModel::handle_payload, this, std::placeholders::_1)); - } - - void stop() { - m_data_receiver->remove_callback(); - } - - bool handle_payload(trigger::TPSet& data) // NOLINT(build/unsigned) - { - for (auto tpraw : data.objects) { - TriggerPrimitiveTypeAdapter tp; - tp.tp = tpraw; - if (!m_data_sender->try_send(std::move(tp), iomanager::Sender::s_no_block)) { - ++m_dropped_packets; - } - } - return true; - } - -private: - using source_t = dunedaq::iomanager::ReceiverConcept; - std::shared_ptr m_data_receiver; - - using sink_t = dunedaq::iomanager::SenderConcept; - std::shared_ptr m_data_sender; - - //Stats - std::atomic m_dropped_packets{0}; -}; - -} // namespace dunedaq::trigger - -#endif // TRIGGER_SRC_TRIGGER_TPSETSOURCEMODEL_HPP_ diff --git a/src/trigger/TriggerSourceModel.hpp b/src/trigger/TriggerSourceModel.hpp deleted file mode 100644 index 4fdadc86..00000000 --- a/src/trigger/TriggerSourceModel.hpp +++ /dev/null @@ -1,103 +0,0 @@ -/** - * @file TriggerSourceModel.hpp - * - * This is part of the DUNE DAQ , copyright 2020. - * Licensing/copyright details are in the COPYING file that you should have - * received with this code. - */ -#ifndef TRIGGER_SRC_TRIGGER_TRIGGERSOURCEMODEL_HPP_ -#define TRIGGER_SRC_TRIGGER_TRIGGERSOURCEMODEL_HPP_ - -#include -#include "datahandlinglibs/concepts/SourceConcept.hpp" -#include "detdataformats/DetID.hpp" -#include "dfmessages/HSIEvent.hpp" -#include "triggeralgs/TriggerCandidate.hpp" -#include "trigger/TCWrapper.hpp" - - -#include "iomanager/IOManager.hpp" -#include "iomanager/Sender.hpp" -#include "iomanager/Receiver.hpp" -#include "logging/Logging.hpp" -#include "confmodel/DaqModule.hpp" -#include "appmodel/DataSubscriberModule.hpp" -#include "trigger/TAWrapper.hpp" -#include "trigger/TCWrapper.hpp" - -//#include "appmodel/HSI2TCTranslatorConf.hpp" -//#include "appmodel/HSISignalWindow.hpp" - -namespace dunedaq::trigger { - - -template -class TriggerSourceModel : public datahandlinglibs::SourceConcept -{ -public: - using inherited = datahandlinglibs::SourceConcept; - - /** - * @brief SourceModel Constructor - * @param name Instance name for this SourceModel instance - */ - - TriggerSourceModel(): datahandlinglibs::SourceConcept() {} - ~TriggerSourceModel() {} - - void init(const confmodel::DaqModule* cfg) override { - if (cfg->get_outputs().size() != 1) { - throw datahandlinglibs::InitializationError(ERS_HERE, "Only 1 output supported for subscribers"); - } - m_data_sender = get_iom_sender(cfg->get_outputs()[0]->UID()); - - if (cfg->get_inputs().size() != 1) { - throw datahandlinglibs::InitializationError(ERS_HERE, "Only 1 input supported for subscribers"); - } - m_data_receiver = get_iom_receiver(cfg->get_inputs()[0]->UID()); -/* - auto data_reader = cfg->cast(); - if (data_reader == nullptr) { - throw datahandlinglibs::InitializationError(ERS_HERE, "DAQ module is not a DataReader"); - } - auto hsi_conf = data_reader->get_configuration()->cast(); - if (hsi_conf == nullptr) { - throw datahandlinglibs::InitializationError(ERS_HERE, "Missing HSI2TCTranslatorConf"); - } - for (auto win : hsi_conf->get_signals()) { - m_signals[win->get_signal_type()] = std::pair(win->get_time_before(), win->get_time_after()); - } - */ - } - - void start() { - m_data_receiver->add_callback(std::bind(&TriggerSourceModel::handle_payload, this, std::placeholders::_1)); - } - - void stop() { - m_data_receiver->remove_callback(); - } - - bool handle_payload(TriggerXObject& data) // NOLINT(build/unsigned) - { - TXWrapper tx(data); - if (!m_data_sender->try_send(std::move(tx), iomanager::Sender::s_no_block)) { - ++m_dropped_packets; - } - return true; - } - -private: - using source_t = dunedaq::iomanager::ReceiverConcept; - std::shared_ptr m_data_receiver; - - using sink_t = dunedaq::iomanager::SenderConcept; - std::shared_ptr m_data_sender; - - //Stats - std::atomic m_dropped_packets{0}; -}; - -} // namespace dunedaq::trigger - -#endif // TRIGGER_SRC_TRIGGER_TRIGGERSOURCEMODEL_HPP_