$treeview $search $mathjax $extrastylesheet
artdaq
v3_04_01
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "artdaq/Application/Routing/RoutingMasterPolicy.hh" 00002 #include "artdaq/Application/Routing/PolicyMacros.hh" 00003 #include "fhiclcpp/ParameterSet.h" 00004 #include <cmath> 00005 00006 namespace artdaq 00007 { 00011 class CapacityTestPolicy : public RoutingMasterPolicy 00012 { 00013 public: 00023 explicit CapacityTestPolicy(fhicl::ParameterSet ps); 00024 00028 virtual ~CapacityTestPolicy() = default; 00029 00040 detail::RoutingPacket GetCurrentTable() override; 00041 private: 00042 int tokenUsagePercent_; 00043 }; 00044 00045 CapacityTestPolicy::CapacityTestPolicy(fhicl::ParameterSet ps) 00046 : RoutingMasterPolicy(ps) 00047 , tokenUsagePercent_(ps.get<int>("tokens_used_per_table_percent", 50)) 00048 {} 00049 00050 detail::RoutingPacket CapacityTestPolicy::GetCurrentTable() 00051 { 00052 auto tokens = getTokensSnapshot(); 00053 std::map<int, int> table; 00054 auto tokenCount = 0; 00055 for (auto token : *tokens) 00056 { 00057 table[token]++; 00058 tokenCount++; 00059 } 00060 tokens->clear(); 00061 00062 int tokensToUse = ceil(tokenCount * tokenUsagePercent_ / 100.0); 00063 auto tokensUsed = 0; 00064 00065 detail::RoutingPacket output; 00066 for (auto r : table) 00067 { 00068 bool breakCondition = false; 00069 while (table[r.first] > 0) { 00070 output.emplace_back(detail::RoutingPacketEntry(next_sequence_id_++, r.first)); 00071 table[r.first]--; 00072 tokensUsed++; 00073 if(tokensUsed >= tokensToUse) 00074 { 00075 breakCondition = true; 00076 break; 00077 } 00078 } 00079 if (breakCondition) break; 00080 } 00081 00082 for (auto r : table) 00083 { 00084 for (auto i = 0; i < r.second; ++i) 00085 { 00086 tokens->push_back(r.first); 00087 } 00088 } 00089 addUnusedTokens(std::move(tokens)); 00090 00091 return output; 00092 } 00093 } 00094 00095 DEFINE_ARTDAQ_ROUTING_POLICY(artdaq::CapacityTestPolicy)