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 };
00037 fhicl::Atom<short> partition_number{ fhicl::Name{"partition_number"},fhicl::Comment{"Partition that this TransferInterface is a part of"}, 0 };
00038
00039 };
00040 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103
00041 using Parameters = fhicl::WrappedTable<Config>;
00042 #endif
00043
00047 enum ReceiveReturnCode : int
00048 {
00049 DATA_END = -2222,
00050 RECV_TIMEOUT = -1111,
00051 RECV_SUCCESS = 0
00052 };
00053
00057 enum class Role
00058 {
00059 kSend,
00060 kReceive
00061 };
00062
00067 enum class CopyStatus
00068 {
00069 kSuccess,
00070 kTimeout,
00071 kErrorNotRequiringException
00072 };
00073
00079 static std::string CopyStatusToString(CopyStatus in)
00080 {
00081 switch (in)
00082 {
00083 case CopyStatus::kSuccess: return "Success";
00084 case CopyStatus::kTimeout: return "Timeout";
00085 case CopyStatus::kErrorNotRequiringException: return "Error";
00086 default: return "UNKNOWN";
00087 }
00088 return "SWITCHERROR";
00089 }
00090
00096 TransferInterface(const fhicl::ParameterSet& ps, Role role);
00097
00101 TransferInterface(const TransferInterface&) = delete;
00102
00107 TransferInterface& operator=(const TransferInterface&) = delete;
00108
00112 virtual ~TransferInterface() = default;
00113
00120 virtual int receiveFragment(artdaq::Fragment& fragment, size_t receiveTimeout);
00121
00128 virtual int receiveFragmentHeader(detail::RawFragmentHeader& header, size_t receiveTimeout) = 0;
00129
00139 virtual int receiveFragmentData(RawDataType* destination, size_t wordCount) = 0;
00140
00147 virtual CopyStatus copyFragment(artdaq::Fragment& fragment, size_t send_timeout_usec) = 0;
00148
00149
00155 virtual CopyStatus moveFragment(artdaq::Fragment&& fragment) = 0;
00156
00161 std::string uniqueLabel() const { return unique_label_; }
00162
00167 virtual int source_rank() const { return source_rank_; }
00172 virtual int destination_rank() const { return destination_rank_; }
00173
00178 virtual bool isRunning() { return false; }
00179
00180
00182 #define GetTraceName() unique_label_ << (role_ == Role::kSend ? "_SEND" : "_RECV")
00183
00185 protected:
00186 const Role role_;
00187
00188 const int source_rank_;
00189 const int destination_rank_;
00190 const std::string unique_label_;
00191
00192 size_t buffer_count_;
00193 const size_t max_fragment_size_words_;
00194 const short partition_number_;
00195
00196 protected:
00201 Role role() const { return role_; }
00202 };
00203 }
00204
00207 #ifndef EXTERN_C_FUNC_DECLARE_START
00208 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
00209 #endif
00210
00211 #define DEFINE_ARTDAQ_TRANSFER(klass) \
00212 EXTERN_C_FUNC_DECLARE_START \
00213 std::unique_ptr<artdaq::TransferInterface> make(fhicl::ParameterSet const & ps, artdaq::TransferInterface::Role role) { \
00214 return std::unique_ptr<artdaq::TransferInterface>(new klass(ps, role)); \
00215 }}
00216
00220 #endif
00221
00222
00223
00224