artdaq  v3_00_03
TransferInterface.hh
1 #ifndef artdaq_ArtModules_TransferInterface_hh
2 #define artdaq_ArtModules_TransferInterface_hh
3 
4 #include "artdaq/DAQdata/Globals.hh"
5 #include "artdaq-core/Data/Fragment.hh"
6 #include "fhiclcpp/ParameterSet.h"
7 
8 #include <limits>
9 #include <iostream>
10 #include <sstream>
11 
12 namespace artdaq
13 {
18  {
19  public:
24  static const int RECV_TIMEOUT = 0xfedcba98;
25 
29  enum class Role
30  {
31  kSend,
32  kReceive
33  };
34 
39  enum class CopyStatus
40  {
41  kSuccess,
42  kTimeout,
44  };
45 
61  TransferInterface(const fhicl::ParameterSet& ps, Role role);
62 
66  TransferInterface(const TransferInterface&) = delete;
67 
73 
77  virtual ~TransferInterface() = default;
78 
85  virtual int receiveFragment(artdaq::Fragment& fragment, size_t receiveTimeout);
86 
93  virtual int receiveFragmentHeader(detail::RawFragmentHeader& header, size_t receiveTimeout) = 0;
94 
104  virtual int receiveFragmentData(RawDataType* destination, size_t wordCount) = 0;
105 
112  virtual CopyStatus copyFragment(artdaq::Fragment& fragment, size_t send_timeout_usec = std::numeric_limits<size_t>::max()) = 0;
113 
114  // Move fragment (should be reliable)
121  virtual CopyStatus moveFragment(artdaq::Fragment&& fragment, size_t send_timeout_usec = std::numeric_limits<size_t>::max()) = 0;
122 
127  std::string uniqueLabel() const { return unique_label_; }
128 
133  virtual int source_rank() const { return source_rank_; }
138  virtual int destination_rank() const { return destination_rank_; }
139  private:
140  const Role role_;
141 
142  const int source_rank_;
143  const int destination_rank_;
144  const std::string unique_label_;
145 
146  protected:
147  size_t buffer_count_;
149  protected:
154  Role role() const { return role_; }
155  };
156 }
157 
158 #define DEFINE_ARTDAQ_TRANSFER(klass) \
159  extern "C" std::unique_ptr<artdaq::TransferInterface> make(fhicl::ParameterSet const & ps, \
160  artdaq::TransferInterface::Role role) { \
161  return std::unique_ptr<artdaq::TransferInterface>(new klass(ps, role)); \
162 }
163 
164 
165 #endif /* artdaq_ArtModules_TransferInterface.hh */
166 
167 // Local Variables:
168 // mode: c++
169 // End:
size_t buffer_count_
The number of Fragment transfers the TransferInterface can handle simultaneously. ...
virtual CopyStatus moveFragment(artdaq::Fragment &&fragment, size_t send_timeout_usec=std::numeric_limits< size_t >::max())=0
Move a Fragment to the destination. This should be reliable, if the underlying transport mechanism su...
virtual int receiveFragmentHeader(detail::RawFragmentHeader &header, size_t receiveTimeout)=0
Receive a Fragment Header from the transport mechanism.
virtual int source_rank() const
Get the source rank for this TransferInterface instance.
TransferInterface & operator=(const TransferInterface &)=delete
Copy Assignment operator is deleted.
Role role() const
Get the TransferInterface::Role of this TransferInterface.
virtual ~TransferInterface()=default
Default virtual Destructor.
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.
This TransferInterface is a Receiver.
virtual int receiveFragmentData(RawDataType *destination, size_t wordCount)=0
Receive the body of a Fragment to the given destination pointer.
This TransferInterface is a Sender.
Some error occurred, but no exception was thrown.
Role
Used to determine if a TransferInterface is a Sender or Receiver.
virtual CopyStatus copyFragment(artdaq::Fragment &fragment, size_t send_timeout_usec=std::numeric_limits< size_t >::max())=0
Copy a Fragment to the destination. May not necessarily be reliable.
The send operation completed successfully.
std::string uniqueLabel() const
Get the unique label of this TransferInterface instance.
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(const fhicl::ParameterSet &ps, Role role)
TransferInterface Constructor.
virtual int receiveFragment(artdaq::Fragment &fragment, size_t receiveTimeout)
Receive a Fragment from the transport mechanism.
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.
const size_t max_fragment_size_words_
The maximum size of the transferred Fragment objects, in artdaq::Fragment::RawDataType words...