artdaq  v3_01_00
DataSenderManager.hh
1 #ifndef ARTDAQ_DAQRATE_DATASENDERMANAGER_HH
2 #define ARTDAQ_DAQRATE_DATASENDERMANAGER_HH
3 
4 #include <map>
5 #include <set>
6 #include <memory>
7 #include <netinet/in.h>
8 
9 #include "fhiclcpp/fwd.h"
10 
11 #include "artdaq-core/Data/Fragment.hh"
12 #include "artdaq/TransferPlugins/TransferInterface.hh"
13 #include "artdaq/DAQrate/detail/FragCounter.hh"
14 #include "artdaq-utilities/Plugins/MetricManager.hh"
15 #include "artdaq/DAQrate/detail/RoutingPacket.hh"
16 
17 namespace artdaq
18 {
19  class DataSenderManager;
20 }
21 
27 {
28 public:
29 
54  explicit DataSenderManager(const fhicl::ParameterSet& ps);
55 
59  virtual ~DataSenderManager();
60 
66  std::pair<int, TransferInterface::CopyStatus> sendFragment(Fragment&& frag);
67 
72  size_t count() const;
73 
79  size_t slotCount(size_t rank) const;
80 
85  size_t destinationCount() const { return destinations_.size(); }
86 
91  std::set<int> enabled_destinations() const { return enabled_destinations_; }
92 
97  size_t GetRoutingTableEntryCount() const;
98 private:
99 
100  // Calculate where the fragment with this sequenceID should go.
101  int calcDest_(Fragment::sequence_id_t) const;
102 
103  void setupTableListener_();
104 
105  void startTableReceiverThread_();
106 
107  void receiveTableUpdatesLoop_();
108 private:
109 
110  std::map<int, std::unique_ptr<artdaq::TransferInterface>> destinations_;
111  std::set<int> enabled_destinations_;
112 
113  detail::FragCounter sent_frag_count_;
114 
115  bool broadcast_sends_;
116  bool non_blocking_mode_;
117  size_t send_timeout_us_;
118  size_t send_retry_count_;
119 
120  bool use_routing_master_;
121  detail::RoutingMasterMode routing_master_mode_;
122  std::atomic<bool> should_stop_;
123  int table_port_;
124  std::string table_address_;
125  int ack_port_;
126  std::string ack_address_;
127  struct sockaddr_in ack_addr_;
128  int ack_socket_;
129  int table_socket_;
130  std::map<Fragment::sequence_id_t, int> routing_table_;
131  mutable std::mutex routing_mutex_;
132  boost::thread routing_thread_;
133  mutable std::atomic<size_t> routing_wait_time_;
134 
135  int routing_timeout_ms_;
136  int routing_retry_count_;
137 };
138 
139 inline
140 size_t
142 count() const
143 {
144  return sent_frag_count_.count();
145 }
146 
147 inline
148 size_t
150 slotCount(size_t rank) const
151 {
152  return sent_frag_count_.slotCount(rank);
153 }
154 #endif //ARTDAQ_DAQRATE_DATASENDERMANAGER_HH
RoutingMasterMode
Mode indicating whether the RoutingMaster is routing events by Sequence ID or by Send Count...
size_t destinationCount() const
Get the number of configured destinations.
Sends Fragment objects using TransferInterface plugins. Uses Routing Tables if confgiured, otherwise will Round-Robin Fragments to the destinations.
virtual ~DataSenderManager()
DataSenderManager Destructor.
size_t slotCount(size_t rank) const
Get the count of Fragment objects sent by this DataSenderManager to a given destination.
Keep track of the count of Fragments received from a set of sources.
Definition: FragCounter.hh:20
std::pair< int, TransferInterface::CopyStatus > sendFragment(Fragment &&frag)
Send the given Fragment. Return the rank of the destination to which the Fragment was sent...
DataSenderManager(const fhicl::ParameterSet &ps)
DataSenderManager Constructor.
size_t GetRoutingTableEntryCount() const
Gets the current size of the Routing Table, in case other parts of the system want to use this inform...
size_t count() const
Return the count of Fragment objects sent by this DataSenderManagerq.
std::set< int > enabled_destinations() const
Get the list of enabled destinations.
size_t count() const
Get the total number of Fragments received.
Definition: FragCounter.hh:128