diff --git a/form/README.md b/form/README.md index a84ae0538..785b687a2 100644 --- a/form/README.md +++ b/form/README.md @@ -2,6 +2,19 @@ Prototype development for I/O infrastructure supporting Phlex +## Product suffix text + +The Phlex FORM writer copies the textual value of each product specification's +`suffix_t` into FORM's product label. An explicit empty suffix (`empty_string{}`) +is written as `""`; a named suffix is written with its original spelling, including +case and underscores (for example, `Hits_2`). Empty text is a concrete product +suffix, not an omitted product or an unrestricted selector. + +The persisted representation is unchanged: the product dictionary retains that +suffix text in `product_name`, and its `container_name` remains `row_space/suffix`. +An empty suffix therefore retains the trailing `/`, while a named suffix retains +its text after `/`. No placeholder name or file-format migration is introduced. + ## build `cmake -DUSE_FORM_ALONE=ON -DFORM_USE_ROOT_STORAGE=ON ../phlex/ ; make` diff --git a/phlex/core/consumer.hpp b/phlex/core/consumer.hpp index 0694ea7d9..54c56ea78 100644 --- a/phlex/core/consumer.hpp +++ b/phlex/core/consumer.hpp @@ -19,6 +19,13 @@ namespace phlex::detail { enum class require_layers : char { multi_input_only, always }; + + /// Base class of nodes that consume data products. + /// + /// Accessor contract: `name()` is the complete node name. `name().plugin()` is its plugin + /// component, which is absent (`std::nullopt`) for an unqualified name, such as one registered + /// without a configuration; it is never an invalid empty `identifier`. + /// `name().algorithm()` is the non-empty algorithm component. class PHLEX_CORE_EXPORT consumer { using layer_check_node_t = tbb::flow::multifunction_node>; diff --git a/phlex/core/detail/make_algorithm_name.cpp b/phlex/core/detail/make_algorithm_name.cpp index 8bc7f2d0c..7eff0c172 100644 --- a/phlex/core/detail/make_algorithm_name.cpp +++ b/phlex/core/detail/make_algorithm_name.cpp @@ -7,6 +7,10 @@ #include namespace phlex::experimental::internal { + // The plugin component is absent only when there is no configuration. A + // configuration must supply a non-empty 'module_label': a missing label is an error reported by + // the configuration, and an empty label is rejected by algorithm_name::create rather than + // treated as an absent plugin. algorithm_name make_algorithm_name(configuration const* config, std::string_view name) { std::optional plugin_label; diff --git a/phlex/core/producer.hpp b/phlex/core/producer.hpp index 7b84a931b..a5f374697 100644 --- a/phlex/core/producer.hpp +++ b/phlex/core/producer.hpp @@ -9,6 +9,9 @@ #include namespace phlex::detail { + /// Independent producer interface used by the catalog, including translators. + /// Outputs carry explicit empty or named `suffix_t` values; `name()` retains the creator's + /// plugin component. The producer must outlive edges using its borrowed output port. class PHLEX_CORE_EXPORT producer { public: virtual ~producer() = default; diff --git a/phlex/core/producer_catalog.cpp b/phlex/core/producer_catalog.cpp index e299502b4..5d9c1da86 100644 --- a/phlex/core/producer_catalog.cpp +++ b/phlex/core/producer_catalog.cpp @@ -28,7 +28,7 @@ namespace { using named_output_port = producer_catalog::named_output_port; bool providers_only(product_selector const& query, - std::multimap const& producers, + std::multimap const& producers, identifier const& stage) { if (query.stage.has_value() && query.stage.value() != "CURRENT"_idq && diff --git a/phlex/core/producer_catalog.hpp b/phlex/core/producer_catalog.hpp index 867c651ec..fa3ab3388 100644 --- a/phlex/core/producer_catalog.hpp +++ b/phlex/core/producer_catalog.hpp @@ -19,6 +19,9 @@ namespace phlex::detail { class producer; using product_suffix_t = phlex::experimental::suffix_t; + /// Catalogs independent producers by their explicit empty or named `suffix_t` outputs. + /// An omitted selector suffix searches all keys; an explicit suffix searches only that key. + /// Creator values retain both plugin and algorithm components, and output ports are borrowed. class PHLEX_CORE_EXPORT producer_catalog { public: explicit producer_catalog(std::span producers); @@ -36,7 +39,7 @@ namespace phlex::detail { auto values() const { return producers_ | std::views::values; } private: - std::multimap producers_; + std::multimap producers_; }; } diff --git a/phlex/core/product_selector.cpp b/phlex/core/product_selector.cpp index 70ac5c1d2..b1ea75cb3 100644 --- a/phlex/core/product_selector.cpp +++ b/phlex/core/product_selector.cpp @@ -73,7 +73,7 @@ namespace phlex { bool product_selector::creator_match(experimental::algorithm_name const& alg) const { if (!creator) { - return true; // empty creator matches everything + return true; // an omitted creator criterion matches everything } experimental::identifier const& creator{*(this->creator)}; return alg.plugin() == creator || alg.algorithm() == creator; diff --git a/phlex/core/product_selector.hpp b/phlex/core/product_selector.hpp index 08b48f111..f36f6bcd1 100644 --- a/phlex/core/product_selector.hpp +++ b/phlex/core/product_selector.hpp @@ -93,11 +93,16 @@ namespace phlex { /// from a configuration object with @c config.get(key). struct PHLEX_CORE_EXPORT product_selector { /// Plugin label (configuration key) or algorithm name of the product's creator. + /// An omitted creator is unrestricted. + /// A supplied name matches either the plugin or the algorithm of a specification's creator. detail::creator_name creator; /// Data layer of the product. Required for every input of multi-input algorithms, /// folds and unfolds; products from other layers are not delivered. detail::layer_name layer; /// Product suffix, as given to @c output_product_suffixes(...). + /// Omitted matches any suffix; empty matches only empty; named matches only that name. + /// C-string literals convert implicitly; runtime strings require explicit suffix_t construction. + /// Equality, ordering, and diagnostics distinguish all three states. std::optional suffix; /// Stage that created the product; @c "CURRENT" means the job's own stage. std::optional stage; diff --git a/phlex/core/upstream_predicates.hpp b/phlex/core/upstream_predicates.hpp index e1e7471c9..7ae7a473a 100644 --- a/phlex/core/upstream_predicates.hpp +++ b/phlex/core/upstream_predicates.hpp @@ -36,6 +36,10 @@ namespace phlex::detail { return experimental_when({std::forward(names)...}); } + // Fluent suffix registration is textual: the strings given here, including the empty string + // and the default used when no suffixes are registered, stay strings in the registrar. They + // become `suffix_t` values (empty text as `empty_string`, non-empty text as a named + // identifier) when `to_product_specifications()` creates the product specifications. template requires(NumberOutputProducts > 0) void output_product_suffixes(std::array outputs) diff --git a/phlex/model/algorithm_name.hpp b/phlex/model/algorithm_name.hpp index c1dc20bcd..97b2f17de 100644 --- a/phlex/model/algorithm_name.hpp +++ b/phlex/model/algorithm_name.hpp @@ -10,9 +10,25 @@ #include namespace phlex::experimental { + /// The creator of a product or the name of an algorithm. + /// + /// An algorithm name always has a non-empty algorithm component. Its plugin component is + /// optional: either a non-empty plugin name or absent (for an unqualified name). A + /// default-constructed algorithm name is not valid, so one must always be constructed from a + /// name. class PHLEX_MODEL_EXPORT algorithm_name { public: - /// Parse text that is either `algorithm` or `plugin_label:algorithm`. + algorithm_name() = delete; + + /// Parses a creator name, which is either `algorithm` or `plugin_label:algorithm`. + /// + /// Accepted forms: + /// - `algorithm`: the plugin component is absent. + /// - `plugin_label:algorithm`: both components are non-empty identifiers. + /// + /// Each component must satisfy the character rules of `identifier`. Rejected inputs include + /// the empty string, a leading colon (`:algorithm`), a trailing colon (`plugin_label:`), and + /// any empty component. /// /// Throws `std::invalid_argument` if `spec` is malformed. The message quotes the offending /// text and says which part of the name is invalid and why. Only the first problem found is diff --git a/phlex/model/handle.hpp b/phlex/model/handle.hpp index 15e9e406d..39022836a 100644 --- a/phlex/model/handle.hpp +++ b/phlex/model/handle.hpp @@ -7,6 +7,7 @@ #include +#include #include #include #include @@ -54,6 +55,10 @@ namespace phlex { using const_reference = value_type const&; using const_pointer = value_type const*; + /// Borrowed textual views of the creator's components. Each view refers to the text owned + /// by the product specification that the handle references, so it is valid only while that + /// specification (and thus the handle's source) is alive. No copy is stored. A component that + /// is absent (the plugin of an unqualified creator) is an empty view. struct algorithm_name_view { std::string_view plugin; std::string_view algorithm; @@ -87,7 +92,9 @@ namespace phlex { // NOLINTEND(google-explicit-constructor) auto const& data_cell_index() const noexcept { return *index_; } - // Product specification information + // Product specification information. The handle exposes borrowed textual views, not the + // domain types (`suffix_t`, `identifier`), so callers need not depend on them. + /// Views of the creator's plugin and algorithm names. Absent components are empty views. algorithm_name_view creator() const noexcept { auto const& creator = spec_->creator(); @@ -95,6 +102,7 @@ namespace phlex { return {plugin ? std::string_view(*plugin) : std::string_view{}, std::string_view(creator.algorithm())}; } + /// View of the suffix text; empty for the explicit empty suffix. std::string_view suffix() const noexcept { return spec_->suffix().text(); } std::string_view layer() const noexcept { return std::string_view(index_->layer_name()); } std::string_view stage() const noexcept { return std::string_view(*stage_); } diff --git a/phlex/model/product_specification.cpp b/phlex/model/product_specification.cpp index 0014e28fc..7fdf757c3 100644 --- a/phlex/model/product_specification.cpp +++ b/phlex/model/product_specification.cpp @@ -70,6 +70,8 @@ namespace phlex::detail { { static std::string const default_product_suffix; + // Fluent suffix registration is textual; empty text becomes `empty_string` and non-empty + // text a named identifier here, when the specifications are created. if (output_suffixes.empty()) { // This happens whenever the user does not specify output_product_suffixes(...), so we // assign the default suffix to all output data products. diff --git a/phlex/model/product_specification.hpp b/phlex/model/product_specification.hpp index 9797121e1..8a0d3b1f5 100644 --- a/phlex/model/product_specification.hpp +++ b/phlex/model/product_specification.hpp @@ -16,15 +16,39 @@ namespace phlex::experimental { /// Describes a product supplied by an algorithm. /// + /// A product specification is a partial label: it carries the creator, suffix, and type of a + /// product. Its metadata combines with a concrete data-cell/provider layer to form the complete + /// label of a created product, so the layer is deliberately not a member of this class. + /// + /// The creator is a required `algorithm_name`; there is no default or creator-less + /// construction. Equality, ordering, and hashing cover the creator, suffix, and type. A + /// specification whose type is unspecified is an exact key, not a wildcard. + /// + /// The suffix is a `suffix_t`: either the explicit empty value (`empty_string`) or a named + /// `identifier`. Parsing, defaulting, formatting, equality, ordering, and hashing all preserve + /// that representation without manufacturing an empty `identifier`. The default suffix is + /// explicitly empty. It is never an omitted selection criterion, which is `std::nullopt` in a + /// product selector. + /// + /// Textual boundary: specifications supplied as text (the `creator/suffix` text accepted by + /// the text constructors, and the strings given to the fluent `output_product_suffixes(...)` + /// registration + /// API, which `phlex::detail::to_product_specifications()` converts) remain strings. Empty + /// suffix text becomes `empty_string` and non-empty suffix text becomes a named `identifier`, + /// when the specification is created. Non-empty text that is not a valid name is rejected rather + /// than stored as an empty suffix. + /// /// This source-provider construction API is experimental and may change before it is /// promoted to the stable phlex namespace. class PHLEX_MODEL_EXPORT product_specification { public: // There is no default or creator-less construction: every specification names its creator. - // Text constructors parse the `creator/suffix` form, which must contain the slash. Structural - // errors throw `std::runtime_error`; an invalid creator or suffix throws - // `std::invalid_argument`. + /// Parses `creator/suffix` text, which must contain the slash; `creator/` has an empty + /// suffix. Text without a slash, with an empty creator part (`/hits`, `/`), or empty is + /// invalid and throws `std::runtime_error`; an invalid creator or suffix throws + /// `std::invalid_argument`. Empty suffix text yields an explicit `empty_string` suffix; + /// non-empty suffix text yields a named `identifier`. // NOLINTBEGIN(google-explicit-constructor) - Implicit conversion is intentional product_specification(char const* name); product_specification(std::string const& name); @@ -32,8 +56,11 @@ namespace phlex::experimental { // NOLINTEND(google-explicit-constructor) product_specification(algorithm_name creator, suffix_t suffix, type_id type); + /// Text of the specification in the form `creator/suffix`; the type is not part of the text. std::string to_string() const; + /// The creator; always present. algorithm_name const& creator() const noexcept { return creator_; } + /// The suffix: `empty_string` or a named `identifier`. suffix_t const& suffix() const noexcept { return suffix_; } type_id type() const noexcept { return type_id_; } @@ -65,6 +92,7 @@ template <> struct std::hash { std::size_t operator()(phlex::experimental::product_specification const& spec) const noexcept { + // Hash the same components that equality compares, including whether the plugin is present. std::size_t hash = 0; auto const& plugin = spec.creator_.plugin(); boost::hash_combine(hash, plugin.has_value()); diff --git a/phlex/model/product_store.cpp b/phlex/model/product_store.cpp index ae44d860c..74d22cfda 100644 --- a/phlex/model/product_store.cpp +++ b/phlex/model/product_store.cpp @@ -53,7 +53,7 @@ namespace phlex::experimental { algorithm_name product_store::default_source() { - static algorithm_name const def = algorithm_name{"Source"}; + static algorithm_name const def = algorithm_name{"phlex_source"}; return def; } } diff --git a/phlex/model/product_store.hpp b/phlex/model/product_store.hpp index 975df8dfb..23debbabe 100644 --- a/phlex/model/product_store.hpp +++ b/phlex/model/product_store.hpp @@ -53,7 +53,10 @@ namespace phlex::experimental { template void add_product(product_specification const& key, std::unique_ptr>&& t); - // default Source identifier + /// The creator used by default for products supplied by a source. + /// + /// This is the valid internal creator name `phlex_source`: an unqualified algorithm name + /// with no plugin component. static experimental::algorithm_name default_source(); private: diff --git a/phlex/model/products.cpp b/phlex/model/products.cpp index b45b43780..7c3fc0e4f 100644 --- a/phlex/model/products.cpp +++ b/phlex/model/products.cpp @@ -27,6 +27,8 @@ namespace phlex::detail { gsl::not_null products::find_product(product_specification const& spec) const { + // Lookup is exact: product_specification equality covers the creator, suffix, and type, so a + // specification matches only a product stored under all three. auto it = std::ranges::find(products_, spec, [](auto const& p) -> auto const& { return p.first; }); if (it == products_.end()) { diff --git a/test/core_misc_test.cpp b/test/core_misc_test.cpp index 0a013fcdf..0be02aa72 100644 --- a/test/core_misc_test.cpp +++ b/test/core_misc_test.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -27,35 +28,38 @@ TEST_CASE("algorithm_name tests", "[model]") using namespace phlex::experimental; using namespace phlex::experimental::literals; + SECTION("Empty creator name is rejected") + { + STATIC_CHECK_FALSE(std::is_default_constructible_v); + CHECK_THROWS_AS(algorithm_name{""}, std::invalid_argument); + } SECTION("Create from string with colon") { auto an = algorithm_name{"plugin:algo"}; CHECK(an.to_string() == "plugin:algo"); + REQUIRE(an.plugin().has_value()); + CHECK(an.plugin().value() == "plugin"_id); + CHECK(an.algorithm() == "algo"_id); } - SECTION("Create from string without colon") + SECTION("Create from string without colon has an absent plugin") { auto an = algorithm_name{"algo"}; // For 'either' cases, the word is stored as algorithm_ CHECK(an.to_string() == "algo"); + CHECK_FALSE(an.plugin().has_value()); + CHECK(an.algorithm() == "algo"_id); + } + SECTION("Create rejects an empty plugin or algorithm") + { + CHECK_THROWS_AS(algorithm_name{":find_hits"}, std::invalid_argument); + CHECK_THROWS_AS(algorithm_name{"reco:"}, std::invalid_argument); + CHECK_THROWS_AS(algorithm_name{":"}, std::invalid_argument); } SECTION("Create from char pointer") { auto an = algorithm_name{"ptr:algo"}; CHECK(an.to_string() == "ptr:algo"); } - SECTION("Unqualified name has no plugin") - { - auto const an = algorithm_name{"algo"}; - CHECK_FALSE(an.plugin().has_value()); - CHECK(an.algorithm() == "algo"_id); - } - SECTION("Qualified name has plugin and algorithm") - { - auto const an = algorithm_name{"plugin:algo"}; - REQUIRE(an.plugin().has_value()); - CHECK(an.plugin().value() == "plugin"_id); - CHECK(an.algorithm() == "algo"_id); - } SECTION("Construct from typed components") { algorithm_name const unqualified{std::nullopt, "algo"_id}; @@ -155,6 +159,7 @@ TEST_CASE("make_algorithm_name tests", "[core]") auto const name = make_algorithm_name(nullptr, "my_algorithm"); CHECK_FALSE(name.plugin().has_value()); CHECK(name.algorithm() == "my_algorithm"_id); + CHECK(name.to_string() == "my_algorithm"); } SECTION("With configuration the module label is the plugin") @@ -166,6 +171,7 @@ TEST_CASE("make_algorithm_name tests", "[core]") auto const name = make_algorithm_name(&config, "my_algorithm"); REQUIRE(name.plugin().has_value()); CHECK(name.plugin().value() == "my_module"_id); + CHECK(name.algorithm() == "my_algorithm"_id); CHECK(name.to_string() == "my_module:my_algorithm"); } @@ -185,6 +191,24 @@ TEST_CASE("make_algorithm_name tests", "[core]") "Invalid algorithm name \"my_module:\": the algorithm after ':' is missing")); } + SECTION("A configuration without a module label is an error, not an absent plugin") + { + phlex::configuration const config{boost::json::object{}}; + CHECK_THROWS_AS(make_algorithm_name(&config, "my_algorithm"), std::runtime_error); + } + + SECTION("A configured empty module label is an error, not an absent plugin") + { + boost::json::object obj; + obj["module_label"] = ""; + phlex::configuration const config{obj}; + CHECK_THROWS_AS(make_algorithm_name(&config, "my_algorithm"), std::invalid_argument); + CHECK_THROWS_WITH( + make_algorithm_name(&config, "my_algorithm"), + Catch::Matchers::ContainsSubstring( + "Invalid algorithm name \":my_algorithm\": the plugin label before ':' is missing")); + } + SECTION("A malformed algorithm name is reported with the composed name") { boost::json::object obj; diff --git a/test/form/form_basics_test.cpp b/test/form/form_basics_test.cpp index 857bdfd37..0e78018f3 100644 --- a/test/form/form_basics_test.cpp +++ b/test/form/form_basics_test.cpp @@ -14,6 +14,8 @@ #include "persistence/navigation_naming.hpp" #include "persistence/persistence_reader.hpp" #include "persistence/persistence_writer.hpp" +#include "phlex/model/product_specification.hpp" +#include "phlex/model/products.hpp" #include "phlex/model/type_id.hpp" #include "storage/descriptor.hpp" #include "storage/factories.hpp" @@ -791,6 +793,110 @@ TEST_CASE("form_writer_interface creates containers once across events", "[form] CHECK(spy_raw->commit_calls == 2); } +TEST_CASE("FORM writer persists explicit empty and named suffix text", "[form]") +{ + using namespace form::experimental::config; + using namespace phlex::experimental; + + product_specification const empty{ + algorithm_name{"tracker"}, empty_string{}, make_type_id()}; + product_specification const named{ + algorithm_name{"tracker"}, identifier{"Hits_2"}, make_type_id()}; + std::string const empty_payload{"empty suffix payload"}; + std::string const named_payload{"named suffix payload"}; + std::vector const products{ + {std::string{empty.suffix().text()}, &empty_payload, &typeid(std::string)}, + {std::string{named.suffix().text()}, &named_payload, &typeid(std::string)}}; + + std::string const file_name = "form_suffix_text.root"; + item_config cfg; + cfg.add_item("", file_name, form::technology::root_ttree); + cfg.add_item("Hits_2", file_name, form::technology::root_ttree); + + SECTION("finalized dictionary preserves both labels and the existing layout without ROOT") + { + auto spy = std::make_unique(); + auto* store = spy.get(); + form::experimental::form_writer_interface writer{ + cfg, + tech_setting_config{}, + std::make_unique(std::move(spy))}; + writer.write("tracker", test_stage, event_cell(1), products); + writer.write("tracker", test_stage, event_cell(2), products); + writer.finalize(); + + CHECK(std::ranges::count(store->filled_containers, "root_ttree__tracker__test_stage/") == 2); + CHECK(std::ranges::count(store->filled_containers, "root_ttree__tracker__test_stage/Hits_2") == + 2); + auto const& dictionary = store->tables.at("nav_root_ttree_products"); + CHECK(dictionary.columns == std::vector{"product_name", + "creator", + "stage", + "container_name", + "hierarchy_key", + "navigation_container", + "navigation_column"}); + using row = std::vector; + CHECK(dictionary.rows == std::vector{{"", + "tracker", + test_stage, + "root_ttree__tracker__test_stage/", + "event", + "nav_root_ttree_cells_event", + "tracker__test_stage_row"}, + {"Hits_2", + "tracker", + test_stage, + "root_ttree__tracker__test_stage/Hits_2", + "event", + "nav_root_ttree_cells_event", + "tracker__test_stage_row"}}); + } + +#ifdef USE_ROOT_STORAGE + SECTION("ROOT TTree stores the exact suffix text and reads both payloads back") + { + { + form::experimental::form_writer_interface writer{cfg, tech_setting_config{}}; + writer.write("tracker", test_stage, event_cell(0), products); + writer.finalize(); + } + + // Reopen the finalized file and inspect persisted labels, not just in-memory conversions. + auto storage = create_storage_reader(); + auto const check_text = + [&](std::string const& column, std::uint64_t row, std::string const& expected) { + void const* raw = nullptr; + storage->read_container( + token{file_name, "nav_root_ttree_products/" + column, form::technology::root_ttree, row}, + &raw, + typeid(std::string), + tech_setting_config{}); + std::unique_ptr const text{static_cast(raw)}; + REQUIRE(text != nullptr); + CHECK(*text == expected); + }; + check_text("product_name", 0, ""); + check_text("product_name", 1, "Hits_2"); + check_text("container_name", 0, "root_ttree__tracker__test_stage/"); + check_text("container_name", 1, "root_ttree__tracker__test_stage/Hits_2"); + + form::experimental::form_reader_interface reader{cfg, tech_setting_config{}}; + for (auto product : products) { + CHECK(reader.indices("tracker", test_stage, product.label) == + std::vector{event_cell(0).id}); + auto const expected = *static_cast(product.data); + product.data = nullptr; + reader.read("tracker", test_stage, event_cell(0).id, product); + std::unique_ptr const payload{ + static_cast(product.data)}; + REQUIRE(payload != nullptr); + CHECK(*payload == expected); + } + } +#endif +} + TEST_CASE("form_writer_interface fans a product out to multiple destinations", "[form]") { using namespace form::experimental::config; diff --git a/test/output_products_test.cpp b/test/output_products_test.cpp index 762e0c2b4..f2e8d4473 100644 --- a/test/output_products_test.cpp +++ b/test/output_products_test.cpp @@ -10,7 +10,10 @@ #include "phlex/core/product_selector.hpp" #include "phlex/core/provider_node.hpp" #include "phlex/core/source.hpp" +#include "phlex/model/algorithm_name.hpp" #include "phlex/model/data_cell_index.hpp" +#include "phlex/model/identifier.hpp" +#include "phlex/model/product_specification.hpp" #include "phlex/model/product_store.hpp" #include "phlex/model/products.hpp" #include "phlex/model/type_id.hpp" @@ -18,9 +21,14 @@ #include +#include +#include +#include #include #include +#include #include +#include #include using namespace phlex; @@ -55,8 +63,9 @@ namespace { provider_bundles bundles; std::string const layer = "spill"; std::string const stage = "previous_process"; + // The source's product has an explicitly empty suffix. experimental::product_specification spec{ - "provide_name", "", experimental::make_type_id()}; + "provide_name", empty_string{}, experimental::make_type_id()}; if (selector.match(spec, identifier{layer}, identifier{stage})) { bundles.push_back(provider_bundle{.provider_function = give_me_a_name, @@ -70,6 +79,131 @@ namespace { }; } +TEST_CASE("Parse product specification text", "[data model]") +{ + using experimental::product_specification; + using namespace experimental::literals; + + SECTION("A named suffix follows the creator and slash") + { + auto const spec = product_specification{"find_hits/hits"}; + CHECK(spec.creator().to_string() == "find_hits"); + CHECK_FALSE(spec.creator().plugin().has_value()); + CHECK(spec.suffix() == "hits"_id); + CHECK(spec.to_string() == "find_hits/hits"); + } + + SECTION("A trailing slash gives an explicitly empty suffix") + { + auto const spec = product_specification{"find_hits/"}; + CHECK(spec.suffix().empty()); + CHECK(spec.to_string() == "find_hits/"); + } + + SECTION("A qualified creator is parsed") + { + auto const spec = product_specification{"reco:find_hits/hits"}; + CHECK(spec.creator().to_string() == "reco:find_hits"); + REQUIRE(spec.creator().plugin().has_value()); + CHECK(*spec.creator().plugin() == "reco"_id); + CHECK(spec.suffix() == "hits"_id); + CHECK(spec != product_specification{"find_hits/hits"}); + } + + SECTION("Text without a creator and slash is rejected") + { + for (auto const* text : {"hits", "/hits", "", "/"}) { + CHECK_THROWS_AS(product_specification{text}, std::runtime_error); + } + } + + SECTION("An invalid creator is rejected") + { + CHECK_THROWS_AS(product_specification{"reco:/hits"}, std::invalid_argument); + CHECK_THROWS_AS(product_specification{":find_hits/hits"}, std::invalid_argument); + } +} + +TEST_CASE("Product specification suffixes are explicit values", "[data model]") +{ + using experimental::algorithm_name; + using experimental::empty_string; + using experimental::product_specification; + using experimental::suffix_t; + using namespace experimental::literals; + + STATIC_CHECK( + std::is_same_v().suffix()), suffix_t const&>); + + SECTION("Parsed empty and named suffixes keep their representation") + { + auto const empty = product_specification{"reco:find_hits/"}; + CHECK(empty.suffix().empty()); + CHECK(empty.suffix() == suffix_t{empty_string{}}); + CHECK(empty.to_string() == "reco:find_hits/"); + + auto const named = product_specification{"reco:find_hits/hits"}; + CHECK_FALSE(named.suffix().empty()); + CHECK(named.suffix() == suffix_t{"hits"_id}); + CHECK(named.suffix().text() == "hits"); + CHECK(named.to_string() == "reco:find_hits/hits"); + + CHECK(empty != named); + CHECK((empty <=> named) == std::strong_ordering::less); + CHECK(std::hash{}(empty) != std::hash{}(named)); + CHECK(std::hash{}(empty) == + std::hash{}(product_specification{"reco:find_hits/"})); + } + + SECTION("Constructed specifications accept the empty and named alternatives") + { + auto const creator = algorithm_name{"reco:find_hits"}; + product_specification const empty{creator, empty_string{}, experimental::make_type_id()}; + product_specification const named{creator, "hits"_id, experimental::make_type_id()}; + CHECK(empty.suffix().empty()); + CHECK(named.suffix().text() == "hits"); + CHECK(empty != named); + } +} + +TEST_CASE("Fluent output suffixes become explicit suffix values", "[data model]") +{ + using experimental::algorithm_name; + using experimental::empty_string; + using experimental::suffix_t; + using namespace experimental::literals; + + auto const creator = algorithm_name{"reco:find_hits"}; + auto const int_id = experimental::make_type_id(); + auto const double_id = experimental::make_type_id(); + + SECTION("No registered suffixes default to explicitly empty suffixes") + { + auto const specs = phlex::detail::to_product_specifications(creator, {}, {int_id, double_id}); + REQUIRE(specs.size() == 2ull); + for (auto const& spec : specs) { + CHECK(spec.suffix() == suffix_t{empty_string{}}); + CHECK(spec.suffix().empty()); + CHECK(spec.creator() == creator); + } + CHECK(specs[0].type() == int_id); + CHECK(specs[1].type() == double_id); + CHECK(specs[0].to_string() == "reco:find_hits/"); + } + + SECTION("Empty and named registered suffixes are converted at specification creation") + { + auto const specs = + phlex::detail::to_product_specifications(creator, {"", "hits"}, {int_id, double_id}); + REQUIRE(specs.size() == 2ull); + CHECK(specs[0].suffix() == suffix_t{empty_string{}}); + CHECK(specs[1].suffix() == suffix_t{"hits"_id}); + CHECK(specs[0].to_string() == "reco:find_hits/"); + CHECK(specs[1].to_string() == "reco:find_hits/hits"); + CHECK(specs[0] != specs[1]); + } +} + TEST_CASE("Output data products", "[graph]") { auto gen = experimental::layer_generator::make(); diff --git a/test/producer_catalog_test.cpp b/test/producer_catalog_test.cpp index 287502159..57ad0d3ce 100644 --- a/test/producer_catalog_test.cpp +++ b/test/producer_catalog_test.cpp @@ -28,9 +28,10 @@ namespace { product_specifications const& output() const override { return products_; } private: - algorithm_name name_{"test_producer"}; - product_specifications products_{{name_, identifier{"number"}, make_type_id()}, - {name_, identifier{"label"}, make_type_id()}}; + algorithm_name name_{"test_plugin:test_producer"}; + product_specifications products_{{name_, empty_string{}, make_type_id()}, + {name_, suffix_t{"number"}, make_type_id()}, + {name_, suffix_t{"label"}, make_type_id()}}; tbb::flow::queue_node port_; }; } @@ -55,7 +56,9 @@ TEST_CASE("producer_catalog registers all products from a producer", "[producer_ std::vector producers{&node}; producer_catalog const catalog{producers}; - CHECK(std::ranges::distance(catalog.values()) == 2); + CHECK(std::ranges::distance(catalog.values()) == 3); + CHECK(node.output()[0].suffix().empty()); + CHECK(node.output()[1].suffix().text() == "number"); for (auto const& spec : node.output()) { phlex::product_selector const query{ .creator = node.name().algorithm(), .suffix = spec.suffix(), .type = spec.type()}; @@ -63,10 +66,37 @@ TEST_CASE("producer_catalog registers all products from a producer", "[producer_ catalog.find_producers(query, algorithm_name{"consumer"}, identifier{"test_stage"}); REQUIRE(matches.size() == 1u); CHECK(matches[0]->node == node.name()); + CHECK(matches[0]->node.plugin() == identifier{"test_plugin"}); CHECK(matches[0]->output_port == &node.output_port()); CHECK(matches[0]->type == spec.type()); + + auto plugin_query = query; + plugin_query.creator = "test_plugin"; + CHECK(catalog.find_producers( + plugin_query, algorithm_name{"consumer"}, identifier{"test_stage"}) == matches); } + // The empty and named int products differ only in suffix, so omission is ambiguous even + // when the consumer's type is known. + phlex::product_selector const ambiguous_suffix_query{.creator = node.name().algorithm(), + .type = make_type_id()}; + CHECK_THROWS_WITH(catalog.find_producers( + ambiguous_suffix_query, algorithm_name{"consumer"}, identifier{"test_stage"}), + "Ambiguous product selector -- see errors"); + + phlex::product_selector const omitted_suffix_query{.creator = node.name().algorithm(), + .type = make_type_id()}; + auto const omitted_matches = catalog.find_producers( + omitted_suffix_query, algorithm_name{"consumer"}, identifier{"test_stage"}); + REQUIRE(omitted_matches.size() == 1u); + CHECK(omitted_matches[0]->type == make_type_id()); + + phlex::product_selector const missing_suffix_query{.suffix = "missing"}; + CHECK( + catalog + .find_producers(missing_suffix_query, algorithm_name{"consumer"}, identifier{"test_stage"}) + .empty()); + // Algorithm registration via framework_graph::input_family always populates // product_selector::type from the consumer callback's parameter types, so an // untyped selector matching products of different types can only be tested by diff --git a/test/product_handle_test.cpp b/test/product_handle_test.cpp index 4df2942fa..94cbfeed8 100644 --- a/test/product_handle_test.cpp +++ b/test/product_handle_test.cpp @@ -8,6 +8,8 @@ #include #include +#include +#include #include using namespace phlex; @@ -155,6 +157,98 @@ TEST_CASE("Retrieve unqualified creator and empty suffix from handle", "[data mo CHECK(h.suffix().empty()); } +TEST_CASE("Handle metadata accessors return textual views", "[data model]") +{ + using handle_t = handle; + STATIC_CHECK(std::is_same_v().suffix()), std::string_view>); + STATIC_CHECK(std::is_same_v().layer()), std::string_view>); + STATIC_CHECK(std::is_same_v().stage()), std::string_view>); + STATIC_CHECK( + std::is_same_v().creator().plugin), std::string_view>); + STATIC_CHECK( + std::is_same_v().creator().algorithm), std::string_view>); +} + +TEST_CASE("Handle suffix views distinguish empty and named suffixes", "[data model]") +{ + int const number{3}; + auto const job = data_cell_index::job(); + + SECTION("Explicit empty suffix") + { + spec_t const spec{"creator/"}; + auto const h = make_handle(number, *job, spec); + CHECK(h.suffix().empty()); + CHECK(h.suffix() == ""); + CHECK(h.creator().algorithm == "creator"); + } + + SECTION("Named suffix") + { + spec_t const spec{"creator/hits"}; + auto const h = make_handle(number, *job, spec); + CHECK_FALSE(h.suffix().empty()); + CHECK(h.suffix() == "hits"); + } +} + +TEST_CASE("Handle creator views for unqualified and qualified creators", "[data model]") +{ + int const number{3}; + auto const job = data_cell_index::job(); + + SECTION("Unqualified creator has an empty plugin view") + { + spec_t const spec{"find_hits/hits"}; + auto const h = make_handle(number, *job, spec); + CHECK(h.creator().plugin.empty()); + CHECK(h.creator().algorithm == "find_hits"); + CHECK(h.suffix() == "hits"); + } + + SECTION("Unqualified creator with an empty suffix") + { + spec_t const spec{"find_hits/"}; + auto const h = make_handle(number, *job, spec); + CHECK(h.creator().plugin.empty()); + CHECK(h.creator().algorithm == "find_hits"); + CHECK(h.suffix().empty()); + } + + SECTION("Qualified creator exposes both components") + { + spec_t const spec{"reco:find_hits/hits"}; + auto const h = make_handle(number, *job, spec); + CHECK(h.creator().plugin == "reco"); + CHECK(h.creator().algorithm == "find_hits"); + CHECK(h.suffix() == "hits"); + } +} + +TEST_CASE("Handle views are borrowed from the owning specification", "[data model]") +{ + int const number{3}; + auto const job = data_cell_index::job(); + spec_t const spec{"reco:find_hits/hits"}; + auto const h = make_handle(number, *job, spec); + + // The views alias the text stored in the specification's values, rather than copies. + auto const creator = h.creator(); + REQUIRE(spec.creator().plugin().has_value()); + CHECK(creator.plugin.data() == std::string_view(*spec.creator().plugin()).data()); + CHECK(creator.algorithm.data() == std::string_view(spec.creator().algorithm()).data()); + CHECK(h.suffix().data() == spec.suffix().text().data()); + + // Repeated calls refer to the same borrowed storage. + CHECK(h.suffix().data() == h.suffix().data()); + CHECK(h.creator().plugin.data() == creator.plugin.data()); + + // A copy of the handle borrows from the same specification. + auto const copy = h; + CHECK(copy.suffix().data() == spec.suffix().text().data()); + CHECK(copy.creator().algorithm.data() == creator.algorithm.data()); +} + TEST_CASE("Retrieve stage from handle", "[data model]") { int const number{3}; diff --git a/test/product_selecting_test.cpp b/test/product_selecting_test.cpp index 5e8978456..8e6080f11 100644 --- a/test/product_selecting_test.cpp +++ b/test/product_selecting_test.cpp @@ -254,3 +254,102 @@ TEST_CASE("Querying products in different ways", "[graph]") CHECK_THROWS_WITH(g.execute(), "Ambiguous product selector -- see errors"); } } + +TEST_CASE("Selecting empty, named, and omitted producer suffixes", "[graph]") +{ + constexpr int num_events = 3; + auto gen = experimental::layer_generator::make(); + gen->add_layer("event", {.parent_layer = "job", .count = num_events}); + auto g = phlex::detail::framework_graph::without_driver("test"); + g.add_driver(gen); + g.provide("provide_number", provide_idx, concurrency::unlimited) + .output_product("input", "number", "event"); + + auto const input = product_selector{.creator = "input", .suffix = "number"}; + g.transform("both_suffixes", [](int const n) { return std::tuple{n + 1, n + 2}; }) + .input_family(input) + .output_product_suffixes("", "number"); + + SECTION("Explicit empty suffix selects only the empty product") + { + g.observe("selected", + [](handle const number) { + CHECK(number.creator().algorithm == "both_suffixes"); + CHECK(number.suffix().empty()); + CHECK(*number == static_cast(number.data_cell_index().number()) + 1); + }) + .input_family( + product_selector{.creator = "both_suffixes", .suffix = experimental::empty_string{}}); + g.execute(); + CHECK(g.execution_count("selected") == num_events); + } + + SECTION("Named suffix selects only the named product") + { + g.observe("selected", + [](handle const number) { + CHECK(number.creator().algorithm == "both_suffixes"); + CHECK(number.suffix() == "number"); + CHECK(*number == static_cast(number.data_cell_index().number()) + 2); + }) + .input_family(product_selector{.creator = "both_suffixes", .suffix = "number"}); + g.execute(); + CHECK(g.execution_count("selected") == num_events); + } + + SECTION("Omitted suffix matches both empty and named products and is ambiguous") + { + g.observe("ambiguous_suffix", [](int const) {}) + .input_family(product_selector{.creator = "both_suffixes"}); + CHECK_THROWS_WITH(g.execute(), "Ambiguous product selector -- see errors"); + } + + SECTION("Omitted suffix selects a single default empty output") + { + g.transform("single_suffix", [](int const n) { return n; }).input_family(input); + g.observe("selected", + [](handle const number) { + CHECK(number.creator().algorithm == "single_suffix"); + CHECK(number.suffix().empty()); + CHECK(*number == static_cast(number.data_cell_index().number())); + }) + .input_family(product_selector{.creator = "single_suffix"}); + g.execute(); + CHECK(g.execution_count("selected") == num_events); + } + + SECTION("Omitted suffix selects a single named output") + { + g.transform("single_suffix", [](int const n) { return n; }) + .input_family(input) + .output_product_suffixes("number"); + g.observe("selected", + [](handle const number) { + CHECK(number.creator().algorithm == "single_suffix"); + CHECK(number.suffix() == "number"); + CHECK(*number == static_cast(number.data_cell_index().number())); + }) + .input_family(product_selector{.creator = "single_suffix"}); + g.execute(); + CHECK(g.execution_count("selected") == num_events); + } + + SECTION("Explicit empty suffix remains ambiguous across creators") + { + g.transform("another_suffix", [](int const n) { return n; }) + .input_family(input) + .output_product_suffixes(""); + g.observe("ambiguous_creator", [](int const) {}).input_family(product_selector{.suffix = ""}); + CHECK_THROWS_WITH(g.execute(), "Ambiguous product selector -- see errors"); + } + + SECTION("Named suffix remains ambiguous across creators") + { + g.transform("another_suffix", [](int const n) { return n; }) + .input_family(input) + .output_product_suffixes("number"); + g.observe("ambiguous_creator", [](int const) {}) + .input_family(product_selector{.suffix = "number"}); + CHECK_THROWS_WITH(g.execute(), "Ambiguous product selector -- see errors"); + } +} diff --git a/test/product_selector_test.cpp b/test/product_selector_test.cpp index e30314cb4..9ab99a299 100644 --- a/test/product_selector_test.cpp +++ b/test/product_selector_test.cpp @@ -10,6 +10,8 @@ #include #include +#include +#include using namespace phlex; @@ -68,6 +70,93 @@ TEST_CASE("Product name with data layer", "[data model]") CHECK((label <=> label) == std::strong_ordering::equal); } +TEST_CASE("Selector suffix construction preserves all three states", "[data model]") +{ + using experimental::empty_string; + using experimental::suffix_t; + std::string const named_text{"hits"}; + std::string const empty_text; + std::vector const named{{.suffix = "hits"}, + {.suffix = "hits"_id}, + {.suffix = suffix_t{"hits"}}, + {.suffix = suffix_t{named_text}}, + {.suffix = suffix_t{std::string_view{named_text}}}}; + std::vector const empty{{.suffix = ""}, + {.suffix = empty_string{}}, + {.suffix = suffix_t{}}, + {.suffix = suffix_t{empty_text}}, + {.suffix = suffix_t{std::string_view{empty_text}}}}; + product_selector const omitted; + CHECK_FALSE(omitted.suffix.has_value()); + for (auto const& selector : named) { + REQUIRE(selector.suffix.has_value()); + CHECK(selector.suffix->text() == "hits"); + CHECK(selector == named.front()); + CHECK((selector <=> named.front()) == std::strong_ordering::equal); + CHECK(selector != empty.front()); + CHECK(selector != omitted); + } + for (auto const& selector : empty) { + REQUIRE(selector.suffix.has_value()); + CHECK(selector.suffix->empty()); + CHECK(selector == empty.front()); + CHECK((selector <=> empty.front()) == std::strong_ordering::equal); + CHECK(omitted < selector); + CHECK(selector < named.front()); + } +} + +TEST_CASE("Selector suffix matching and diagnostics preserve three states", "[data model]") +{ + using experimental::algorithm_name; + using experimental::empty_string; + using experimental::product_specification; + auto const creator = algorithm_name{"reco:find_hits"}; + product_specification const empty_product{creator, empty_string{}, {}}; + product_specification const named_product{creator, "hits", {}}; + product_selector const omitted; + product_selector const empty{.suffix = ""}; + product_selector const named{.suffix = "hits"}; + product_selector const different{.suffix = "tracks"}; + for (auto const& selector : {omitted, empty, named}) { + CHECK(selector.match(empty_product) == (!selector.suffix || selector.suffix->empty())); + CHECK(selector.match(named_product) == (!selector.suffix || selector.suffix->text() == "hits")); + for (auto const& other : {omitted, empty, named}) { + CHECK(selector.match(other) == (!selector.suffix || selector.suffix == other.suffix)); + } + } + CHECK_FALSE(different.match(empty_product)); + CHECK_FALSE(different.match(named_product)); + CHECK(omitted.to_string() == + ""); + CHECK(empty.to_string() == + ""); + CHECK(named.to_string() == + ""); +} + +TEST_CASE("Selector creator criterion matches one name or is unrestricted", "[data model]") +{ + using experimental::algorithm_name; + using experimental::product_specification; + product_specification const qualified{algorithm_name{"reco:find_hits"}, "hits", {}}; + product_specification const unqualified{algorithm_name{"find_hits"}, "hits", {}}; + product_selector const omitted{.suffix = "hits"}; + product_selector const plugin{.creator = "reco", .suffix = "hits"}; + product_selector const algorithm{.creator = "find_hits", .suffix = "hits"}; + product_selector const different{.creator = "other", .suffix = "hits"}; + for (auto const& spec : {qualified, unqualified}) { + CHECK(omitted.match(spec)); + CHECK_FALSE(different.match(spec)); + } + CHECK(plugin.match(qualified)); + CHECK_FALSE(plugin.match(unqualified)); + CHECK(algorithm.match(qualified)); + CHECK(algorithm.match(unqualified)); + CHECK(fmt::format("{}", plugin.creator) == "reco"); + CHECK(fmt::format("{}", omitted.creator) == "[ANY]"); +} + // Regression test for issue #707: the converting constructors of creator_name and // required_layer_name once moved from their lvalue arguments, silently emptying them. // Do not remove this test on the assumption that "specifying an lvalue as an argument diff --git a/test/product_store_test.cpp b/test/product_store_test.cpp index 751d7ee34..c01413e7f 100644 --- a/test/product_store_test.cpp +++ b/test/product_store_test.cpp @@ -21,15 +21,6 @@ using namespace phlex::experimental; using namespace phlex::experimental::literals; -TEST_CASE("Product store default source", "[data model]") -{ - auto const source = product_store::default_source(); - CHECK(source.to_string() == "Source"); - CHECK(source.algorithm() == "Source"_id); - CHECK_FALSE(source.plugin().has_value()); - CHECK(product_store::default_source() == source); -} - TEST_CASE("Product store insertion", "[data model]") { auto const creator = algorithm_name{"test_algorithm"}; @@ -70,6 +61,66 @@ TEST_CASE("Product store insertion", "[data model]") CHECK(store->get_product>(gsl::make_not_null(&numbers_spec)) == many_numbers); } +TEST_CASE("Product store lookup of specifications is exact", "[data model]") +{ + auto const creator = algorithm_name{"test_algorithm"}; + auto const stage = "test_stage"_id; + auto store = product_store::base(gsl::make_not_null(&creator), gsl::make_not_null(&stage)); + + auto const type = make_type_id(); + product_specification const unqualified{creator, "hits"_id, type}; + product_specification const other_creator{algorithm_name{"reco:test_algorithm"}, "hits"_id, type}; + product_specification parsed{"test_algorithm/hits"}; + parsed.set_type(make_type_id()); + + store->add_product(unqualified, 1); + + // A parsed specification finds the same product once its type is supplied. + CHECK(parsed == unqualified); + CHECK(store->get_product(gsl::make_not_null(&unqualified)) == 1); + CHECK(store->get_product(gsl::make_not_null(&parsed)) == 1); + + // A missing type is not a wildcard for a typed storage key. + product_specification const untyped{"test_algorithm/hits"}; + CHECK(untyped != unqualified); + CHECK_THROWS_WITH(store->get_product(gsl::make_not_null(&untyped)), + Catch::Matchers::ContainsSubstring( + "No product exists with the specification 'test_algorithm/hits'.")); + + // A different creator, even with the same algorithm and suffix, does not match. + CHECK_THROWS_WITH(store->get_handle(gsl::make_not_null(&other_creator)), + Catch::Matchers::ContainsSubstring( + "No product exists with the specification 'reco:test_algorithm/hits'.")); + CHECK(store->get_handle(gsl::make_not_null(&unqualified)).suffix() == "hits"); +} + +TEST_CASE("Product store with the default source creator", "[data model]") +{ + auto const source = product_store::default_source(); + CHECK(source.to_string() == "phlex_source"); + CHECK_FALSE(source.plugin().has_value()); + CHECK(source.algorithm() == "phlex_source"_id); + CHECK(source == algorithm_name{"phlex_source"}); + CHECK(product_store::default_source() == source); + + auto const stage = "test_stage"_id; + auto store = product_store::base(gsl::make_not_null(&source), gsl::make_not_null(&stage)); + CHECK(store->source() == source); + + // Insertion of a product created by the source, and exact lookup by its specification. + auto const type = make_type_id(); + product_specification const from_source{source, "hits"_id, type}; + product_specification const other_creator{algorithm_name{"test_algorithm"}, "hits"_id, type}; + store->add_product(from_source, 7); + + CHECK(store->size() == 1ull); + CHECK(store->get_product(gsl::make_not_null(&from_source)) == 7); + CHECK(store->get_handle(gsl::make_not_null(&from_source)).suffix() == "hits"); + CHECK_THROWS_WITH(store->get_handle(gsl::make_not_null(&other_creator)), + Catch::Matchers::ContainsSubstring( + "No product exists with the specification 'test_algorithm/hits'.")); +} + TEST_CASE("Product retrieval requires exactly one match", "[data model]") { using Catch::Matchers::ContainsSubstring; diff --git a/test/products_test.cpp b/test/products_test.cpp index 4773c24cd..753e6658f 100644 --- a/test/products_test.cpp +++ b/test/products_test.cpp @@ -1,7 +1,17 @@ +#include "phlex/model/algorithm_name.hpp" +#include "phlex/model/identifier.hpp" +#include "phlex/model/product_specification.hpp" #include "phlex/model/products.hpp" +#include "phlex/model/type_id.hpp" #include #include +#include + +#include +#include +#include +#include TEST_CASE("Reject null product pointers", "[data model]") { @@ -9,3 +19,64 @@ TEST_CASE("Reject null product pointers", "[data model]") CHECK_THROWS_WITH(product_for(product_ptr{}), "Cannot store a null product pointer."); CHECK_THROWS_WITH(product_for(nullptr), "Cannot store a null product pointer."); } + +TEST_CASE("Product specifications are exact keys", "[data model]") +{ + using namespace phlex::experimental; + using namespace phlex::experimental::literals; + using Catch::Matchers::ContainsSubstring; + + auto const type = make_type_id(); + product_specification const unqualified{algorithm_name{"find_hits"}, "hits"_id, type}; + product_specification const qualified{algorithm_name{"reco:find_hits"}, "hits"_id, type}; + product_specification const other_suffix{algorithm_name{"find_hits"}, "tracks"_id, type}; + + SECTION("An unqualified creator is distinct from a qualified creator") + { + CHECK_FALSE(unqualified.creator().plugin().has_value()); + REQUIRE(qualified.creator().plugin().has_value()); + CHECK(*qualified.creator().plugin() == "reco"_id); + CHECK(qualified.creator().algorithm() == "find_hits"_id); + + CHECK(unqualified == product_specification{algorithm_name{"find_hits"}, "hits"_id, type}); + CHECK(unqualified != qualified); + CHECK(unqualified != other_suffix); + CHECK((unqualified <=> qualified) == std::strong_ordering::less); + CHECK(std::hash{}(unqualified) == + std::hash{}( + product_specification{algorithm_name{"find_hits"}, "hits"_id, type})); + CHECK(std::hash{}(unqualified) != + std::hash{}(qualified)); + + std::set const ordered{unqualified, qualified, other_suffix}; + CHECK(ordered.size() == 3ull); + std::unordered_set const hashed{unqualified, qualified, other_suffix}; + CHECK(hashed.size() == 3ull); + } + + SECTION("Text names the creator and the suffix") + { + CHECK(unqualified.to_string() == "find_hits/hits"); + CHECK(qualified.to_string() == "reco:find_hits/hits"); + } + + SECTION("Lookup is exact and a different creator is not a match") + { + phlex::detail::products products; + products.add(unqualified, 1); + CHECK(products.get(unqualified) == 1); + CHECK_THROWS_WITH(products.get(qualified), + ContainsSubstring("No product exists with the specification " + "'reco:find_hits/hits'.")); + + phlex::detail::products with_plugin; + with_plugin.add(qualified, 2); + CHECK(with_plugin.get(qualified) == 2); + CHECK_THROWS_WITH(with_plugin.get(unqualified), + ContainsSubstring("No product exists with the specification " + "'find_hits/hits'.")); + CHECK_THROWS_WITH(with_plugin.get(other_suffix), + ContainsSubstring("No product exists with the specification " + "'find_hits/tracks'.")); + } +} diff --git a/test/transform_node_test.cpp b/test/transform_node_test.cpp index af86975c3..0b3498cb1 100644 --- a/test/transform_node_test.cpp +++ b/test/transform_node_test.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -76,7 +77,7 @@ namespace { template product_specification spec(algorithm_name const& creator) { - return {creator, suffix_t{}, make_type_id()}; + return {creator, empty_string{}, make_type_id()}; } template @@ -105,6 +106,19 @@ namespace { TEST_CASE("transform_node directly transforms one input product", "[transform_node]") { + std::string expected_name{"double_value"}; + std::optional expected_plugin; + std::vector predicates; + + SECTION("Qualified name with ordered predicate metadata") + { + expected_name = "test_plugin:double_value"; + expected_plugin = identifier{"test_plugin"}; + predicates = {"pred2", "pred1"}; + } + SECTION("Unqualified name with no predicates") {} + + algorithm_name const expected_creator{expected_name}; oneapi::tbb::flow::graph graph; auto const input_creator_name = algorithm_name{"input"}; identifier const stage_name = "test_stage"_id; @@ -114,10 +128,10 @@ TEST_CASE("transform_node directly transforms one input product", "[transform_no auto alg = algorithm_bits_for(double_value); resource_catalog resources; - transform_node node{algorithm_name{"double_value"}, + transform_node node{expected_creator, "test_stage"_id, 1u, - {}, + predicates, graph, std::move(alg), {input_selector}, @@ -125,10 +139,18 @@ TEST_CASE("transform_node directly transforms one input product", "[transform_no resources}; declared_transform& transform = node; + CHECK(transform.name().to_string() == expected_name); + CHECK(transform.name().plugin() == expected_plugin); + CHECK(transform.name().plugin().has_value() == expected_plugin.has_value()); + CHECK(transform.name().algorithm() == "double_value"_id); + // Direct construction checks stored metadata, not graph-installed predicate gating. + CHECK(transform.when() == predicates); + CHECK(transform.when().empty() == predicates.empty()); + auto const& output_specs = transform.output(); REQUIRE(output_specs.size() == 1u); - CHECK(output_specs[0].creator() == algorithm_name{"double_value"}); - CHECK(output_specs[0].suffix() == suffix_t{}); + CHECK(output_specs[0].creator() == expected_creator); + CHECK(output_specs[0].suffix() == empty_string{}); CHECK(output_specs[0].type() == make_type_id()); oneapi::tbb::flow::queue_node sink{graph}; @@ -143,7 +165,7 @@ TEST_CASE("transform_node directly transforms one input product", "[transform_no CHECK(output.id == message_id); REQUIRE(output.store); CHECK(output.store->index() == input_store->index()); - CHECK(output.store->source() == algorithm_name{"double_value"}); + CHECK(output.store->source() == expected_creator); CHECK(output.store->get_product( gsl::make_not_null(std::addressof(output_specs[0]))) == output_type_1{42});