$treeview $search $mathjax $extrastylesheet
artdaq
v3_04_01
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #ifndef artdaq_DAQrate_RequestSender_hh 00002 #define artdaq_DAQrate_RequestSender_hh 00003 00004 #include "artdaq/DAQdata/Globals.hh" // Before trace.h gets included in ConcurrentQueue (from GlobalQueue) 00005 #include "artdaq-core/Data/RawEvent.hh" 00006 #include "artdaq-utilities/Plugins/MetricManager.hh" 00007 #include "artdaq/DAQrate/detail/RequestMessage.hh" 00008 #include "fhiclcpp/ParameterSet.h" 00009 #include "fhiclcpp/types/Table.h" 00010 00011 #include <map> 00012 #include <memory> 00013 #include <chrono> 00014 #include <future> 00015 #include <stdint.h> 00016 #include <arpa/inet.h> 00017 #include <netinet/in.h> 00018 #include <sys/types.h> 00019 #include <sys/socket.h> 00020 00021 namespace artdaq 00022 { 00023 00027 class RequestSender 00028 { 00029 public: 00035 struct RoutingTokenConfig 00036 { 00038 fhicl::Atom<bool> use_routing_master{ fhicl::Name{ "use_routing_master" }, fhicl::Comment{ "True if using the Routing Master" }, false }; 00040 fhicl::Atom<int> routing_token_port{ fhicl::Name{ "routing_token_port" },fhicl::Comment{ "Port to send tokens on" },35555 }; 00042 fhicl::Atom<std::string> routing_token_host{ fhicl::Name{ "routing_master_hostname" }, fhicl::Comment{ "Hostname or IP of RoutingMaster" },"localhost" }; 00043 }; 00044 00048 struct Config 00049 { 00051 fhicl::Atom<bool> send_requests{ fhicl::Name{ "send_requests" }, fhicl::Comment{ "Enable sending Data Request messages" }, false }; 00053 fhicl::Atom<int> request_port{ fhicl::Name{"request_port"}, fhicl::Comment{"Port to send DataRequests on"},3001 }; 00055 fhicl::Atom<size_t> request_delay_ms{ fhicl::Name{"request_delay_ms"}, fhicl::Comment{"How long to wait before sending new DataRequests"}, 10 }; 00057 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 }; 00059 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" }; 00061 fhicl::Atom<std::string> request_address{ fhicl::Name{"request_address"}, fhicl::Comment{ "Multicast address to send DataRequests to" }, "227.128.12.26" }; 00062 fhicl::Table<RoutingTokenConfig> routing_token_config{ fhicl::Name{"routing_token_config"}, fhicl::Comment{"FHiCL table containing RoutingToken configuration"} }; 00063 }; 00065 using Parameters = fhicl::WrappedTable<Config>; 00066 00070 RequestSender() = delete; 00071 00075 RequestSender(RequestSender const&) = delete; 00076 00081 RequestSender& operator=(RequestSender const&) = delete; 00082 00087 RequestSender(const fhicl::ParameterSet& pset); 00091 virtual ~RequestSender(); 00092 00093 00098 void SetRequestMode(detail::RequestMessageMode mode); 00099 00104 detail::RequestMessageMode GetRequestMode() const { return request_mode_; } 00105 00110 void SendRequest(bool endOfRunOnly = false); 00111 00117 void AddRequest(Fragment::sequence_id_t seqID, Fragment::timestamp_t timestamp); 00118 00123 void RemoveRequest(Fragment::sequence_id_t seqID); 00124 00130 void SendRoutingToken(int nSlots, int run_number); 00131 00136 size_t GetSentTokenCount() const { return tokens_sent_.load(); } 00137 00142 void SetRunNumber(uint32_t run) { run_number_ = run; } 00143 private: 00144 00145 // Request stuff 00146 bool send_requests_; 00147 std::atomic<bool> initialized_; 00148 mutable std::mutex request_mutex_; 00149 mutable std::mutex request_send_mutex_; 00150 std::map<Fragment::sequence_id_t, Fragment::timestamp_t> active_requests_; 00151 std::string request_address_; 00152 int request_port_; 00153 size_t request_delay_; 00154 size_t request_shutdown_timeout_us_; 00155 int request_socket_; 00156 struct sockaddr_in request_addr_; 00157 std::string multicast_out_addr_; 00158 detail::RequestMessageMode request_mode_; 00159 00160 bool send_routing_tokens_; 00161 int token_port_; 00162 int token_socket_; 00163 std::string token_address_; 00164 std::atomic<int> request_sending_; 00165 std::atomic<size_t> tokens_sent_; 00166 uint32_t run_number_; 00167 00168 private: 00169 void setup_requests_(); 00170 00171 void do_send_request_(); 00172 00173 void setup_tokens_(); 00174 00175 void send_routing_token_(int nSlots, int run_number); 00176 }; 00177 } 00178 #endif /* artdaq_DAQrate_RequestSender_hh */