artdaq  v3_04_00
requestSender.cc
1 #define TRACE_NAME "RequestSender"
2 
3 #include <boost/program_options.hpp>
4 #include "fhiclcpp/make_ParameterSet.h"
5 namespace bpo = boost::program_options;
6 
7 #include "artdaq/DAQrate/RequestSender.hh"
8 #include "artdaq/DAQrate/RequestReceiver.hh"
9 #include "artdaq-core/Utilities/configureMessageFacility.hh"
10 #include "artdaq/Application/LoadParameterSet.hh"
11 
12 int main(int argc, char* argv[])
13 {
14  artdaq::configureMessageFacility("RequestSender");
15 
16  struct Config
17  {
18  fhicl::TableFragment<artdaq::RequestSender::Config> senderConfig;
19  fhicl::Atom<bool> use_receiver{ fhicl::Name{"use_receiver"}, fhicl::Comment{"Whether to setup a RequestReceiver to verify that requests are being sent"}, false };
20  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 };
21  fhicl::Table<artdaq::RequestReceiver::Config> receiver_config{ fhicl::Name{"receiver_config"}, fhicl::Comment{"Configuration for RequestReceiver, if used"} };
22  fhicl::Atom<int> num_requests{ fhicl::Name{"num_requests"}, fhicl::Comment{"Number of requests to send"} };
23  fhicl::Atom<artdaq::Fragment::sequence_id_t> starting_sequence_id{ fhicl::Name{ "starting_sequence_id" }, fhicl::Comment{ "Sequence ID of first request" },1 };
24  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 };
25  fhicl::Atom<artdaq::Fragment::timestamp_t> starting_timestamp{ fhicl::Name{"starting_timestamp"}, fhicl::Comment{"Timestamp of first request"},1 };
26  fhicl::Atom<artdaq::Fragment::timestamp_t> timestamp_scale{ fhicl::Name{"timestamp_scale"}, fhicl::Comment{"Amount to increment timestamp for each request"}, 1 };
27  };
28 
29  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");
30 
31  int rc = 0;
32 
33  artdaq::RequestSender sender(pset);
34 
35  std::unique_ptr<artdaq::RequestReceiver> receiver(nullptr);
36  int num_requests = pset.get <int>("num_requests", 1);
37  if (pset.get<bool>("use_receiver", false))
38  {
39  receiver.reset(new artdaq::RequestReceiver(pset.get<fhicl::ParameterSet>("receiver_config")));
40  receiver->startRequestReception();
41  }
42 
43  auto seq = pset.get<artdaq::Fragment::sequence_id_t>("starting_sequence_id", 1);
44  auto seq_scale = pset.get<artdaq::Fragment::sequence_id_t>("sequence_id_scale", 1);
45  auto ts = pset.get<artdaq::Fragment::timestamp_t>("starting_timestamp", 1);
46  auto ts_scale = pset.get<artdaq::Fragment::timestamp_t>("timestamp_scale", 1);
47  auto tmo = pset.get<size_t>("recevier_timeout_ms", 1000);
48 
49  for (auto ii = 0; ii < num_requests; ++ii)
50  {
51  sender.AddRequest(seq, ts);
52  sender.SendRequest();
53 
54  if (receiver)
55  {
56  auto start_time = std::chrono::steady_clock::now();
57  bool recvd = false;
58  while (!recvd && artdaq::TimeUtils::GetElapsedTimeMilliseconds(start_time) < tmo)
59  {
60  auto reqs = receiver->GetRequests();
61  if (reqs.count(seq))
62  {
63  TLOG(TLVL_INFO) << "Received Request for Sequence ID " << seq << ", timestamp " << reqs[seq];
64  receiver->RemoveRequest(seq);
65  sender.RemoveRequest(seq);
66  recvd = true;
67  }
68  else
69  {
70  usleep(10000);
71  }
72  }
73  }
74 
75  seq += seq_scale;
76  ts += ts_scale;
77  }
78 
79  return rc;
80 }
The RequestSender contains methods used to send data requests and Routing tokens. ...
Receive data requests and make them available to CommandableFragmentGenerator or other interested par...