1 #define TRACE_NAME "NthEventPolicy"
2 #include "artdaq/RoutingPolicies/PolicyMacros.hh"
3 #include "artdaq/RoutingPolicies/RoutingManagerPolicy.hh"
4 #include "cetlib_except/exception.h"
5 #include "fhiclcpp/ParameterSet.h"
42 : RoutingManagerPolicy(ps), nth_(ps.get<size_t>(
"nth_event")), nth_rank_(ps.get<int>(
"target_receiver"))
46 throw cet::exception(
"NthEvent_policy") <<
"nth_event must be greater than 0!";
58 auto tokens = getTokensSnapshot();
59 std::map<int, int> table;
60 for (
auto token : *tokens)
64 if (table.count(nth_rank_) == 0)
70 detail::RoutingPacket output;
71 TLOG(5) <<
"table[nth_rank_]=" << (table[nth_rank_])
72 <<
", Next nth=" << (((next_sequence_id_ / nth_) + 1) * nth_)
73 <<
", max seq=" << (next_sequence_id_ + table.size() - 1);
75 table.size() < GetReceiverCount() ||
76 (table[nth_rank_] <= 0 && (next_sequence_id_ % nth_ == 0 || ((next_sequence_id_ / nth_) + 1) * nth_ <
77 next_sequence_id_ + table.size() - 1));
82 TLOG(5) <<
"nth_=" << nth_ <<
", nth_rank=" << nth_rank_ <<
", r=" << r.first
83 <<
", next_sequence_id=" << next_sequence_id_;
84 if (next_sequence_id_ % nth_ == 0)
86 TLOG(5) <<
"Diverting event " << next_sequence_id_ <<
" to EVB " << nth_rank_;
87 output.emplace_back(detail::RoutingPacketEntry(next_sequence_id_++, nth_rank_));
90 if (r.first != nth_rank_)
92 TLOG(5) <<
"Sending event " << next_sequence_id_ <<
" to EVB " << r.first;
93 output.emplace_back(detail::RoutingPacketEntry(next_sequence_id_++, r.first));
96 endCondition = r.second == 1;
101 TLOG(5) <<
"table[nth_rank_]=" << table[nth_rank_]
102 <<
", Next nth=" << (((next_sequence_id_ / nth_) + 1) * nth_)
103 <<
", max seq=" << (next_sequence_id_ + table.size() - 1);
104 endCondition = endCondition || (table[nth_rank_] <= 0 && (next_sequence_id_ % nth_ == 0 ||
105 (next_sequence_id_ / nth_) * nth_ + nth_ <
106 next_sequence_id_ + table.size() - 1));
111 for (
auto i = 0; i < r.second; ++i)
113 tokens->push_back(r.first);
116 addUnusedTokens(std::move(tokens));
An example RoutingManagerPolicy which redirects every Nth event to a desginated destination. Other events are Round-Robin'ed to the other configured destinations.
detail::RoutingPacket GetCurrentTable() override
Construct a Routing Table using the current tokens.
NthEventPolicy(const fhicl::ParameterSet &ps)
NthEventPolicy Constructor.