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
48 size_t send_timeout_usec = std::numeric_limits<size_t>::max())
override;
56 TransferInterface::CopyStatus
58 size_t send_timeout_usec = std::numeric_limits<size_t>::max())
override;
67 size_t receiveTimeout)
override
70 return physical_transfer_->receiveFragment(fragment, receiveTimeout);
81 return physical_transfer_->receiveFragmentHeader(header, receiveTimeout);
92 return physical_transfer_->receiveFragmentData(destination, wordCount);
99 int source_rank()
const {
return physical_transfer_->source_rank(); }
110 bool pass(
const artdaq::Fragment& )
const;
112 std::unique_ptr<TransferInterface> physical_transfer_;
118 TransferInterface(pset, role)
119 , nth_(pset.get<size_t>(
"nth")),
120 offset_(pset.get<size_t>(
"offset",0))
122 if (pset.has_key(
"source_rank") || pset.has_key(
"destination_rank")) {
123 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";
127 if (offset_ >= nth_) {
128 throw cet::exception(
"NthEvent") <<
"Offset value of " << offset_ <<
129 " must not be larger than the modulus value of " << nth_;
134 mf::LogWarning(
"NthEventTransfer") <<
"0 was passed as the nth parameter to NthEventTransfer. Will change to 1 (0 is undefined behavior)";
138 physical_transfer_ = MakeTransferPlugin(pset,
"physical_transfer_plugin", role);
142 TransferInterface::CopyStatus
144 size_t send_timeout_usec)
150 return TransferInterface::CopyStatus::kSuccess;
154 return physical_transfer_->copyFragment(fragment, send_timeout_usec);
157 TransferInterface::CopyStatus
159 size_t send_timeout_usec)
164 return TransferInterface::CopyStatus::kSuccess;
168 return physical_transfer_->moveFragment(std::move(fragment), send_timeout_usec);
172 NthEventTransfer::pass(
const artdaq::Fragment& fragment)
const
176 if (fragment.type() == artdaq::Fragment::DataFragmentType) {
177 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.
int destination_rank() const
Get the destination rank from the physical transfer.
NthEventTransfer(fhicl::ParameterSet const &ps, artdaq::TransferInterface::Role role)
NthEventTransfer Constructor.
TransferInterface::CopyStatus copyFragment(artdaq::Fragment &fragment, size_t send_timeout_usec=std::numeric_limits< size_t >::max()) override
Copy a fragment, using the non-reliable channel.
int receiveFragmentData(RawDataType *destination, size_t wordCount) override
Receive the body of a Fragment to the given destination pointer.
int source_rank() const
Get the source rank from the physical transfer.
TransferInterface::CopyStatus moveFragment(artdaq::Fragment &&fragment, size_t send_timeout_usec=std::numeric_limits< size_t >::max()) override
Copy a fragment, using the reliable channel. moveFragment assumes ownership of the fragment...