artdaq  v2_03_02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
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/Application/Routing/RoutingPacket.hh"
16 
17 namespace artdaq
18 {
19  class DataSenderManager;
20 }
21 
27 {
28 public:
29 
51  explicit DataSenderManager(const fhicl::ParameterSet& ps);
52 
56  virtual ~DataSenderManager();
57 
63  int sendFragment(Fragment&& frag);
64 
69  size_t count() const;
70 
76  size_t slotCount(size_t rank) const;
77 
82  size_t destinationCount() const { return destinations_.size(); }
83 
88  std::set<int> enabled_destinations() const { return enabled_destinations_; }
89 
94  size_t GetRoutingTableEntryCount() const;
95 private:
96 
97  // Calculate where the fragment with this sequenceID should go.
98  int calcDest_(Fragment::sequence_id_t) const;
99 
100  void setupTableListener_();
101 
102  void startTableReceiverThread_();
103 
104  void receiveTableUpdatesLoop_();
105 private:
106 
107  std::map<int, std::unique_ptr<artdaq::TransferInterface>> destinations_;
108  std::set<int> enabled_destinations_;
109 
110  detail::FragCounter sent_frag_count_;
111 
112  bool broadcast_sends_;
113  bool non_blocking_mode_;
114 
115  bool use_routing_master_;
116  detail::RoutingMasterMode routing_master_mode_;
117  std::atomic<bool> should_stop_;
118  int table_port_;
119  std::string table_address_;
120  struct sockaddr_in table_addr_;
121  int ack_port_;
122  std::string ack_address_;
123  struct sockaddr_in ack_addr_;
124  int ack_socket_;
125  int table_socket_;
126  std::map<Fragment::sequence_id_t, int> routing_table_;
127  mutable std::mutex routing_mutex_;
128  std::thread routing_thread_;
129  mutable std::atomic<size_t> routing_wait_time_;
130 
131  int routing_timeout_ms_;
132 };
133 
134 inline
135 size_t
137 count() const
138 {
139  return sent_frag_count_.count();
140 }
141 
142 inline
143 size_t
145 slotCount(size_t rank) const
146 {
147  return sent_frag_count_.slotCount(rank);
148 }
149 #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