artdaq  v2_03_00
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
RoutingMasterCore.hh
1 #ifndef artdaq_Application_MPI2_RoutingMasterCore_hh
2 #define artdaq_Application_MPI2_RoutingMasterCore_hh
3 
4 #include <string>
5 #include <vector>
6 
7 // Socket Includes
8 #include <netinet/in.h>
9 #include <sys/epoll.h>
10 
11 #include "fhiclcpp/ParameterSet.h"
12 #include "canvas/Persistency/Provenance/RunID.h"
13 
14 #include "artdaq-utilities/Plugins/MetricManager.hh"
15 
16 #include "artdaq/Application/StatisticsHelper.hh"
17 #include "artdaq/Application/Routing/RoutingPacket.hh"
18 #include "artdaq/Application/Routing/RoutingMasterPolicy.hh"
19 #include "artdaq/DAQrate/detail/FragCounter.hh"
20 
21 namespace artdaq
22 {
23  class RoutingMasterCore;
24 }
25 
32 {
33 public:
34  static const std::string TABLE_UPDATES_STAT_KEY;
35  static const std::string TOKENS_RECEIVED_STAT_KEY;
36 
42  RoutingMasterCore(int rank, std::string name);
43 
47  RoutingMasterCore(RoutingMasterCore const&) = delete;
48 
53 
59 
83  bool initialize(fhicl::ParameterSet const& pset, uint64_t, uint64_t);
84 
90  bool start(art::RunID id, uint64_t, uint64_t);
91 
96  bool stop(uint64_t, uint64_t);
97 
102  bool pause(uint64_t, uint64_t);
103 
108  bool resume(uint64_t, uint64_t);
109 
114  bool shutdown(uint64_t);
115 
123  bool soft_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
124 
132  bool reinitialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
133 
139  size_t process_event_table();
140 
152 
158  std::string report(std::string const&) const;
159 
160 private:
161  void receive_tokens_();
162  void start_recieve_token_thread_();
163 
164  art::RunID run_id_;
165  std::string name_;
166 
167  fhicl::ParameterSet policy_pset_;
168  int rt_priority_;
169 
170  size_t max_table_update_interval_ms_;
171  size_t max_ack_cycle_count_;
172  detail::RoutingMasterMode routing_mode_;
173  size_t current_table_interval_ms_;
174  std::atomic<size_t> table_update_count_;
175  std::atomic<size_t> received_token_count_;
176  std::unordered_map<int,size_t> received_token_counter_;
177 
178  std::vector<int> sender_ranks_;
179  size_t num_receivers_;
180 
181  std::unique_ptr<RoutingMasterPolicy> policy_;
182 
183  std::atomic<bool> shutdown_requested_;
184  std::atomic<bool> stop_requested_;
185  std::atomic<bool> pause_requested_;
186 
187  // attributes and methods for statistics gathering & reporting
188  artdaq::StatisticsHelper statsHelper_;
189 
190  std::string buildStatisticsString_() const;
191 
192  artdaq::MetricManager metricMan_;
193 
194  void sendMetrics_();
195 
196 
197  // FHiCL-configurable variables. Note that the C++ variable names
198  // are the FHiCL variable names with a "_" appended
199  int receive_token_port_;
200  int send_tables_port_;
201  int receive_acks_port_;
202  std::string send_tables_address_;
203  std::string receive_address_;
204  struct sockaddr_in receive_addr_;
205  struct sockaddr_in send_tables_addr_;
206  std::vector<epoll_event> receive_ack_events_;
207  std::vector<epoll_event> receive_token_events_;
208  std::unordered_map<int, std::string> receive_token_addrs_;
209  int token_epoll_fd_;
210 
211  //Socket parameters
212  int token_socket_;
213  int table_socket_;
214  int ack_socket_;
215  mutable std::mutex request_mutex_;
216  std::thread ev_token_receive_thread_;
217 
218 };
219 
220 #endif /* artdaq_Application_MPI2_RoutingMasterCore_hh */
This class manages MonitoredQuantity instances for the *Core classes.
bool resume(uint64_t, uint64_t)
Resumes the RoutingMasterCore.
size_t process_event_table()
Main loop of the RoutingMasterCore. Determines when to send the next table update, asks the RoutingMasterPolicy for the table to send, and sends it.
bool soft_initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Soft-Initializes the RoutingMasterCore.
static const std::string TOKENS_RECEIVED_STAT_KEY
Key for the Tokens Received MonitoredQuantity.
bool reinitialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Reinitializes the RoutingMasterCore.
RoutingMasterCore & operator=(RoutingMasterCore const &)=delete
Copy Assignment operator is deleted.
bool start(art::RunID id, uint64_t, uint64_t)
Start the RoutingMasterCore.
RoutingMasterCore(int rank, std::string name)
RoutingMasterCore Constructor.
bool initialize(fhicl::ParameterSet const &pset, uint64_t, uint64_t)
Processes the initialize request.
bool pause(uint64_t, uint64_t)
Pauses the RoutingMasterCore.
std::vector< RoutingPacketEntry > RoutingPacket
A RoutingPacket is simply a vector of RoutingPacketEntry objects. It is not suitable for network tran...
bool stop(uint64_t, uint64_t)
Stops the RoutingMasterCore.
std::string report(std::string const &) const
Send a report on the current status of the RoutingMasterCore.
static const std::string TABLE_UPDATES_STAT_KEY
Key for Table Update count MonnitoredQuantity.
bool shutdown(uint64_t)
Shuts Down the RoutingMasterCore.
RoutingMasterCore implements the state machine for the RoutingMaster artdaq application. RoutingMasterCore collects tokens from receivers, and at regular intervals uses these tokens to build Routing Tables that are sent to the senders.
void send_event_table(detail::RoutingPacket table)
Sends a detail::RoutingPacket to the table receivers.