artdaq  v3_02_00
RequestSender.hh
1 #ifndef artdaq_DAQrate_RequestSender_hh
2 #define artdaq_DAQrate_RequestSender_hh
3 
4 #include "artdaq/DAQdata/Globals.hh" // Before trace.h gets included in ConcurrentQueue (from GlobalQueue)
5 #include "artdaq-core/Data/RawEvent.hh"
6 #include "artdaq-utilities/Plugins/MetricManager.hh"
7 #include "artdaq/DAQrate/detail/RequestMessage.hh"
8 #include "fhiclcpp/ParameterSet.h"
9 #include "fhiclcpp/types/Table.h"
10 
11 #include <map>
12 #include <memory>
13 #include <chrono>
14 #include <future>
15 #include <stdint.h>
16 #include <arpa/inet.h>
17 #include <netinet/in.h>
18 #include <sys/types.h>
19 #include <sys/socket.h>
20 
21 namespace artdaq
22 {
23 
28  {
29  public:
31  {
32  fhicl::Atom<bool> use_routing_master{ fhicl::Name{ "use_routing_master" }, fhicl::Comment{ "True if using the Routing Master" }, false };
33  fhicl::Atom<int> routing_token_port{ fhicl::Name{ "routing_token_port" },fhicl::Comment{ "Port to send tokens on" },35555 };
34  fhicl::Atom<std::string> routing_token_host{ fhicl::Name{ "routing_master_hostname" }, fhicl::Comment{ "Hostname or IP of RoutingMaster" },"localhost" };
35  };
36 
37  struct Config
38  {
39  fhicl::Atom<bool> send_requests{ fhicl::Name{ "send_requests" }, fhicl::Comment{ "Enable sending Data Request messages" }, false };
40  fhicl::Atom<int> request_port{ fhicl::Name{"request_port"}, fhicl::Comment{"Port to send DataRequests on"},3001 };
41  fhicl::Atom<size_t> request_delay_ms{ fhicl::Name{"request_delay_ms"}, fhicl::Comment{"How long to wait before sending new DataRequests"}, 10 };
42  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" };
44  fhicl::Atom<std::string> request_address{ fhicl::Name{"request_address"}, fhicl::Comment{ "Multicast address to send DataRequests to" }, "227.128.12.26" };
45  fhicl::Table<RoutingTokenConfig> routing_token_config{ fhicl::Name{"routing_token_config"}, fhicl::Comment{"FHiCL table containing RoutingToken configuration"} };
46  };
47 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103
48  using Parameters = fhicl::WrappedTable<Config>;
49 #endif
50 
54  RequestSender() = delete;
55 
59  RequestSender(RequestSender const&) = delete;
60 
65  RequestSender& operator=(RequestSender const&) = delete;
66 
85  RequestSender(const fhicl::ParameterSet& pset);
89  virtual ~RequestSender();
90 
91 
97 
102  detail::RequestMessageMode GetRequestMode() const { return request_mode_; }
103 
108  void SendRequest(bool endOfRunOnly = false);
109 
115  void AddRequest(Fragment::sequence_id_t seqID, Fragment::timestamp_t timestamp);
116 
121  void RemoveRequest(Fragment::sequence_id_t seqID);
122 
127  void SendRoutingToken(int nSlots);
128  private:
129 
130  // Request stuff
131  bool send_requests_;
132  mutable std::mutex request_mutex_;
133  mutable std::mutex request_send_mutex_;
134  std::map<Fragment::sequence_id_t, Fragment::timestamp_t> active_requests_;
135  std::string request_address_;
136  int request_port_;
137  size_t request_delay_;
138  size_t request_shutdown_timeout_us_;
139  int request_socket_;
140  struct sockaddr_in request_addr_;
141  std::string multicast_out_addr_;
142  detail::RequestMessageMode request_mode_;
143 
144  bool send_routing_tokens_;
145  int token_port_;
146  int token_socket_;
147  std::string token_address_;
148  std::atomic<int> request_sending_;
149 
150  private:
151  void setup_requests_();
152 
153  void do_send_request_();
154 
155  void setup_tokens_();
156 
157  void send_routing_token_(int nSlots);
158  };
159 }
160 #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.
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.
void SendRoutingToken(int nSlots)
Send a RoutingToken message indicating that slots are available.
RequestSender()=delete
Default Constructor is deleted.
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.
RequestSender & operator=(RequestSender const &)=delete
Copy Assignment operator is deleted.
void AddRequest(Fragment::sequence_id_t seqID, Fragment::timestamp_t timestamp)
Add a request to the request list.