$treeview $search $mathjax $extrastylesheet
artdaq
v3_04_01
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #define TRACE_NAME "RequestSender" 00002 00003 #include <boost/program_options.hpp> 00004 #include "fhiclcpp/make_ParameterSet.h" 00005 namespace bpo = boost::program_options; 00006 00007 #include "artdaq/DAQrate/RequestSender.hh" 00008 #include "artdaq/DAQrate/RequestReceiver.hh" 00009 #include "artdaq-core/Utilities/configureMessageFacility.hh" 00010 #include "artdaq/Application/LoadParameterSet.hh" 00011 00012 int main(int argc, char* argv[]) 00013 { 00014 artdaq::configureMessageFacility("RequestSender"); 00015 00016 struct Config 00017 { 00018 fhicl::TableFragment<artdaq::RequestSender::Config> senderConfig; 00019 fhicl::Atom<bool> use_receiver{ fhicl::Name{"use_receiver"}, fhicl::Comment{"Whether to setup a RequestReceiver to verify that requests are being sent"}, false }; 00020 fhicl::Atom<size_t> receiver_timeout_ms{ fhicl::Name{"recevier_timeout_ms"}, fhicl::Comment{"Amount of time to wait for the receiver to receive a request message"}, 1000 }; 00021 fhicl::Table<artdaq::RequestReceiver::Config> receiver_config{ fhicl::Name{"receiver_config"}, fhicl::Comment{"Configuration for RequestReceiver, if used"} }; 00022 fhicl::Atom<int> num_requests{ fhicl::Name{"num_requests"}, fhicl::Comment{"Number of requests to send"} }; 00023 fhicl::Atom<artdaq::Fragment::sequence_id_t> starting_sequence_id{ fhicl::Name{ "starting_sequence_id" }, fhicl::Comment{ "Sequence ID of first request" },1 }; 00024 fhicl::Atom<artdaq::Fragment::sequence_id_t> sequence_id_scale{ fhicl::Name{ "sequence_id_scale" }, fhicl::Comment{ "Amount to increment Sequence ID for each request" },1 }; 00025 fhicl::Atom<artdaq::Fragment::timestamp_t> starting_timestamp{ fhicl::Name{"starting_timestamp"}, fhicl::Comment{"Timestamp of first request"},1 }; 00026 fhicl::Atom<artdaq::Fragment::timestamp_t> timestamp_scale{ fhicl::Name{"timestamp_scale"}, fhicl::Comment{"Amount to increment timestamp for each request"}, 1 }; 00027 }; 00028 00029 auto pset = LoadParameterSet<Config>(argc, argv, "sender", "This test application sends Data Request messages and optionally receives them to detect issues in the network transport"); 00030 00031 int rc = 0; 00032 00033 artdaq::RequestSender sender(pset); 00034 00035 std::unique_ptr<artdaq::RequestReceiver> receiver(nullptr); 00036 int num_requests = pset.get <int>("num_requests", 1); 00037 if (pset.get<bool>("use_receiver", false)) 00038 { 00039 receiver.reset(new artdaq::RequestReceiver(pset.get<fhicl::ParameterSet>("receiver_config"))); 00040 receiver->startRequestReception(); 00041 } 00042 00043 auto seq = pset.get<artdaq::Fragment::sequence_id_t>("starting_sequence_id", 1); 00044 auto seq_scale = pset.get<artdaq::Fragment::sequence_id_t>("sequence_id_scale", 1); 00045 auto ts = pset.get<artdaq::Fragment::timestamp_t>("starting_timestamp", 1); 00046 auto ts_scale = pset.get<artdaq::Fragment::timestamp_t>("timestamp_scale", 1); 00047 auto tmo = pset.get<size_t>("recevier_timeout_ms", 1000); 00048 00049 for (auto ii = 0; ii < num_requests; ++ii) 00050 { 00051 sender.AddRequest(seq, ts); 00052 sender.SendRequest(); 00053 00054 if (receiver) 00055 { 00056 auto start_time = std::chrono::steady_clock::now(); 00057 bool recvd = false; 00058 while (!recvd && artdaq::TimeUtils::GetElapsedTimeMilliseconds(start_time) < tmo) 00059 { 00060 auto reqs = receiver->GetRequests(); 00061 if (reqs.count(seq)) 00062 { 00063 TLOG(TLVL_INFO) << "Received Request for Sequence ID " << seq << ", timestamp " << reqs[seq]; 00064 receiver->RemoveRequest(seq); 00065 sender.RemoveRequest(seq); 00066 recvd = true; 00067 } 00068 else 00069 { 00070 usleep(10000); 00071 } 00072 } 00073 } 00074 00075 seq += seq_scale; 00076 ts += ts_scale; 00077 } 00078 00079 return rc; 00080 }