artdaq  v3_00_01
RoundRobin_policy.cc
1 #include "artdaq/Application/Routing/RoutingMasterPolicy.hh"
2 #include "artdaq/Application/Routing/PolicyMacros.hh"
3 #include "fhiclcpp/ParameterSet.h"
4 
5 namespace artdaq
6 {
12  {
13  public:
20  explicit RoundRobinPolicy(fhicl::ParameterSet ps) : RoutingMasterPolicy(ps) {}
21 
25  virtual ~RoundRobinPolicy() = default;
26 
36  };
37 
39  {
40  auto tokens = getTokensSnapshot();
41  std::map<int, int> table;
42  for (auto token : *tokens.get())
43  {
44  table[token]++;
45  }
46  tokens->clear();
47 
48  detail::RoutingPacket output;
49  auto endCondition = table.size() < GetReceiverCount();
50  while (!endCondition)
51  {
52  for (auto r : table)
53  {
54  output.emplace_back(detail::RoutingPacketEntry(next_sequence_id_++, r.first));
55  if(!endCondition) endCondition = r.second == 1;
56  table[r.first]--;
57  }
58  }
59 
60  for(auto r : table)
61  {
62  for(auto i = 0;i < r.second; ++i)
63  {
64  tokens->push_back(r.first);
65  }
66  }
67  addUnusedTokens(std::move(tokens));
68 
69  return output;
70  }
71 }
72 
73 DEFINE_ARTDAQ_ROUTING_POLICY(artdaq::RoundRobinPolicy)
A row of the Routing Table.
A RoutingMasterPolicy which evenly distributes Sequence IDs to all receivers. If an uneven number of ...
virtual ~RoundRobinPolicy()=default
Default virtual Destructor.
The interface through which RoutingMasterCore obtains Routing Tables using received Routing Tokens...
detail::RoutingPacket GetCurrentTable() override
Create a Routing Table using the tokens that have been received.
std::vector< RoutingPacketEntry > RoutingPacket
A RoutingPacket is simply a vector of RoutingPacketEntry objects. It is not suitable for network tran...
Fragment::sequence_id_t next_sequence_id_
The next sequence ID to be assigned.
std::unique_ptr< std::deque< int > > getTokensSnapshot()
Gets the current token list, used for building Routing Tables.
void addUnusedTokens(std::unique_ptr< std::deque< int >> tokens)
If necessary, return unused tokens to the token list, for subsequent updates.
RoundRobinPolicy(fhicl::ParameterSet ps)
RoundRobinPolicy Constructor.
size_t GetReceiverCount() const
Get the number of configured receivers.