$treeview $search $mathjax $extrastylesheet
artdaq
v3_04_00
$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 }; 00064 using Parameters = fhicl::WrappedTable<Config>; 00065 00069 RequestSender() = delete; 00070 00074 RequestSender(RequestSender const&) = delete; 00075 00080 RequestSender& operator=(RequestSender const&) = delete; 00081 00086 RequestSender(const fhicl::ParameterSet& pset); 00090 virtual ~RequestSender(); 00091 00092 00097 void SetRequestMode(detail::RequestMessageMode mode); 00098 00103 detail::RequestMessageMode GetRequestMode() const { return request_mode_; } 00104 00109 void SendRequest(bool endOfRunOnly = false); 00110 00116 void AddRequest(Fragment::sequence_id_t seqID, Fragment::timestamp_t timestamp); 00117 00122 void RemoveRequest(Fragment::sequence_id_t seqID); 00123 00129 void SendRoutingToken(int nSlots, int run_number); 00130 00135 size_t GetSentTokenCount() const { return tokens_sent_.load(); } 00136 00141 void SetRunNumber(uint32_t run) { run_number_ = run; } 00142 private: 00143 00144 // Request stuff 00145 bool send_requests_; 00146 std::atomic<bool> initialized_; 00147 mutable std::mutex request_mutex_; 00148 mutable std::mutex request_send_mutex_; 00149 std::map<Fragment::sequence_id_t, Fragment::timestamp_t> active_requests_; 00150 std::string request_address_; 00151 int request_port_; 00152 size_t request_delay_; 00153 size_t request_shutdown_timeout_us_; 00154 int request_socket_; 00155 struct sockaddr_in request_addr_; 00156 std::string multicast_out_addr_; 00157 detail::RequestMessageMode request_mode_; 00158 00159 bool send_routing_tokens_; 00160 int token_port_; 00161 int token_socket_; 00162 std::string token_address_; 00163 std::atomic<int> request_sending_; 00164 std::atomic<size_t> tokens_sent_; 00165 uint32_t run_number_; 00166 00167 private: 00168 void setup_requests_(); 00169 00170 void do_send_request_(); 00171 00172 void setup_tokens_(); 00173 00174 void send_routing_token_(int nSlots, int run_number); 00175 }; 00176 } 00177 #endif /* artdaq_DAQrate_RequestSender_hh */