artdaq  v3_03_01
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 transfer_fragment_min_blocking_mode(artdaq::Fragment const& fragment,
58  size_t send_timeout_usec = std::numeric_limits<size_t>::max()) override;
59 
65  CopyStatus transfer_fragment_reliable_mode(artdaq::Fragment&& fragment) override;
66 
71  bool isRunning() override
72  {
73  switch (role())
74  {
76  return rtidds_writer_ != nullptr;
78  return rtidds_reader_ != nullptr;
79  }
80  }
81  private:
82  std::unique_ptr<artdaq::RTIDDS> rtidds_reader_;
83  std::unique_ptr<artdaq::RTIDDS> rtidds_writer_;
84  };
85 }
86 
87 int artdaq::RTIDDSTransfer::receiveFragment(artdaq::Fragment& fragment,
88  size_t receiveTimeout)
89 {
90  bool receivedFragment = false;
91  // static std::size_t consecutive_timeouts = 0;
92  // std::size_t message_after_N_timeouts = 10;
93 
94  // while (!receivedFragment) {
95 
96  try
97  {
98  receivedFragment = rtidds_reader_->octets_listener_.receiveFragmentFromDDS(fragment, receiveTimeout);
99  }
100  catch (...)
101  {
102  ExceptionHandler(ExceptionHandlerRethrow::yes,
103  "Error in RTIDDS transfer plugin: caught exception in call to OctetsListener::receiveFragmentFromDDS, rethrowing");
104  }
105 
106  // if (!receivedFragment) {
107 
108  // consecutive_timeouts++;
109 
110  // if (consecutive_timeouts % message_after_N_timeouts == 0) {
111  // TLOG_INFO("RTIDDSTransfer") << consecutive_timeouts << " consecutive " <<
112  // static_cast<float>(receiveTimeout)/1e6 << "-second timeouts calling OctetsListener::receiveFragmentFromDDS, will continue trying..." ;
113  // }
114  // } else {
115  // consecutive_timeouts = 0;
116  // }
117  // }
118 
119  // return 0;
120 
121  return receivedFragment ? source_rank() : TransferInterface::RECV_TIMEOUT;
122 }
123 
126 {
127  rtidds_writer_->transfer_fragment_reliable_mode_via_DDS_(std::move(fragment));
128  return CopyStatus::kSuccess;
129 }
130 
133  size_t send_timeout_usec)
134 {
135  (void) &send_timeout_usec; // No-op to get the compiler not to complain about unused parameter
136 
137  rtidds_writer_->transfer_fragment_min_blocking_mode_via_DDS_(fragment);
138  return CopyStatus::kSuccess;
139 }
140 
141 DEFINE_ARTDAQ_TRANSFER(artdaq::RTIDDSTransfer)
142 
143 // Local Variables:
144 // mode: c++
145 // End:
CopyStatus transfer_fragment_reliable_mode(artdaq::Fragment &&fragment) override
Transfer a Fragment to the destination. This should be reliable, if the underlying transport mechanis...
DDS Transport Implementation.
Definition: RTIDDS.hh:21
virtual int source_rank() const
Get the source rank for this TransferInterface instance.
Role role() const
Get the TransferInterface::Role of this TransferInterface.
CopyStatus transfer_fragment_min_blocking_mode(artdaq::Fragment const &fragment, size_t send_timeout_usec=std::numeric_limits< size_t >::max()) override
Transfer a Fragment to the destination. May not necessarily be reliable, but will not block longer th...
This TransferInterface is a Receiver.
bool isRunning() override
Determine whether the TransferInterface plugin is able to send/receive data.
This TransferInterface is a Sender.
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.
Value to be returned upon receive timeout.
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.