$treeview $search $mathjax $extrastylesheet
artdaq
v3_04_01
$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 }; 00038 using Parameters = fhicl::WrappedTable<Config>; 00039 00043 enum ReceiveReturnCode : int 00044 { 00045 DATA_END = -2222, 00046 RECV_TIMEOUT = -1111, 00047 NO_RANK_INFO = -1, 00048 RECV_SUCCESS = 0 00049 }; 00050 00054 enum class Role 00055 { 00056 kSend, 00057 kReceive 00058 }; 00059 00064 enum class CopyStatus 00065 { 00066 kSuccess, 00067 kTimeout, 00068 kErrorNotRequiringException 00069 }; 00070 00076 static std::string CopyStatusToString(CopyStatus in) 00077 { 00078 switch (in) 00079 { 00080 case CopyStatus::kSuccess: return "Success"; 00081 case CopyStatus::kTimeout: return "Timeout"; 00082 case CopyStatus::kErrorNotRequiringException: return "Error"; 00083 default: return "UNKNOWN"; 00084 } 00085 return "SWITCHERROR"; 00086 } 00087 00093 TransferInterface(const fhicl::ParameterSet& ps, Role role); 00094 00098 TransferInterface(const TransferInterface&) = delete; 00099 00104 TransferInterface& operator=(const TransferInterface&) = delete; 00105 00109 virtual ~TransferInterface() = default; 00110 00117 virtual int receiveFragment(artdaq::Fragment& fragment, size_t receiveTimeout); 00118 00125 virtual int receiveFragmentHeader(detail::RawFragmentHeader& header, size_t receiveTimeout) = 0; 00126 00136 virtual int receiveFragmentData(RawDataType* destination, size_t wordCount) = 0; 00137 00144 virtual CopyStatus transfer_fragment_min_blocking_mode(artdaq::Fragment const& fragment, size_t send_timeout_usec) = 0; 00145 00151 virtual CopyStatus transfer_fragment_reliable_mode(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 00179 virtual void flush_buffers() = 0; 00180 00181 00183 #define GetTraceName() unique_label_ << (role_ == Role::kSend ? "_SEND" : "_RECV") 00184 00186 protected: 00187 const Role role_; 00188 00189 const int source_rank_; 00190 const int destination_rank_; 00191 const std::string unique_label_; 00192 00193 size_t buffer_count_; 00194 const size_t max_fragment_size_words_; 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 /* artdaq_ArtModules_TransferInterface.hh */ 00221 00222 // Local Variables: 00223 // mode: c++ 00224 // End: