artdaq  v3_02_00
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 #include "cetlib/compiler_macros.h"
8 
9 #include <limits>
10 #include <iostream>
11 #include <sstream>
12 
13 namespace artdaq
14 {
19  {
20  public:
21  struct Config
22  {
23  fhicl::Atom<int> source_rank{ fhicl::Name{"source_rank"}, fhicl::Comment{"The rank that data is coming from"}, my_rank };
24  fhicl::Atom<int> destination_rank{ fhicl::Name{ "destination_rank"}, fhicl::Comment{"The rank that data is going to"}, my_rank };
25  fhicl::Atom<std::string> unique_label{ fhicl::Name{"unique_label"}, fhicl::Comment{"A label that uniquely identifies the TransferInterface instance"},"transfer_between_[source_rank]_and_[destination_rank]" };
26  fhicl::Atom<size_t> buffer_count{ fhicl::Name{"buffer_count"}, fhicl::Comment{"How many Fragments can the TransferInterface handle simultaneously"},10 };
27  fhicl::Atom<size_t> max_fragment_size{ fhicl::Name{"max_fragment_size_words" }, fhicl::Comment{ "The maximum Fragment size expected.May be used for static memory allocation, and will cause errors if larger Fragments are sent." }, 1024 };
28  fhicl::Atom<short> partition_number{ fhicl::Name{"partition_number"},fhicl::Comment{"Partition that this TransferInterface is a part of"}, 0 };
29 
30  };
31 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103
32  using Parameters = fhicl::WrappedTable<Config>;
33 #endif
34 
35  enum : int
36  {
37  DATA_END = -2222,
38  RECV_TIMEOUT = -1111,
40  };
41 
45  enum class Role
46  {
47  kSend,
48  kReceive
49  };
50 
55  enum class CopyStatus
56  {
57  kSuccess,
58  kTimeout,
60  };
61 
62  static std::string CopyStatusToString(CopyStatus in)
63  {
64  switch (in)
65  {
66  case CopyStatus::kSuccess: return "Success";
67  case CopyStatus::kTimeout: return "Timeout";
68  case CopyStatus::kErrorNotRequiringException: return "Error";
69  default: return "UNKNOWN";
70  }
71  return "SWITCHERROR";
72  }
73 
90  TransferInterface(const fhicl::ParameterSet& ps, Role role);
91 
95  TransferInterface(const TransferInterface&) = delete;
96 
102 
106  virtual ~TransferInterface() = default;
107 
114  virtual int receiveFragment(artdaq::Fragment& fragment, size_t receiveTimeout);
115 
122  virtual int receiveFragmentHeader(detail::RawFragmentHeader& header, size_t receiveTimeout) = 0;
123 
133  virtual int receiveFragmentData(RawDataType* destination, size_t wordCount) = 0;
134 
141  virtual CopyStatus copyFragment(artdaq::Fragment& fragment, size_t send_timeout_usec) = 0;
142 
143  // Move fragment (should be reliable)
149  virtual CopyStatus moveFragment(artdaq::Fragment&& fragment) = 0;
150 
155  std::string uniqueLabel() const { return unique_label_; }
156 
161  virtual int source_rank() const { return source_rank_; }
166  virtual int destination_rank() const { return destination_rank_; }
167 
172  virtual bool isRunning() { return false; }
173 
174 
175 
180  std::string GetTraceName() const { return unique_label_ + (role_ == Role::kSend ? "_SEND" : "_RECV"); }
181  private:
182  const Role role_;
183 
184  const int source_rank_;
185  const int destination_rank_;
186  const std::string unique_label_;
187 
188  protected:
189  size_t buffer_count_;
191  const short partition_number_;
192 
193  protected:
198  Role role() const { return role_; }
199  };
200 }
201 
202 #ifndef EXTERN_C_FUNC_DECLARE_START
203 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
204 #endif
205 
206 #define DEFINE_ARTDAQ_TRANSFER(klass) \
207  EXTERN_C_FUNC_DECLARE_START \
208 std::unique_ptr<artdaq::TransferInterface> make(fhicl::ParameterSet const & ps, \
209  artdaq::TransferInterface::Role role) { \
210  return std::unique_ptr<artdaq::TransferInterface>(new klass(ps, role)); \
211 }}
212 
213 
214 #endif /* artdaq_ArtModules_TransferInterface.hh */
215 
216 // Local Variables:
217 // mode: c++
218 // End:
size_t buffer_count_
The number of Fragment transfers the TransferInterface can handle simultaneously. ...
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.
Value to be returned upon receive timeout.
Role role() const
Get the TransferInterface::Role of this TransferInterface.
For code clarity, things checking for successful receive should check retval &gt;= RECV_SUCCESS.
std::string GetTraceName() const
Constructs a name suitable for TRACE messages.
virtual ~TransferInterface()=default
Default virtual Destructor.
This TransferInterface is a Receiver.
const short partition_number_
The partition number of the DAQ.
virtual int receiveFragmentData(RawDataType *destination, size_t wordCount)=0
Receive the body of a Fragment to the given destination pointer.
Value that is to be returned when a Transfer plugin determines that no more data will be arriving...
virtual bool isRunning()
Determine whether the TransferInterface plugin is able to send/receive data.
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.
The send operation completed successfully.
std::string uniqueLabel() const
Get the unique label of this TransferInterface instance.
virtual CopyStatus copyFragment(artdaq::Fragment &fragment, size_t send_timeout_usec)=0
Copy a Fragment to the destination. May not necessarily be reliable.
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.
virtual CopyStatus moveFragment(artdaq::Fragment &&fragment)=0
Move a Fragment to the destination. This should be reliable, if the underlying transport mechanism su...
const size_t max_fragment_size_words_
The maximum size of the transferred Fragment objects, in artdaq::Fragment::RawDataType words...