diff --git a/phlex/core/cached_product_stores.hpp b/phlex/core/cached_product_stores.hpp index d7a27dd05..706279e69 100644 --- a/phlex/core/cached_product_stores.hpp +++ b/phlex/core/cached_product_stores.hpp @@ -4,26 +4,26 @@ // FIXME: only intended to be used in a single-threaded context as std::map is not // thread-safe. +#include "phlex/model/data_cell_index.hpp" #include "phlex/model/fwd.hpp" -#include "phlex/model/level_id.hpp" #include "phlex/model/product_store.hpp" namespace phlex::experimental { class cached_product_stores { public: - product_store_ptr get_store(level_id_ptr id = level_id::base_ptr()) + product_store_ptr get_store(data_cell_index_ptr id = data_cell_index::base_ptr()) { auto it = product_stores_.find(id->hash()); if (it != cend(product_stores_)) { return it->second; } - if (id == level_id::base_ptr()) { + if (id == data_cell_index::base_ptr()) { return new_store(product_store::base()); } return new_store( get_store(id->parent()) - ->make_child(id->number(), id->level_name(), source_name_, stage::process)); + ->make_child(id->number(), id->layer_name(), source_name_, stage::process)); } private: @@ -33,7 +33,7 @@ namespace phlex::experimental { } std::string const source_name_{"Source"}; - std::map product_stores_{}; + std::map product_stores_{}; }; } diff --git a/phlex/core/declared_fold.hpp b/phlex/core/declared_fold.hpp index 9461f2ca2..fdabc8e36 100644 --- a/phlex/core/declared_fold.hpp +++ b/phlex/core/declared_fold.hpp @@ -11,8 +11,8 @@ #include "phlex/core/products_consumer.hpp" #include "phlex/core/store_counters.hpp" #include "phlex/model/algorithm_name.hpp" +#include "phlex/model/data_cell_index.hpp" #include "phlex/model/handle.hpp" -#include "phlex/model/level_id.hpp" #include "phlex/model/product_specification.hpp" #include "phlex/model/product_store.hpp" #include "phlex/utilities/simple_ptr_map.hpp" @@ -92,7 +92,7 @@ namespace phlex::experimental { if (store->is_flush()) { // Downstream nodes always get the flush. get<0>(outputs).try_put(msg); - if (store->id()->level_name() != partition_) { + if (store->id()->layer_name() != partition_) { return; } } @@ -105,7 +105,7 @@ namespace phlex::experimental { counter_for(id_hash_for_counter).set_flush_value(store, original_message_id); } else { call(ft, messages, std::make_index_sequence{}); - counter_for(id_hash_for_counter).increment(store->id()->level_hash()); + counter_for(id_hash_for_counter).increment(store->id()->layer_hash()); } if (auto counter = done_with(id_hash_for_counter)) { @@ -179,7 +179,7 @@ namespace phlex::experimental { std::string partition_; join_or_none_t join_; tbb::flow::multifunction_node, messages_t<1>> fold_; - tbb::concurrent_unordered_map> results_; + tbb::concurrent_unordered_map> results_; std::atomic calls_; std::atomic product_count_; }; diff --git a/phlex/core/declared_observer.cpp b/phlex/core/declared_observer.cpp index 47076705b..2f53f66e9 100644 --- a/phlex/core/declared_observer.cpp +++ b/phlex/core/declared_observer.cpp @@ -14,7 +14,7 @@ namespace phlex::experimental { declared_observer::~declared_observer() = default; void declared_observer::report_cached_hashes( - tbb::concurrent_hash_map const& hashes) const + tbb::concurrent_hash_map const& hashes) const { if (hashes.size() > 0ull) { spdlog::warn("Monitor {} has {} cached hashes.", full_name(), hashes.size()); diff --git a/phlex/core/declared_observer.hpp b/phlex/core/declared_observer.hpp index ad6581267..568a0a925 100644 --- a/phlex/core/declared_observer.hpp +++ b/phlex/core/declared_observer.hpp @@ -10,8 +10,8 @@ #include "phlex/core/store_counters.hpp" #include "phlex/metaprogramming/type_deduction.hpp" #include "phlex/model/algorithm_name.hpp" +#include "phlex/model/data_cell_index.hpp" #include "phlex/model/handle.hpp" -#include "phlex/model/level_id.hpp" #include "phlex/model/product_specification.hpp" #include "phlex/model/product_store.hpp" #include "phlex/utilities/simple_ptr_map.hpp" @@ -38,7 +38,7 @@ namespace phlex::experimental { virtual ~declared_observer(); protected: - using hashes_t = tbb::concurrent_hash_map; + using hashes_t = tbb::concurrent_hash_map; using accessor = hashes_t::accessor; void report_cached_hashes(hashes_t const& hashes) const; diff --git a/phlex/core/declared_predicate.hpp b/phlex/core/declared_predicate.hpp index ce43277c6..b9709ebdc 100644 --- a/phlex/core/declared_predicate.hpp +++ b/phlex/core/declared_predicate.hpp @@ -11,8 +11,8 @@ #include "phlex/core/store_counters.hpp" #include "phlex/metaprogramming/type_deduction.hpp" #include "phlex/model/algorithm_name.hpp" +#include "phlex/model/data_cell_index.hpp" #include "phlex/model/handle.hpp" -#include "phlex/model/level_id.hpp" #include "phlex/model/product_store.hpp" #include "phlex/utilities/simple_ptr_map.hpp" @@ -43,7 +43,7 @@ namespace phlex::experimental { virtual tbb::flow::sender& sender() = 0; protected: - using results_t = tbb::concurrent_hash_map; + using results_t = tbb::concurrent_hash_map; using accessor = results_t::accessor; using const_accessor = results_t::const_accessor; diff --git a/phlex/core/declared_transform.hpp b/phlex/core/declared_transform.hpp index 2f3ed8b53..125024cd7 100644 --- a/phlex/core/declared_transform.hpp +++ b/phlex/core/declared_transform.hpp @@ -13,8 +13,8 @@ #include "phlex/core/store_counters.hpp" #include "phlex/metaprogramming/type_deduction.hpp" #include "phlex/model/algorithm_name.hpp" +#include "phlex/model/data_cell_index.hpp" #include "phlex/model/handle.hpp" -#include "phlex/model/level_id.hpp" #include "phlex/model/product_specification.hpp" #include "phlex/model/product_store.hpp" #include "phlex/utilities/simple_ptr_map.hpp" @@ -50,7 +50,7 @@ namespace phlex::experimental { virtual std::size_t product_count() const = 0; protected: - using stores_t = tbb::concurrent_hash_map; + using stores_t = tbb::concurrent_hash_map; using accessor = stores_t::accessor; using const_accessor = stores_t::const_accessor; @@ -101,7 +101,7 @@ namespace phlex::experimental { if (stores_.insert(a, store->id()->hash())) { auto result = call(ft, messages, std::make_index_sequence{}); ++calls_; - ++product_count_[store->id()->level_hash()]; + ++product_count_[store->id()->layer_hash()]; products new_products; new_products.add_all(output_, std::move(result)); a->second = diff --git a/phlex/core/declared_unfold.cpp b/phlex/core/declared_unfold.cpp index 05ce2579c..bd8f5639a 100644 --- a/phlex/core/declared_unfold.cpp +++ b/phlex/core/declared_unfold.cpp @@ -1,6 +1,6 @@ #include "phlex/core/declared_unfold.hpp" +#include "phlex/model/data_cell_counter.hpp" #include "phlex/model/handle.hpp" -#include "phlex/model/level_counter.hpp" #include "fmt/std.h" #include "spdlog/spdlog.h" @@ -9,17 +9,17 @@ namespace phlex::experimental { generator::generator(product_store_const_ptr const& parent, std::string node_name, - std::string const& new_level_name) : + std::string const& new_layer_name) : parent_{std::const_pointer_cast(parent)}, node_name_{std::move(node_name)}, - new_level_name_{new_level_name} + new_layer_name_{new_layer_name} { } product_store_const_ptr generator::make_child(std::size_t const i, products new_products) { - auto child = parent_->make_child(i, new_level_name_, node_name_, std::move(new_products)); - ++child_counts_[child->id()->level_hash()]; + auto child = parent_->make_child(i, new_layer_name_, node_name_, std::move(new_products)); + ++child_counts_[child->id()->layer_hash()]; return child; } diff --git a/phlex/core/declared_unfold.hpp b/phlex/core/declared_unfold.hpp index 4d40b4ec6..2754d9dab 100644 --- a/phlex/core/declared_unfold.hpp +++ b/phlex/core/declared_unfold.hpp @@ -9,8 +9,8 @@ #include "phlex/core/products_consumer.hpp" #include "phlex/core/store_counters.hpp" #include "phlex/model/algorithm_name.hpp" +#include "phlex/model/data_cell_index.hpp" #include "phlex/model/handle.hpp" -#include "phlex/model/level_id.hpp" #include "phlex/model/product_specification.hpp" #include "phlex/model/product_store.hpp" #include "phlex/utilities/simple_ptr_map.hpp" @@ -37,7 +37,7 @@ namespace phlex::experimental { public: explicit generator(product_store_const_ptr const& parent, std::string node_name, - std::string const& new_level_name); + std::string const& new_layer_name); product_store_const_ptr flush_store() const; product_store_const_ptr make_child_for(std::size_t const level_number, products new_products) @@ -49,8 +49,8 @@ namespace phlex::experimental { product_store_const_ptr make_child(std::size_t i, products new_products); product_store_ptr parent_; std::string node_name_; - std::string const& new_level_name_; - std::map child_counts_; + std::string const& new_layer_name_; + std::map child_counts_; }; class declared_unfold : public products_consumer { @@ -66,7 +66,7 @@ namespace phlex::experimental { virtual std::size_t product_count() const = 0; protected: - using stores_t = tbb::concurrent_hash_map; + using stores_t = tbb::concurrent_hash_map; using accessor = stores_t::accessor; using const_accessor = stores_t::const_accessor; @@ -93,12 +93,12 @@ namespace phlex::experimental { Unfold&& unfold, product_queries product_labels, std::vector output_products, - std::string new_level_name) : + std::string new_layer_name) : declared_unfold{std::move(name), std::move(predicates), std::move(product_labels)}, output_{to_product_specifications(full_name(), std::move(output_products), make_type_ids>>())}, - new_level_name_{std::move(new_level_name)}, + new_layer_name_{std::move(new_layer_name)}, join_{make_join_or_none(g, std::make_index_sequence{})}, unfold_{ g, @@ -112,7 +112,7 @@ namespace phlex::experimental { std::get<0>(output).try_put(msg); } else if (accessor a; stores_.insert(a, store->id()->hash())) { std::size_t const original_message_id{msg_counter_}; - generator g{msg.store, this->full_name(), new_level_name_}; + generator g{msg.store, this->full_name(), new_layer_name_}; call(p, ufold, msg.store->id(), g, msg.eom, messages, std::make_index_sequence{}); message const flush_msg{g.flush_store(), msg.eom, ++msg_counter_, original_message_id}; @@ -144,7 +144,7 @@ namespace phlex::experimental { template void call(Predicate const& predicate, Unfold const& unfold, - level_id_ptr const& unfolded_id, + data_cell_index_ptr const& unfolded_id, generator& g, end_of_message_ptr const& eom, messages_t const& messages, @@ -156,7 +156,7 @@ namespace phlex::experimental { auto running_value = obj.initial_value(); while (std::invoke(predicate, obj, running_value)) { products new_products; - auto new_id = unfolded_id->make_child(counter, new_level_name_); + auto new_id = unfolded_id->make_child(counter, new_layer_name_); if constexpr (requires { std::invoke(unfold, obj, running_value, *new_id); }) { auto [next_value, prods] = std::invoke(unfold, obj, running_value, *new_id); new_products.add_all(output_, std::move(prods)); @@ -178,10 +178,10 @@ namespace phlex::experimental { input_retriever_types input_{input_arguments()}; product_specifications output_; - std::string new_level_name_; + std::string new_layer_name_; join_or_none_t join_; tbb::flow::multifunction_node, messages_t<1u>> unfold_; - tbb::concurrent_hash_map stores_; + tbb::concurrent_hash_map stores_; std::atomic msg_counter_{}; // Is this sufficient? Probably not. std::atomic calls_{}; std::atomic product_count_{}; diff --git a/phlex/core/end_of_message.cpp b/phlex/core/end_of_message.cpp index 89a1ec73d..1559aefb1 100644 --- a/phlex/core/end_of_message.cpp +++ b/phlex/core/end_of_message.cpp @@ -1,21 +1,22 @@ #include "phlex/core/end_of_message.hpp" -#include "phlex/model/level_hierarchy.hpp" +#include "phlex/model/data_layer_hierarchy.hpp" namespace phlex::experimental { end_of_message::end_of_message(end_of_message_ptr parent, - level_hierarchy* hierarchy, - level_id_ptr id) : + data_layer_hierarchy* hierarchy, + data_cell_index_ptr id) : parent_{parent}, hierarchy_{hierarchy}, id_{id} { } - end_of_message_ptr end_of_message::make_base(level_hierarchy* hierarchy, level_id_ptr id) + end_of_message_ptr end_of_message::make_base(data_layer_hierarchy* hierarchy, + data_cell_index_ptr id) { return end_of_message_ptr{new end_of_message{nullptr, hierarchy, id}}; } - end_of_message_ptr end_of_message::make_child(level_id_ptr id) + end_of_message_ptr end_of_message::make_child(data_cell_index_ptr id) { return end_of_message_ptr{new end_of_message{shared_from_this(), hierarchy_, id}}; } diff --git a/phlex/core/end_of_message.hpp b/phlex/core/end_of_message.hpp index 9082c6217..efe2f1109 100644 --- a/phlex/core/end_of_message.hpp +++ b/phlex/core/end_of_message.hpp @@ -10,16 +10,18 @@ namespace phlex::experimental { class end_of_message : public std::enable_shared_from_this { public: - static end_of_message_ptr make_base(level_hierarchy* hierarchy, level_id_ptr id); - end_of_message_ptr make_child(level_id_ptr id); + static end_of_message_ptr make_base(data_layer_hierarchy* hierarchy, data_cell_index_ptr id); + end_of_message_ptr make_child(data_cell_index_ptr id); ~end_of_message(); private: - end_of_message(end_of_message_ptr parent, level_hierarchy* hierarchy, level_id_ptr id); + end_of_message(end_of_message_ptr parent, + data_layer_hierarchy* hierarchy, + data_cell_index_ptr id); end_of_message_ptr parent_; - level_hierarchy* hierarchy_; - level_id_ptr id_; + data_layer_hierarchy* hierarchy_; + data_cell_index_ptr id_; }; } diff --git a/phlex/core/framework_graph.cpp b/phlex/core/framework_graph.cpp index 64520562f..aae1fe9e3 100644 --- a/phlex/core/framework_graph.cpp +++ b/phlex/core/framework_graph.cpp @@ -2,7 +2,7 @@ #include "phlex/concurrency.hpp" #include "phlex/core/edge_maker.hpp" -#include "phlex/model/level_counter.hpp" +#include "phlex/model/data_cell_counter.hpp" #include "phlex/model/product_store.hpp" #include "fmt/std.h" @@ -13,7 +13,7 @@ #include namespace phlex::experimental { - level_sentry::level_sentry(flush_counters& counters, + layer_sentry::layer_sentry(flush_counters& counters, message_sender& sender, product_store_ptr store) : counters_{counters}, sender_{sender}, store_{store}, depth_{store_->id()->depth()} @@ -21,7 +21,7 @@ namespace phlex::experimental { counters_.update(store_->id()); } - level_sentry::~level_sentry() + layer_sentry::~layer_sentry() { auto flush_result = counters_.extract(store_->id()); auto flush_store = store_->make_flush(); @@ -32,7 +32,7 @@ namespace phlex::experimental { sender_.send_flush(std::move(flush_store)); } - std::size_t level_sentry::depth() const noexcept { return depth_; } + std::size_t layer_sentry::depth() const noexcept { return depth_; } framework_graph::framework_graph(product_store_ptr store, int const max_parallelism) : framework_graph{[store](framework_driver& driver) { driver.yield(store); }, max_parallelism} diff --git a/phlex/core/framework_graph.hpp b/phlex/core/framework_graph.hpp index 18aa00cc5..fbfe367bf 100644 --- a/phlex/core/framework_graph.hpp +++ b/phlex/core/framework_graph.hpp @@ -11,7 +11,7 @@ #include "phlex/core/message_sender.hpp" #include "phlex/core/multiplexer.hpp" #include "phlex/core/node_catalog.hpp" -#include "phlex/model/level_hierarchy.hpp" +#include "phlex/model/data_layer_hierarchy.hpp" #include "phlex/model/product_store.hpp" #include "phlex/source.hpp" #include "phlex/utilities/max_allowed_parallelism.hpp" @@ -32,10 +32,10 @@ namespace phlex::experimental { class configuration; - class level_sentry { + class layer_sentry { public: - level_sentry(flush_counters& counters, message_sender& sender, product_store_ptr store); - ~level_sentry(); + layer_sentry(flush_counters& counters, message_sender& sender, product_store_ptr store); + ~layer_sentry(); std::size_t depth() const noexcept; private: @@ -133,7 +133,7 @@ namespace phlex::experimental { resource_usage graph_resource_usage_{}; max_allowed_parallelism parallelism_limit_; - level_hierarchy hierarchy_{}; + data_layer_hierarchy hierarchy_{}; node_catalog nodes_{}; std::map filters_{}; // The graph_ object uses the filters_, nodes_, and hierarchy_ objects implicitly. @@ -146,7 +146,7 @@ namespace phlex::experimental { message_sender sender_{hierarchy_, multiplexer_, eoms_}; std::queue pending_stores_; flush_counters counters_; - std::stack levels_; + std::stack levels_; bool shutdown_{false}; }; } diff --git a/phlex/core/message.cpp b/phlex/core/message.cpp index 456b147de..ac816fbdf 100644 --- a/phlex/core/message.cpp +++ b/phlex/core/message.cpp @@ -1,5 +1,5 @@ #include "phlex/core/message.hpp" -#include "phlex/model/level_id.hpp" +#include "phlex/model/data_cell_index.hpp" #include #include diff --git a/phlex/core/message_sender.cpp b/phlex/core/message_sender.cpp index 22c90ff4b..969ed1d77 100644 --- a/phlex/core/message_sender.cpp +++ b/phlex/core/message_sender.cpp @@ -6,7 +6,7 @@ #include namespace phlex::experimental { - message_sender::message_sender(level_hierarchy& hierarchy, + message_sender::message_sender(data_layer_hierarchy& hierarchy, multiplexer& mplexer, std::stack& eoms) : hierarchy_{hierarchy}, multiplexer_{mplexer}, eoms_{eoms} diff --git a/phlex/core/message_sender.hpp b/phlex/core/message_sender.hpp index 2ef9162f1..8fb9abb51 100644 --- a/phlex/core/message_sender.hpp +++ b/phlex/core/message_sender.hpp @@ -13,7 +13,7 @@ namespace phlex::experimental { class message_sender { public: - explicit message_sender(level_hierarchy& hierarchy, + explicit message_sender(data_layer_hierarchy& hierarchy, multiplexer& mplexer, std::stack& eoms); @@ -23,10 +23,10 @@ namespace phlex::experimental { private: std::size_t original_message_id(product_store_ptr const& store); - level_hierarchy& hierarchy_; + data_layer_hierarchy& hierarchy_; multiplexer& multiplexer_; std::stack& eoms_; - std::map original_message_ids_; + std::map original_message_ids_; std::size_t calls_{}; }; diff --git a/phlex/core/multiplexer.cpp b/phlex/core/multiplexer.cpp index 2ac6f57d9..cd3a37e75 100644 --- a/phlex/core/multiplexer.cpp +++ b/phlex/core/multiplexer.cpp @@ -16,14 +16,14 @@ namespace { phlex::experimental::product_store_const_ptr store, phlex::experimental::product_query const& label) { - auto const& [product_name, family] = label; - if (family.empty()) { + auto const& [product_name, layer] = label; + if (layer.empty()) { return store->store_for_product(product_name.full()); } - if (store->level_name() == family and store->contains_product(product_name.full())) { + if (store->layer_name() == layer and store->contains_product(product_name.full())) { return store; } - auto parent = store->parent(family); + auto parent = store->parent(layer); if (not parent) { return nullptr; } @@ -56,8 +56,8 @@ namespace { continue; } - if (auto const& allowed_family = product_label.family; not allowed_family.empty()) { - if (store_to_send->level_name() != allowed_family) { + if (auto const& allowed_layer = product_label.layer; not allowed_layer.empty()) { + if (store_to_send->layer_name() != allowed_layer) { continue; } } diff --git a/phlex/core/multiplexer.hpp b/phlex/core/multiplexer.hpp index c72fd5f38..bb956f29c 100644 --- a/phlex/core/multiplexer.hpp +++ b/phlex/core/multiplexer.hpp @@ -2,7 +2,7 @@ #define PHLEX_CORE_MULTIPLEXER_HPP #include "phlex/core/message.hpp" -#include "phlex/model/level_id.hpp" +#include "phlex/model/data_cell_index.hpp" #include "oneapi/tbb/concurrent_hash_map.h" #include "oneapi/tbb/flow_graph.h" diff --git a/phlex/core/product_query.cpp b/phlex/core/product_query.cpp index 48421b88f..e3c425030 100644 --- a/phlex/core/product_query.cpp +++ b/phlex/core/product_query.cpp @@ -7,17 +7,17 @@ #include namespace phlex::experimental { - product_query product_query::operator()(std::string family) && + product_query product_query::operator()(std::string layer) && { - return {std::move(name), std::move(family)}; + return {std::move(name), std::move(layer)}; } std::string product_query::to_string() const { - if (family.empty()) { + if (layer.empty()) { return name.full(); } - return fmt::format("{} ϵ {}", name.full(), family); + return fmt::format("{} ϵ {}", name.full(), layer); } product_query operator""_in(char const* name, std::size_t length) @@ -30,14 +30,14 @@ namespace phlex::experimental { bool operator==(product_query const& a, product_query const& b) { - return std::tie(a.name, a.family) == std::tie(b.name, b.family); + return std::tie(a.name, a.layer) == std::tie(b.name, b.layer); } bool operator!=(product_query const& a, product_query const& b) { return !(a == b); } bool operator<(product_query const& a, product_query const& b) { - return std::tie(a.name, a.family) < std::tie(b.name, b.family); + return std::tie(a.name, a.layer) < std::tie(b.name, b.layer); } std::ostream& operator<<(std::ostream& os, product_query const& label) diff --git a/phlex/core/product_query.hpp b/phlex/core/product_query.hpp index 026d51a93..cce79e8f5 100644 --- a/phlex/core/product_query.hpp +++ b/phlex/core/product_query.hpp @@ -12,8 +12,8 @@ namespace phlex::experimental { struct product_query { product_specification name; - std::string family; - product_query operator()(std::string family) &&; + std::string layer; + product_query operator()(std::string layer) &&; std::string to_string() const; static product_query create(char const* c); @@ -24,7 +24,7 @@ namespace phlex::experimental { using product_queries = std::vector; inline auto& to_name(product_query const& label) { return label.name.name(); } - inline auto& to_family(product_query& label) { return label.family; } + inline auto& to_layer(product_query& label) { return label.layer; } product_query operator""_in(char const* str, std::size_t); bool operator==(product_query const& a, product_query const& b); diff --git a/phlex/core/store_counters.cpp b/phlex/core/store_counters.cpp index 3f9216854..d09cd4e88 100644 --- a/phlex/core/store_counters.cpp +++ b/phlex/core/store_counters.cpp @@ -1,5 +1,5 @@ #include "phlex/core/store_counters.hpp" -#include "phlex/model/level_counter.hpp" +#include "phlex/model/data_cell_counter.hpp" #include "fmt/std.h" #include "spdlog/spdlog.h" @@ -18,7 +18,7 @@ namespace phlex::experimental { unsigned int store_flag::original_message_id() const noexcept { return original_message_id_; } - store_flag& detect_flush_flag::flag_for(level_id::hash_type const hash) + store_flag& detect_flush_flag::flag_for(data_cell_index::hash_type const hash) { flag_accessor fa; flags_.emplace(fa, hash, std::make_unique()); @@ -52,7 +52,10 @@ namespace phlex::experimental { original_message_id_ = original_message_id; } - void store_counter::increment(level_id::hash_type const level_hash) { ++counts_[level_hash]; } + void store_counter::increment(data_cell_index::hash_type const layer_hash) + { + ++counts_[layer_hash]; + } bool store_counter::is_complete() { @@ -75,8 +78,8 @@ namespace phlex::experimental { return false; } - for (auto const& [level_hash, count] : counts_) { - auto maybe_count = flush_counts->count_for(level_hash); + for (auto const& [layer_hash, count] : counts_) { + auto maybe_count = flush_counts->count_for(layer_hash); if (!maybe_count or count != *maybe_count) { return false; } @@ -88,7 +91,7 @@ namespace phlex::experimental { unsigned int store_counter::original_message_id() const noexcept { return original_message_id_; } - store_counter& count_stores::counter_for(level_id::hash_type const hash) + store_counter& count_stores::counter_for(data_cell_index::hash_type const hash) { counter_accessor ca; if (!counters_.find(ca, hash)) { @@ -97,7 +100,7 @@ namespace phlex::experimental { return *ca->second; } - std::unique_ptr count_stores::done_with(level_id::hash_type const hash) + std::unique_ptr count_stores::done_with(data_cell_index::hash_type const hash) { // Must be called after an insertion has already been performed counter_accessor ca; diff --git a/phlex/core/store_counters.hpp b/phlex/core/store_counters.hpp index a32b083d6..99216c944 100644 --- a/phlex/core/store_counters.hpp +++ b/phlex/core/store_counters.hpp @@ -2,8 +2,8 @@ #define PHLEX_CORE_STORE_COUNTERS_HPP #include "phlex/core/fwd.hpp" -#include "phlex/model/level_counter.hpp" -#include "phlex/model/level_id.hpp" +#include "phlex/model/data_cell_counter.hpp" +#include "phlex/model/data_cell_index.hpp" #include "phlex/model/product_store.hpp" #include "oneapi/tbb/concurrent_hash_map.h" @@ -29,11 +29,12 @@ namespace phlex::experimental { class detect_flush_flag { protected: - store_flag& flag_for(level_id::hash_type hash); + store_flag& flag_for(data_cell_index::hash_type hash); bool done_with(product_store_const_ptr const& store); private: - using flags_t = tbb::concurrent_hash_map>; + using flags_t = + tbb::concurrent_hash_map>; using flag_accessor = flags_t::accessor; using const_flag_accessor = flags_t::const_accessor; @@ -45,12 +46,13 @@ namespace phlex::experimental { class store_counter { public: void set_flush_value(product_store_const_ptr const& ptr, std::size_t original_message_id); - void increment(level_id::hash_type level_hash); + void increment(data_cell_index::hash_type layer_hash); bool is_complete(); unsigned int original_message_id() const noexcept; private: - using counts_t2 = tbb::concurrent_unordered_map>; + using counts_t2 = + tbb::concurrent_unordered_map>; counts_t2 counts_{}; #ifdef __cpp_lib_atomic_shared_ptr @@ -64,12 +66,12 @@ namespace phlex::experimental { class count_stores { protected: - store_counter& counter_for(level_id::hash_type hash); - std::unique_ptr done_with(level_id::hash_type hash); + store_counter& counter_for(data_cell_index::hash_type hash); + std::unique_ptr done_with(data_cell_index::hash_type hash); private: using counters_t = - tbb::concurrent_hash_map>; + tbb::concurrent_hash_map>; using counter_accessor = counters_t::accessor; counters_t counters_; diff --git a/phlex/model/CMakeLists.txt b/phlex/model/CMakeLists.txt index 9ec2f0745..95c2e9766 100644 --- a/phlex/model/CMakeLists.txt +++ b/phlex/model/CMakeLists.txt @@ -1,9 +1,9 @@ add_library( phlex_model SHARED algorithm_name.cpp - level_counter.cpp - level_hierarchy.cpp - level_id.cpp + data_cell_counter.cpp + data_layer_hierarchy.cpp + data_cell_index.cpp product_matcher.cpp product_store.cpp products.cpp diff --git a/phlex/model/data_cell_counter.cpp b/phlex/model/data_cell_counter.cpp new file mode 100644 index 000000000..f25382d7f --- /dev/null +++ b/phlex/model/data_cell_counter.cpp @@ -0,0 +1,62 @@ +#include "phlex/model/data_cell_counter.hpp" +#include "phlex/utilities/hashing.hpp" + +#include + +namespace phlex::experimental { + + flush_counts::flush_counts() = default; + + flush_counts::flush_counts(std::map child_counts) : + child_counts_{std::move(child_counts)} + { + } + + data_cell_counter::data_cell_counter() : data_cell_counter{nullptr, "job"} {} + + data_cell_counter::data_cell_counter(data_cell_counter* parent, std::string const& layer_name) : + parent_{parent}, layer_hash_{parent_ ? hash(parent->layer_hash_, layer_name) : hash(layer_name)} + { + } + + data_cell_counter::~data_cell_counter() + { + if (parent_) { + parent_->adjust(*this); + } + } + + data_cell_counter data_cell_counter::make_child(std::string const& layer_name) + { + return {this, layer_name}; + } + + void data_cell_counter::adjust(data_cell_counter& child) + { + auto it2 = child_counts_.find(child.layer_hash_); + if (it2 == cend(child_counts_)) { + it2 = child_counts_.try_emplace(child.layer_hash_, 0).first; + } + ++it2->second; + for (auto const& [nested_layer_hash, count] : child.child_counts_) { + child_counts_[nested_layer_hash] += count; + } + } + + void flush_counters::update(data_cell_index_ptr const id) + { + data_cell_counter* parent_counter = nullptr; + if (auto parent = id->parent()) { + auto it = counters_.find(parent->hash()); + assert(it != counters_.cend()); + parent_counter = it->second.get(); + } + counters_[id->hash()] = std::make_shared(parent_counter, id->layer_name()); + } + + flush_counts flush_counters::extract(data_cell_index_ptr const id) + { + auto counter = counters_.extract(id->hash()); + return counter.mapped()->result(); + } +} diff --git a/phlex/model/data_cell_counter.hpp b/phlex/model/data_cell_counter.hpp new file mode 100644 index 000000000..f744a18b1 --- /dev/null +++ b/phlex/model/data_cell_counter.hpp @@ -0,0 +1,71 @@ +#ifndef PHLEX_MODEL_DATA_CELL_COUNTER_HPP +#define PHLEX_MODEL_DATA_CELL_COUNTER_HPP + +#include "phlex/model/data_cell_index.hpp" +#include "phlex/model/fwd.hpp" + +#include "oneapi/tbb/concurrent_hash_map.h" + +#include +#include +#include + +namespace phlex::experimental { + class flush_counts { + public: + flush_counts(); + explicit flush_counts(std::map child_counts); + + auto begin() const { return child_counts_.begin(); } + auto end() const { return child_counts_.end(); } + bool empty() const { return child_counts_.empty(); } + auto size() const { return child_counts_.size(); } + + std::optional count_for(data_cell_index::hash_type const layer_hash) const + { + if (auto it = child_counts_.find(layer_hash); it != child_counts_.end()) { + return it->second; + } + return std::nullopt; + } + + private: + std::map child_counts_{}; + }; + + using flush_counts_ptr = std::shared_ptr; + + class data_cell_counter { + public: + data_cell_counter(); + data_cell_counter(data_cell_counter* parent, std::string const& layer_name); + ~data_cell_counter(); + + data_cell_counter make_child(std::string const& layer_name); + flush_counts result() const + { + if (empty(child_counts_)) { + return flush_counts{}; + } + return flush_counts{child_counts_}; + } + + private: + void adjust(data_cell_counter& child); + + data_cell_counter* parent_; + data_cell_index::hash_type layer_hash_; + std::map child_counts_{}; + }; + + class flush_counters { + public: + void update(data_cell_index_ptr const id); + flush_counts extract(data_cell_index_ptr const id); + + private: + std::map> counters_; + }; +} + +#endif // PHLEX_MODEL_DATA_CELL_COUNTER_HPP diff --git a/phlex/model/data_cell_index.cpp b/phlex/model/data_cell_index.cpp new file mode 100644 index 000000000..b7fee40a9 --- /dev/null +++ b/phlex/model/data_cell_index.cpp @@ -0,0 +1,162 @@ +#include "phlex/model/data_cell_index.hpp" +#include "phlex/utilities/hashing.hpp" + +#include "boost/algorithm/string.hpp" + +#include +#include +#include +#include +#include + +namespace { + + std::vector all_numbers(phlex::experimental::data_cell_index const& id) + { + if (!id.has_parent()) { + return {}; + } + + auto const* current = &id; + std::vector result(id.depth()); + for (std::size_t i = id.depth(); i > 0; --i) { + result[i - 1] = current->number(); + current = current->parent().get(); + } + return result; + } + +} + +namespace phlex::experimental { + + data_cell_index::data_cell_index() : + layer_name_{"job"}, layer_hash_{phlex::experimental::hash(layer_name_)} + { + } + + data_cell_index::data_cell_index(data_cell_index_ptr parent, + std::size_t i, + std::string layer_name) : + parent_{std::move(parent)}, + number_{i}, + layer_name_{std::move(layer_name)}, + layer_hash_{phlex::experimental::hash(parent_->layer_hash_, layer_name_)}, + depth_{parent_->depth_ + 1}, + hash_{phlex::experimental::hash(parent_->hash_, number_, layer_hash_)} + { + // FIXME: Should it be an error to create an ID with an empty name? + } + + data_cell_index const& data_cell_index::base() { return *base_ptr(); } + data_cell_index_ptr data_cell_index::base_ptr() + { + static phlex::experimental::data_cell_index_ptr base_id{new data_cell_index}; + return base_id; + } + + std::string const& data_cell_index::layer_name() const noexcept { return layer_name_; } + std::size_t data_cell_index::depth() const noexcept { return depth_; } + + data_cell_index_ptr data_cell_index::make_child(std::size_t const new_level_number, + std::string new_layer_name) const + { + return data_cell_index_ptr{ + new data_cell_index{shared_from_this(), new_level_number, std::move(new_layer_name)}}; + } + + bool data_cell_index::has_parent() const noexcept { return static_cast(parent_); } + + std::size_t data_cell_index::number() const { return number_; } + std::size_t data_cell_index::hash() const noexcept { return hash_; } + std::size_t data_cell_index::layer_hash() const noexcept { return layer_hash_; } + + bool data_cell_index::operator==(data_cell_index const& other) const + { + if (depth_ != other.depth_) + return false; + auto const same_numbers = number_ == other.number_; + if (not parent_) { + return same_numbers; + } + return *parent_ == *other.parent_ && same_numbers; + } + + bool data_cell_index::operator<(data_cell_index const& other) const + { + auto these_numbers = all_numbers(*this); + auto those_numbers = all_numbers(other); + return std::lexicographical_compare( + begin(these_numbers), end(these_numbers), begin(those_numbers), end(those_numbers)); + } + + data_cell_index_ptr id_for(std::vector nums) + { + auto current = data_cell_index::base_ptr(); + for (auto const num : nums) { + current = current->make_child(num, ""); + } + return current; + } + + data_cell_index_ptr id_for(char const* c_str) + { + std::vector strs; + split(strs, c_str, boost::is_any_of(":")); + + erase_if(strs, [](auto& str) { return empty(str); }); + + std::vector nums; + std::transform(begin(strs), end(strs), back_inserter(nums), [](auto const& str) { + return std::stoull(str); + }); + return id_for(std::move(nums)); + } + + data_cell_index_ptr operator""_id(char const* c_str, std::size_t) { return id_for(c_str); } + + data_cell_index_ptr data_cell_index::parent() const noexcept { return parent_; } + + data_cell_index_ptr data_cell_index::parent(std::string const& layer_name) const + { + data_cell_index_ptr parent = parent_; + while (parent) { + if (parent->layer_name_ == layer_name) { + return parent; + } + parent = parent->parent_; + } + return nullptr; + } + + std::string data_cell_index::to_string() const + { + // FIXME: prefix needs to be adjusted esp. if a root name can be supplied by the user. + std::string prefix{"["}; //"root: ["}; + std::string result; + std::string suffix{"]"}; + + if (number_ != -1ull) { + result = to_string_this_level(); + auto parent = parent_; + while (parent != nullptr and parent->number_ != -1ull) { + result.insert(0, parent->to_string_this_level() + ", "); + parent = parent->parent_; + } + } + return prefix + result + suffix; + } + + std::string data_cell_index::to_string_this_level() const + { + if (empty(layer_name_)) { + return std::to_string(number_); + } + return layer_name_ + ":" + std::to_string(number_); + } + + std::ostream& operator<<(std::ostream& os, data_cell_index const& id) + { + return os << id.to_string(); + } +} diff --git a/phlex/model/data_cell_index.hpp b/phlex/model/data_cell_index.hpp new file mode 100644 index 000000000..f7338dfef --- /dev/null +++ b/phlex/model/data_cell_index.hpp @@ -0,0 +1,65 @@ +#ifndef PHLEX_MODEL_DATA_CELL_ID_HPP +#define PHLEX_MODEL_DATA_CELL_ID_HPP + +#include "phlex/model/fwd.hpp" + +#include +#include +#include +#include +#include +#include +#include + +namespace phlex::experimental { + class data_cell_index : public std::enable_shared_from_this { + public: + static data_cell_index const& base(); + static data_cell_index_ptr base_ptr(); + + using hash_type = std::size_t; + data_cell_index_ptr make_child(std::size_t new_level_number, std::string layer_name) const; + std::string const& layer_name() const noexcept; + std::size_t depth() const noexcept; + data_cell_index_ptr parent(std::string const& layer_name) const; + data_cell_index_ptr parent() const noexcept; + bool has_parent() const noexcept; + std::size_t number() const; + std::size_t hash() const noexcept; + std::size_t layer_hash() const noexcept; + bool operator==(data_cell_index const& other) const; + bool operator<(data_cell_index const& other) const; + + std::string to_string() const; + std::string to_string_this_level() const; + + friend std::ostream& operator<<(std::ostream& os, data_cell_index const& id); + + private: + data_cell_index(); + explicit data_cell_index(data_cell_index_ptr parent, std::size_t i, std::string layer_name); + data_cell_index_ptr parent_{nullptr}; + std::size_t number_{-1ull}; + std::string layer_name_; + std::size_t layer_hash_; + std::size_t depth_{}; + hash_type hash_{0}; + }; + + data_cell_index_ptr id_for(char const* str); + data_cell_index_ptr id_for(std::vector nums); + data_cell_index_ptr operator""_id(char const* str, std::size_t); + std::ostream& operator<<(std::ostream& os, data_cell_index const& id); +} + +namespace std { + template <> + struct hash { + std::size_t operator()(phlex::experimental::data_cell_index const& id) const noexcept + { + return id.hash(); + } + }; +} + +#endif // PHLEX_MODEL_DATA_CELL_ID_HPP diff --git a/phlex/model/level_hierarchy.cpp b/phlex/model/data_layer_hierarchy.cpp similarity index 54% rename from phlex/model/level_hierarchy.cpp rename to phlex/model/data_layer_hierarchy.cpp index eefb430e6..09f6a719e 100644 --- a/phlex/model/level_hierarchy.cpp +++ b/phlex/model/data_layer_hierarchy.cpp @@ -1,5 +1,5 @@ -#include "phlex/model/level_hierarchy.hpp" -#include "phlex/model/level_id.hpp" +#include "phlex/model/data_layer_hierarchy.hpp" +#include "phlex/model/data_cell_index.hpp" #include "fmt/format.h" #include "fmt/std.h" @@ -12,38 +12,39 @@ namespace { namespace phlex::experimental { - level_hierarchy::~level_hierarchy() { print(); } + data_layer_hierarchy::~data_layer_hierarchy() { print(); } - void level_hierarchy::increment_count(level_id_ptr const& id) + void data_layer_hierarchy::increment_count(data_cell_index_ptr const& id) { - if (auto it = levels_.find(id->level_hash()); it != levels_.cend()) { + if (auto it = layers_.find(id->layer_hash()); it != layers_.cend()) { ++it->second->count; return; } - auto const parent_hash = id->has_parent() ? id->parent()->level_hash() : -1ull; + auto const parent_hash = id->has_parent() ? id->parent()->layer_hash() : -1ull; // Warning: It can happen that two threads get to this location at the same time. To // guard against overwriting the value of "count", we use the returned iterator "it", // which will either refer to the new node in the map, or to the already-emplaced // node. We then increment the count. - auto [it, _] = levels_.emplace(id->level_hash(), - std::make_shared(id->level_name(), parent_hash)); + auto [it, _] = layers_.emplace(id->layer_hash(), + std::make_shared(id->layer_name(), parent_hash)); ++it->second->count; } - std::size_t level_hierarchy::count_for(std::string const& level_name) const + std::size_t data_layer_hierarchy::count_for(std::string const& layer_name) const { - auto it = find_if(begin(levels_), end(levels_), [&level_name](auto const& level) { - return level.second->name == level_name; + auto it = find_if(begin(layers_), end(layers_), [&layer_name](auto const& level) { + return level.second->name == layer_name; }); - return it != cend(levels_) ? it->second->count.load() : 0; + return it != cend(layers_) ? it->second->count.load() : 0; } - void level_hierarchy::print() const { spdlog::info("{}", graph_layout()); } + void data_layer_hierarchy::print() const { spdlog::info("{}", graph_layout()); } - std::string level_hierarchy::pretty_recurse(std::map const& tree, - std::string const& name, - std::string indent) const + std::string data_layer_hierarchy::pretty_recurse( + std::map const& tree, + std::string const& name, + std::string indent) const { auto it = tree.find(name); if (it == cend(tree)) { @@ -55,7 +56,7 @@ namespace phlex::experimental { for (std::size_t i = 0; auto const& [child_name, child_hash] : it->second) { bool const at_end = ++i == n; auto child_prefix = !at_end ? indent + " ├ " : indent + " └ "; - auto const& entry = *levels_.at(child_hash); + auto const& entry = *layers_.at(child_hash); result += "\n" + indent + " │ "; result += fmt::format("\n{}{}: {}", child_prefix, maybe_name(child_name), entry.count); @@ -66,20 +67,20 @@ namespace phlex::experimental { return result; } - std::string level_hierarchy::graph_layout() const + std::string data_layer_hierarchy::graph_layout() const { - if (empty(levels_)) { + if (empty(layers_)) { return {}; } std::map> tree; - for (auto const& [level_hash, level_entry] : levels_) { - auto parent_hash = level_entry->parent_hash; + for (auto const& [layer_hash, layer_entry] : layers_) { + auto parent_hash = layer_entry->parent_hash; if (parent_hash == -1ull) { continue; } - auto const& parent_name = levels_.at(parent_hash)->name; - tree[parent_name].emplace_back(level_entry->name, level_hash); + auto const& parent_name = layers_.at(parent_hash)->name; + tree[parent_name].emplace_back(layer_entry->name, layer_hash); } auto const initial_indent = " "; diff --git a/phlex/model/level_hierarchy.hpp b/phlex/model/data_layer_hierarchy.hpp similarity index 63% rename from phlex/model/level_hierarchy.hpp rename to phlex/model/data_layer_hierarchy.hpp index bf4b8e5ce..b6cad43e5 100644 --- a/phlex/model/level_hierarchy.hpp +++ b/phlex/model/data_layer_hierarchy.hpp @@ -1,8 +1,8 @@ -#ifndef PHLEX_MODEL_LEVEL_HIERARCHY_HPP -#define PHLEX_MODEL_LEVEL_HIERARCHY_HPP +#ifndef PHLEX_MODEL_DATA_LAYER_HIERARCHY_HPP +#define PHLEX_MODEL_DATA_LAYER_HIERARCHY_HPP +#include "phlex/model/data_cell_index.hpp" #include "phlex/model/fwd.hpp" -#include "phlex/model/level_id.hpp" #include "oneapi/tbb/concurrent_unordered_map.h" @@ -13,11 +13,11 @@ namespace phlex::experimental { - class level_hierarchy { + class data_layer_hierarchy { public: - ~level_hierarchy(); - void increment_count(level_id_ptr const& id); - std::size_t count_for(std::string const& level_name) const; + ~data_layer_hierarchy(); + void increment_count(data_cell_index_ptr const& id); + std::size_t count_for(std::string const& layer_name) const; void print() const; @@ -30,8 +30,8 @@ namespace phlex::experimental { std::string const& parent_name, std::string indent = {}) const; - struct level_entry { - level_entry(std::string n, std::size_t par_hash) : name{std::move(n)}, parent_hash{par_hash} + struct layer_entry { + layer_entry(std::string n, std::size_t par_hash) : name{std::move(n)}, parent_hash{par_hash} { } @@ -40,9 +40,9 @@ namespace phlex::experimental { std::atomic count{}; }; - tbb::concurrent_unordered_map> levels_; + tbb::concurrent_unordered_map> layers_; }; } -#endif // PHLEX_MODEL_LEVEL_HIERARCHY_HPP +#endif // PHLEX_MODEL_DATA_LAYER_HIERARCHY_HPP diff --git a/phlex/model/fwd.hpp b/phlex/model/fwd.hpp index 7aeffc9e6..568d6fc64 100644 --- a/phlex/model/fwd.hpp +++ b/phlex/model/fwd.hpp @@ -4,12 +4,12 @@ #include namespace phlex::experimental { - class level_counter; - class level_hierarchy; - class level_id; + class data_cell_counter; + class data_layer_hierarchy; + class data_cell_index; class product_store; - using level_id_ptr = std::shared_ptr; + using data_cell_index_ptr = std::shared_ptr; using product_store_const_ptr = std::shared_ptr; using product_store_ptr = std::shared_ptr; diff --git a/phlex/model/handle.hpp b/phlex/model/handle.hpp index 21987c2e5..555b09663 100644 --- a/phlex/model/handle.hpp +++ b/phlex/model/handle.hpp @@ -1,7 +1,7 @@ #ifndef PHLEX_MODEL_HANDLE_HPP #define PHLEX_MODEL_HANDLE_HPP -#include "phlex/model/level_id.hpp" +#include "phlex/model/data_cell_index.hpp" #include #include @@ -53,7 +53,7 @@ namespace phlex::experimental { using const_pointer = value_type const*; // The 'product' parameter is not 'const_reference' to avoid avoid implicit type conversions. - explicit handle(std::same_as auto const& product, level_id const& id) : + explicit handle(std::same_as auto const& product, data_cell_index const& id) : product_{&product}, id_{&id} { } @@ -74,7 +74,7 @@ namespace phlex::experimental { operator const_reference() const noexcept { return operator*(); } operator const_pointer() const noexcept { return operator->(); } - auto const& level_id() const noexcept { return *id_; } + auto const& data_cell_index() const noexcept { return *id_; } template friend class handle; @@ -85,12 +85,12 @@ namespace phlex::experimental { } private: - const_pointer product_; // Non-null, by construction - class level_id const* id_; // Non-null, by construction + const_pointer product_; // Non-null, by construction + class data_cell_index const* id_; // Non-null, by construction }; template - handle(T const&, level_id const&) -> handle; + handle(T const&, data_cell_index const&) -> handle; } #endif // PHLEX_MODEL_HANDLE_HPP diff --git a/phlex/model/level_counter.cpp b/phlex/model/level_counter.cpp deleted file mode 100644 index 68770e2e6..000000000 --- a/phlex/model/level_counter.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "phlex/model/level_counter.hpp" -#include "phlex/utilities/hashing.hpp" - -#include - -namespace phlex::experimental { - - flush_counts::flush_counts() = default; - - flush_counts::flush_counts(std::map child_counts) : - child_counts_{std::move(child_counts)} - { - } - - level_counter::level_counter() : level_counter{nullptr, "job"} {} - - level_counter::level_counter(level_counter* parent, std::string const& level_name) : - parent_{parent}, level_hash_{parent_ ? hash(parent->level_hash_, level_name) : hash(level_name)} - { - } - - level_counter::~level_counter() - { - if (parent_) { - parent_->adjust(*this); - } - } - - level_counter level_counter::make_child(std::string const& level_name) - { - return {this, level_name}; - } - - void level_counter::adjust(level_counter& child) - { - auto it2 = child_counts_.find(child.level_hash_); - if (it2 == cend(child_counts_)) { - it2 = child_counts_.try_emplace(child.level_hash_, 0).first; - } - ++it2->second; - for (auto const& [nested_level_hash, count] : child.child_counts_) { - child_counts_[nested_level_hash] += count; - } - } - - void flush_counters::update(level_id_ptr const id) - { - level_counter* parent_counter = nullptr; - if (auto parent = id->parent()) { - auto it = counters_.find(parent->hash()); - assert(it != counters_.cend()); - parent_counter = it->second.get(); - } - counters_[id->hash()] = std::make_shared(parent_counter, id->level_name()); - } - - flush_counts flush_counters::extract(level_id_ptr const id) - { - auto counter = counters_.extract(id->hash()); - return counter.mapped()->result(); - } -} diff --git a/phlex/model/level_counter.hpp b/phlex/model/level_counter.hpp deleted file mode 100644 index 0ba3c2295..000000000 --- a/phlex/model/level_counter.hpp +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef PHLEX_MODEL_LEVEL_COUNTER_HPP -#define PHLEX_MODEL_LEVEL_COUNTER_HPP - -#include "phlex/model/fwd.hpp" -#include "phlex/model/level_id.hpp" - -#include "oneapi/tbb/concurrent_hash_map.h" - -#include -#include -#include - -namespace phlex::experimental { - class flush_counts { - public: - flush_counts(); - explicit flush_counts(std::map child_counts); - - auto begin() const { return child_counts_.begin(); } - auto end() const { return child_counts_.end(); } - bool empty() const { return child_counts_.empty(); } - auto size() const { return child_counts_.size(); } - - std::optional count_for(level_id::hash_type const level_hash) const - { - if (auto it = child_counts_.find(level_hash); it != child_counts_.end()) { - return it->second; - } - return std::nullopt; - } - - private: - std::map child_counts_{}; - }; - - using flush_counts_ptr = std::shared_ptr; - - class level_counter { - public: - level_counter(); - level_counter(level_counter* parent, std::string const& level_name); - ~level_counter(); - - level_counter make_child(std::string const& level_name); - flush_counts result() const - { - if (empty(child_counts_)) { - return flush_counts{}; - } - return flush_counts{child_counts_}; - } - - private: - void adjust(level_counter& child); - - level_counter* parent_; - level_id::hash_type level_hash_; - std::map child_counts_{}; - }; - - class flush_counters { - public: - void update(level_id_ptr const id); - flush_counts extract(level_id_ptr const id); - - private: - std::map> counters_; - }; -} - -#endif // PHLEX_MODEL_LEVEL_COUNTER_HPP diff --git a/phlex/model/level_id.cpp b/phlex/model/level_id.cpp deleted file mode 100644 index 390308921..000000000 --- a/phlex/model/level_id.cpp +++ /dev/null @@ -1,154 +0,0 @@ -#include "phlex/model/level_id.hpp" -#include "phlex/utilities/hashing.hpp" - -#include "boost/algorithm/string.hpp" - -#include -#include -#include -#include -#include - -namespace { - - std::vector all_numbers(phlex::experimental::level_id const& id) - { - if (!id.has_parent()) { - return {}; - } - - auto const* current = &id; - std::vector result(id.depth()); - for (std::size_t i = id.depth(); i > 0; --i) { - result[i - 1] = current->number(); - current = current->parent().get(); - } - return result; - } - -} - -namespace phlex::experimental { - - level_id::level_id() : level_name_{"job"}, level_hash_{phlex::experimental::hash(level_name_)} {} - - level_id::level_id(level_id_ptr parent, std::size_t i, std::string level_name) : - parent_{std::move(parent)}, - number_{i}, - level_name_{std::move(level_name)}, - level_hash_{phlex::experimental::hash(parent_->level_hash_, level_name_)}, - depth_{parent_->depth_ + 1}, - hash_{phlex::experimental::hash(parent_->hash_, number_, level_hash_)} - { - // FIXME: Should it be an error to create an ID with an empty name? - } - - level_id const& level_id::base() { return *base_ptr(); } - level_id_ptr level_id::base_ptr() - { - static phlex::experimental::level_id_ptr base_id{new level_id}; - return base_id; - } - - std::string const& level_id::level_name() const noexcept { return level_name_; } - std::size_t level_id::depth() const noexcept { return depth_; } - - level_id_ptr level_id::make_child(std::size_t const new_level_number, - std::string new_level_name) const - { - return level_id_ptr{ - new level_id{shared_from_this(), new_level_number, std::move(new_level_name)}}; - } - - bool level_id::has_parent() const noexcept { return static_cast(parent_); } - - std::size_t level_id::number() const { return number_; } - std::size_t level_id::hash() const noexcept { return hash_; } - std::size_t level_id::level_hash() const noexcept { return level_hash_; } - - bool level_id::operator==(level_id const& other) const - { - if (depth_ != other.depth_) - return false; - auto const same_numbers = number_ == other.number_; - if (not parent_) { - return same_numbers; - } - return *parent_ == *other.parent_ && same_numbers; - } - - bool level_id::operator<(level_id const& other) const - { - auto these_numbers = all_numbers(*this); - auto those_numbers = all_numbers(other); - return std::lexicographical_compare( - begin(these_numbers), end(these_numbers), begin(those_numbers), end(those_numbers)); - } - - level_id_ptr id_for(std::vector nums) - { - auto current = level_id::base_ptr(); - for (auto const num : nums) { - current = current->make_child(num, ""); - } - return current; - } - - level_id_ptr id_for(char const* c_str) - { - std::vector strs; - split(strs, c_str, boost::is_any_of(":")); - - erase_if(strs, [](auto& str) { return empty(str); }); - - std::vector nums; - std::transform(begin(strs), end(strs), back_inserter(nums), [](auto const& str) { - return std::stoull(str); - }); - return id_for(std::move(nums)); - } - - level_id_ptr operator""_id(char const* c_str, std::size_t) { return id_for(c_str); } - - level_id_ptr level_id::parent() const noexcept { return parent_; } - - level_id_ptr level_id::parent(std::string const& level_name) const - { - level_id_ptr parent = parent_; - while (parent) { - if (parent->level_name_ == level_name) { - return parent; - } - parent = parent->parent_; - } - return nullptr; - } - - std::string level_id::to_string() const - { - // FIXME: prefix needs to be adjusted esp. if a root name can be supplied by the user. - std::string prefix{"["}; //"root: ["}; - std::string result; - std::string suffix{"]"}; - - if (number_ != -1ull) { - result = to_string_this_level(); - auto parent = parent_; - while (parent != nullptr and parent->number_ != -1ull) { - result.insert(0, parent->to_string_this_level() + ", "); - parent = parent->parent_; - } - } - return prefix + result + suffix; - } - - std::string level_id::to_string_this_level() const - { - if (empty(level_name_)) { - return std::to_string(number_); - } - return level_name_ + ":" + std::to_string(number_); - } - - std::ostream& operator<<(std::ostream& os, level_id const& id) { return os << id.to_string(); } -} diff --git a/phlex/model/level_id.hpp b/phlex/model/level_id.hpp deleted file mode 100644 index 94e488e2c..000000000 --- a/phlex/model/level_id.hpp +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef PHLEX_MODEL_LEVEL_ID_HPP -#define PHLEX_MODEL_LEVEL_ID_HPP - -#include "phlex/model/fwd.hpp" - -#include -#include -#include -#include -#include -#include -#include - -namespace phlex::experimental { - class level_id : public std::enable_shared_from_this { - public: - static level_id const& base(); - static level_id_ptr base_ptr(); - - using hash_type = std::size_t; - level_id_ptr make_child(std::size_t new_level_number, std::string level_name) const; - std::string const& level_name() const noexcept; - std::size_t depth() const noexcept; - level_id_ptr parent(std::string const& level_name) const; - level_id_ptr parent() const noexcept; - bool has_parent() const noexcept; - std::size_t number() const; - std::size_t hash() const noexcept; - std::size_t level_hash() const noexcept; - bool operator==(level_id const& other) const; - bool operator<(level_id const& other) const; - - std::string to_string() const; - std::string to_string_this_level() const; - - friend std::ostream& operator<<(std::ostream& os, level_id const& id); - - private: - level_id(); - explicit level_id(level_id_ptr parent, std::size_t i, std::string level_name); - level_id_ptr parent_{nullptr}; - std::size_t number_{-1ull}; - std::string level_name_; - std::size_t level_hash_; - std::size_t depth_{}; - hash_type hash_{0}; - }; - - level_id_ptr id_for(char const* str); - level_id_ptr id_for(std::vector nums); - level_id_ptr operator""_id(char const* str, std::size_t); - std::ostream& operator<<(std::ostream& os, level_id const& id); -} - -namespace std { - template <> - struct hash { - std::size_t operator()(phlex::experimental::level_id const& id) const noexcept - { - return id.hash(); - } - }; -} - -#endif // PHLEX_MODEL_LEVEL_ID_HPP diff --git a/phlex/model/product_matcher.cpp b/phlex/model/product_matcher.cpp index af3b568a9..a190da122 100644 --- a/phlex/model/product_matcher.cpp +++ b/phlex/model/product_matcher.cpp @@ -20,17 +20,17 @@ namespace { throw std::runtime_error("The matcher specification may not start with a forward slash (/)."); } - std::string const optional_level_path{R"((?:(.*)/)?)"}; + std::string const optional_layer_path{R"((?:(.*)/)?)"}; std::string const optional_qualified_node_name{R"((?:(\w+)?(?:@(\w+))?:)?)"}; std::string const product_name{R"((\w+))"}; - std::regex const pattern{optional_level_path + optional_qualified_node_name + product_name}; + std::regex const pattern{optional_layer_path + optional_qualified_node_name + product_name}; std::smatch submatches; bool const matched = std::regex_match(matcher_spec, submatches, pattern); if (not matched) { throw std::runtime_error( "Provided product specification does not match the supported pattern:\n" - "\"[level path spec/][[module name][@node name]:]product name\""); + "\"[layer path spec/][[module name][@node name]:]product name\""); } assert(submatches.size() == 5); assert(submatches[0] == matcher_spec); @@ -46,7 +46,7 @@ namespace phlex::experimental { } product_matcher::product_matcher(std::array fields) : - level_path_{std::move(fields[0])}, + layer_path_{std::move(fields[0])}, module_name_{std::move(fields[1])}, node_name_{std::move(fields[2])}, product_name_{std::move(fields[3])} @@ -55,6 +55,6 @@ namespace phlex::experimental { std::string product_matcher::encode() const { - return fmt::format("{}/{}@{}:{}", level_path_, module_name_, node_name_, product_name_); + return fmt::format("{}/{}@{}:{}", layer_path_, module_name_, node_name_, product_name_); } } diff --git a/phlex/model/product_matcher.hpp b/phlex/model/product_matcher.hpp index 2be28f04a..632273f06 100644 --- a/phlex/model/product_matcher.hpp +++ b/phlex/model/product_matcher.hpp @@ -19,7 +19,7 @@ namespace phlex::experimental { public: explicit product_matcher(std::string matcher_spec); bool matches(product_store_const_ptr const& store) const; - std::string const& level_path() const noexcept { return level_path_; } + std::string const& layer_path() const noexcept { return layer_path_; } std::string const& module_name() const noexcept { return module_name_; } std::string const& node_name() const noexcept { return node_name_; } std::string const& product_name() const noexcept { return product_name_; } @@ -28,7 +28,7 @@ namespace phlex::experimental { private: explicit product_matcher(std::array fields); - std::string level_path_; + std::string layer_path_; std::string module_name_; std::string node_name_; std::string product_name_; diff --git a/phlex/model/product_store.cpp b/phlex/model/product_store.cpp index 22823a49b..cb35c89fc 100644 --- a/phlex/model/product_store.cpp +++ b/phlex/model/product_store.cpp @@ -1,5 +1,5 @@ #include "phlex/model/product_store.hpp" -#include "phlex/model/level_id.hpp" +#include "phlex/model/data_cell_index.hpp" #include #include @@ -7,7 +7,7 @@ namespace phlex::experimental { product_store::product_store(product_store_const_ptr parent, - level_id_ptr id, + data_cell_index_ptr id, std::string source, stage processing_stage, products new_products) : @@ -21,12 +21,12 @@ namespace phlex::experimental { product_store::product_store(product_store_const_ptr parent, std::size_t new_level_number, - std::string const& new_level_name, + std::string const& new_layer_name, std::string source, products new_products) : parent_{parent}, products_{std::move(new_products)}, - id_{parent->id()->make_child(new_level_number, new_level_name)}, + id_{parent->id()->make_child(new_level_number, new_layer_name)}, source_{std::move(source)}, stage_{stage::process} { @@ -34,11 +34,11 @@ namespace phlex::experimental { product_store::product_store(product_store_const_ptr parent, std::size_t new_level_number, - std::string const& new_level_name, + std::string const& new_layer_name, std::string source, stage processing_stage) : parent_{parent}, - id_{parent->id()->make_child(new_level_number, new_level_name)}, + id_{parent->id()->make_child(new_level_number, new_layer_name)}, source_{std::move(source)}, stage_{processing_stage} { @@ -49,14 +49,14 @@ namespace phlex::experimental { product_store_ptr product_store::base(std::string base_name) { return product_store_ptr{ - new product_store{nullptr, level_id::base_ptr(), std::move(base_name)}}; + new product_store{nullptr, data_cell_index::base_ptr(), std::move(base_name)}}; } - product_store_const_ptr product_store::parent(std::string const& level_name) const noexcept + product_store_const_ptr product_store::parent(std::string const& layer_name) const noexcept { auto store = parent_; while (store != nullptr) { - if (store->level_name() == level_name) { + if (store->layer_name() == layer_name) { return store; } store = store->parent_; @@ -89,30 +89,30 @@ namespace phlex::experimental { } product_store_ptr product_store::make_child(std::size_t new_level_number, - std::string const& new_level_name, + std::string const& new_layer_name, std::string source, products new_products) { return product_store_ptr{new product_store{shared_from_this(), new_level_number, - new_level_name, + new_layer_name, std::move(source), std::move(new_products)}}; } product_store_ptr product_store::make_child(std::size_t new_level_number, - std::string const& new_level_name, + std::string const& new_layer_name, std::string source, stage processing_stage) { return product_store_ptr{new product_store{ - shared_from_this(), new_level_number, new_level_name, std::move(source), processing_stage}}; + shared_from_this(), new_level_number, new_layer_name, std::move(source), processing_stage}}; } - std::string const& product_store::level_name() const noexcept { return id_->level_name(); } + std::string const& product_store::layer_name() const noexcept { return id_->layer_name(); } std::string const& product_store::source() const noexcept { return source_; } product_store_const_ptr product_store::parent() const noexcept { return parent_; } - level_id_ptr const& product_store::id() const noexcept { return id_; } + data_cell_index_ptr const& product_store::id() const noexcept { return id_; } bool product_store::is_flush() const noexcept { return stage_ == stage::flush; } bool product_store::contains_product(std::string const& product_name) const diff --git a/phlex/model/product_store.hpp b/phlex/model/product_store.hpp index c0060902f..00aa2d4d9 100644 --- a/phlex/model/product_store.hpp +++ b/phlex/model/product_store.hpp @@ -1,9 +1,9 @@ #ifndef PHLEX_MODEL_PRODUCT_STORE_HPP #define PHLEX_MODEL_PRODUCT_STORE_HPP +#include "phlex/model/data_cell_index.hpp" #include "phlex/model/fwd.hpp" #include "phlex/model/handle.hpp" -#include "phlex/model/level_id.hpp" #include "phlex/model/products.hpp" #include @@ -24,21 +24,21 @@ namespace phlex::experimental { auto begin() const noexcept { return products_.begin(); } auto end() const noexcept { return products_.end(); } - std::string const& level_name() const noexcept; + std::string const& layer_name() const noexcept; std::string const& source() const noexcept; - product_store_const_ptr parent(std::string const& level_name) const noexcept; + product_store_const_ptr parent(std::string const& layer_name) const noexcept; product_store_const_ptr parent() const noexcept; product_store_ptr make_flush() const; product_store_ptr make_continuation(std::string source, products new_products = {}) const; product_store_ptr make_child(std::size_t new_level_number, - std::string const& new_level_name, + std::string const& new_layer_name, std::string source, products new_products); product_store_ptr make_child(std::size_t new_level_number, - std::string const& new_level_name, + std::string const& new_layer_name, std::string source = {}, stage st = stage::process); - level_id_ptr const& id() const noexcept; + data_cell_index_ptr const& id() const noexcept; bool is_flush() const noexcept; // Product interface @@ -59,24 +59,24 @@ namespace phlex::experimental { private: explicit product_store(product_store_const_ptr parent, - level_id_ptr id, + data_cell_index_ptr id, std::string source, stage processing_stage = stage::process, products new_products = {}); explicit product_store(product_store_const_ptr parent, std::size_t new_level_number, - std::string const& new_level_name, + std::string const& new_layer_name, std::string source, products new_products); explicit product_store(product_store_const_ptr parent, std::size_t new_level_number, - std::string const& new_level_name, + std::string const& new_layer_name, std::string source, stage processing_stage); product_store_const_ptr parent_{nullptr}; products products_{}; - level_id_ptr id_; + data_cell_index_ptr id_; std::string source_; // FIXME: Should not have to copy the string (the source should outlive the product store) stage stage_; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3af3c2e16..d67473cc1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -43,8 +43,8 @@ add_catch_test(filter LIBRARIES phlex::core Boost::json) add_catch_test(function_registration LIBRARIES phlex::core Boost::json) add_catch_test(hierarchical_nodes LIBRARIES Boost::json TBB::tbb phlex::core) add_catch_test(multiple_function_registration LIBRARIES Boost::json phlex::core) -add_catch_test(level_counting LIBRARIES phlex::model phlex::utilities) -add_catch_test(level_id LIBRARIES phlex::model) +add_catch_test(data_cell_counting LIBRARIES phlex::model phlex::utilities) +add_catch_test(data_cell_index LIBRARIES phlex::model) add_catch_test(product_handle LIBRARIES phlex::core) add_catch_test(product_matcher LIBRARIES phlex::model) add_catch_test(product_store LIBRARIES phlex::core) diff --git a/test/allowed_families.cpp b/test/allowed_families.cpp index 204c5d37a..ee64cf34e 100644 --- a/test/allowed_families.cpp +++ b/test/allowed_families.cpp @@ -1,5 +1,5 @@ #include "phlex/core/framework_graph.hpp" -#include "phlex/model/level_id.hpp" +#include "phlex/model/data_cell_index.hpp" #include "phlex/model/product_store.hpp" #include "catch2/catch_test_macros.hpp" @@ -11,7 +11,7 @@ using namespace oneapi::tbb; namespace { - void levels_to_process(framework_driver& driver) + void cells_to_process(framework_driver& driver) { auto job_store = product_store::base(); job_store->add_product("id", *job_store->id()); @@ -30,15 +30,15 @@ namespace { driver.yield(event_store); } - void check_two_ids(level_id const& parent_id, level_id const& id) + void check_two_ids(data_cell_index const& parent_id, data_cell_index const& id) { CHECK(parent_id.depth() + 1ull == id.depth()); CHECK(parent_id.hash() == id.parent()->hash()); } - void check_three_ids(level_id const& grandparent_id, - level_id const& parent_id, - level_id const& id) + void check_three_ids(data_cell_index const& grandparent_id, + data_cell_index const& parent_id, + data_cell_index const& id) { CHECK(id.depth() == 3ull); CHECK(parent_id.depth() == 2ull); @@ -52,7 +52,7 @@ namespace { TEST_CASE("Testing families", "[data model]") { - framework_graph g{levels_to_process, 2}; + framework_graph g{cells_to_process, 2}; g.observe("se", check_two_ids).input_family("id"_in("subrun"), "id"_in("event")); g.observe("rs", check_two_ids).input_family("id"_in("run"), "id"_in("subrun")); g.observe("rse", check_three_ids) diff --git a/test/benchmarks/accept_even_ids.cpp b/test/benchmarks/accept_even_ids.cpp index e490c46b6..b98b5ddd4 100644 --- a/test/benchmarks/accept_even_ids.cpp +++ b/test/benchmarks/accept_even_ids.cpp @@ -1,4 +1,4 @@ -#include "phlex/model/level_id.hpp" +#include "phlex/model/data_cell_index.hpp" #include "phlex/module.hpp" #include @@ -7,7 +7,7 @@ PHLEX_EXPERIMENTAL_REGISTER_ALGORITHMS(m, config) { m.predicate( "accept_even_ids", - [](phlex::experimental::level_id const& id) { return id.number() % 2 == 0; }, + [](phlex::experimental::data_cell_index const& id) { return id.number() % 2 == 0; }, phlex::experimental::concurrency::unlimited) .input_family(config.get("product_name")); } diff --git a/test/benchmarks/last_index.cpp b/test/benchmarks/last_index.cpp index bf113dfca..41d0a45f1 100644 --- a/test/benchmarks/last_index.cpp +++ b/test/benchmarks/last_index.cpp @@ -1,10 +1,10 @@ -#include "phlex/model/level_id.hpp" +#include "phlex/model/data_cell_index.hpp" #include "phlex/module.hpp" using namespace phlex::experimental; namespace { - int last_index(level_id const& id) { return static_cast(id.number()); } + int last_index(data_cell_index const& id) { return static_cast(id.number()); } } PHLEX_EXPERIMENTAL_REGISTER_ALGORITHMS(m, config) diff --git a/test/benchmarks/read_id.cpp b/test/benchmarks/read_id.cpp index cc8c1667c..02d6117ed 100644 --- a/test/benchmarks/read_id.cpp +++ b/test/benchmarks/read_id.cpp @@ -1,8 +1,8 @@ -#include "phlex/model/level_id.hpp" +#include "phlex/model/data_cell_index.hpp" #include "phlex/module.hpp" namespace { - void read_id(phlex::experimental::level_id const&) {} + void read_id(phlex::experimental::data_cell_index const&) {} } PHLEX_EXPERIMENTAL_REGISTER_ALGORITHMS(m) diff --git a/test/benchmarks/read_index.cpp b/test/benchmarks/read_index.cpp index f2de1b186..ebc8d3677 100644 --- a/test/benchmarks/read_index.cpp +++ b/test/benchmarks/read_index.cpp @@ -1,4 +1,4 @@ -#include "phlex/model/level_id.hpp" +#include "phlex/model/data_cell_index.hpp" #include "phlex/module.hpp" namespace { diff --git a/test/cached_product_stores.cpp b/test/cached_product_stores.cpp index c7a09a8f1..0ba7710b3 100644 --- a/test/cached_product_stores.cpp +++ b/test/cached_product_stores.cpp @@ -1,5 +1,5 @@ #include "phlex/core/cached_product_stores.hpp" -#include "phlex/model/level_id.hpp" +#include "phlex/model/data_cell_index.hpp" #include "phlex/model/product_store.hpp" #include "catch2/catch_test_macros.hpp" @@ -13,17 +13,17 @@ TEST_CASE("Cached product stores", "[data model]") { auto store = stores.get_store(); REQUIRE(store); - CHECK(store->id() == level_id::base_ptr()); + CHECK(store->id() == data_cell_index::base_ptr()); } - SECTION("One level down") + SECTION("One layer down") { auto store = stores.get_store("1"_id); REQUIRE(store); CHECK(*store->id() == *"1"_id); REQUIRE(store->parent()); - CHECK(store->parent()->id() == level_id::base_ptr()); + CHECK(store->parent()->id() == data_cell_index::base_ptr()); } - SECTION("One level down, multiple instances") + SECTION("One layer down, multiple instances") { auto store1 = stores.get_store("1"_id); auto store2 = stores.get_store("2"_id); @@ -34,7 +34,7 @@ TEST_CASE("Cached product stores", "[data model]") // Make sure both stores have the same parent CHECK(store1->parent() == store2->parent()); } - SECTION("Multiple levels") + SECTION("Multiple layers") { auto store1 = stores.get_store("1"_id); auto store2345 = stores.get_store("2:3:4:5"_id); diff --git a/test/level_counting.cpp b/test/data_cell_counting.cpp similarity index 93% rename from test/level_counting.cpp rename to test/data_cell_counting.cpp index 3a3726f53..23abd5b4c 100644 --- a/test/level_counting.cpp +++ b/test/data_cell_counting.cpp @@ -1,6 +1,6 @@ -#include "phlex/model/level_counter.hpp" -#include "phlex/model/level_hierarchy.hpp" -#include "phlex/model/level_id.hpp" +#include "phlex/model/data_cell_counter.hpp" +#include "phlex/model/data_cell_index.hpp" +#include "phlex/model/data_layer_hierarchy.hpp" #include "phlex/model/product_store.hpp" #include "phlex/utilities/hashing.hpp" @@ -14,13 +14,13 @@ namespace { TEST_CASE("Counter with nothing processed", "[data model]") { - level_counter job_counter{}; + data_cell_counter job_counter{}; CHECK(job_counter.result().empty()); } TEST_CASE("Counter one layer deep", "[data model]") { - level_counter job_counter{}; + data_cell_counter job_counter{}; for (std::size_t i = 0; i != 10; ++i) { job_counter.make_child("event"); } @@ -39,7 +39,7 @@ TEST_CASE("Counter multiple layers deep", "[data model]") std::size_t processed_subruns{}; std::size_t processed_events{}; - level_hierarchy h; + data_layer_hierarchy h; flush_counters counters; // Notice the wholesale capture by reference--generally a lazy way of doing things. diff --git a/test/level_id.cpp b/test/data_cell_index.cpp similarity index 77% rename from test/level_id.cpp rename to test/data_cell_index.cpp index be910261b..6f5d55e1f 100644 --- a/test/level_id.cpp +++ b/test/data_cell_index.cpp @@ -1,12 +1,12 @@ -#include "phlex/model/level_id.hpp" +#include "phlex/model/data_cell_index.hpp" #include "catch2/catch_test_macros.hpp" using namespace phlex::experimental; -TEST_CASE("Level ID string literal", "[data model]") +TEST_CASE("Data layer ID string literal", "[data model]") { - CHECK(""_id == level_id::base_ptr()); + CHECK(""_id == data_cell_index::base_ptr()); auto id = "2"_id; CHECK(*id == *id_for({2})); CHECK(id->hash() != 0ull); @@ -20,7 +20,7 @@ TEST_CASE("Verify independent hashes", "[data model]") // In the original implementation of the hash algorithm, there was a collision between the hash for // "run:0 subrun:0 event: 760" and "run:0 subrun:1 event: 4999". - auto base = level_id::base_ptr(); + auto base = data_cell_index::base_ptr(); auto run = base->make_child(0, "run"); auto subrun_0 = run->make_child(0, "subrun"); auto event_760 = subrun_0->make_child(760, "event"); @@ -30,5 +30,5 @@ TEST_CASE("Verify independent hashes", "[data model]") auto event_4999 = subrun_1->make_child(4999, "event"); CHECK(event_760->hash() != event_4999->hash()); - CHECK(event_760->level_hash() == event_4999->level_hash()); + CHECK(event_760->layer_hash() == event_4999->layer_hash()); } diff --git a/test/demo-giantdata/unfold_transform_fold.cpp b/test/demo-giantdata/unfold_transform_fold.cpp index 8c48565b0..a3379d8a5 100644 --- a/test/demo-giantdata/unfold_transform_fold.cpp +++ b/test/demo-giantdata/unfold_transform_fold.cpp @@ -1,5 +1,5 @@ #include "phlex/core/framework_graph.hpp" -#include "phlex/model/level_id.hpp" +#include "phlex/model/data_cell_index.hpp" #include "phlex/model/product_store.hpp" #include "phlex/utilities/async_driver.hpp" #include "test/products_for_output.hpp" @@ -53,15 +53,15 @@ int main(int argc, char* argv[]) std::size_t const wires_per_spill = apas_per_spill * 256ull; - // Create some levels of the data set categories hierarchy. - // We may or may not want to create pre-generated data set categories like this. - // Each data set category gets an index number in the hierarchy. + // Create some data layers of the data-layer hierarchy. + // We may or may not want to create pre-generated data layers. + // Each data layer gets an index number in the hierarchy. auto source = [n_runs, n_subruns, n_spills, wires_per_spill](framework_driver& driver) { auto job_store = product_store::base(); driver.yield(job_store); - // job -> run -> subrun -> spill levels + // job -> run -> subrun -> spill data layers for (unsigned runno : std::views::iota(0u, n_runs)) { auto run_store = job_store->make_child(runno, "run"); driver.yield(run_store); @@ -123,10 +123,10 @@ int main(int argc, char* argv[]) // Add the transform node to the graph. demo::log_record("add_transform"); auto wrapped_user_function = [](phlex::experimental::handle hwf) { - auto apa_id = hwf.level_id().number(); - auto spill_id = hwf.level_id().parent()->number(); - auto subrun_id = hwf.level_id().parent()->parent()->number(); - auto run_id = hwf.level_id().parent()->parent()->parent()->number(); + auto apa_id = hwf.data_cell_index().number(); + auto spill_id = hwf.data_cell_index().parent()->number(); + auto subrun_id = hwf.data_cell_index().parent()->parent()->number(); + auto run_id = hwf.data_cell_index().parent()->parent()->parent()->number(); return demo::clampWaveforms(*hwf, run_id, subrun_id, spill_id, apa_id); }; @@ -139,10 +139,10 @@ int main(int argc, char* argv[]) g.fold( "accum_for_spill", [](demo::SummedClampedWaveforms& scw, phlex::experimental::handle hwf) { - auto apa_id = hwf.level_id().number(); - auto spill_id = hwf.level_id().parent()->number(); - auto subrun_id = hwf.level_id().parent()->parent()->number(); - auto run_id = hwf.level_id().parent()->parent()->parent()->number(); + auto apa_id = hwf.data_cell_index().number(); + auto spill_id = hwf.data_cell_index().parent()->number(); + auto subrun_id = hwf.data_cell_index().parent()->parent()->number(); + auto run_id = hwf.data_cell_index().parent()->parent()->parent()->number(); demo::accumulateSCW(scw, *hwf, run_id, subrun_id, spill_id, apa_id); }, concurrency::unlimited, diff --git a/test/different_hierarchies.cpp b/test/different_hierarchies.cpp index 9f82fdec8..be248629a 100644 --- a/test/different_hierarchies.cpp +++ b/test/different_hierarchies.cpp @@ -50,7 +50,7 @@ namespace { // job -> trigger primitive levels constexpr auto primitive_limit = 10u; - void levels_to_process(framework_driver& driver) + void cells_to_process(framework_driver& driver) { auto job_store = product_store::base(); driver.yield(job_store); @@ -77,7 +77,7 @@ namespace { TEST_CASE("Different hierarchies used with fold", "[graph]") { - framework_graph g{levels_to_process}; + framework_graph g{cells_to_process}; g.fold("run_add", add, concurrency::unlimited, "run", 0u) .input_family("number") diff --git a/test/fold.cpp b/test/fold.cpp index 6654b9f99..328486164 100644 --- a/test/fold.cpp +++ b/test/fold.cpp @@ -24,7 +24,7 @@ // ======================================================================================= #include "phlex/core/framework_graph.hpp" -#include "phlex/model/level_id.hpp" +#include "phlex/model/data_cell_index.hpp" #include "phlex/model/product_store.hpp" #include "catch2/catch_test_macros.hpp" @@ -42,12 +42,12 @@ namespace { void add(std::atomic& counter, unsigned int number) { counter += number; } } -TEST_CASE("Different levels of fold", "[graph]") +TEST_CASE("Different data layers of fold", "[graph]") { constexpr auto index_limit = 2u; constexpr auto number_limit = 5u; - auto levels_to_process = [index_limit, number_limit](framework_driver& driver) { + auto cells_to_process = [index_limit, number_limit](framework_driver& driver) { auto job_store = product_store::base(); driver.yield(job_store); for (unsigned i : std::views::iota(0u, index_limit)) { @@ -61,8 +61,8 @@ TEST_CASE("Different levels of fold", "[graph]") } }; - // framework_graph g{levels_to_process}; - framework_graph g{levels_to_process}; + // framework_graph g{cells_to_process}; + framework_graph g{cells_to_process}; g.fold("run_add", add, concurrency::unlimited, "run") .input_family("number") diff --git a/test/hierarchical_nodes.cpp b/test/hierarchical_nodes.cpp index 588d618b1..0cc36f8b6 100644 --- a/test/hierarchical_nodes.cpp +++ b/test/hierarchical_nodes.cpp @@ -12,12 +12,12 @@ // print_result [also includes output module] // // where the asterisk (*) indicates a fold step. In terms of the data model, -// whenever the add node receives the flush token, a product is inserted at one level -// higher than the level processed by square and add nodes. +// whenever the add node receives the flush token, a product is inserted in one data layer +// higher than the data layer processed by square and add nodes. // ======================================================================================= #include "phlex/core/framework_graph.hpp" -#include "phlex/model/level_id.hpp" +#include "phlex/model/data_cell_index.hpp" #include "phlex/model/product_store.hpp" #include "test/products_for_output.hpp" @@ -38,16 +38,16 @@ namespace { constexpr auto index_limit = 2u; constexpr auto number_limit = 5u; - void levels_to_process(framework_driver& driver) + void cells_to_process(framework_driver& driver) { auto job_store = product_store::base(); driver.yield(job_store); for (unsigned i : std::views::iota(0u, index_limit)) { - auto run_store = job_store->make_child(i, "run", "levels_to_process"); + auto run_store = job_store->make_child(i, "run", "cells_to_process"); run_store->add_product("time", std::time(nullptr)); driver.yield(run_store); for (unsigned j : std::views::iota(0u, number_limit)) { - auto event_store = run_store->make_child(j, "event", "levels_to_process"); + auto event_store = run_store->make_child(j, "event", "cells_to_process"); event_store->add_product("number", i + j); driver.yield(event_store); } @@ -92,7 +92,7 @@ namespace { void print_result(handle result, std::string const& stringized_time) { spdlog::debug("{}: {} @ {}", - result.level_id().to_string(), + result.data_cell_index().to_string(), *result, stringized_time.substr(0, stringized_time.find('\n'))); } @@ -100,7 +100,7 @@ namespace { TEST_CASE("Hierarchical nodes", "[graph]") { - framework_graph g{levels_to_process}; + framework_graph g{cells_to_process}; g.transform("get_the_time", strtime, concurrency::unlimited) .input_family("time") diff --git a/test/memory-checks/many_events.cpp b/test/memory-checks/many_events.cpp index f6175d501..763d93859 100644 --- a/test/memory-checks/many_events.cpp +++ b/test/memory-checks/many_events.cpp @@ -13,7 +13,7 @@ int main() // constexpr auto max_events{1'000'000u}; // spdlog::flush_on(spdlog::level::trace); - auto levels_to_process = [](framework_driver& driver) { + auto cells_to_process = [](framework_driver& driver) { auto job_store = product_store::base(); driver.yield(job_store); @@ -24,7 +24,7 @@ int main() } }; - framework_graph g{levels_to_process}; + framework_graph g{cells_to_process}; g.transform("pass_on", pass_on, concurrency::unlimited) .input_family("number") .output_products("different"); diff --git a/test/mock-workflow/MC_truth_algorithm.cpp b/test/mock-workflow/MC_truth_algorithm.cpp index 78ee8ee54..44a8058f8 100644 --- a/test/mock-workflow/MC_truth_algorithm.cpp +++ b/test/mock-workflow/MC_truth_algorithm.cpp @@ -6,5 +6,5 @@ using namespace phlex::experimental::test; PHLEX_EXPERIMENTAL_REGISTER_ALGORITHMS(m, config) { - define_algorithm(m, config); + define_algorithm(m, config); } diff --git a/test/mock-workflow/three_tuple_algorithm.cpp b/test/mock-workflow/three_tuple_algorithm.cpp index b78de23f9..0424b8665 100644 --- a/test/mock-workflow/three_tuple_algorithm.cpp +++ b/test/mock-workflow/three_tuple_algorithm.cpp @@ -8,7 +8,7 @@ using namespace phlex::experimental::test; PHLEX_EXPERIMENTAL_REGISTER_ALGORITHMS(m, config) { - using inputs = phlex::experimental::level_id; + using inputs = phlex::experimental::data_cell_index; using outputs = std::tuple; define_algorithm(m, config); } diff --git a/test/multiple_function_registration.cpp b/test/multiple_function_registration.cpp index 71f564035..876fba44a 100644 --- a/test/multiple_function_registration.cpp +++ b/test/multiple_function_registration.cpp @@ -1,5 +1,5 @@ #include "phlex/core/framework_graph.hpp" -#include "phlex/model/level_hierarchy.hpp" +#include "phlex/model/data_layer_hierarchy.hpp" #include "phlex/model/product_store.hpp" #include "catch2/catch_test_macros.hpp" diff --git a/test/product_handle.cpp b/test/product_handle.cpp index 403591a35..3af488178 100644 --- a/test/product_handle.cpp +++ b/test/product_handle.cpp @@ -1,5 +1,5 @@ +#include "phlex/model/data_cell_index.hpp" #include "phlex/model/handle.hpp" -#include "phlex/model/level_id.hpp" #include "phlex/model/product_store.hpp" #include "catch2/catch_test_macros.hpp" @@ -32,10 +32,10 @@ TEST_CASE("Can only construct handles with compatible types (compile-time checks static_assert(std::constructible_from, handle&&>); // Moves static_assert(not std::constructible_from, handle>); - static_assert(std::constructible_from, int, level_id>); - static_assert(std::constructible_from, int const, level_id>); - static_assert(std::constructible_from, int const&, level_id>); - static_assert(not std::constructible_from, double, level_id>); + static_assert(std::constructible_from, int, data_cell_index>); + static_assert(std::constructible_from, int const, data_cell_index>); + static_assert(std::constructible_from, int const&, data_cell_index>); + static_assert(not std::constructible_from, double, data_cell_index>); } TEST_CASE("Can only assign handles with compatible types (compile-time checks)", "[data model]") @@ -50,7 +50,7 @@ TEST_CASE("Handle copies and moves", "[data model]") int const two{2}; int const four{4}; - auto job_data_cell = level_id::base_ptr(); + auto job_data_cell = data_cell_index::base_ptr(); auto subrun_6_data_cell = job_data_cell->make_child(6, "subrun"); handle h2{two, *job_data_cell}; @@ -77,23 +77,23 @@ TEST_CASE("Handle comparisons", "[data model]") { int const seventeen{17}; int const eighteen{18}; - handle const h17{seventeen, level_id::base()}; - handle const h18{eighteen, level_id::base()}; + handle const h17{seventeen, data_cell_index::base()}; + handle const h18{eighteen, data_cell_index::base()}; CHECK(h17 == h17); CHECK(h17 != h18); - auto subrun_6_data_cell = level_id::base_ptr()->make_child(6, "subrun"); + auto subrun_6_data_cell = data_cell_index::base_ptr()->make_child(6, "subrun"); handle const h17sr{seventeen, *subrun_6_data_cell}; - CHECK(*h17 == *h17sr); // Products are the same - CHECK(h17.level_id() != h17sr.level_id()); // Levels are not the same - CHECK(h17 != h17sr); // Therefore handles are not the same + CHECK(*h17 == *h17sr); // Products are the same + CHECK(h17.data_cell_index() != h17sr.data_cell_index()); // Data cells are not the same + CHECK(h17 != h17sr); // Therefore handles are not the same } TEST_CASE("Handle type conversions (run-time checks)", "[data model]") { int const number{3}; - handle const h{number, level_id::base()}; - CHECK(h.level_id() == level_id::base()); + handle const h{number, data_cell_index::base()}; + CHECK(h.data_cell_index() == data_cell_index::base()); int const& num_ref = h; int const* num_ptr = h; @@ -102,5 +102,5 @@ TEST_CASE("Handle type conversions (run-time checks)", "[data model]") CHECK(*num_ptr == number); Composer const composer{"Elgar"}; - CHECK(handle{composer, level_id::base()}->name == "Elgar"); + CHECK(handle{composer, data_cell_index::base()}->name == "Elgar"); } diff --git a/test/product_matcher.cpp b/test/product_matcher.cpp index 7f8bfda99..9887ef2fc 100644 --- a/test/product_matcher.cpp +++ b/test/product_matcher.cpp @@ -9,12 +9,12 @@ using namespace phlex::experimental; namespace { - // Spec: [level path spec/][[module name][@node name]:]product name + // Spec: [layer path spec/][[module name][@node name]:]product name - // std::string const optional_level_path{R"((?:(.*)/)?)"}; + // std::string const optional_layer_path{R"((?:(.*)/)?)"}; // std::string const optional_qualified_node_name{R"((?:(\w+)?(?:@(\w+))?:)?)"}; // std::string const product_name{R"((\w+))"}; - // std::regex const pattern{optional_level_path + optional_qualified_node_name + product_name}; + // std::regex const pattern{optional_layer_path + optional_qualified_node_name + product_name}; // void print(std::string const& spec) // { // std::smatch submatches; @@ -36,17 +36,17 @@ TEST_CASE("Simple product matcher", "[data model]") { auto const spec = "event/loaded_module@add:sum"; product_matcher matcher{spec}; - CHECK(matcher.level_path() == "event"); + CHECK(matcher.layer_path() == "event"); CHECK(matcher.module_name() == "loaded_module"); CHECK(matcher.node_name() == "add"); CHECK(matcher.product_name() == "sum"); CHECK(matcher.encode() == spec); } -TEST_CASE("Product matcher with default level path", "[data model]") +TEST_CASE("Product matcher with default layer path", "[data model]") { product_matcher matcher{"loaded_module@add:sum"}; - CHECK(matcher.level_path() == "*"); + CHECK(matcher.layer_path() == "*"); CHECK(matcher.module_name() == "loaded_module"); CHECK(matcher.node_name() == "add"); CHECK(matcher.product_name() == "sum"); @@ -55,10 +55,10 @@ TEST_CASE("Product matcher with default level path", "[data model]") CHECK(product_matcher{"*/loaded_module@add:sum"}.encode() == "*/loaded_module@add:sum"); } -TEST_CASE("Product matcher with multi-part level path", "[data model]") +TEST_CASE("Product matcher with multi-part layer path", "[data model]") { product_matcher matcher{"a/b/c/loaded_module@add:sum"}; - CHECK(matcher.level_path() == "a/b/c"); + CHECK(matcher.layer_path() == "a/b/c"); CHECK(matcher.module_name() == "loaded_module"); CHECK(matcher.node_name() == "add"); CHECK(matcher.product_name() == "sum"); @@ -68,7 +68,7 @@ TEST_CASE("Product matcher with multi-part level path", "[data model]") TEST_CASE("Product with only node spec", "[data model]") { product_matcher matcher{"@add:sum"}; - CHECK(matcher.level_path() == "*"); + CHECK(matcher.layer_path() == "*"); CHECK(matcher.module_name() == ""); CHECK(matcher.node_name() == "add"); CHECK(matcher.product_name() == "sum"); @@ -78,7 +78,7 @@ TEST_CASE("Product with only node spec", "[data model]") TEST_CASE("Product with only module spec", "[data model]") { product_matcher matcher{"loaded_module:sum"}; - CHECK(matcher.level_path() == "*"); + CHECK(matcher.layer_path() == "*"); CHECK(matcher.module_name() == "loaded_module"); CHECK(matcher.node_name() == ""); CHECK(matcher.product_name() == "sum"); diff --git a/test/product_query.cpp b/test/product_query.cpp index 97fbea257..63e54cb33 100644 --- a/test/product_query.cpp +++ b/test/product_query.cpp @@ -16,11 +16,11 @@ TEST_CASE("Only name in label", "[data model]") product_query label{"product"}; CHECK(label == "product"_in); - // Empty family string is interpreted as a wildcard--i.e. any family. + // Empty layer string is interpreted as a wildcard--i.e. any layer. CHECK(label == "product"_in("")); } -TEST_CASE("Label with family", "[data model]") +TEST_CASE("Label with layer", "[data model]") { product_query label{"product", {"event"}}; CHECK(label == "product"_in("event")); diff --git a/test/type_distinction.cpp b/test/type_distinction.cpp index 3fb29b35c..3784188bb 100644 --- a/test/type_distinction.cpp +++ b/test/type_distinction.cpp @@ -1,5 +1,4 @@ #include "phlex/core/framework_graph.hpp" -#include "phlex/model/level_hierarchy.hpp" #include "phlex/model/product_store.hpp" #include "spdlog/spdlog.h" diff --git a/test/unfold.cpp b/test/unfold.cpp index 2690b1bc4..6665f374d 100644 --- a/test/unfold.cpp +++ b/test/unfold.cpp @@ -15,7 +15,7 @@ // ======================================================================================= #include "phlex/core/framework_graph.hpp" -#include "phlex/model/level_id.hpp" +#include "phlex/model/data_cell_index.hpp" #include "phlex/model/product_store.hpp" #include "test/products_for_output.hpp" @@ -49,7 +49,7 @@ namespace { } auto initial_value() const { return begin_; } bool predicate(numbers_t::const_iterator it) const { return it != end_; } - auto unfold(numbers_t::const_iterator it, level_id const& lid) const + auto unfold(numbers_t::const_iterator it, data_cell_index const& lid) const { spdlog::info("Unfolding into {}", lid.to_string()); auto num = *it; @@ -66,7 +66,7 @@ namespace { void check_sum(handle const sum) { - if (sum.level_id().number() == 0ull) { + if (sum.data_cell_index().number() == 0ull) { CHECK(*sum == 45); } else { CHECK(*sum == 190); @@ -75,7 +75,7 @@ namespace { void check_sum_same(handle const sum) { - auto const expected_sum = (sum.level_id().number() + 1) * 10; + auto const expected_sum = (sum.data_cell_index().number() + 1) * 10; CHECK(*sum == expected_sum); } } @@ -84,7 +84,7 @@ TEST_CASE("Splitting the processing", "[graph]") { constexpr auto index_limit = 2u; - auto levels_to_process = [index_limit](auto& driver) { + auto cells_to_process = [index_limit](auto& driver) { auto job_store = product_store::base(); driver.yield(job_store); for (unsigned i : std::views::iota(0u, index_limit)) { @@ -95,7 +95,7 @@ TEST_CASE("Splitting the processing", "[graph]") } }; - framework_graph g{levels_to_process}; + framework_graph g{cells_to_process}; g.unfold(&iota::predicate, &iota::unfold, concurrency::unlimited, "lower1") .input_family("max_number") diff --git a/test/yielding_driver.cpp b/test/yielding_driver.cpp index de0e04907..0c080cfa2 100644 --- a/test/yielding_driver.cpp +++ b/test/yielding_driver.cpp @@ -1,4 +1,4 @@ -#include "phlex/model/level_id.hpp" +#include "phlex/model/data_cell_index.hpp" #include "phlex/utilities/async_driver.hpp" #include "fmt/std.h" @@ -13,13 +13,13 @@ using namespace phlex::experimental; -void levels_to_process(async_driver& d) +void cells_to_process(async_driver& d) { unsigned int const num_runs = 2; unsigned int const num_subruns = 2; unsigned int const num_spills = 3; - auto job_id = level_id::base_ptr(); + auto job_id = data_cell_index::base_ptr(); d.yield(job_id); for (unsigned int r : std::views::iota(0u, num_runs)) { auto run_id = job_id->make_child(r, "run"); @@ -36,9 +36,9 @@ void levels_to_process(async_driver& d) int main() { - async_driver drive{levels_to_process}; + async_driver drive{cells_to_process}; tbb::flow::graph g{}; - tbb::flow::input_node source{g, [&drive](tbb::flow_control& fc) -> level_id_ptr { + tbb::flow::input_node source{g, [&drive](tbb::flow_control& fc) -> data_cell_index_ptr { if (auto next = drive()) { return *next; } @@ -46,7 +46,7 @@ int main() return {}; }}; tbb::flow::function_node receiver{ - g, tbb::flow::unlimited, [](level_id_ptr const& set_id) -> tbb::flow::continue_msg { + g, tbb::flow::unlimited, [](data_cell_index_ptr const& set_id) -> tbb::flow::continue_msg { spdlog::info("Received {}", set_id->to_string()); return {}; }};