2 #include "artdaq/RoutingPolicies/PolicyMacros.hh"
3 #include "artdaq/RoutingPolicies/RoutingManagerPolicy.hh"
4 #include "fhiclcpp/ParameterSet.h"
49 std::pair<size_t, std::map<int, int>> sortTokens_();
50 void restoreUnusedTokens_(std::map<int, int>
const& sorted_tokens);
57 int tokenUsagePercent_;
62 , tokenUsagePercent_(ps.get<int>(
"tokens_used_per_table_percent", 50))
67 auto sorted_tokens = sortTokens_();
68 size_t tokenCount = sorted_tokens.first;
69 auto table = sorted_tokens.second;
70 size_t tokensToUse = ceil(tokenCount * tokenUsagePercent_ / 100.0);
74 bool breakCondition =
false;
75 while (table[r.first] > 0)
82 breakCondition =
true;
92 restoreUnusedTokens_(table);
99 auto sorted_tokens = sortTokens_();
100 if (sorted_tokens.first == 0)
return output;
101 auto dest = sorted_tokens.second.begin()->first;
102 sorted_tokens.second[dest]--;
104 restoreUnusedTokens_(sorted_tokens.second);
111 std::pair<size_t, std::map<int, int>> CapacityTestPolicy::sortTokens_()
113 auto output = std::make_pair(0, std::map<int, int>());
116 output.second[token]++;
123 void CapacityTestPolicy::restoreUnusedTokens_(std::map<int, int>
const& sorted_tokens)
125 for (
auto r : sorted_tokens)
127 for (
auto i = 0; i < r.second; ++i)
129 tokens_.push_back(r.first);
virtual void CreateRoutingTable(detail::RoutingPacket &output) override
Add entries to the given RoutingPacket using currently-held tokens.
A row of the Routing Table.
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...
virtual 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...
~CapacityTestPolicy() override=default
Default virtual Destructor.
std::vector< RoutingPacketEntry > RoutingPacket
A RoutingPacket is simply a vector of RoutingPacketEntry objects. It is not suitable for network tran...
A RoutingManagerPolicy which tries to fully load the first receiver, then the second, and so on.
std::deque< int > tokens_
The list of tokens which are available for use.
CapacityTestPolicy(const fhicl::ParameterSet &ps)
CapacityTestPolicy Constructor.
std::atomic< size_t > tokens_used_since_last_update_
Number of tokens consumed since last metric update.