1 #include "artdaq/TransferPlugins/TransferInterface.hh"
2 #include "artdaq/TransferPlugins/MakeTransferPlugin.hh"
3 #include "artdaq-core/Data/Fragment.hh"
4 #include "artdaq-core/Utilities/ExceptionHandler.hh"
5 #include "cetlib/BasicPluginFactory.h"
7 #include "messagefacility/MessageLogger/MessageLogger.h"
8 #include "fhiclcpp/ParameterSet.h"
10 #include <boost/tokenizer.hpp>
38 NthEventTransfer(fhicl::ParameterSet
const& ps, artdaq::TransferInterface::Role role);
46 TransferInterface::CopyStatus
54 TransferInterface::CopyStatus
64 size_t receiveTimeout)
override
67 return physical_transfer_->receiveFragment(fragment, receiveTimeout);
78 return physical_transfer_->receiveFragmentHeader(header, receiveTimeout);
89 return physical_transfer_->receiveFragmentData(destination, wordCount);
96 int source_rank()
const override {
return physical_transfer_->source_rank(); }
109 bool isRunning()
override {
return physical_transfer_->isRunning(); }
121 std::unique_ptr<TransferInterface> physical_transfer_;
128 , nth_(pset.get<size_t>(
"nth")),
129 offset_(pset.get<size_t>(
"offset", 0))
131 if (pset.has_key(
"source_rank") || pset.has_key(
"destination_rank")) {
132 throw cet::exception(
"NthEvent") <<
"The parameters \"source_rank\" and \"destination_rank\" must be explicitly defined in the body of the physical_transfer_plugin table, and not outside of it";
136 if (offset_ >= nth_) {
137 throw cet::exception(
"NthEvent") <<
"Offset value of " << offset_ <<
138 " must not be larger than the modulus value of " << nth_;
143 mf::LogWarning(
"NthEventTransfer") <<
"0 was passed as the nth parameter to NthEventTransfer. Will change to 1 (0 is undefined behavior)";
147 physical_transfer_ = MakeTransferPlugin(pset,
"physical_transfer_plugin", role);
151 TransferInterface::CopyStatus
153 size_t send_timeout_usec)
159 return TransferInterface::CopyStatus::kSuccess;
163 return physical_transfer_->transfer_fragment_min_blocking_mode(fragment, send_timeout_usec);
166 TransferInterface::CopyStatus
172 return TransferInterface::CopyStatus::kSuccess;
176 return physical_transfer_->transfer_fragment_reliable_mode(std::move(fragment));
185 passed = (fragment.
sequenceID() + nth_ - offset_) % nth_ == 0 ?
true :
false;
Demonstration TransferInterface plugin showing how to discard events Intended for use in the transfer...
int receiveFragment(artdaq::Fragment &fragment, size_t receiveTimeout) override
Receive a fragment from the transfer plugin.
int receiveFragmentHeader(detail::RawFragmentHeader &header, size_t receiveTimeout) override
Receive a Fragment Header from the transport mechanism.
sequence_id_t sequenceID() const
static constexpr type_t DataFragmentType
TransferInterface::CopyStatus transfer_fragment_min_blocking_mode(artdaq::Fragment const &fragment, size_t send_timeout_usec) override
Transfer a Fragment to the destination. May not necessarily be reliable, but will not block longer th...
bool isRunning() override
Determine whether the TransferInterface plugin is able to send/receive data.
NthEventTransfer(fhicl::ParameterSet const &ps, artdaq::TransferInterface::Role role)
NthEventTransfer Constructor.
detail::RawFragmentHeader::RawDataType RawDataType
int destination_rank() const override
Get the destination rank from the physical transfer.
void flush_buffers() override
Flush any in-flight data. This should be used by the receiver after the receive loop has ended...
TransferInterface::CopyStatus transfer_fragment_reliable_mode(artdaq::Fragment &&fragment) override
Copy a fragment, using the reliable channel. moveFragment assumes ownership of the fragment...
int receiveFragmentData(RawDataType *destination, size_t wordCount) override
Receive the body of a Fragment to the given destination pointer.
int source_rank() const override
Get the source rank from the physical transfer.