00001 #ifndef artdaq_ArtModules_TransferInterface_hh
00002 #define artdaq_ArtModules_TransferInterface_hh
00003
00004 #include "artdaq/DAQdata/Globals.hh"
00005 #include "artdaq-core/Data/Fragment.hh"
00006 #include "fhiclcpp/ParameterSet.h"
00007 #include "cetlib/compiler_macros.h"
00008
00009 #include <limits>
00010 #include <iostream>
00011 #include <sstream>
00012
00013 namespace artdaq
00014 {
00018 class TransferInterface
00019 {
00020 public:
00024 struct Config
00025 {
00027 fhicl::Atom<int> source_rank{ fhicl::Name{"source_rank"}, fhicl::Comment{"The rank that data is coming from"}, my_rank };
00029 fhicl::Atom<int> destination_rank{ fhicl::Name{ "destination_rank"}, fhicl::Comment{"The rank that data is going to"}, my_rank };
00031 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]" };
00033 fhicl::Atom<size_t> buffer_count{ fhicl::Name{"buffer_count"}, fhicl::Comment{"How many Fragments can the TransferInterface handle simultaneously"},10 };
00035 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 };
00036 };
00037 using Parameters = fhicl::WrappedTable<Config>;
00038
00042 enum ReceiveReturnCode : int
00043 {
00044 DATA_END = -2222,
00045 RECV_TIMEOUT = -1111,
00046 NO_RANK_INFO = -1,
00047 RECV_SUCCESS = 0
00048 };
00049
00053 enum class Role
00054 {
00055 kSend,
00056 kReceive
00057 };
00058
00063 enum class CopyStatus
00064 {
00065 kSuccess,
00066 kTimeout,
00067 kErrorNotRequiringException
00068 };
00069
00075 static std::string CopyStatusToString(CopyStatus in)
00076 {
00077 switch (in)
00078 {
00079 case CopyStatus::kSuccess: return "Success";
00080 case CopyStatus::kTimeout: return "Timeout";
00081 case CopyStatus::kErrorNotRequiringException: return "Error";
00082 default: return "UNKNOWN";
00083 }
00084 return "SWITCHERROR";
00085 }
00086
00092 TransferInterface(const fhicl::ParameterSet& ps, Role role);
00093
00097 TransferInterface(const TransferInterface&) = delete;
00098
00103 TransferInterface& operator=(const TransferInterface&) = delete;
00104
00108 virtual ~TransferInterface() = default;
00109
00116 virtual int receiveFragment(artdaq::Fragment& fragment, size_t receiveTimeout);
00117
00124 virtual int receiveFragmentHeader(detail::RawFragmentHeader& header, size_t receiveTimeout) = 0;
00125
00135 virtual int receiveFragmentData(RawDataType* destination, size_t wordCount) = 0;
00136
00143 virtual CopyStatus copyFragment(artdaq::Fragment& fragment, size_t send_timeout_usec) = 0;
00144
00145
00151 virtual CopyStatus moveFragment(artdaq::Fragment&& fragment) = 0;
00152
00157 std::string uniqueLabel() const { return unique_label_; }
00158
00163 virtual int source_rank() const { return source_rank_; }
00168 virtual int destination_rank() const { return destination_rank_; }
00169
00174 virtual bool isRunning() { return false; }
00175
00176
00178 #define GetTraceName() unique_label_ << (role_ == Role::kSend ? "_SEND" : "_RECV")
00179
00181 protected:
00182 const Role role_;
00183
00184 const int source_rank_;
00185 const int destination_rank_;
00186 const std::string unique_label_;
00187
00188 size_t buffer_count_;
00189 const size_t max_fragment_size_words_;
00190
00191 protected:
00196 Role role() const { return role_; }
00197 };
00198 }
00199
00202 #ifndef EXTERN_C_FUNC_DECLARE_START
00203 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
00204 #endif
00205
00206 #define DEFINE_ARTDAQ_TRANSFER(klass) \
00207 EXTERN_C_FUNC_DECLARE_START \
00208 std::unique_ptr<artdaq::TransferInterface> make(fhicl::ParameterSet const & ps, artdaq::TransferInterface::Role role) { \
00209 return std::unique_ptr<artdaq::TransferInterface>(new klass(ps, role)); \
00210 }}
00211
00215 #endif
00216
00217
00218
00219