1 #ifndef artdaq_Application_Routing_RoutingManagerPolicy_hh
2 #define artdaq_Application_Routing_RoutingManagerPolicy_hh
4 #include "TRACE/tracemf.h"
5 #include "artdaq-core/Data/Fragment.hh"
7 #include "artdaq/DAQrate/detail/RoutingPacket.hh"
15 #include <unordered_set>
85 std::unique_lock<std::mutex> lk(tokens_mutex_);
120 bool CacheHasRoute(artdaq::Fragment::sequence_id_t seq)
const {
return routing_cache_.count(seq) != 0; }
154 void TrimRoutingCache();
157 struct RoutingCacheEntry
159 bool is_valid{
false};
160 int destination_rank{-1};
161 Fragment::sequence_id_t sequence_id{artdaq::Fragment::InvalidSequenceID};
162 int requesting_rank{-1};
163 bool included_in_table{
false};
165 RoutingCacheEntry() {}
166 RoutingCacheEntry(Fragment::sequence_id_t seq,
int dest,
int source)
167 : is_valid(true), destination_rank(dest), sequence_id(seq), requesting_rank(source) {}
169 std::map<Fragment::sequence_id_t, std::vector<RoutingCacheEntry>> routing_cache_;
170 size_t routing_cache_max_size_;
171 mutable std::mutex routing_cache_mutex_;
172 std::atomic<size_t> max_token_count_;
173 mutable std::mutex tokens_mutex_;
177 #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.