1 #include "artdaq/DAQdata/Globals.hh"
2 #define TRACE_NAME (app_name + "_RoundRobin_policy").c_str()
3 #include "TRACE/tracemf.h"
5 #include "artdaq/RoutingPolicies/PolicyMacros.hh"
6 #include "artdaq/RoutingPolicies/RoutingManagerPolicy.hh"
8 #include "fhiclcpp/ParameterSet.h"
27 , minimum_participants_(ps.get<int>(
"minimum_participants", 0))
59 std::map<int, int> sortTokens_();
60 void restoreUnusedTokens_(std::map<int, int>
const& sorted_tokens_);
61 int calculateMinimum_();
63 int minimum_participants_;
64 std::set<int> receivers_in_current_round_;
69 TLOG(TLVL_DEBUG + 35) <<
"RoundRobinPolicy::GetCurrentTable token list size is " <<
tokens_.size();
70 auto table = sortTokens_();
71 TLOG(TLVL_DEBUG + 36) <<
"RoundRobinPolicy::GetCurrentTable table size is " << table.size();
73 int minimum = calculateMinimum_();
74 bool endCondition = table.size() <
static_cast<size_t>(minimum);
75 TLOG(TLVL_DEBUG + 37) <<
"RoundRobinPolicy::GetCurrentTable initial endCondition is " << endCondition <<
", minimum is " << minimum;
79 for (
auto it = table.begin(); it != table.end();)
81 TLOG(TLVL_DEBUG + 38) <<
"RoundRobinPolicy::GetCurrentTable assigning sequenceID " <<
next_sequence_id_ <<
" to rank " << it->first;
85 if (table[it->first] <= 0)
94 endCondition = table.size() <
static_cast<size_t>(minimum);
97 restoreUnusedTokens_(table);
98 TLOG(TLVL_DEBUG + 36) <<
"RoundRobinPolicy::GetCurrentTable " <<
tokens_.size() <<
" unused tokens will be saved for later";
100 TLOG(TLVL_DEBUG + 35) <<
"RoundRobinPolicy::GetCurrentTable return with table size " << output.size();
107 if (!receivers_in_current_round_.empty())
110 receivers_in_current_round_.erase(receivers_in_current_round_.begin());
115 auto table = sortTokens_();
118 int minimum = calculateMinimum_();
119 if (table.size() <
static_cast<size_t>(minimum))
121 TLOG(TLVL_WARNING) <<
"Do not have tokens from a minimum set of receivers to start a round";
125 for (
auto& entry : table)
127 receivers_in_current_round_.insert(entry.first);
131 receivers_in_current_round_.erase(receivers_in_current_round_.begin());
134 restoreUnusedTokens_(table);
137 std::map<int, int> RoundRobinPolicy::sortTokens_()
139 auto output = std::map<int, int>();
148 void RoundRobinPolicy::restoreUnusedTokens_(std::map<int, int>
const& sorted_tokens)
150 for (
auto r : sorted_tokens)
152 for (
auto i = 0; i < r.second; ++i)
154 tokens_.push_back(r.first);
159 int RoundRobinPolicy::calculateMinimum_()
166 int minimum = minimum_participants_ > 0 ? minimum_participants_ :
GetReceiverCount() + minimum_participants_;
~RoundRobinPolicy() override=default
Default virtual Destructor.
A row of the Routing Table.
A RoutingManagerPolicy which evenly distributes Sequence IDs to all receivers. If an uneven number of...
Fragment::sequence_id_t next_sequence_id_
The next sequence ID to be assigned.
The interface through which RoutingManagerCore obtains Routing Tables using received Routing Tokens...
void CreateRoutingTable(detail::RoutingPacket &output) override
Add entries to the given RoutingPacket using currently-held tokens.
std::vector< RoutingPacketEntry > RoutingPacket
A RoutingPacket is simply a vector of RoutingPacketEntry objects. It is not suitable for network tran...
detail::RoutingPacketEntry CreateRouteForSequenceID(artdaq::Fragment::sequence_id_t seq, int requesting_rank) override
Get an artdaq::detail::RoutingPacketEntry for a given sequence ID and rank. Used by RequestBasedEvent...
size_t GetReceiverCount() const
Get the number of configured receivers.
std::deque< int > tokens_
The list of tokens which are available for use.
RoundRobinPolicy(const fhicl::ParameterSet &ps)
RoundRobinPolicy Constructor.