artdaq  v3_12_02
RoutingManagerCore.hh
1 #ifndef artdaq_Application_MPI2_RoutingManagerCore_hh
2 #define artdaq_Application_MPI2_RoutingManagerCore_hh
3 
4 #include "artdaq/DAQrate/StatisticsHelper.hh"
5 #include "artdaq/DAQrate/detail/RoutingPacket.hh"
6 #include "artdaq/DAQrate/detail/TokenReceiver.hh"
7 #include "artdaq/RoutingPolicies/RoutingManagerPolicy.hh"
8 
9 #include "canvas/Persistency/Provenance/RunID.h"
10 #include "fhiclcpp/ParameterSet.h"
11 
12 #include <boost/thread.hpp>
13 
14 // Socket Includes
15 #include <netinet/in.h>
16 #include <sys/epoll.h>
17 
18 #include <atomic>
19 #include <map>
20 #include <memory>
21 #include <mutex>
22 #include <set>
23 #include <string>
24 
25 namespace artdaq {
26 class RoutingManagerCore;
27 }
28 
35 {
36 public:
37  static const std::string TABLE_UPDATES_STAT_KEY;
38  static const std::string TOKENS_RECEIVED_STAT_KEY;
39  static const std::string CURRENT_TABLE_INTERVAL_STAT_KEY;
40 
45 
49  RoutingManagerCore(RoutingManagerCore const&) = delete;
50 
55 
61 
64 
88  bool initialize(fhicl::ParameterSet const& pset, uint64_t, uint64_t);
89 
95  bool start(art::RunID id, uint64_t, uint64_t);
96 
101  bool stop(uint64_t, uint64_t);
102 
107  bool pause(uint64_t, uint64_t);
108 
113  bool resume(uint64_t, uint64_t);
114 
119  bool shutdown(uint64_t);
120 
128  bool soft_initialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
129 
137  bool reinitialize(fhicl::ParameterSet const& pset, uint64_t timeout, uint64_t timestamp);
138 
143  void process_event_table();
144 
156 
162  std::string report(std::string const&) const;
163 
168  size_t get_update_count() const { return table_update_count_; }
169 
170 private:
171  art::RunID run_id_;
172 
173  fhicl::ParameterSet policy_pset_;
174  fhicl::ParameterSet token_receiver_pset_;
175  int rt_priority_;
176 
177  size_t max_table_update_interval_ms_;
178  std::atomic<size_t> current_table_interval_ms_;
179  double table_update_high_fraction_;
180  double table_update_low_fraction_;
181  std::atomic<size_t> table_update_count_;
182 
183  std::shared_ptr<RoutingManagerPolicy> policy_;
184  std::unique_ptr<TokenReceiver> token_receiver_;
185 
186  std::atomic<bool> shutdown_requested_;
187  std::atomic<bool> stop_requested_;
188  std::atomic<bool> pause_requested_;
189 
190  std::unique_ptr<boost::thread> listen_thread_;
191  int table_listen_port_;
192 
193  std::map<int, std::set<int>> connected_fds_;
194  int epoll_fd_{-1};
195  mutable std::mutex fd_mutex_;
196 
197  // attributes and methods for statistics gathering & reporting
198  std::shared_ptr<artdaq::StatisticsHelper> statsHelperPtr_;
199 
200  std::string buildStatisticsString_() const;
201 
202  void sendMetrics_();
203 
204  void listen_();
205  void receive_();
206  int find_fd_(int fd) const;
207 };
208 
209 #endif /* artdaq_Application_MPI2_RoutingManagerCore_hh */
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.
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 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.
bool soft_initialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Soft-Initializes the RoutingManagerCore.
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.
static const std::string CURRENT_TABLE_INTERVAL_STAT_KEY
Key for the Current Table Interval MonitoredQuantity.
bool reinitialize(fhicl::ParameterSet const &pset, uint64_t timeout, uint64_t timestamp)
Reinitializes the RoutingManagerCore.