00001 #include "artdaq/TransferPlugins/TransferInterface.hh"
00002
00003 #include "artdaq-core/Data/Fragment.hh"
00004 #include "artdaq-core/Utilities/ExceptionHandler.hh"
00005
00006 #include "cetlib/BasicPluginFactory.h"
00007 #include "cetlib/exception.h"
00008 #include "cetlib/filepath_maker.h"
00009 #include "fhiclcpp/ParameterSet.h"
00010 #include "fhiclcpp/make_ParameterSet.h"
00011
00012 #include <boost/asio.hpp>
00013 #include <boost/bind.hpp>
00014
00015 #include <iostream>
00016 #include <string>
00017 #include <limits>
00018
00019
00020
00021
00022
00023
00024 fhicl::ParameterSet ReadParameterSet(const std::string& fhicl_filename)
00025 {
00026 if (std::getenv("FHICL_FILE_PATH") == nullptr)
00027 {
00028 std::cerr
00029 << "INFO: environment variable FHICL_FILE_PATH was not set. Using \".\"\n";
00030 setenv("FHICL_FILE_PATH", ".", 0);
00031 }
00032
00033 fhicl::ParameterSet pset;
00034 cet::filepath_lookup_after1 lookup_policy("FHICL_FILE_PATH");
00035 fhicl::make_ParameterSet(fhicl_filename, lookup_policy, pset);
00036
00037 return pset;
00038 }
00039
00040
00041 int do_check(const artdaq::Fragment& frag);
00042
00043 int main(int argc, char* argv[])
00044 {
00045 if (argc != 2)
00046 {
00047 std::cerr << "Usage: transfer_plugin_receiver <fhicl document>" << std::endl;
00048 return 1;
00049 }
00050
00051 std::string fhicl_filename = boost::lexical_cast<std::string>(argv[1]);
00052
00053 std::unique_ptr<artdaq::TransferInterface> transfer;
00054 auto pset = ReadParameterSet(fhicl_filename);
00055
00056 try
00057 {
00058 static cet::BasicPluginFactory bpf("transfer", "make");
00059
00060 transfer =
00061 bpf.makePlugin<std::unique_ptr<artdaq::TransferInterface>,
00062 const fhicl::ParameterSet&,
00063 artdaq::TransferInterface::Role>(
00064 pset.get<std::string>("transfer_plugin_type"),
00065 pset,
00066 artdaq::TransferInterface::Role::kReceive);
00067 }
00068 catch (...)
00069 {
00070 artdaq::ExceptionHandler(artdaq::ExceptionHandlerRethrow::yes,
00071 "Error creating transfer plugin");
00072 }
00073
00074
00075 while (true)
00076 {
00077 artdaq::Fragment myfrag;
00078 size_t timeout = 10 * 1e6;
00079
00080 auto retval = transfer->receiveFragment(myfrag, timeout);
00081
00082 if (retval != artdaq::TransferInterface::RECV_TIMEOUT)
00083 {
00084 std::cout << "Returned from call to transfer_->receiveFragmentFrom; fragment with seqID == " <<
00085 myfrag.sequenceID() << ", fragID == " << myfrag.fragmentID() << " has size " <<
00086 myfrag.sizeBytes() << " bytes" << std::endl;
00087 }
00088 else
00089 {
00090 std::cerr << "RECV_TIMEOUT received from call to transfer->receiveFragmentFrom" << std::endl;
00091 continue;
00092 }
00093
00094 if (do_check(myfrag) != 0)
00095 {
00096 std::cerr << "Error: do_check indicates fragment failed to transmit correctly" << std::endl;
00097 }
00098 else
00099 {
00100 std::cerr << "Success: do_check indicates fragment transmitted correctly" << std::endl;
00101 }
00102 }
00103
00104 return 0;
00105 }
00106
00107
00108
00109
00110
00111
00112 int do_check(const artdaq::Fragment& frag)
00113 {
00114 uint64_t variable_to_compare = 0;
00115
00116 for (auto ptr_into_frag = reinterpret_cast<const uint64_t*>(frag.dataBeginBytes());
00117 ptr_into_frag != reinterpret_cast<const uint64_t*>(frag.dataEndBytes());
00118 ++ptr_into_frag , ++variable_to_compare)
00119 {
00120 if (variable_to_compare != *ptr_into_frag)
00121 {
00122 std::cerr << "ERROR for fragment with sequence ID " << frag.sequenceID() << ", fragment ID " <<
00123 frag.fragmentID() << ": expected ADC value of " << variable_to_compare << ", got " << *ptr_into_frag << std::endl;
00124 return 1;
00125 }
00126 }
00127
00128 return 0;
00129 }