artdaq  v3_00_03
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 
52  explicit DataSenderManager(const fhicl::ParameterSet& ps);
53 
57  virtual ~DataSenderManager();
58 
64  int sendFragment(Fragment&& frag);
65 
70  size_t count() const;
71 
77  size_t slotCount(size_t rank) const;
78 
83  size_t destinationCount() const { return destinations_.size(); }
84 
89  std::set<int> enabled_destinations() const { return enabled_destinations_; }
90 
95  size_t GetRoutingTableEntryCount() const;
96 private:
97 
98  // Calculate where the fragment with this sequenceID should go.
99  int calcDest_(Fragment::sequence_id_t) const;
100 
101  void setupTableListener_();
102 
103  void startTableReceiverThread_();
104 
105  void receiveTableUpdatesLoop_();
106 private:
107 
108  std::map<int, std::unique_ptr<artdaq::TransferInterface>> destinations_;
109  std::set<int> enabled_destinations_;
110 
111  detail::FragCounter sent_frag_count_;
112 
113  bool broadcast_sends_;
114  bool non_blocking_mode_;
115  size_t send_timeout_us_;
116 
117  bool use_routing_master_;
118  detail::RoutingMasterMode routing_master_mode_;
119  std::atomic<bool> should_stop_;
120  int table_port_;
121  std::string table_address_;
122  struct sockaddr_in table_addr_;
123  int ack_port_;
124  std::string ack_address_;
125  struct sockaddr_in ack_addr_;
126  int ack_socket_;
127  int table_socket_;
128  std::map<Fragment::sequence_id_t, int> routing_table_;
129  mutable std::mutex routing_mutex_;
130  boost::thread routing_thread_;
131  mutable std::atomic<size_t> routing_wait_time_;
132 
133  int routing_timeout_ms_;
134  int routing_retry_count_;
135 };
136 
137 inline
138 size_t
140 count() const
141 {
142  return sent_frag_count_.count();
143 }
144 
145 inline
146 size_t
148 slotCount(size_t rank) const
149 {
150  return sent_frag_count_.slotCount(rank);
151 }
152 #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
int 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