$treeview $search $mathjax $extrastylesheet
artdaq
v3_04_00
$projectbrief
|
$projectbrief
|
$searchbox |
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 transfer_fragment_min_blocking_mode(artdaq::Fragment const& fragment, size_t send_timeout_usec) = 0; 00144 00150 virtual CopyStatus transfer_fragment_reliable_mode(artdaq::Fragment&& fragment) = 0; 00151 00156 std::string uniqueLabel() const { return unique_label_; } 00157 00162 virtual int source_rank() const { return source_rank_; } 00167 virtual int destination_rank() const { return destination_rank_; } 00168 00173 virtual bool isRunning() { return false; } 00174 00178 virtual void flush_buffers() = 0; 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 00195 protected: 00200 Role role() const { return role_; } 00201 }; 00202 } 00203 00206 #ifndef EXTERN_C_FUNC_DECLARE_START 00207 #define EXTERN_C_FUNC_DECLARE_START extern "C" { 00208 #endif 00209 00210 #define DEFINE_ARTDAQ_TRANSFER(klass) \ 00211 EXTERN_C_FUNC_DECLARE_START \ 00212 std::unique_ptr<artdaq::TransferInterface> make(fhicl::ParameterSet const & ps, artdaq::TransferInterface::Role role) { \ 00213 return std::unique_ptr<artdaq::TransferInterface>(new klass(ps, role)); \ 00214 }} 00215 00219 #endif /* artdaq_ArtModules_TransferInterface.hh */ 00220 00221 // Local Variables: 00222 // mode: c++ 00223 // End: