artdaq  v3_09_00
RoutingManagerCore.hh
1 #ifndef artdaq_Application_MPI2_RoutingManagerCore_hh
2 #define artdaq_Application_MPI2_RoutingManagerCore_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 "canvas/Persistency/Provenance/RunID.h"
12 #include "fhiclcpp/ParameterSet.h"
13 
14 #include "artdaq-utilities/Plugins/MetricManager.hh"
15 
16 #include "artdaq/DAQrate/StatisticsHelper.hh"
17 #include "artdaq/DAQrate/TokenReceiver.hh"
18 #include "artdaq/DAQrate/detail/FragCounter.hh"
19 #include "artdaq/DAQrate/detail/RoutingPacket.hh"
20 #include "artdaq/RoutingPolicies/RoutingManagerPolicy.hh"
21 
22 namespace artdaq {
23 class RoutingManagerCore;
24 }
25 
32 {
33 public:
34  static const std::string TABLE_UPDATES_STAT_KEY;
35  static const std::string TOKENS_RECEIVED_STAT_KEY;
36 
41 
45  RoutingManagerCore(RoutingManagerCore const&) = delete;
46 
51 
57 
60 
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 e, uint64_t f);
124 
132  bool reinitialize(fhicl::ParameterSet const& pset, uint64_t e, uint64_t f);
133 
138  void process_event_table();
139 
151 
157  std::string report(std::string const&) const;
158 
163  size_t get_update_count() const { return table_update_count_; }
164 
165 private:
166  art::RunID run_id_;
167 
168  fhicl::ParameterSet policy_pset_;
169  fhicl::ParameterSet token_receiver_pset_;
170  int rt_priority_;
171 
172  size_t max_table_update_interval_ms_;
173  size_t max_ack_cycle_count_;
174  detail::RoutingManagerMode routing_mode_;
175  std::atomic<size_t> current_table_interval_ms_;
176  std::atomic<size_t> table_update_count_;
177 
178  std::vector<int> sender_ranks_;
179  std::set<int> active_ranks_;
180 
181  std::shared_ptr<RoutingManagerPolicy> policy_;
182  std::unique_ptr<TokenReceiver> token_receiver_;
183 
184  std::atomic<bool> shutdown_requested_;
185  std::atomic<bool> stop_requested_;
186  std::atomic<bool> pause_requested_;
187 
188  // attributes and methods for statistics gathering & reporting
189  std::shared_ptr<artdaq::StatisticsHelper> statsHelperPtr_;
190 
191  std::string buildStatisticsString_() const;
192 
193  void sendMetrics_();
194 
195  // FHiCL-configurable variables. Note that the C++ variable names
196  // are the FHiCL variable names with a "_" appended
197  int send_tables_port_;
198  int receive_acks_port_;
199  std::string send_tables_address_;
200  std::string multicast_out_hostname_;
201  struct sockaddr_in send_tables_addr_;
202  std::vector<epoll_event> receive_ack_events_;
203 
204  //Socket parameters
205  int table_socket_{-1};
206  int ack_socket_{-1};
207  mutable std::mutex request_mutex_;
208 };
209 
210 #endif /* artdaq_Application_MPI2_RoutingManagerCore_hh */
bool reinitialize(fhicl::ParameterSet const &pset, uint64_t e, uint64_t f)
Reinitializes the RoutingManagerCore.
bool shutdown(uint64_t)
Shuts Down the RoutingManagerCore.
bool start(art::RunID id, uint64_t, uint64_t)
Start the RoutingManagerCore.
RoutingManagerCore implements the state machine for the RoutingManager artdaq application. RoutingManagerCore collects tokens from receivers, and at regular intervals uses these tokens to build Routing Tables that are sent to the senders.
static const std::string TABLE_UPDATES_STAT_KEY
Key for Table Update count MonnitoredQuantity.
RoutingManagerMode
Mode indicating whether the RoutingManager is routing events by Sequence ID or by Send Count...
bool pause(uint64_t, uint64_t)
Pauses the RoutingManagerCore.
RoutingManagerCore & operator=(RoutingManagerCore const &)=delete
Copy Assignment operator is deleted.
size_t get_update_count() const
Get the number of table updates sent by this RoutingManager this run.
std::vector< RoutingPacketEntry > RoutingPacket
A RoutingPacket is simply a vector of RoutingPacketEntry objects. It is not suitable for network tran...
bool soft_initialize(fhicl::ParameterSet const &pset, uint64_t e, uint64_t f)
Soft-Initializes the RoutingManagerCore.
bool initialize(fhicl::ParameterSet const &pset, uint64_t, uint64_t)
Processes the initialize request.
bool stop(uint64_t, uint64_t)
Stops the RoutingManagerCore.
void process_event_table()
Main loop of the RoutingManagerCore. Determines when to send the next table update, asks the RoutingManagerPolicy for the table to send, and sends it.
static const std::string TOKENS_RECEIVED_STAT_KEY
Key for the Tokens Received MonitoredQuantity.
std::string report(std::string const &) const
Send a report on the current status of the RoutingManagerCore.
bool resume(uint64_t, uint64_t)
Resumes the RoutingManagerCore.
void send_event_table(detail::RoutingPacket packet)
Sends a detail::RoutingPacket to the table receivers.
RoutingManagerCore()
RoutingManagerCore Constructor.