1 #define TRACE_NAME "NthEventPolicy"
2 #include "artdaq/RoutingPolicies/RoutingMasterPolicy.hh"
3 #include "artdaq/RoutingPolicies/PolicyMacros.hh"
4 #include "fhiclcpp/ParameterSet.h"
5 #include "cetlib_except/exception.h"
38 , nth_(ps.get<size_t>(
"nth_event"))
39 , nth_rank_(ps.get<int>(
"target_receiver"))
41 if (nth_ == 0)
throw cet::exception(
"NthEvent_policy") <<
"nth_event must be greater than 0!";
52 auto tokens = getTokensSnapshot();
53 std::map<int, int> table;
54 for (
auto token : *tokens.get())
58 if (table.count(nth_rank_) == 0) table[nth_rank_] = 0;
61 detail::RoutingPacket output;
62 TLOG(5) <<
"table[nth_rank_]=" << (table[nth_rank_])
63 <<
", Next nth=" << (((next_sequence_id_ / nth_) + 1) * nth_)
64 <<
", max seq=" << (next_sequence_id_ + table.size() - 1) ;
65 auto endCondition = table.size() < GetReceiverCount() || (table[nth_rank_] <= 0 && (next_sequence_id_ % nth_ == 0 || ((next_sequence_id_ / nth_) + 1) * nth_ < next_sequence_id_ + table.size() - 1));
70 TLOG(5) <<
"nth_=" << nth_
71 <<
", nth_rank=" << nth_rank_
73 <<
", next_sequence_id=" << next_sequence_id_;
74 if (next_sequence_id_ % nth_ == 0)
76 TLOG(5) <<
"Diverting event " << next_sequence_id_ <<
" to EVB " << nth_rank_ ;
80 if (r.first != nth_rank_) {
81 TLOG(5) <<
"Sending event " << next_sequence_id_ <<
" to EVB " << r.first ;
83 if (!endCondition) endCondition = r.second == 1;
87 TLOG(5) <<
"table[nth_rank_]=" << table[nth_rank_]
88 <<
", Next nth=" << (((next_sequence_id_ / nth_) + 1) * nth_)
89 <<
", max seq=" << (next_sequence_id_ + table.size() - 1) ;
90 endCondition = endCondition || (table[nth_rank_] <= 0 && (next_sequence_id_ % nth_ == 0 || (next_sequence_id_ / nth_) * nth_ + nth_ < next_sequence_id_ + table.size() - 1));
95 for (
auto i = 0; i < r.second; ++i)
97 tokens->push_back(r.first);
100 addUnusedTokens(std::move(tokens));
NthEventPolicy(fhicl::ParameterSet ps)
NthEventPolicy Constructor.
An example RoutingMasterPolicy 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.