artdaq  v3_00_01
TransferInterface.cc
1 #include "artdaq/TransferPlugins/TransferInterface.hh"
2 #include "cetlib_except/exception.h"
3 
4 artdaq::TransferInterface::TransferInterface(const fhicl::ParameterSet& ps, Role role)
5  : role_(role)
6  , source_rank_(ps.get<int>("source_rank", my_rank))
7  , destination_rank_(ps.get<int>("destination_rank", my_rank))
8  , unique_label_(ps.get<std::string>("unique_label", "transfer_between_" + std::to_string(source_rank_) + "_and_" + std::to_string(destination_rank_)))
9  , buffer_count_(ps.get<size_t>("buffer_count", 10))
10  , max_fragment_size_words_(ps.get<size_t>("max_fragment_size_words", 1024))
11 {
12  TLOG_DEBUG(uniqueLabel()) << "TransferInterface constructor has " << ps.to_string() << TLOG_ENDL;
13 }
14 
15 int artdaq::TransferInterface::receiveFragment(artdaq::Fragment& frag, size_t receive_timeout)
16 {
17  auto ret = RECV_TIMEOUT;
18 
19  TLOG_TRACE("TransferInterface") << "Receiving Fragment Header from rank " << source_rank() << TLOG_ENDL;
20  ret = receiveFragmentHeader(*reinterpret_cast<detail::RawFragmentHeader*>(frag.headerAddress()), receive_timeout);
21 
22  TLOG_TRACE("TransferInterface") << "Done receiving Header, ret is " << ret << ", should be " << source_rank() << TLOG_ENDL;
23  if (ret == RECV_TIMEOUT) return ret;
24 
25  frag.autoResize();
26 
27  TLOG_TRACE("TransferInterface") << "Receiving Fragment Body from rank " << source_rank() << TLOG_ENDL;
28  auto bodyret = receiveFragmentData(frag.headerAddress() + detail::RawFragmentHeader::num_words(), frag.sizeBytes() - detail::RawFragmentHeader::num_words() * sizeof(RawDataType));
29  TLOG_TRACE("TransferInterface") << "Done receiving Body, ret is " << bodyret << ", should be " << source_rank() << TLOG_ENDL;
30 
31  if (bodyret != ret) throw cet::exception("TransferInterface") << "Got different return codes from receiveFragmentHeader and receiveFragmentData!";
32 
33  return ret;
34 }
Role
Used to determine if a TransferInterface is a Sender or Receiver.
std::string uniqueLabel() const
Get the unique label of this TransferInterface instance.
TransferInterface(const fhicl::ParameterSet &ps, Role role)
TransferInterface Constructor.
virtual int receiveFragment(artdaq::Fragment &fragment, size_t receiveTimeout)
Receive a Fragment from the transport mechanism.