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 , partition_number_(ps.get<short>("partition_number", Globals::GetPartitionNumber())) 00013 { 00014 TLOG(TLVL_DEBUG) << uniqueLabel() << " role:"<<(int)role<<" TransferInterface constructor has " 00015 << ps.to_string() ; 00016 } 00017 00018 int artdaq::TransferInterface::receiveFragment(artdaq::Fragment& frag, size_t receive_timeout) 00019 { 00020 auto ret = static_cast<int>(RECV_TIMEOUT); 00021 00022 TLOG(TLVL_TRACE) << "Receiving Fragment Header from rank " << source_rank() ; 00023 ret = receiveFragmentHeader(*reinterpret_cast<detail::RawFragmentHeader*>(frag.headerAddress()), receive_timeout); 00024 00025 TLOG(TLVL_TRACE) << "Done receiving Header, ret is " << ret << ", should be " << source_rank() ; 00026 if (ret < RECV_SUCCESS) return ret; 00027 00028 frag.autoResize(); 00029 00030 TLOG(TLVL_TRACE) << "Receiving Fragment Body from rank " << source_rank() ; 00031 auto bodyret = receiveFragmentData(frag.headerAddress() + detail::RawFragmentHeader::num_words(), frag.sizeBytes() - detail::RawFragmentHeader::num_words() * sizeof(RawDataType)); 00032 TLOG(TLVL_TRACE) << "Done receiving Body, ret is " << bodyret << ", should be " << source_rank() ; 00033 00034 if (bodyret != ret) throw cet::exception("TransferInterface") << "Got different return codes from receiveFragmentHeader and receiveFragmentData!"; 00035 00036 return ret; 00037 }