artdaq  v3_02_01
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:
24  struct Config
25  {
27  fhicl::Atom<int> source_rank{ fhicl::Name{"source_rank"}, fhicl::Comment{"The rank that data is coming from"}, my_rank };
29  fhicl::Atom<int> destination_rank{ fhicl::Name{ "destination_rank"}, fhicl::Comment{"The rank that data is going to"}, my_rank };
31  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]" };
33  fhicl::Atom<size_t> buffer_count{ fhicl::Name{"buffer_count"}, fhicl::Comment{"How many Fragments can the TransferInterface handle simultaneously"},10 };
35  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 };
37  fhicl::Atom<short> partition_number{ fhicl::Name{"partition_number"},fhicl::Comment{"Partition that this TransferInterface is a part of"}, 0 };
38 
39  };
40 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103
41  using Parameters = fhicl::WrappedTable<Config>;
42 #endif
43 
47  enum ReceiveReturnCode : int
48  {
49  DATA_END = -2222,
50  RECV_TIMEOUT = -1111,
52  };
53 
57  enum class Role
58  {
59  kSend,
60  kReceive
61  };
62 
67  enum class CopyStatus
68  {
69  kSuccess,
70  kTimeout,
72  };
73 
79  static std::string CopyStatusToString(CopyStatus in)
80  {
81  switch (in)
82  {
83  case CopyStatus::kSuccess: return "Success";
84  case CopyStatus::kTimeout: return "Timeout";
85  case CopyStatus::kErrorNotRequiringException: return "Error";
86  default: return "UNKNOWN";
87  }
88  return "SWITCHERROR";
89  }
90 
96  TransferInterface(const fhicl::ParameterSet& ps, Role role);
97 
101  TransferInterface(const TransferInterface&) = delete;
102 
108 
112  virtual ~TransferInterface() = default;
113 
120  virtual int receiveFragment(artdaq::Fragment& fragment, size_t receiveTimeout);
121 
128  virtual int receiveFragmentHeader(detail::RawFragmentHeader& header, size_t receiveTimeout) = 0;
129 
139  virtual int receiveFragmentData(RawDataType* destination, size_t wordCount) = 0;
140 
147  virtual CopyStatus copyFragment(artdaq::Fragment& fragment, size_t send_timeout_usec) = 0;
148 
149  // Move fragment (should be reliable)
155  virtual CopyStatus moveFragment(artdaq::Fragment&& fragment) = 0;
156 
161  std::string uniqueLabel() const { return unique_label_; }
162 
167  virtual int source_rank() const { return source_rank_; }
172  virtual int destination_rank() const { return destination_rank_; }
173 
178  virtual bool isRunning() { return false; }
179 
180 
182  #define GetTraceName() unique_label_ << (role_ == Role::kSend ? "_SEND" : "_RECV")
183 
185  protected:
186  const Role role_;
187 
188  const int source_rank_;
189  const int destination_rank_;
190  const std::string unique_label_;
191 
192  size_t buffer_count_;
194  const short partition_number_;
195 
196  protected:
201  Role role() const { return role_; }
202  };
203 }
204 
207 #ifndef EXTERN_C_FUNC_DECLARE_START
208 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
209 #endif
210 
211 #define DEFINE_ARTDAQ_TRANSFER(klass) \
212  EXTERN_C_FUNC_DECLARE_START \
213 std::unique_ptr<artdaq::TransferInterface> make(fhicl::ParameterSet const & ps, artdaq::TransferInterface::Role role) { \
214  return std::unique_ptr<artdaq::TransferInterface>(new klass(ps, role)); \
215 }}
216 
220 #endif /* artdaq_ArtModules_TransferInterface.hh */
221 
222 // Local Variables:
223 // mode: c++
224 // End:
size_t buffer_count_
The number of Fragment transfers the TransferInterface can handle simultaneously. ...
ReceiveReturnCode
Return codes from receive operations
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.
const std::string unique_label_
Unique label of transfer (ideally the same on sender and receiver)
virtual ~TransferInterface()=default
Default virtual Destructor.
This TransferInterface is a Receiver.
const short partition_number_
The partition number of the DAQ.
const int destination_rank_
Rank of destination.
static std::string CopyStatusToString(CopyStatus in)
Convert a CopyStatus variable to its string represenatation
fhicl::Atom< short > partition_number
&quot;partition_number&quot; (Default: 0) : Partition that this TransferInterface is a part of ...
virtual int receiveFragmentData(RawDataType *destination, size_t wordCount)=0
Receive the body of a Fragment to the given destination pointer.
fhicl::Atom< std::string > unique_label
&quot;unique_label&quot; (Default: &quot;transfer_between_[source_rank]_and_[destination_rank]&quot;) : A label that uniq...
Value that is to be returned when a Transfer plugin determines that no more data will be arriving...
Configuration of the TransferInterface. May be used for parameter validation
virtual bool isRunning()
Determine whether the TransferInterface plugin is able to send/receive data.
This TransferInterface is a Sender.
fhicl::Atom< size_t > max_fragment_size
&quot;max_fragment_size_words&quot; (Default: 1024) : The maximum Fragment size expected.May be used for static...
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.
fhicl::Atom< size_t > buffer_count
&quot;buffer_count&quot; (Default: 10) : How many Fragments can the TransferInterface handle simultaneously ...
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.
For code clarity, things checking for successful receive should check retval &gt;= RECV_SUCCESS.
const Role role_
Whether this instance of TransferInterface is a sender or receiver.
fhicl::Atom< int > source_rank
&quot;source_rank&quot; (Default: my_rank) : The rank that data is coming from
fhicl::Atom< int > destination_rank
&quot;destination_rank&quot; (Default: my_rank) : The rank that data is going to
Value to be returned upon receive timeout.
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...
const int source_rank_
Rank of source.