00001 #include "artdaq/Application/Routing/RoutingMasterPolicy.hh" 00002 #include <fhiclcpp/ParameterSet.h> 00003 00004 artdaq::RoutingMasterPolicy::RoutingMasterPolicy(fhicl::ParameterSet ps) 00005 : next_sequence_id_(0) 00006 , tokens_() 00007 , max_token_count_(0) 00008 { 00009 auto receiver_ranks = ps.get<std::vector<int>>("receiver_ranks"); 00010 receiver_ranks_.insert(receiver_ranks.begin(), receiver_ranks.end()); 00011 } 00012 00013 void artdaq::RoutingMasterPolicy::AddReceiverToken(int rank, unsigned new_slots_free) 00014 { 00015 if (!receiver_ranks_.count(rank)) return; 00016 TRACE(10, "RoutingMasterPolicy::AddReceiverToken BEGIN"); 00017 std::unique_lock<std::mutex> lk(tokens_mutex_); 00018 for (unsigned i = 0; i < new_slots_free; ++i) 00019 { 00020 tokens_.push_back(rank); 00021 } 00022 if (tokens_.size() > max_token_count_) max_token_count_ = tokens_.size(); 00023 TRACE(10, "RoutingMasterPolicy::AddReceiverToken END"); 00024 } 00025 00026 std::unique_ptr<std::deque<int>> artdaq::RoutingMasterPolicy::getTokensSnapshot() 00027 { 00028 TRACE(10, "RoutingMasterPolicy::getTokensSnapshot BEGIN"); 00029 std::unique_lock<std::mutex> lk(tokens_mutex_); 00030 auto out = std::make_unique<std::deque<int>>(tokens_); 00031 tokens_.clear(); 00032 TRACE(10, "RoutingMasterPolicy::getTokensSnapshot END"); 00033 return out; 00034 } 00035 00036 void artdaq::RoutingMasterPolicy::addUnusedTokens(std::unique_ptr<std::deque<int>> tokens) 00037 { 00038 std::unique_lock<std::mutex> lk(tokens_mutex_); 00039 for (auto token = tokens.get()->rbegin(); token != tokens.get()->rend(); ++token) 00040 { 00041 tokens_.push_front(*token); 00042 } 00043 if (tokens_.size() > max_token_count_) max_token_count_ = tokens_.size(); 00044 }