$treeview $search $mathjax $extrastylesheet
artdaq
v3_04_01
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #define TRACE_NAME "RoutingMasterPolicy" 00002 00003 #include "artdaq/Application/Routing/RoutingMasterPolicy.hh" 00004 #include "fhiclcpp/ParameterSet.h" 00005 00006 artdaq::RoutingMasterPolicy::RoutingMasterPolicy(fhicl::ParameterSet ps) 00007 : next_sequence_id_(1) 00008 , tokens_() 00009 , max_token_count_(0) 00010 { 00011 auto receiver_ranks = ps.get<std::vector<int>>("receiver_ranks"); 00012 receiver_ranks_.insert(receiver_ranks.begin(), receiver_ranks.end()); 00013 } 00014 00015 void artdaq::RoutingMasterPolicy::AddReceiverToken(int rank, unsigned new_slots_free) 00016 { 00017 if (!receiver_ranks_.count(rank)) return; 00018 TLOG(10) << "AddReceiverToken BEGIN" ; 00019 std::unique_lock<std::mutex> lk(tokens_mutex_); 00020 if (new_slots_free == 1) 00021 { 00022 tokens_.push_back(rank); 00023 } 00024 else 00025 { 00026 // Randomly distribute multitokens through the token list 00027 // Only used at start run time, so we can take the performance hit 00028 for (unsigned i = 0; i < new_slots_free; ++i) 00029 { 00030 auto it = tokens_.begin(); 00031 if(tokens_.size()) std::advance(it, rand() % tokens_.size()); 00032 tokens_.insert(it, rank); 00033 } 00034 } 00035 if (tokens_.size() > max_token_count_) max_token_count_ = tokens_.size(); 00036 TLOG(10) << "AddReceiverToken END" ; 00037 } 00038 00039 std::unique_ptr<std::deque<int>> artdaq::RoutingMasterPolicy::getTokensSnapshot() 00040 { 00041 TLOG(10) << "getTokensSnapshot BEGIN" ; 00042 std::unique_lock<std::mutex> lk(tokens_mutex_); 00043 auto out = std::make_unique<std::deque<int>>(tokens_); 00044 tokens_.clear(); 00045 TLOG(10) << "getTokensSnapshot END" ; 00046 return out; 00047 } 00048 00049 void artdaq::RoutingMasterPolicy::addUnusedTokens(std::unique_ptr<std::deque<int>> tokens) 00050 { 00051 std::unique_lock<std::mutex> lk(tokens_mutex_); 00052 for (auto token = tokens.get()->rbegin(); token != tokens.get()->rend(); ++token) 00053 { 00054 tokens_.push_front(*token); 00055 } 00056 if (tokens_.size() > max_token_count_) max_token_count_ = tokens_.size(); 00057 } 00058 00059 void artdaq::RoutingMasterPolicy::Reset() 00060 { 00061 next_sequence_id_ = 1; 00062 std::unique_lock<std::mutex> lk(tokens_mutex_); 00063 tokens_.clear(); 00064 }