artdaq  v2_03_02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Autodetect_transfer.cc
1 #include "artdaq/TransferPlugins/TransferInterface.hh"
2 #include "artdaq/TransferPlugins/TCPSocketTransfer.hh"
3 #include "artdaq/TransferPlugins/ShmemTransfer.hh"
4 
5 namespace artdaq
6 {
14  {
15  public:
21  AutodetectTransfer(const fhicl::ParameterSet& pset, Role role);
22 
26  virtual ~AutodetectTransfer() = default;
27 
34  int receiveFragment(artdaq::Fragment& fragment,
35  size_t receiveTimeout) override
36  {
37  return theTransfer_->receiveFragment(fragment, receiveTimeout);
38  }
39 
46  CopyStatus copyFragment(artdaq::Fragment& fragment,
47  size_t send_timeout_usec = std::numeric_limits<size_t>::max()) override
48  {
49  return theTransfer_->copyFragment(fragment, send_timeout_usec);
50  }
51 
58  CopyStatus moveFragment(artdaq::Fragment&& fragment,
59  size_t send_timeout_usec = std::numeric_limits<size_t>::max()) override
60  {
61  return theTransfer_->moveFragment(std::move(fragment), send_timeout_usec);
62  }
63 
64  private:
65  std::unique_ptr<TransferInterface> theTransfer_;
66  };
67 }
68 
69 artdaq::AutodetectTransfer::AutodetectTransfer(const fhicl::ParameterSet& pset, Role role)
70  : TransferInterface(pset, role)
71 {
72  TLOG_DEBUG(uniqueLabel()) << "Begin AutodetectTransfer constructor" << TLOG_ENDL;
73  std::string srcHost, destHost;
74  auto hosts = pset.get<std::vector<fhicl::ParameterSet>>("host_map");
75  for (auto& ps : hosts)
76  {
77  auto rank = ps.get<int>("rank", -1);
78  if (rank == source_rank())
79  {
80  srcHost = ps.get<std::string>("host", "localhost");
81  }
82  if (rank == destination_rank())
83  {
84  destHost = ps.get<std::string>("host", "localhost");
85  }
86  }
87  TLOG_DEBUG(uniqueLabel()) << "ADT: srcHost=" << srcHost << ", destHost=" << destHost << TLOG_ENDL;
88  if (srcHost == destHost)
89  {
90  TLOG_DEBUG(uniqueLabel()) << "ADT: Constructing ShmemTransfer" << TLOG_ENDL;
91  theTransfer_.reset(new ShmemTransfer(pset, role));
92  }
93  else
94  {
95  TLOG_DEBUG(uniqueLabel()) << "ADT: Constructing TCPSocketTransfer" << TLOG_ENDL;
96  theTransfer_.reset(new TCPSocketTransfer(pset, role));
97  }
98 }
99 
100 DEFINE_ARTDAQ_TRANSFER(artdaq::AutodetectTransfer)
virtual int source_rank() const
Get the source rank for this TransferInterface instance.
Role role() const
Get the TransferInterface::Role of this TransferInterface.
virtual ~AutodetectTransfer()=default
AutodetectTransfer default Destructor.
CopyStatus copyFragment(artdaq::Fragment &fragment, size_t send_timeout_usec=std::numeric_limits< size_t >::max()) override
Send a Fragment in non-reliable mode, using the underlying transfer plugin.
int receiveFragment(artdaq::Fragment &fragment, size_t receiveTimeout) override
Receive a Fragment, using the underlying transfer plugin.
AutodetectTransfer(const fhicl::ParameterSet &pset, Role role)
AutodetectTransfer Constructor.
Role
Used to determine if a TransferInterface is a Sender or Receiver.
std::string uniqueLabel() const
Get the unique label of this TransferInterface instance.
A TransferInterface implementation plugin that transfers data using Shared Memory.
This interface defines the functions used to transfer data between artdaq applications.
virtual int destination_rank() const
Get the destination rank for this TransferInterface instance.
TransferInterface implementation plugin that sends data using TCP sockets.
CopyStatus moveFragment(artdaq::Fragment &&fragment, size_t send_timeout_usec=std::numeric_limits< size_t >::max()) override
Send a Fragment in reliable mode, using the underlying transfer plugin.
The AutodetectTransfer TransferInterface plugin sets up a Shmem_transfer plugin or TCPSocket_transfer...
CopyStatus
Returned from the send functions, this enumeration describes the possible return codes. If an exception occurs, it will be thrown and should be handled normally.