artdaq  v3_11_01
DataSenderManager.hh
1 #ifndef ARTDAQ_DAQRATE_DATASENDERMANAGER_HH
2 #define ARTDAQ_DAQRATE_DATASENDERMANAGER_HH
3 
4 #include <netinet/in.h>
5 #include <map>
6 #include <memory>
7 #include <set>
8 
9 #include "fhiclcpp/fwd.h"
10 
11 #include "artdaq-core/Data/Fragment.hh"
12 #include "artdaq-utilities/Plugins/MetricManager.hh"
13 #include "artdaq/DAQdata/HostMap.hh"
14 #include "artdaq/DAQrate/detail/FragCounter.hh"
15 #include "artdaq/DAQrate/detail/RoutingPacket.hh"
16 #include "artdaq/DAQrate/detail/TableReceiver.hh"
17 #include "artdaq/TransferPlugins/TransferInterface.hh"
18 #include "fhiclcpp/types/Atom.h"
19 #include "fhiclcpp/types/OptionalTable.h"
20 #include "fhiclcpp/types/TableFragment.h"
21 
22 namespace artdaq {
23 class DataSenderManager;
24 }
25 
31 {
32 public:
37  {
39  fhicl::OptionalTable<artdaq::TransferInterface::Config> dest{fhicl::Name{"d1"}, fhicl::Comment{"Configuration for transfer to destination"}};
40  };
41 
45  struct Config
46  {
48  fhicl::Atom<bool> broadcast_sends{fhicl::Name{"broadcast_sends"}, fhicl::Comment{"Send all Fragments to all destinations"}, false};
50  fhicl::Atom<bool> nonblocking_sends{fhicl::Name{"nonblocking_sends"}, fhicl::Comment{"Whether sends should block. Used for DL->DISP connection."}, false};
52  fhicl::Atom<size_t> send_timeout_us{fhicl::Name{"send_timeout_usec"}, fhicl::Comment{"Timeout for sends in non-reliable modes (broadcast and nonblocking)"}, 5000000};
54  fhicl::Atom<size_t> send_retry_count{fhicl::Name{"send_retry_count"}, fhicl::Comment{"Number of times to retry a send in non-reliable mode"}, 2};
55  fhicl::OptionalTable<artdaq::TableReceiver::Config> routing_table_config{fhicl::Name{"routing_table_config"}};
56  fhicl::OptionalTable<DestinationsConfig> destinations{fhicl::Name{"destinations"}};
60  fhicl::TableFragment<artdaq::HostMap::Config> host_map;
62  fhicl::Sequence<size_t> enabled_destinations{fhicl::Name{"enabled_destinations"}, fhicl::Comment{"List of destiantion ranks to activate (must be defined in destinations block)"}, std::vector<size_t>()};
63  };
65  using Parameters = fhicl::WrappedTable<Config>;
66 
71  explicit DataSenderManager(const fhicl::ParameterSet& ps);
72 
76  virtual ~DataSenderManager();
77 
83  std::pair<int, TransferInterface::CopyStatus> sendFragment(Fragment&& frag);
84 
89  size_t count() const;
90 
96  size_t slotCount(size_t rank) const;
97 
102  size_t destinationCount() const { return destinations_.size(); }
103 
108  std::set<int> enabled_destinations() const { return enabled_destinations_; }
109 
114  size_t GetRoutingTableEntryCount() const;
115 
120  size_t GetRemainingRoutingTableEntries() const;
121 
125  void StopSender() { should_stop_ = true; }
126 
131  void RemoveRoutingTableEntry(Fragment::sequence_id_t seq);
137  size_t GetSentSequenceIDCount(Fragment::sequence_id_t seq);
138 
139 private:
140  DataSenderManager(DataSenderManager const&) = delete;
142  DataSenderManager& operator=(DataSenderManager const&) = delete;
143  DataSenderManager& operator=(DataSenderManager&&) = delete;
144 
145  // Calculate where the fragment with this sequenceID should go.
146  int calcDest_(Fragment::sequence_id_t) const;
147 
148 private:
149  std::map<int, std::unique_ptr<artdaq::TransferInterface>> destinations_;
150  std::set<int> enabled_destinations_;
151 
152  detail::FragCounter sent_frag_count_;
153 
154  bool broadcast_sends_;
155  bool non_blocking_mode_;
156  size_t send_timeout_us_;
157  size_t send_retry_count_;
158 
159  std::unique_ptr<TableReceiver> table_receiver_;
160  std::atomic<bool> should_stop_;
161  std::map<Fragment::sequence_id_t, size_t> sent_sequence_id_count_;
162 
163  mutable std::mutex sent_sequence_id_mutex_;
164 
165  mutable std::atomic<uint64_t> highest_sequence_id_routed_;
166 };
167 
168 inline size_t
170  count() const
171 {
172  return sent_frag_count_.count();
173 }
174 
175 inline size_t
177  slotCount(size_t rank) const
178 {
179  return sent_frag_count_.slotCount(rank);
180 }
181 #endif //ARTDAQ_DAQRATE_DATASENDERMANAGER_HH
fhicl::TableFragment< artdaq::HostMap::Config > host_map
Optional host_map configuration (Can also be specified in each DestinationsConfig entry...
void RemoveRoutingTableEntry(Fragment::sequence_id_t seq)
Remove the given sequence ID from the routing table and sent_count lists.
size_t destinationCount() const
Get the number of configured destinations.
fhicl::WrappedTable< Config > Parameters
Used for ParameterSet validation (if desired)
Sends Fragment objects using TransferInterface plugins. Uses Routing Tables if confgiured, otherwise will Round-Robin Fragments to the destinations.
virtual ~DataSenderManager()
DataSenderManager Destructor.
fhicl::OptionalTable< artdaq::TableReceiver::Config > routing_table_config
size_t slotCount(size_t rank) const
Get the count of Fragment objects sent by this DataSenderManager to a given destination.
fhicl::OptionalTable< artdaq::TransferInterface::Config > dest
Example Configuration for transfer to destination. See artdaq::TransferInterface::Config.
Keep track of the count of Fragments received from a set of sources.
Definition: FragCounter.hh:18
size_t GetSentSequenceIDCount(Fragment::sequence_id_t seq)
Get the number of Fragments sent with a given Sequence ID.
fhicl::Atom< size_t > send_timeout_us
&quot;send_timeout_usec&quot; (Default: 5000000 (5 seconds): Timeout for sends in non-reliable modes (broadcast...
fhicl::OptionalTable< DestinationsConfig > destinations
std::pair< int, TransferInterface::CopyStatus > sendFragment(Fragment &&frag)
Send the given Fragment. Return the rank of the destination to which the Fragment was sent...
size_t GetRemainingRoutingTableEntries() const
Gets the number of sends remaining in the routing table, in case other parts of the system want to us...
DataSenderManager(const fhicl::ParameterSet &ps)
DataSenderManager Constructor.
fhicl::Atom< size_t > send_retry_count
&quot;send_retry_count&quot; (Default: 2): Number of times to retry a send in non-reliable mode ...
fhicl::Atom< bool > broadcast_sends
&quot;broadcast_sends&quot; (Default: false): Send all Fragments to all destinations
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.
Configuration for transfers to destinations
size_t slotCount(size_t slot) const
Get the current count for the requested slot.
Definition: FragCounter.hh:133
Configuration of DataSenderManager. May be used for parameter validation
fhicl::Sequence< size_t > enabled_destinations
enabled_destinations" (OPTIONAL): If specified, only the destination ranks listed will be enabled...
void StopSender()
Stop the DataSenderManager, aborting any sends in progress.
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:120
fhicl::Atom< bool > nonblocking_sends
&quot;nonblocking_sends&quot; (Default: false): If true, will use non-reliable mode of TransferInterface plugin...