1 #ifndef artdaq_Application_Routing_RoutingManagerPolicy_hh
2 #define artdaq_Application_Routing_RoutingManagerPolicy_hh
4 #include "artdaq-core/Data/Fragment.hh"
5 #include "artdaq/DAQdata/Globals.hh"
6 #include "artdaq/DAQrate/detail/RoutingPacket.hh"
10 #include <unordered_set>
11 #include "fhiclcpp/fwd.h"
81 std::unique_lock<std::mutex> lk(tokens_mutex_);
116 bool CacheHasRoute(artdaq::Fragment::sequence_id_t seq)
const {
return routing_cache_.count(seq) != 0; }
149 void TrimRoutingCache();
152 struct RoutingCacheEntry
154 bool is_valid{
false };
155 int destination_rank{ -1 };
156 Fragment::sequence_id_t sequence_id{ artdaq::Fragment::InvalidSequenceID };
157 int requesting_rank{ -1 };
158 bool included_in_table{
false };
160 RoutingCacheEntry() {}
161 RoutingCacheEntry(Fragment::sequence_id_t seq,
int dest,
int source)
162 : is_valid(true), destination_rank(dest), sequence_id(seq), requesting_rank(source) {}
164 std::map<Fragment::sequence_id_t, std::vector<RoutingCacheEntry>> routing_cache_;
165 size_t routing_cache_max_size_;
166 mutable std::mutex routing_cache_mutex_;
167 std::atomic<size_t> max_token_count_;
168 mutable std::mutex tokens_mutex_;
172 #endif // artdaq_Application_Routing_RoutingManagerPolicy_hh
void AddReceiverToken(int rank, unsigned new_slots_free)
Add a token to the token list.
A row of the Routing Table.
void Reset()
Reset the policy, setting the next sequence ID to be used to 1, and removing any tokens.
size_t GetHeldTokenCount() const
Get the number of tokens that are waiting to be used.
void ResetTokensUsedSinceLastUpdate()
Reset the number of tokens used.
size_t GetMaxNumberOfTokens() const
Get the largest number of tokens that the RoutingManagerPolicy has seen at any one time...
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...
RoutingManagerMode
Mode indicating whether the RoutingManager is routing events by Sequence ID or by Send Count...
virtual ~RoutingManagerPolicy()=default
Default virtual Destructor.
virtual detail::RoutingPacketEntry CreateRouteForSequenceID(artdaq::Fragment::sequence_id_t seq, int requesting_rank)=0
Generate a route for the given sequence ID and source rank.
detail::RoutingPacketEntry GetRouteForSequenceID(artdaq::Fragment::sequence_id_t seq, int requesting_rank)
Get an artdaq::detail::RoutingPacketEntry for a given sequence ID and rank. Used by RequestBasedEvent...
Fragment::sequence_id_t GetNextSequenceID() const
Get the next sequence ID to be routed.
size_t GetCacheSize() const
Get the size of the routing cache. For testing.
std::vector< RoutingPacketEntry > RoutingPacket
A RoutingPacket is simply a vector of RoutingPacketEntry objects. It is not suitable for network tran...
virtual void CreateRoutingTable(detail::RoutingPacket &tables)=0
Generate entries to add to the given table.
size_t GetTokensUsedSinceLastUpdate() const
Get the number of tokens that have been used since the last update.
RoutingManagerPolicy(const fhicl::ParameterSet &ps)
RoutingManagerPolicy Constructor.
bool CacheHasRoute(artdaq::Fragment::sequence_id_t seq) const
Determine whether the routing cache has a route for the given sequence ID. For testing.
detail::RoutingManagerMode routing_mode_
Current routing mode.
size_t GetReceiverCount() const
Get the number of configured receivers.
std::deque< int > tokens_
The list of tokens which are available for use.
detail::RoutingPacket GetCurrentTable()
Create a RoutingPacket from currently-owned tokens. Used by EventBuilder and RequestBasedEventBuilder...
std::unordered_set< int > receiver_ranks_
Configured receiver (e.g. EventBuilder for BR->EB routing) ranks.
std::atomic< size_t > tokens_used_since_last_update_
Number of tokens consumed since last metric update.
detail::RoutingManagerMode GetRoutingMode() const
Get the current RoutingManagerMode of this RoutingManager.