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