00001 #include "artdaq/TransferPlugins/TransferInterface.hh"
00002 #include "artdaq-core/Data/Fragment.hh"
00003 #include "artdaq-core/Utilities/ExceptionHandler.hh"
00004
00005 #include "cetlib/BasicPluginFactory.h"
00006 #include "cetlib/filepath_maker.h"
00007 #include "fhiclcpp/ParameterSet.h"
00008 #include "fhiclcpp/make_ParameterSet.h"
00009
00010 #include <boost/asio.hpp>
00011 #include <boost/bind.hpp>
00012 #include <boost/lexical_cast.hpp>
00013
00014 #include <algorithm>
00015 #include <numeric>
00016 #include <iostream>
00017 #include <sstream>
00018 #include <string>
00019 #include <cstdlib>
00020 #include <memory>
00021 #include <limits>
00022
00023
00024
00025
00026
00027 fhicl::ParameterSet ReadParameterSet(const std::string fhicl_filename)
00028 {
00029 if (std::getenv("FHICL_FILE_PATH") == nullptr)
00030 {
00031 std::cerr
00032 << "INFO: environment variable FHICL_FILE_PATH was not set. Using \".\"\n";
00033 setenv("FHICL_FILE_PATH", ".", 0);
00034 }
00035
00036 fhicl::ParameterSet pset;
00037 cet::filepath_lookup_after1 lookup_policy("FHICL_FILE_PATH");
00038 fhicl::make_ParameterSet(fhicl_filename, lookup_policy, pset);
00039
00040 return pset;
00041 }
00042
00043
00044 int main(int argc, char* argv[])
00045 {
00046 if (argc != 4)
00047 {
00048 std::cerr << "Usage: <fhicl document> <number of sends (should be greater than 1) > <fragment payload size>" << std::endl;
00049 return 1;
00050 }
00051
00052 std::string fhicl_filename = boost::lexical_cast<std::string>(argv[1]);
00053 size_t num_sends = boost::lexical_cast<size_t>(argv[2]);
00054 size_t fragment_size = boost::lexical_cast<size_t>(argv[3]);
00055
00056 if (num_sends <= 1)
00057 {
00058 std::cerr << "Logic in the program requires requested # of sends to be greater than 1" << std::endl;
00059 return 1;
00060 }
00061
00062 std::unique_ptr<artdaq::TransferInterface> transfer;
00063
00064 auto pset = ReadParameterSet(fhicl_filename);
00065
00066 try
00067 {
00068 static cet::BasicPluginFactory bpf("transfer", "make");
00069
00070 transfer =
00071 bpf.makePlugin<std::unique_ptr<artdaq::TransferInterface>,
00072 const fhicl::ParameterSet&,
00073 artdaq::TransferInterface::Role>(
00074 pset.get<std::string>("transfer_plugin_type"),
00075 pset,
00076 artdaq::TransferInterface::Role::kSend);
00077 }
00078 catch (...)
00079 {
00080 artdaq::ExceptionHandler(artdaq::ExceptionHandlerRethrow::no,
00081 "Error creating transfer plugin");
00082 return 1;
00083 }
00084
00085 std::unique_ptr<artdaq::Fragment> frag = artdaq::Fragment::FragmentBytes(fragment_size);
00086
00087 struct ArbitraryMetadata
00088 {
00089 const uint64_t val1 = 0;
00090 const uint32_t val2 = 0;
00091 };
00092
00093 ArbitraryMetadata arbitraryMetadata;
00094
00095 frag->setMetadata(arbitraryMetadata);
00096
00097
00098
00099
00100 std::iota(reinterpret_cast<uint64_t*>(frag->dataBeginBytes()),
00101 reinterpret_cast<uint64_t*>(frag->dataEndBytes()),
00102 0);
00103
00104 size_t timeout = pset.get<size_t>("send_timeout_usecs", std::numeric_limits<size_t>::max());
00105
00106 for (size_t i_i = 0; i_i < num_sends; ++i_i)
00107 {
00108 frag->setSequenceID(i_i + 1);
00109 frag->setFragmentID(0);
00110 frag->setUserType(artdaq::Fragment::FirstUserFragmentType);
00111
00112 transfer->copyFragment(*frag, timeout);
00113 }
00114
00115 std::cout << "# of sent fragments attempted == " << num_sends << std::endl;
00116
00117 return 0;
00118 }