artdaq  v2_03_00
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
RTIDDS_transfer.cc
1 #include "artdaq/TransferPlugins/TransferInterface.hh"
2 
3 #include "artdaq/RTIDDS/RTIDDS.hh"
4 
5 #include "artdaq-core/Utilities/ExceptionHandler.hh"
6 #include <memory>
7 #include <iostream>
8 
9 
10 namespace fhicl
11 {
12  class ParameterSet;
13 }
14 
15 // ----------------------------------------------------------------------
16 
17 namespace artdaq
18 {
23  {
24  public:
28  virtual ~RTIDDSTransfer() = default;
29 
37  RTIDDSTransfer(fhicl::ParameterSet const& ps, Role role) :
38  TransferInterface(ps, role)
39  , rtidds_reader_(std::make_unique<artdaq::RTIDDS>("RTIDDSTransfer_reader", artdaq::RTIDDS::IOType::reader))
40  , rtidds_writer_(std::make_unique<artdaq::RTIDDS>("RTIDDSTransfer_writer", artdaq::RTIDDS::IOType::writer)) { }
41 
48  int receiveFragment(artdaq::Fragment& fragment,
49  size_t receiveTimeout) override;
50 
57  CopyStatus copyFragment(artdaq::Fragment& fragment,
58  size_t send_timeout_usec = std::numeric_limits<size_t>::max()) override;
59 
66  CopyStatus moveFragment(artdaq::Fragment&& fragment,
67  size_t send_timeout_usec = std::numeric_limits<size_t>::max()) override;
68 
69  private:
70  std::unique_ptr<artdaq::RTIDDS> rtidds_reader_;
71  std::unique_ptr<artdaq::RTIDDS> rtidds_writer_;
72  };
73 }
74 
75 int artdaq::RTIDDSTransfer::receiveFragment(artdaq::Fragment& fragment,
76  size_t receiveTimeout)
77 {
78  bool receivedFragment = false;
79  // static std::size_t consecutive_timeouts = 0;
80  // std::size_t message_after_N_timeouts = 10;
81 
82  // while (!receivedFragment) {
83 
84  try
85  {
86  receivedFragment = rtidds_reader_->octets_listener_.receiveFragmentFromDDS(fragment, receiveTimeout);
87  }
88  catch (...)
89  {
90  ExceptionHandler(ExceptionHandlerRethrow::yes,
91  "Error in RTIDDS transfer plugin: caught exception in call to OctetsListener::receiveFragmentFromDDS, rethrowing");
92  }
93 
94  // if (!receivedFragment) {
95 
96  // consecutive_timeouts++;
97 
98  // if (consecutive_timeouts % message_after_N_timeouts == 0) {
99  // TLOG_INFO("RTIDDSTransfer") << consecutive_timeouts << " consecutive " <<
100  // static_cast<float>(receiveTimeout)/1e6 << "-second timeouts calling OctetsListener::receiveFragmentFromDDS, will continue trying..." << TLOG_ENDL;
101  // }
102  // } else {
103  // consecutive_timeouts = 0;
104  // }
105  // }
106 
107  // return 0;
108 
109  return receivedFragment ? source_rank() : TransferInterface::RECV_TIMEOUT;
110 }
111 
113 artdaq::RTIDDSTransfer::moveFragment(artdaq::Fragment&& fragment, size_t send_timeout_usec)
114 {
115  (void)&send_timeout_usec; // No-op to get the compiler not to complain about unused parameter
116 
117  rtidds_writer_->moveFragmentToDDS_(std::move(fragment));
118  return CopyStatus::kSuccess;
119 }
120 
122 artdaq::RTIDDSTransfer::copyFragment(artdaq::Fragment& fragment,
123  size_t send_timeout_usec)
124 {
125  (void) &send_timeout_usec; // No-op to get the compiler not to complain about unused parameter
126 
127  rtidds_writer_->copyFragmentToDDS_(fragment);
128  return CopyStatus::kSuccess;
129 }
130 
131 DEFINE_ARTDAQ_TRANSFER(artdaq::RTIDDSTransfer)
132 
133 // Local Variables:
134 // mode: c++
135 // End:
DDS Transport Implementation.
Definition: RTIDDS.hh:21
virtual int source_rank() const
Get the source rank for this TransferInterface instance.
CopyStatus moveFragment(artdaq::Fragment &&fragment, size_t send_timeout_usec=std::numeric_limits< size_t >::max()) override
Move a Fragment to the destination.
Role role() const
Get the TransferInterface::Role of this TransferInterface.
static const int RECV_TIMEOUT
Value to be returned upon receive timeout. Because receivers otherwise return rank, this is also the limit on the number of ranks that artdaq currently supports.
Role
Used to determine if a TransferInterface is a Sender or Receiver.
int receiveFragment(artdaq::Fragment &fragment, size_t receiveTimeout) override
Receive a Fragment using DDS.
RTIDDSTransfer is a TransferInterface implementation plugin that transfers data using RTI DDS...
This interface defines the functions used to transfer data between artdaq applications.
RTIDDSTransfer(fhicl::ParameterSet const &ps, Role role)
RTIDDSTransfer Constructor.
virtual ~RTIDDSTransfer()=default
RTIDDSTransfer default Destructor.
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.
CopyStatus copyFragment(artdaq::Fragment &fragment, size_t send_timeout_usec=std::numeric_limits< size_t >::max()) override
Copy a Fragment to the destination.