artdaq  v3_07_02
TransferInterface.cc
1 #include "artdaq/DAQdata/Globals.hh"
2 #define TRACE_NAME (app_name + "_TransferInterface").c_str()
3 
4 #include "artdaq/TransferPlugins/TransferInterface.hh"
5 #include "cetlib_except/exception.h"
6 
7 artdaq::TransferInterface::TransferInterface(const fhicl::ParameterSet& ps, Role role)
8  : role_(role)
9  , source_rank_(ps.get<int>("source_rank", my_rank))
10  , destination_rank_(ps.get<int>("destination_rank", my_rank))
11  , unique_label_(ps.get<std::string>("unique_label", "transfer_between_" + std::to_string(source_rank_) + "_and_" + std::to_string(destination_rank_)))
12  , buffer_count_(ps.get<size_t>("buffer_count", 10))
13  , max_fragment_size_words_(ps.get<size_t>("max_fragment_size_words", 1024))
14 {
15  TLOG(TLVL_DEBUG) << uniqueLabel() << " role:" << (int)role << " TransferInterface constructor has "
16  << ps.to_string();
17 }
18 
19 int artdaq::TransferInterface::receiveFragment(artdaq::Fragment& frag, size_t receive_timeout)
20 {
21  auto ret = static_cast<int>(RECV_TIMEOUT);
22 
23  TLOG(TLVL_TRACE) << "Receiving Fragment Header from rank " << source_rank();
24  ret = receiveFragmentHeader(*reinterpret_cast<detail::RawFragmentHeader*>(frag.headerAddress()), receive_timeout);
25 
26  TLOG(TLVL_TRACE) << "Done receiving Header, ret is " << ret << ", should be " << source_rank();
27  if (ret < RECV_SUCCESS) return ret;
28 
29  frag.autoResize();
30 
31  TLOG(TLVL_TRACE) << "Receiving Fragment Body from rank " << source_rank();
32  auto bodyret = receiveFragmentData(frag.headerAddress() + detail::RawFragmentHeader::num_words(), frag.sizeBytes() - detail::RawFragmentHeader::num_words() * sizeof(RawDataType));
33  TLOG(TLVL_TRACE) << "Done receiving Body, ret is " << bodyret << ", should be " << source_rank();
34 
35  if (bodyret != ret) throw cet::exception("TransferInterface") << "Got different return codes from receiveFragmentHeader and receiveFragmentData!";
36 
37  return ret;
38 }
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.