00001 #define TRACE_NAME "TransferInterface" 00002 #include "artdaq/TransferPlugins/TransferInterface.hh" 00003 #include "cetlib_except/exception.h" 00004 00005 artdaq::TransferInterface::TransferInterface(const fhicl::ParameterSet& ps, Role role) 00006 : role_(role) 00007 , source_rank_(ps.get<int>("source_rank", my_rank)) 00008 , destination_rank_(ps.get<int>("destination_rank", my_rank)) 00009 , unique_label_(ps.get<std::string>("unique_label", "transfer_between_" + std::to_string(source_rank_) + "_and_" + std::to_string(destination_rank_))) 00010 , buffer_count_(ps.get<size_t>("buffer_count", 10)) 00011 , max_fragment_size_words_(ps.get<size_t>("max_fragment_size_words", 1024)) 00012 { 00013 TLOG_DEBUG("TransferInterface") << uniqueLabel() << " role:"<<(int)role<<" TransferInterface constructor has " 00014 << ps.to_string() << TLOG_ENDL; 00015 } 00016 00017 int artdaq::TransferInterface::receiveFragment(artdaq::Fragment& frag, size_t receive_timeout) 00018 { 00019 auto ret = RECV_TIMEOUT; 00020 00021 TLOG_TRACE("TransferInterface") << "Receiving Fragment Header from rank " << source_rank() << TLOG_ENDL; 00022 ret = receiveFragmentHeader(*reinterpret_cast<detail::RawFragmentHeader*>(frag.headerAddress()), receive_timeout); 00023 00024 TLOG_TRACE("TransferInterface") << "Done receiving Header, ret is " << ret << ", should be " << source_rank() << TLOG_ENDL; 00025 if (ret == RECV_TIMEOUT) return ret; 00026 00027 frag.autoResize(); 00028 00029 TLOG_TRACE("TransferInterface") << "Receiving Fragment Body from rank " << source_rank() << TLOG_ENDL; 00030 auto bodyret = receiveFragmentData(frag.headerAddress() + detail::RawFragmentHeader::num_words(), frag.sizeBytes() - detail::RawFragmentHeader::num_words() * sizeof(RawDataType)); 00031 TLOG_TRACE("TransferInterface") << "Done receiving Body, ret is " << bodyret << ", should be " << source_rank() << TLOG_ENDL; 00032 00033 if (bodyret != ret) throw cet::exception("TransferInterface") << "Got different return codes from receiveFragmentHeader and receiveFragmentData!"; 00034 00035 return ret; 00036 }