Line data Source code
1 : #define TRACE_NAME (app_name + "_TransferInterface").c_str()
2 : #include "artdaq/DAQdata/Globals.hh"
3 :
4 : #include "artdaq/TransferPlugins/TransferInterface.hh"
5 :
6 : #include "fhiclcpp/ParameterSet.h"
7 :
8 : #include "cetlib_except/exception.h"
9 :
10 : #include <string>
11 :
12 3 : artdaq::TransferInterface::TransferInterface(const fhicl::ParameterSet& ps, Role role)
13 3 : : role_(role)
14 6 : , source_rank_(ps.get<int>("source_rank", my_rank))
15 3 : , destination_rank_(ps.get<int>("destination_rank", my_rank))
16 9 : , unique_label_(ps.get<std::string>("unique_label", "transfer_between_" + std::to_string(source_rank_) + "_and_" + std::to_string(destination_rank_)))
17 6 : , buffer_count_(ps.get<size_t>("buffer_count", 10))
18 9 : , max_fragment_size_words_(ps.get<size_t>("max_fragment_size_words", 1024))
19 : {
20 6 : TLOG(TLVL_DEBUG + 32) << GetTraceName() << " TransferInterface constructor has "
21 3 : << ps.to_string();
22 3 : }
23 :
24 0 : int artdaq::TransferInterface::receiveFragment(artdaq::Fragment& frag, size_t receive_timeout)
25 : {
26 0 : auto ret = static_cast<int>(RECV_TIMEOUT);
27 :
28 0 : TLOG(TLVL_DEBUG + 33) << GetTraceName() << "Receiving Fragment Header from rank " << source_rank();
29 0 : ret = receiveFragmentHeader(*reinterpret_cast<detail::RawFragmentHeader*>(frag.headerAddress()), receive_timeout); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
30 :
31 0 : TLOG(TLVL_DEBUG + 33) << GetTraceName() << "Done receiving Header, ret is " << ret << ", should be " << source_rank();
32 0 : if (ret < RECV_SUCCESS)
33 : {
34 0 : return ret;
35 : }
36 :
37 0 : frag.autoResize();
38 :
39 0 : TLOG(TLVL_DEBUG + 33) << GetTraceName() << "Receiving Fragment Body from rank " << source_rank();
40 0 : auto bodyret = receiveFragmentData(frag.headerAddress() + detail::RawFragmentHeader::num_words(), frag.sizeBytes() - detail::RawFragmentHeader::num_words() * sizeof(RawDataType)); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
41 0 : TLOG(TLVL_DEBUG + 33) << GetTraceName() << "Done receiving Body, ret is " << bodyret << ", should be " << source_rank();
42 :
43 0 : if (bodyret != ret)
44 : {
45 0 : throw cet::exception("TransferInterface") << "Got different return codes from receiveFragmentHeader and receiveFragmentData!"; // NOLINT(cert-err60-cpp)
46 : }
47 :
48 0 : return ret;
49 : }
|