artdaq  v3_07_01
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 "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/RoutingMasterPolicy.hh"
21 
22 namespace artdaq {
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 
41 
45  RoutingMasterCore(RoutingMasterCore const&) = delete;
46 
51 
57 
80  bool initialize(fhicl::ParameterSet const& pset, uint64_t, uint64_t);
81 
87  bool start(art::RunID id, uint64_t, uint64_t);
88 
93  bool stop(uint64_t, uint64_t);
94 
99  bool pause(uint64_t, uint64_t);
100 
105  bool resume(uint64_t, uint64_t);
106 
111  bool shutdown(uint64_t);
112 
120  bool soft_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
121 
129  bool reinitialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
130 
135  void process_event_table();
136 
148 
154  std::string report(std::string const&) const;
155 
160  size_t get_update_count() const { return table_update_count_; }
161 
162 private:
163  art::RunID run_id_;
164 
165  fhicl::ParameterSet policy_pset_;
166  fhicl::ParameterSet token_receiver_pset_;
167  int rt_priority_;
168 
169  size_t max_table_update_interval_ms_;
170  size_t max_ack_cycle_count_;
171  detail::RoutingMasterMode routing_mode_;
172  std::atomic<size_t> current_table_interval_ms_;
173  std::atomic<size_t> table_update_count_;
174 
175  std::vector<int> sender_ranks_;
176 
177  std::shared_ptr<RoutingMasterPolicy> policy_;
178  std::unique_ptr<TokenReceiver> token_receiver_;
179 
180  std::atomic<bool> shutdown_requested_;
181  std::atomic<bool> stop_requested_;
182  std::atomic<bool> pause_requested_;
183 
184  // attributes and methods for statistics gathering & reporting
185  std::shared_ptr<artdaq::StatisticsHelper> statsHelperPtr_;
186 
187  std::string buildStatisticsString_() const;
188 
189  void sendMetrics_();
190 
191  // FHiCL-configurable variables. Note that the C++ variable names
192  // are the FHiCL variable names with a "_" appended
193  int send_tables_port_;
194  int receive_acks_port_;
195  std::string send_tables_address_;
196  std::string multicast_out_hostname_;
197  struct sockaddr_in send_tables_addr_;
198  std::vector<epoll_event> receive_ack_events_;
199 
200  //Socket parameters
201  int table_socket_;
202  int ack_socket_;
203  mutable std::mutex request_mutex_;
204 };
205 
206 #endif /* artdaq_Application_MPI2_RoutingMasterCore_hh */
bool resume(uint64_t, uint64_t)
Resumes the RoutingMasterCore.
RoutingMasterMode
Mode indicating whether the RoutingMaster is routing events by Sequence ID or by Send Count...
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()
RoutingMasterCore Constructor.
bool initialize(fhicl::ParameterSet const &pset, uint64_t, uint64_t)
Processes the initialize request.
size_t get_update_count() const
Get the number of table updates sent by this RoutingMaster this run.
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 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.
void send_event_table(detail::RoutingPacket table)
Sends a detail::RoutingPacket to the table receivers.