artdaq  v3_11_00
TokenSender.hh
1 #ifndef artdaq_DAQrate_TokenSender_hh
2 #define artdaq_DAQrate_TokenSender_hh
3 
4 #include "artdaq-core/Data/RawEvent.hh"
5 #include "artdaq-utilities/Plugins/MetricManager.hh"
6 #include "artdaq/DAQdata/Globals.hh" // Before trace.h gets included in ConcurrentQueue (from GlobalQueue)
7 #include "artdaq/DAQrate/detail/RequestMessage.hh"
8 #include "fhiclcpp/ParameterSet.h"
9 #include "fhiclcpp/types/Table.h"
10 
11 #include <arpa/inet.h>
12 #include <netinet/in.h>
13 #include <sys/socket.h>
14 #include <sys/types.h>
15 #include <chrono>
16 #include <cstdint>
17 #include <future>
18 #include <map>
19 #include <memory>
20 
21 namespace artdaq {
22 
27 {
28 public:
34  struct Config
35  {
37  fhicl::Atom<bool> use_routing_manager{fhicl::Name{"use_routing_manager"}, fhicl::Comment{"True if using the Routing Manager"}, false};
39  fhicl::Atom<int> routing_token_port{fhicl::Name{"routing_token_port"}, fhicl::Comment{"Port to send tokens on"}, 35555};
41  fhicl::Atom<std::string> routing_token_host{fhicl::Name{"routing_manager_hostname"}, fhicl::Comment{"Hostname or IP of RoutingManager"}, "localhost"};
42  };
44  using Parameters = fhicl::WrappedTable<Config>;
45 
49  TokenSender() = delete;
50 
54  TokenSender(TokenSender const&) = delete;
55 
60  TokenSender& operator=(TokenSender const&) = delete;
61 
62  TokenSender(TokenSender&&) = delete;
63  TokenSender& operator=(TokenSender&&) = delete;
64 
69  explicit TokenSender(const fhicl::ParameterSet& pset);
73  virtual ~TokenSender();
74 
81  void SendRoutingToken(int nSlots, int run_number, int rank = my_rank);
82 
87  size_t GetSentTokenCount() const { return tokens_sent_.load(); }
88 
93  void SetRunNumber(uint32_t run) { run_number_ = run; }
94 
99  bool RoutingTokenSendsEnabled() { return send_routing_tokens_; }
100 
101 private:
102  std::atomic<bool> initialized_;
103 
104  bool send_routing_tokens_;
105  int token_port_;
106  int token_socket_;
107  std::string token_address_;
108  std::atomic<size_t> tokens_sent_;
109  uint32_t run_number_;
110 
111 private:
112  void setup_tokens_();
113 
114  void send_routing_token_(int nSlots, int run_number, int rank);
115 };
116 } // namespace artdaq
117 #endif /* artdaq_DAQrate_TokenSender_hh */
fhicl::Atom< bool > use_routing_manager
&quot;use_routing_manager&quot; (Default: false) : Whether to send tokens to a RoutingManager ...
Definition: TokenSender.hh:37
fhicl::Atom< int > routing_token_port
&quot;routing_token_port&quot; (Default: 35555) : Port to send tokens on
Definition: TokenSender.hh:39
fhicl::Atom< std::string > routing_token_host
&quot;routing_manager_hostname&quot; (Default: &quot;localhost&quot;) : Hostname or IP of RoutingManager ...
Definition: TokenSender.hh:41
TokenSender & operator=(TokenSender const &)=delete
Copy Assignment operator is deleted.
fhicl::WrappedTable< Config > Parameters
Used for ParameterSet validation (if desired)
Definition: TokenSender.hh:44
void SendRoutingToken(int nSlots, int run_number, int rank=my_rank)
Send a RoutingToken message indicating that slots are available.
Definition: TokenSender.cc:113
The TokenSender contains methods used to send data requests and Routing tokens.
Definition: TokenSender.hh:26
Configuration for Routing token sending
Definition: TokenSender.hh:34
size_t GetSentTokenCount() const
Get the count of number of tokens sent.
Definition: TokenSender.hh:87
bool RoutingTokenSendsEnabled()
Determine if routing token sends are enabled.
Definition: TokenSender.hh:99
virtual ~TokenSender()
TokenSender Destructor.
Definition: TokenSender.cc:34
TokenSender()=delete
Default Constructor is deleted.
void SetRunNumber(uint32_t run)
Set the run number to be used in request messages.
Definition: TokenSender.hh:93