artdaq  v2_03_00
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
RoutingMasterPolicy.hh
1 #ifndef artdaq_Application_Routing_RoutingMasterPolicy_hh
2 #define artdaq_Application_Routing_RoutingMasterPolicy_hh
3 
4 #include "artdaq/DAQdata/Globals.hh"
5 #include "artdaq/Application/Routing/RoutingPacket.hh"
6 #include "artdaq-core/Data/Fragment.hh"
7 
8 #include "fhiclcpp/fwd.h"
9 #include <mutex>
10 #include <deque>
11 #include <unordered_set>
12 
13 namespace artdaq
14 {
19  {
20  public:
30  explicit RoutingMasterPolicy(fhicl::ParameterSet ps);
34  virtual ~RoutingMasterPolicy() = default;
35 
43 
48  size_t GetReceiverCount() const { return receiver_ranks_.size(); }
49 
54  size_t GetMaxNumberOfTokens() const { return max_token_count_; }
55 
61  void AddReceiverToken(int rank, unsigned new_slots_free);
62 
66  void Reset() { next_sequence_id_ = 0; }
67  protected:
68  Fragment::sequence_id_t next_sequence_id_;
69 
70  std::unique_ptr<std::deque<int>> getTokensSnapshot();
71  void addUnusedTokens(std::unique_ptr<std::deque<int>> tokens);
72  private:
73  mutable std::mutex tokens_mutex_;
74  std::unordered_set<int> receiver_ranks_;
75  std::deque<int> tokens_;
76  size_t max_token_count_;
77 
78  };
79 }
80 
81 
82 #endif // artdaq_Application_Routing_RoutingMasterPolicy_hh
void AddReceiverToken(int rank, unsigned new_slots_free)
Add a token to the token list.
The interface through which RoutingMasterCore obtains Routing Tables using received Routing Tokens...
virtual detail::RoutingPacket GetCurrentTable()=0
Generate a Routing Table using received tokens.
size_t GetMaxNumberOfTokens() const
Get the largest number of tokens that the RoutingMasterPolicy has seen at any one time...
std::vector< RoutingPacketEntry > RoutingPacket
A RoutingPacket is simply a vector of RoutingPacketEntry objects. It is not suitable for network tran...
Fragment::sequence_id_t next_sequence_id_
The next sequence ID to be assigned.
std::unique_ptr< std::deque< int > > getTokensSnapshot()
Gets the current token list, used for building Routing Tables.
void Reset()
Reset the policy, setting the next sequence ID to be used to 0.
void addUnusedTokens(std::unique_ptr< std::deque< int >> tokens)
If necessary, return unused tokens to the token list, for subsequent updates.
RoutingMasterPolicy(fhicl::ParameterSet ps)
RoutingMasterPolicy Constructor.
virtual ~RoutingMasterPolicy()=default
Default virtual Destructor.
size_t GetReceiverCount() const
Get the number of configured receivers.