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);
73 int source_rank()
const {
return physical_transfer_->source_rank(); }
74 int destination_rank()
const {
return physical_transfer_->destination_rank(); }
79 bool pass(
const artdaq::Fragment& )
const;
81 std::unique_ptr<TransferInterface> physical_transfer_;
87 TransferInterface(pset, role)
88 , nth_(pset.get<size_t>(
"nth")),
89 offset_(pset.get<size_t>(
"offset",0))
91 if (pset.has_key(
"source_rank") || pset.has_key(
"destination_rank")) {
92 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";
96 if (offset_ >= nth_) {
97 throw cet::exception(
"NthEvent") <<
"Offset value of " << offset_ <<
98 " must not be larger than the modulus value of " << nth_;
103 mf::LogWarning(
"NthEventTransfer") <<
"0 was passed as the nth parameter to NthEventTransfer. Will change to 1 (0 is undefined behavior)";
107 physical_transfer_ = MakeTransferPlugin(pset,
"physical_transfer_plugin", role);
111 TransferInterface::CopyStatus
113 size_t send_timeout_usec)
119 return TransferInterface::CopyStatus::kSuccess;
123 return physical_transfer_->copyFragment(fragment, send_timeout_usec);
126 TransferInterface::CopyStatus
128 size_t send_timeout_usec)
133 return TransferInterface::CopyStatus::kSuccess;
137 return physical_transfer_->moveFragment(std::move(fragment), send_timeout_usec);
141 NthEventTransfer::pass(
const artdaq::Fragment& fragment)
const
145 if (fragment.type() == artdaq::Fragment::DataFragmentType) {
146 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.
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.
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...