artdaq  v3_06_00
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/DAQrate/StatisticsHelper.hh"
17 #include "artdaq/DAQrate/detail/RoutingPacket.hh"
18 #include "artdaq/RoutingPolicies/RoutingMasterPolicy.hh"
19 #include "artdaq/DAQrate/detail/FragCounter.hh"
20 #include "artdaq/DAQrate/TokenReceiver.hh"
21 
22 namespace artdaq
23 {
24  class RoutingMasterCore;
25 }
26 
33 {
34 public:
35  static const std::string TABLE_UPDATES_STAT_KEY;
36  static const std::string TOKENS_RECEIVED_STAT_KEY;
37 
42 
46  RoutingMasterCore(RoutingMasterCore const&) = delete;
47 
52 
58 
81  bool initialize(fhicl::ParameterSet const& pset, uint64_t, uint64_t);
82 
88  bool start(art::RunID id, uint64_t, uint64_t);
89 
94  bool stop(uint64_t, uint64_t);
95 
100  bool pause(uint64_t, uint64_t);
101 
106  bool resume(uint64_t, uint64_t);
107 
112  bool shutdown(uint64_t);
113 
121  bool soft_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
122 
130  bool reinitialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
131 
136  void process_event_table();
137 
149 
155  std::string report(std::string const&) const;
156 
161  size_t get_update_count() const { return table_update_count_; }
162 
163 private:
164  art::RunID run_id_;
165 
166  fhicl::ParameterSet policy_pset_;
167  fhicl::ParameterSet token_receiver_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  std::atomic<size_t> current_table_interval_ms_;
174  std::atomic<size_t> table_update_count_;
175 
176  std::vector<int> sender_ranks_;
177 
178  std::shared_ptr<RoutingMasterPolicy> policy_;
179  std::unique_ptr<TokenReceiver> token_receiver_;
180 
181  std::atomic<bool> shutdown_requested_;
182  std::atomic<bool> stop_requested_;
183  std::atomic<bool> pause_requested_;
184 
185  // attributes and methods for statistics gathering & reporting
186  std::shared_ptr<artdaq::StatisticsHelper> statsHelperPtr_;
187 
188  std::string buildStatisticsString_() const;
189 
190  void sendMetrics_();
191 
192 
193  // FHiCL-configurable variables. Note that the C++ variable names
194  // are the FHiCL variable names with a "_" appended
195  int send_tables_port_;
196  int receive_acks_port_;
197  std::string send_tables_address_;
198  std::string multicast_out_hostname_;
199  struct sockaddr_in send_tables_addr_;
200  std::vector<epoll_event> receive_ack_events_;
201 
202  //Socket parameters
203  int table_socket_;
204  int ack_socket_;
205  mutable std::mutex request_mutex_;
206 
207 };
208 
209 #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.