Skip to content

Commit dac08f3

Browse files
committed
DPL: ask a record how many inputs it holds, rather than the container
The relayer tests and benchmarks reach into the consumed record with .size() and .at(), which pins them to the record being a vector. Both operator[] and a count_inputs pipe work on anything the relayer might hand back -- a vector of per-input sets, or an arena holding them in one buffer -- so a change of storage leaves this code untouched instead of rewriting thirty call sites.
1 parent 5236336 commit dac08f3

3 files changed

Lines changed: 39 additions & 22 deletions

File tree

Framework/Core/include/Framework/DataModelViews.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@ struct count_payloads {
4949
}
5050
};
5151

52+
// How many inputs a consumed record holds. A record is either a vector of
53+
// per-input message sets or an arena keeping them in one buffer; both answer
54+
// this, but they spell it differently, so ask through here and callers stay put
55+
// when the storage underneath them changes.
56+
struct count_inputs {
57+
// ends the pipeline, returns the number of inputs
58+
template <typename R>
59+
friend size_t operator|(R&& r, count_inputs self)
60+
{
61+
if constexpr (requires { r.numInputs(); }) {
62+
return r.numInputs();
63+
} else {
64+
return r.size();
65+
}
66+
}
67+
};
68+
5269
struct count_parts {
5370
// ends the pipeline, returns the number of parts
5471
template <typename R>

Framework/Core/test/benchmark_DataRelayer.cxx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ static void BM_RelaySingleSlot(benchmark::State& state)
139139
assert(ready[0].slot.index == 0);
140140
assert(ready[0].op == CompletionPolicy::CompletionOp::Consume);
141141
auto result = relayer.consumeAllInputsForTimeslice(ready[0].slot);
142-
assert(result.size() == 1);
143-
assert((result.at(0) | count_parts{}) == 1);
142+
assert((result | count_inputs{}) == 1);
143+
assert((result[0] | count_parts{}) == 1);
144144
inflightMessages.assign(std::make_move_iterator(result[0].begin()),
145145
std::make_move_iterator(result[0].end()));
146146
}
@@ -196,8 +196,8 @@ static void BM_RelayMultipleSlots(benchmark::State& state)
196196
assert(ready.size() == 1);
197197
assert(ready[0].op == CompletionPolicy::CompletionOp::Consume);
198198
auto result = relayer.consumeAllInputsForTimeslice(ready[0].slot);
199-
assert(result.size() == 1);
200-
assert((result.at(0) | count_parts{}) == 1);
199+
assert((result | count_inputs{}) == 1);
200+
assert((result[0] | count_parts{}) == 1);
201201
inflightMessages.assign(std::make_move_iterator(result[0].begin()),
202202
std::make_move_iterator(result[0].end()));
203203
}
@@ -271,9 +271,9 @@ static void BM_RelayMultipleRoutes(benchmark::State& state)
271271
assert(ready.size() == 1);
272272
assert(ready[0].op == CompletionPolicy::CompletionOp::Consume);
273273
auto result = relayer.consumeAllInputsForTimeslice(ready[0].slot);
274-
assert(result.size() == 2);
275-
assert((result.at(0) | count_parts{}) == 1);
276-
assert((result.at(1) | count_parts{}) == 1);
274+
assert((result | count_inputs{}) == 2);
275+
assert((result[0] | count_parts{}) == 1);
276+
assert((result[1] | count_parts{}) == 1);
277277
inflightMessages.assign(std::make_move_iterator(result[0].begin()),
278278
std::make_move_iterator(result[0].end()));
279279
inflightMessages.insert(inflightMessages.end(),

Framework/Core/test/test_DataRelayer.cxx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ TEST_CASE("DataRelayer")
158158
REQUIRE(payload.get() == nullptr);
159159
auto result = relayer.consumeAllInputsForTimeslice(ready[0].slot);
160160
// one MessageSet with one PartRef with header and payload
161-
REQUIRE(result.size() == 1);
162-
REQUIRE((result.at(0) | count_parts{}) == 1);
161+
REQUIRE((result | count_inputs{}) == 1);
162+
REQUIRE((result[0] | count_parts{}) == 1);
163163
}
164164

165165
//
@@ -208,8 +208,8 @@ TEST_CASE("DataRelayer")
208208
REQUIRE(payload.get() == nullptr);
209209
auto result = relayer.consumeAllInputsForTimeslice(ready[0].slot);
210210
// one MessageSet with one PartRef with header and payload
211-
REQUIRE(result.size() == 1);
212-
REQUIRE((result.at(0) | count_parts{}) == 1);
211+
REQUIRE((result | count_inputs{}) == 1);
212+
REQUIRE((result[0] | count_parts{}) == 1);
213213
}
214214

215215
// This test a more complicated set of inputs, and verifies that data is
@@ -288,9 +288,9 @@ TEST_CASE("DataRelayer")
288288

289289
auto result = relayer.consumeAllInputsForTimeslice(ready[0].slot);
290290
// two MessageSets, each with one PartRef
291-
REQUIRE(result.size() == 2);
292-
REQUIRE((result.at(0) | count_parts{}) == 1);
293-
REQUIRE((result.at(1) | count_parts{}) == 1);
291+
REQUIRE((result | count_inputs{}) == 2);
292+
REQUIRE((result[0] | count_parts{}) == 1);
293+
REQUIRE((result[1] | count_parts{}) == 1);
294294
}
295295

296296
// This test a more complicated set of inputs, and verifies that data is
@@ -458,8 +458,8 @@ TEST_CASE("DataRelayer")
458458
auto result1 = relayer.consumeAllInputsForTimeslice(ready[0].slot);
459459
auto result2 = relayer.consumeAllInputsForTimeslice(ready[1].slot);
460460
// One for the header, one for the payload
461-
REQUIRE(result1.size() == 1);
462-
REQUIRE(result2.size() == 1);
461+
REQUIRE((result1 | count_inputs{}) == 1);
462+
REQUIRE((result2 | count_inputs{}) == 1);
463463
}
464464

465465
// This the any policy. Even when there are two inputs, given the any policy
@@ -776,7 +776,7 @@ TEST_CASE("DataRelayer")
776776
auto messageSet = relayer.consumeAllInputsForTimeslice(ready[0].slot);
777777
// we have one input route and thus one message set containing pairs for all
778778
// payloads
779-
REQUIRE(messageSet.size() == 1);
779+
REQUIRE((messageSet | count_inputs{}) == 1);
780780
REQUIRE((messageSet[0] | count_parts{}) == nSplitParts);
781781
REQUIRE((messageSet[0] | get_num_payloads{0}) == 1);
782782
}
@@ -838,7 +838,7 @@ TEST_CASE("DataRelayer")
838838
REQUIRE(ready[0].op == CompletionPolicy::CompletionOp::Consume);
839839
auto messageSet = relayer.consumeAllInputsForTimeslice(ready[0].slot);
840840
// we have one input route
841-
REQUIRE(messageSet.size() == 1);
841+
REQUIRE((messageSet | count_inputs{}) == 1);
842842
// one message set containing number of added sequences of messages
843843
REQUIRE((messageSet[0] | count_parts{}) == sequenceSize.size());
844844
size_t counter = 0;
@@ -930,8 +930,8 @@ TEST_CASE("DataRelayer")
930930
REQUIRE(ready[0].op == CompletionPolicy::CompletionOp::Consume);
931931

932932
auto result = relayer.consumeAllInputsForTimeslice(ready[0].slot);
933-
REQUIRE(result.size() == 1);
934-
REQUIRE((result.at(0) | count_parts{}) == 1);
933+
REQUIRE((result | count_inputs{}) == 1);
934+
REQUIRE((result[0] | count_parts{}) == 1);
935935
}
936936

937937
SECTION("ProcessDanglingInputsSkipsWhenDataPresent")
@@ -1079,7 +1079,7 @@ TEST_CASE("DataRelayer")
10791079
REQUIRE(ready[0].op == CompletionPolicy::CompletionOp::Consume);
10801080

10811081
auto result = relayer.consumeAllInputsForTimeslice(ready[0].slot);
1082-
REQUIRE(result.size() == 3);
1082+
REQUIRE((result | count_inputs{}) == 3);
10831083

10841084
std::array<size_t, 3> const expectedParts = {2, 2, 1};
10851085
auto checkContents = [&]() {
@@ -1200,7 +1200,7 @@ TEST_CASE("DataRelayer")
12001200
REQUIRE(ready[0].op == CompletionPolicy::CompletionOp::Consume);
12011201

12021202
auto result = relayer.consumeAllInputsForTimeslice(ready[0].slot);
1203-
REQUIRE(result.size() == 3);
1203+
REQUIRE((result | count_inputs{}) == 3);
12041204
REQUIRE((result[1] | count_parts{}) == 1);
12051205
for (size_t i : {0u, 2u}) {
12061206
REQUIRE((result[i] | count_parts{}) == 1);

0 commit comments

Comments
 (0)