1 #include "artdaq/TransferPlugins/TransferInterface.hh"
3 #include "artdaq-core/Data/Fragment.hh"
4 #include "artdaq-core/Utilities/ExceptionHandler.hh"
6 #include "cetlib/BasicPluginFactory.h"
7 #include "cetlib/filepath_maker.h"
8 #include "cetlib_except/exception.h"
9 #include "fhiclcpp/ParameterSet.h"
11 #include <boost/asio.hpp>
21 fhicl::ParameterSet ReadParameterSet(
const std::string& fhicl_filename)
23 if (std::getenv(
"FHICL_FILE_PATH") ==
nullptr)
26 <<
"INFO: environment variable FHICL_FILE_PATH was not set. Using \".\"\n";
27 setenv(
"FHICL_FILE_PATH",
".", 0);
30 cet::filepath_lookup_after1 lookup_policy(
"FHICL_FILE_PATH");
31 auto pset = fhicl::ParameterSet::make(fhicl_filename, lookup_policy);
36 int do_check(
const artdaq::Fragment& frag);
38 int main(
int argc,
char* argv[])
43 std::cerr <<
"Usage: transfer_plugin_receiver <fhicl document>" << std::endl;
47 auto fhicl_filename = boost::lexical_cast<std::string>(argv[1]);
49 std::unique_ptr<artdaq::TransferInterface> transfer;
50 auto pset = ReadParameterSet(fhicl_filename);
54 static cet::BasicPluginFactory bpf(
"transfer",
"make");
57 bpf.makePlugin<std::unique_ptr<artdaq::TransferInterface>,
58 const fhicl::ParameterSet&,
60 pset.get<std::string>(
"transfer_plugin_type"),
66 artdaq::ExceptionHandler(artdaq::ExceptionHandlerRethrow::no,
67 "Error creating transfer plugin");
73 artdaq::Fragment myfrag;
74 size_t timeout = 10000000;
76 auto retval = transfer->receiveFragment(myfrag, timeout);
80 std::cout <<
"Returned from call to transfer_->receiveFragmentFrom; fragment with seqID == " << myfrag.sequenceID() <<
", fragID == " << myfrag.fragmentID() <<
" has size " << myfrag.sizeBytes() <<
" bytes" << std::endl;
84 std::cerr <<
"RECV_TIMEOUT received from call to transfer->receiveFragmentFrom" << std::endl;
88 if (do_check(myfrag) != 0)
90 std::cerr <<
"Error: do_check indicates fragment failed to transmit correctly" << std::endl;
94 std::cerr <<
"Success: do_check indicates fragment transmitted correctly" << std::endl;
110 int do_check(
const artdaq::Fragment& frag)
112 uint64_t variable_to_compare = 0;
114 for (
auto ptr_into_frag = reinterpret_cast<const uint64_t*>(frag.dataBeginBytes());
115 ptr_into_frag !=
reinterpret_cast<const uint64_t*
>(frag.dataEndBytes());
116 ++ptr_into_frag, ++variable_to_compare)
118 if (variable_to_compare != *ptr_into_frag)
120 std::cerr <<
"ERROR for fragment with sequence ID " << frag.sequenceID() <<
", fragment ID " << frag.fragmentID() <<
": expected ADC value of " << variable_to_compare <<
", got " << *ptr_into_frag << std::endl;
This TransferInterface is a Receiver.
Role
Used to determine if a TransferInterface is a Sender or Receiver.
For code clarity, things checking for successful receive should check retval >= NO_RANK_INFO.