Skip to content

Commit cbc8a9f

Browse files
authored
Simplify specification of product-query fields (#373)
1 parent b9c382c commit cbc8a9f

31 files changed

+195
-239
lines changed

phlex/core/product_query.hpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "phlex/model/product_specification.hpp"
66
#include "phlex/model/type_id.hpp"
77

8+
#include <concepts>
89
#include <optional>
910
#include <string>
1011
#include <tuple>
@@ -15,16 +16,17 @@ using namespace phlex::experimental::literals;
1516

1617
namespace phlex {
1718
namespace detail {
18-
template <typename T>
19-
requires std::is_same_v<experimental::identifier,
20-
T> // has to be a template for static_assert(false)
19+
// The required_creator_name has to be a template for static_assert(false)
20+
template <std::same_as<experimental::identifier> T>
2121
class required_creator_name {
2222
public:
2323
required_creator_name()
2424
{
2525
static_assert(false, "The creator name has not been set in this product_query.");
2626
}
27-
required_creator_name(T&& rhs) : content_(std::move(rhs))
27+
template <typename U>
28+
requires std::constructible_from<T, U>
29+
required_creator_name(U&& rhs) : content_(std::forward_like<T>(rhs))
2830
{
2931
if (content_.empty()) {
3032
throw std::runtime_error("Cannot specify product with empty creator name.");
@@ -37,16 +39,17 @@ namespace phlex {
3739
experimental::identifier content_;
3840
};
3941

40-
template <typename T>
41-
requires std::is_same_v<experimental::identifier,
42-
T> // has to be a template for static_assert(false)
42+
// The required_layer_name has to be a template for static_assert(false)
43+
template <std::same_as<experimental::identifier> T>
4344
class required_layer_name {
4445
public:
4546
required_layer_name()
4647
{
4748
static_assert(false, "The layer name has not been set in this product_query.");
4849
}
49-
required_layer_name(T&& rhs) : content_(std::move(rhs))
50+
template <typename U>
51+
requires std::constructible_from<T, U>
52+
required_layer_name(U&& rhs) : content_(std::forward_like<T>(rhs))
5053
{
5154
if (content_.empty()) {
5255
throw std::runtime_error("Cannot specify the empty string as a data layer.");

phlex/model/identifier.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace phlex::experimental {
3434
explicit identifier(std::string&& str);
3535

3636
// char const* calls string_view
37-
explicit identifier(char const* lit) : identifier(std::string_view(lit)) {}
37+
identifier(char const* lit) : identifier(std::string_view(lit)) {}
3838

3939
identifier& operator=(identifier const& rhs) = default;
4040
identifier& operator=(identifier&& rhs) noexcept = default;

test/allowed_families.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,22 @@ TEST_CASE("Testing families", "[data model]")
4343

4444
// Wire up providers for each level
4545
g.provide("run_id_provider", provide_index, concurrency::unlimited)
46-
.output_product(product_query{.creator = "dummy"_id, .layer = "run"_id, .suffix = "id"_id});
46+
.output_product(product_query{.creator = "dummy", .layer = "run", .suffix = "id"});
4747
g.provide("subrun_id_provider", provide_index, concurrency::unlimited)
48-
.output_product(product_query{.creator = "dummy"_id, .layer = "subrun"_id, .suffix = "id"_id});
48+
.output_product(product_query{.creator = "dummy", .layer = "subrun", .suffix = "id"});
4949
g.provide("event_id_provider", provide_index, concurrency::unlimited)
50-
.output_product(product_query{.creator = "dummy"_id, .layer = "event"_id, .suffix = "id"_id});
50+
.output_product(product_query{.creator = "dummy", .layer = "event", .suffix = "id"});
5151

5252
g.observe("se", check_two_ids)
53-
.input_family(product_query{.creator = "dummy"_id, .layer = "subrun"_id, .suffix = "id"_id},
54-
product_query{.creator = "dummy"_id, .layer = "event"_id, .suffix = "id"_id});
53+
.input_family(product_query{.creator = "dummy", .layer = "subrun", .suffix = "id"},
54+
product_query{.creator = "dummy", .layer = "event", .suffix = "id"});
5555
g.observe("rs", check_two_ids)
56-
.input_family(product_query{.creator = "dummy"_id, .layer = "run"_id, .suffix = "id"_id},
57-
product_query{.creator = "dummy"_id, .layer = "subrun"_id, .suffix = "id"_id});
56+
.input_family(product_query{.creator = "dummy", .layer = "run", .suffix = "id"},
57+
product_query{.creator = "dummy", .layer = "subrun", .suffix = "id"});
5858
g.observe("rse", check_three_ids)
59-
.input_family(product_query{.creator = "dummy"_id, .layer = "run"_id, .suffix = "id"_id},
60-
product_query{.creator = "dummy"_id, .layer = "subrun"_id, .suffix = "id"_id},
61-
product_query{.creator = "dummy"_id, .layer = "event"_id, .suffix = "id"_id});
59+
.input_family(product_query{.creator = "dummy", .layer = "run", .suffix = "id"},
60+
product_query{.creator = "dummy", .layer = "subrun", .suffix = "id"},
61+
product_query{.creator = "dummy", .layer = "event", .suffix = "id"});
6262
g.execute();
6363

6464
CHECK(g.execution_count("se") == 1ull);

test/benchmarks/benchmarks_provider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ PHLEX_REGISTER_PROVIDERS(s)
44
{
55
using namespace phlex;
66
s.provide("provide_id", [](data_cell_index const& id) { return id; })
7-
.output_product(product_query{.creator = "input"_id, .layer = "event"_id, .suffix = "id"_id});
7+
.output_product(product_query{.creator = "input", .layer = "event", .suffix = "id"});
88
}

test/benchmarks/last_index.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ namespace {
1010
PHLEX_REGISTER_ALGORITHMS(m, config)
1111
{
1212
m.transform("last_index", last_index, concurrency::unlimited)
13-
.input_family(product_query{.creator = "input"_id, .layer = "event"_id, .suffix = "id"_id})
13+
.input_family(product_query{.creator = "input", .layer = "event", .suffix = "id"})
1414
.output_products(config.get<std::string>("produces", "a"));
1515
}

test/benchmarks/read_id.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ namespace {
1010
PHLEX_REGISTER_ALGORITHMS(m)
1111
{
1212
m.observe("read_id", read_id, concurrency::unlimited)
13-
.input_family(product_query{.creator = "input"_id, .layer = "event"_id, .suffix = "id"_id});
13+
.input_family(product_query{.creator = "input", .layer = "event", .suffix = "id"});
1414
}

test/cached_execution.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,37 +61,34 @@ TEST_CASE("Cached function calls", "[data model]")
6161

6262
// Register providers
6363
g.provide("provide_number", provide_number, concurrency::unlimited)
64-
.output_product(product_query{.creator = "input"_id, .layer = "run"_id, .suffix = "number"_id});
64+
.output_product(product_query{.creator = "input", .layer = "run", .suffix = "number"});
6565
g.provide("provide_another", provide_another, concurrency::unlimited)
66-
.output_product(
67-
product_query{.creator = "input"_id, .layer = "subrun"_id, .suffix = "another"_id});
66+
.output_product(product_query{.creator = "input", .layer = "subrun", .suffix = "another"});
6867
g.provide("provide_still", provide_still, concurrency::unlimited)
69-
.output_product(
70-
product_query{.creator = "input"_id, .layer = "event"_id, .suffix = "still"_id});
68+
.output_product(product_query{.creator = "input", .layer = "event", .suffix = "still"});
7169

7270
g.transform("A1", call_one, concurrency::unlimited)
73-
.input_family(product_query{.creator = "input"_id, .layer = "run"_id, .suffix = "number"_id})
71+
.input_family(product_query{.creator = "input", .layer = "run", .suffix = "number"})
7472
.output_products("one");
7573
g.transform("A2", call_one, concurrency::unlimited)
76-
.input_family(product_query{.creator = "A1"_id, .layer = "run"_id, .suffix = "one"_id})
74+
.input_family(product_query{.creator = "A1", .layer = "run", .suffix = "one"})
7775
.output_products("used_one");
7876
g.transform("A3", call_one, concurrency::unlimited)
79-
.input_family(product_query{.creator = "A2"_id, .layer = "run"_id, .suffix = "used_one"_id})
77+
.input_family(product_query{.creator = "A2", .layer = "run", .suffix = "used_one"})
8078
.output_products("done_one");
8179

8280
g.transform("B1", call_two, concurrency::unlimited)
83-
.input_family(
84-
product_query{.creator = "A1"_id, .layer = "run"_id, .suffix = "one"_id},
85-
product_query{.creator = "input"_id, .layer = "subrun"_id, .suffix = "another"_id})
81+
.input_family(product_query{.creator = "A1", .layer = "run", .suffix = "one"},
82+
product_query{.creator = "input", .layer = "subrun", .suffix = "another"})
8683
.output_products("two");
8784
g.transform("B2", call_two, concurrency::unlimited)
88-
.input_family(product_query{.creator = "A2"_id, .layer = "run"_id, .suffix = "used_one"_id},
89-
product_query{.creator = "B1"_id, .layer = "subrun"_id, .suffix = "two"_id})
85+
.input_family(product_query{.creator = "A2", .layer = "run", .suffix = "used_one"},
86+
product_query{.creator = "B1", .layer = "subrun", .suffix = "two"})
9087
.output_products("used_two");
9188

9289
g.transform("C", call_two, concurrency::unlimited)
93-
.input_family(product_query{.creator = "B2"_id, .layer = "subrun"_id, .suffix = "used_two"_id},
94-
product_query{.creator = "input"_id, .layer = "event"_id, .suffix = "still"_id})
90+
.input_family(product_query{.creator = "B2", .layer = "subrun", .suffix = "used_two"},
91+
product_query{.creator = "input", .layer = "event", .suffix = "still"})
9592
.output_products("three");
9693

9794
g.execute();

test/class_registration.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,20 @@ namespace {
6060
TEST_CASE("Call non-framework functions", "[programming model]")
6161
{
6262
std::array const product_names{
63-
product_query{.creator = "input"_id, .layer = "job"_id, .suffix = "number"_id},
64-
product_query{.creator = "input"_id, .layer = "job"_id, .suffix = "temperature"_id},
65-
product_query{.creator = "input"_id, .layer = "job"_id, .suffix = "name"_id}};
63+
product_query{.creator = "input", .layer = "job", .suffix = "number"},
64+
product_query{.creator = "input", .layer = "job", .suffix = "temperature"},
65+
product_query{.creator = "input", .layer = "job", .suffix = "name"}};
6666
std::array const oproduct_names{"onumber"s, "otemperature"s, "oname"s};
6767

6868
experimental::framework_graph g{data_cell_index::base_ptr()};
6969

7070
// Register providers for the input products
7171
g.provide("provide_number", provide_number, concurrency::unlimited)
72-
.output_product(product_query{.creator = "input"_id, .layer = "job"_id, .suffix = "number"_id});
72+
.output_product(product_query{.creator = "input", .layer = "job", .suffix = "number"});
7373
g.provide("provide_temperature", provide_temperature, concurrency::unlimited)
74-
.output_product(
75-
product_query{.creator = "input"_id, .layer = "job"_id, .suffix = "temperature"_id});
74+
.output_product(product_query{.creator = "input", .layer = "job", .suffix = "temperature"});
7675
g.provide("provide_name", provide_name, concurrency::unlimited)
77-
.output_product(product_query{.creator = "input"_id, .layer = "job"_id, .suffix = "name"_id});
76+
.output_product(product_query{.creator = "input", .layer = "job", .suffix = "name"});
7877

7978
auto glueball = g.make<A>();
8079
SECTION("No framework")

test/configuration.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ TEST_CASE("Retrieve product_query", "[config]")
5252
configuration config{underlying_config};
5353

5454
auto input_query = config.get<product_query>("input");
55-
CHECK(input_query.match(
56-
product_query{.creator = "tracks_alg"_id, .layer = "job"_id, .suffix = "tracks"_id}));
55+
CHECK(
56+
input_query.match(product_query{.creator = "tracks_alg", .layer = "job", .suffix = "tracks"}));
5757
CHECK_THROWS_WITH(config.get<product_query>("malformed1"),
5858
ContainsSubstring("Error retrieving parameter 'malformed1'") &&
5959
ContainsSubstring("not a string"));

test/demo-giantdata/unfold_transform_fold.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ TEST_CASE("Unfold-transform-fold pipeline", "[concurrency][unfold][fold]")
5959
spill_index.parent()->number(),
6060
spill_index.number());
6161
})
62-
.output_product(product_query{.creator = "input"_id, .layer = "spill"_id, .suffix = "wgen"_id});
62+
.output_product(product_query{.creator = "input", .layer = "spill", .suffix = "wgen"});
6363

6464
g.unfold<demo::WaveformGenerator>(
6565
"WaveformGenerator",
@@ -71,7 +71,7 @@ TEST_CASE("Unfold-transform-fold pipeline", "[concurrency][unfold][fold]")
7171
},
7272
concurrency::unlimited,
7373
"APA")
74-
.input_family(product_query{.creator = "input"_id, .layer = "spill"_id, .suffix = "wgen"_id})
74+
.input_family(product_query{.creator = "input", .layer = "spill", .suffix = "wgen"})
7575
.output_products("waves_in_apa");
7676

7777
// Add the transform node to the graph
@@ -80,8 +80,8 @@ TEST_CASE("Unfold-transform-fold pipeline", "[concurrency][unfold][fold]")
8080
};
8181

8282
g.transform("clamp_node", wrapped_user_function, concurrency::unlimited)
83-
.input_family(product_query{
84-
.creator = "WaveformGenerator"_id, .layer = "APA"_id, .suffix = "waves_in_apa"_id})
83+
.input_family(
84+
product_query{.creator = "WaveformGenerator", .layer = "APA", .suffix = "waves_in_apa"})
8585
.output_products("clamped_waves");
8686

8787
// Add the fold node with instrumentation to detect pipelined execution
@@ -98,8 +98,7 @@ TEST_CASE("Unfold-transform-fold pipeline", "[concurrency][unfold][fold]")
9898
},
9999
concurrency::unlimited,
100100
"spill")
101-
.input_family(
102-
product_query{.creator = "clamp_node"_id, .layer = "APA"_id, .suffix = "clamped_waves"_id})
101+
.input_family(product_query{.creator = "clamp_node", .layer = "APA", .suffix = "clamped_waves"})
103102
.output_products("summed_waveforms");
104103

105104
// Execute the graph

0 commit comments

Comments
 (0)