artdaq  v3_12_02
RequestSender.hh
1 #ifndef artdaq_DAQrate_RequestSender_hh
2 #define artdaq_DAQrate_RequestSender_hh
3 
4 #include "artdaq/DAQrate/detail/RequestMessage.hh"
5 
6 #include "fhiclcpp/types/Atom.h"
7 #include "fhiclcpp/types/Comment.h"
8 #include "fhiclcpp/types/ConfigurationTable.h"
9 #include "fhiclcpp/types/Name.h"
10 #include "fhiclcpp/types/Table.h"
11 
12 #include <arpa/inet.h>
13 #include <netinet/in.h>
14 #include <sys/socket.h>
15 #include <sys/types.h>
16 #include <chrono>
17 #include <cstdint>
18 #include <map>
19 #include <memory>
20 
21 namespace artdaq {
22 
27 {
28 public:
32  struct Config
33  {
35  fhicl::Atom<bool> send_requests{fhicl::Name{"send_requests"}, fhicl::Comment{"Enable sending Data Request messages"}, false};
37  fhicl::Atom<int> request_port{fhicl::Name{"request_port"}, fhicl::Comment{"Port to send DataRequests on"}, 3001};
39  fhicl::Atom<size_t> request_delay_ms{fhicl::Name{"request_delay_ms"}, fhicl::Comment{"How long to wait before sending new DataRequests"}, 10};
41  fhicl::Atom<size_t> request_shutdown_timeout_us{fhicl::Name{"request_shutdown_timeout_us"}, fhicl::Comment{"How long to wait for pending requests to be sent at shutdown"}, 100000};
43  fhicl::Atom<std::string> output_address{fhicl::Name{"multicast_interface_ip"}, fhicl::Comment{"Use this hostname for multicast output(to assign to the proper NIC)"}, "0.0.0.0"};
45  fhicl::Atom<std::string> request_address{fhicl::Name{"request_address"}, fhicl::Comment{"Multicast address to send DataRequests to"}, "227.128.12.26"};
47  fhicl::Atom<size_t> min_request_interval_ms{fhicl::Name{"min_request_interval_ms"}, fhicl::Comment{"Minimum time between automatic sends (ignored in EndOfRun RequetsMode)"}, 100};
48  };
50  using Parameters = fhicl::WrappedTable<Config>;
51 
55  RequestSender() = delete;
56 
60  RequestSender(RequestSender const&) = delete;
61 
66  RequestSender& operator=(RequestSender const&) = delete;
67 
68  RequestSender(RequestSender&&) = delete;
70 
75  explicit RequestSender(const fhicl::ParameterSet& pset);
79  virtual ~RequestSender();
80 
86 
91  detail::RequestMessageMode GetRequestMode() const { return request_mode_; }
92 
97  void SendRequest(bool endOfRunOnly = false);
98 
104  void AddRequest(Fragment::sequence_id_t seqID, Fragment::timestamp_t timestamp);
105 
110  void RemoveRequest(Fragment::sequence_id_t seqID);
111 
116  void SetRunNumber(uint32_t run) { run_number_ = run; }
117 
124  bool RequestsInFlight() { return request_sending_.load() != 0; }
125 
126 private:
127 private:
128  // Request stuff
129  bool send_requests_;
130  std::atomic<bool> initialized_;
131  mutable std::mutex request_mutex_;
132  mutable std::mutex request_send_mutex_;
133  std::map<Fragment::sequence_id_t, Fragment::timestamp_t> active_requests_;
134  std::string request_address_;
135  int request_port_;
136  size_t request_delay_;
137  size_t request_shutdown_timeout_us_;
138  int request_socket_;
139  struct sockaddr_in request_addr_;
140  std::string multicast_out_addr_;
141  detail::RequestMessageMode request_mode_;
142  std::chrono::steady_clock::time_point last_request_send_time_;
143  size_t min_request_interval_ms_;
144 
145  std::atomic<int> request_sending_;
146  uint32_t run_number_;
147 
148 private:
149  void setup_requests_();
150 
151  void do_send_request_();
152 };
153 } // namespace artdaq
154 #endif /* artdaq_DAQrate_RequestSender_hh */
void RemoveRequest(Fragment::sequence_id_t seqID)
Remove a request from the request list.
detail::RequestMessageMode GetRequestMode() const
Get the mode for RequestMessages.
fhicl::Atom< int > request_port
&quot;request_port&quot; (Default: 3001): Port to send DataRequests on
The RequestSender contains methods used to send data requests and Routing tokens. ...
virtual ~RequestSender()
RequestSender Destructor.
void SendRequest(bool endOfRunOnly=false)
Send a request message containing all current requests.
fhicl::Atom< bool > send_requests
&quot;send_requests&quot; (Default: false): Whether to send DataRequests when new sequence IDs are seen ...
RequestSender()=delete
Default Constructor is deleted.
fhicl::Atom< size_t > min_request_interval_ms
&quot;min_request_interval_ms&quot; (Default: 500): Minimum time between automatic sends (ignored in EndOfRun R...
void SetRunNumber(uint32_t run)
Set the run number to be used in request messages.
fhicl::WrappedTable< Config > Parameters
Used for ParameterSet validation (if desired)
fhicl::Atom< std::string > output_address
&quot;multicast_interface_ip&quot; (Default: &quot;0.0.0.0&quot;): Use this hostname for multicast output (to assign to t...
void SetRequestMode(detail::RequestMessageMode mode)
Set the mode for RequestMessages. Used to indicate when RequestSender should enter &quot;EndOfRun&quot; mode...
RequestMessageMode
Mode used to indicate current run conditions to the request receiver.
fhicl::Atom< size_t > request_shutdown_timeout_us
&quot;request_shutdown_timeout_us&quot; (Default: 100000 us): How long to wait for pending requests to be sent ...
RequestSender & operator=(RequestSender const &)=delete
Copy Assignment operator is deleted.
fhicl::Atom< size_t > request_delay_ms
&quot;request_delay_ms&quot; (Default: 10): How long to wait before sending new DataRequests ...
bool RequestsInFlight()
Determine if the RequestSender is currently sending any requests.
fhicl::Atom< std::string > request_address
&quot;request_address&quot; (Default: &quot;227.128.12.26&quot;): Multicast address to send DataRequests to ...
void AddRequest(Fragment::sequence_id_t seqID, Fragment::timestamp_t timestamp)
Add a request to the request list.
Configuration of the RequestSender. May be used for parameter validation