artdaq  v3_12_02
TokenSender.hh
1 #ifndef artdaq_DAQrate_TokenSender_hh
2 #define artdaq_DAQrate_TokenSender_hh
3 
4 namespace fhicl {
5 class ParameterSet;
6 }
7 #include "fhiclcpp/types/Atom.h"
8 #include "fhiclcpp/types/Comment.h"
9 #include "fhiclcpp/types/ConfigurationTable.h"
10 #include "fhiclcpp/types/Name.h"
11 
12 #include <arpa/inet.h>
13 #include <netinet/in.h>
14 #include <sys/socket.h>
15 #include <sys/types.h>
16 #include <atomic>
17 #include <chrono>
18 #include <cstdint>
19 #include <map>
20 #include <memory>
21 #include <string>
22 
23 namespace artdaq {
24 
29 {
30 public:
36  struct Config
37  {
39  fhicl::Atom<bool> use_routing_manager{fhicl::Name{"use_routing_manager"}, fhicl::Comment{"True if using the Routing Manager"}, false};
41  fhicl::Atom<int> routing_token_port{fhicl::Name{"routing_token_port"}, fhicl::Comment{"Port to send tokens on"}, 35555};
43  fhicl::Atom<std::string> routing_token_host{fhicl::Name{"routing_manager_hostname"}, fhicl::Comment{"Hostname or IP of RoutingManager"}, "localhost"};
44  };
46  using Parameters = fhicl::WrappedTable<Config>;
47 
51  TokenSender() = delete;
52 
56  TokenSender(TokenSender const&) = delete;
57 
62  TokenSender& operator=(TokenSender const&) = delete;
63 
64  TokenSender(TokenSender&&) = delete;
65  TokenSender& operator=(TokenSender&&) = delete;
66 
71  explicit TokenSender(const fhicl::ParameterSet& pset);
75  virtual ~TokenSender();
76 
83  void SendRoutingToken(int nSlots, int run_number, int rank = my_rank);
84 
89  size_t GetSentTokenCount() const { return tokens_sent_.load(); }
90 
95  void SetRunNumber(uint32_t run) { run_number_ = run; }
96 
101  bool RoutingTokenSendsEnabled() { return send_routing_tokens_; }
102 
103 private:
104  std::atomic<bool> initialized_;
105 
106  bool send_routing_tokens_;
107  int token_port_;
108  int token_socket_;
109  std::string token_address_;
110  std::atomic<size_t> tokens_sent_;
111  uint32_t run_number_;
112 
113 private:
114  void setup_tokens_();
115 
116  void send_routing_token_(int nSlots, int run_number, int rank);
117 };
118 } // namespace artdaq
119 #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:39
fhicl::Atom< int > routing_token_port
&quot;routing_token_port&quot; (Default: 35555) : Port to send tokens on
Definition: TokenSender.hh:41
fhicl::Atom< std::string > routing_token_host
&quot;routing_manager_hostname&quot; (Default: &quot;localhost&quot;) : Hostname or IP of RoutingManager ...
Definition: TokenSender.hh:43
TokenSender & operator=(TokenSender const &)=delete
Copy Assignment operator is deleted.
fhicl::WrappedTable< Config > Parameters
Used for ParameterSet validation (if desired)
Definition: TokenSender.hh:46
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:28
Configuration for Routing token sending
Definition: TokenSender.hh:36
size_t GetSentTokenCount() const
Get the count of number of tokens sent.
Definition: TokenSender.hh:89
bool RoutingTokenSendsEnabled()
Determine if routing token sends are enabled.
Definition: TokenSender.hh:101
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:95