-
Notifications
You must be signed in to change notification settings - Fork 14
Enable direct conversion from configuration parameter to product_query #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3e55f54
Enable direct conversion from configuration parameter to product_query
knoepfel 1bd0f35
Apply cmake-format fixes
github-actions[bot] bc61d7b
Test parameter-retrieval failures
knoepfel 325877a
Use ranges algorithm for keys() implementation
knoepfel 131bece
Decorate exceptions when attempting to retrieve product_query configu…
knoepfel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #include "phlex/configuration.hpp" | ||
| #include "phlex/core/product_query.hpp" | ||
|
|
||
| #include <ranges> | ||
| #include <string> | ||
|
|
||
| namespace phlex::experimental { | ||
| std::vector<std::string> configuration::keys() const | ||
| { | ||
| std::vector<std::string> result; | ||
| result.reserve(config_.size()); | ||
| std::ranges::transform( | ||
| config_, std::back_inserter(result), [](auto const& element) { return element.key(); }); | ||
| return result; | ||
| } | ||
|
|
||
| configuration tag_invoke(boost::json::value_to_tag<configuration> const&, | ||
| boost::json::value const& jv) | ||
| { | ||
| return configuration{jv.as_object()}; | ||
| } | ||
|
|
||
| product_query tag_invoke(boost::json::value_to_tag<product_query> const&, | ||
| boost::json::value const& jv) | ||
| { | ||
| using detail::value_decorate_exception; | ||
| auto query_object = jv.as_object(); | ||
| return product_query{.spec = {value_decorate_exception<std::string>(query_object, "product")}, | ||
| .layer = value_decorate_exception<std::string>(query_object, "layer")}; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #include "phlex/configuration.hpp" | ||
|
|
||
| #include "boost/json.hpp" | ||
| #include "catch2/catch_test_macros.hpp" | ||
| #include "catch2/matchers/catch_matchers_string.hpp" | ||
|
|
||
| using namespace phlex::experimental; | ||
| using namespace Catch::Matchers; | ||
|
|
||
| TEST_CASE("Check parameter-retrieval errors", "[config]") | ||
| { | ||
| boost::json::object underlying_config; | ||
| underlying_config["b"] = 2.5; | ||
| configuration const config{underlying_config}; | ||
|
|
||
| CHECK(config.keys() == std::vector<std::string>{"b"}); | ||
|
|
||
| CHECK_THROWS_WITH(config.get<int>("a"), ContainsSubstring("Error retrieving parameter 'a'")); | ||
| CHECK_THROWS_WITH(config.get<std::string>("b"), | ||
| ContainsSubstring("Error retrieving parameter 'b'")); | ||
| } | ||
|
|
||
| TEST_CASE("Retrieve value that is a configuration object", "[config]") | ||
| { | ||
| boost::json::object underlying_config; | ||
| underlying_config["nested_table"] = boost::json::object{}; | ||
| configuration const config{underlying_config}; | ||
| auto nested_table = config.get<configuration>("nested_table"); | ||
| CHECK(nested_table.keys().empty()); | ||
| } | ||
|
|
||
| TEST_CASE("Retrieve product_query", "[config]") | ||
| { | ||
| boost::json::object input; | ||
| input["product"] = "tracks"; | ||
| input["layer"] = "job"; | ||
|
|
||
| boost::json::object malformed_input1; | ||
| malformed_input1["product"] = 16.; // Should be string | ||
| malformed_input1["layer"] = "job"; | ||
|
|
||
| boost::json::object malformed_input2; | ||
| malformed_input2["product"] = "hits"; | ||
| malformed_input2["level"] = "should be layer, not level"; | ||
|
|
||
| boost::json::object underlying_config; | ||
| underlying_config["input"] = std::move(input); | ||
| underlying_config["malformed1"] = std::move(malformed_input1); | ||
| underlying_config["malformed2"] = std::move(malformed_input2); | ||
| configuration config{underlying_config}; | ||
|
|
||
| auto input_query = config.get<product_query>("input"); | ||
| CHECK(input_query == "tracks"_in("job")); | ||
| CHECK_THROWS_WITH(config.get<product_query>("malformed1"), | ||
| ContainsSubstring("Error retrieving parameter 'malformed1'") && | ||
| ContainsSubstring("Error retrieving parameter 'product'")); | ||
| CHECK_THROWS_WITH(config.get<product_query>("malformed2"), | ||
| ContainsSubstring("Error retrieving parameter 'malformed2'") && | ||
| ContainsSubstring("Error retrieving parameter 'layer'")); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| local ev = import "event_product.libsonnet"; | ||
| local generators = import 'SinglesGen.libsonnet'; | ||
|
|
||
| { | ||
| largeant: { | ||
| plugin: 'largeant', | ||
| duration_usec: 156, # Typical: 15662051 | ||
| inputs: [f + "/MCTruths" for f in std.objectFields(generators)], | ||
| inputs: [ev.event_product(f + "/MCTruths") for f in std.objectFields(generators)], | ||
| outputs: ["ParticleAncestryMap", "Assns", "SimEnergyDeposits", "AuxDetHits", "MCParticles"], | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,17 @@ | ||
| local ev = import "event_product.libsonnet"; | ||
| local g4stage1 = import 'G4Stage1.libsonnet'; | ||
|
|
||
| { | ||
| IonAndScint: { | ||
| plugin: 'ion_and_scint', | ||
| duration_usec: 546, # Typical: 5457973 | ||
| inputs: [f + "/SimEnergyDeposits" for f in std.objectFields(g4stage1)], | ||
| inputs: [ev.event_product(f + "/SimEnergyDeposits") for f in std.objectFields(g4stage1)], | ||
| outputs: ["SimEnergyDeposits", "SimEnergyDeposits_priorSCE"], | ||
| }, | ||
| PDFastSim: { | ||
| plugin: 'pd_fast_sim', | ||
| duration_usec: 69, # Typical: 69681950 | ||
| inputs: ['SimEnergyDeposits_priorSCE'], | ||
| inputs: [ev.event_product('SimEnergyDeposits_priorSCE')], | ||
| outputs: ['SimPhotonLites', 'OpDetBacktrackerRecords'], | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,40 @@ | ||
| local ev = import 'event_product.libsonnet'; | ||
|
|
||
| { | ||
| rn222: { | ||
| plugin: "MC_truth_algorithm", | ||
| duration_usec: 39, | ||
| inputs: ["id"], | ||
| inputs: [ev.event_product("id")], | ||
| outputs: ["MCTruths"] | ||
| }, | ||
| ar39: { | ||
| plugin: "MC_truth_algorithm", | ||
| duration_usec: 12410, | ||
| inputs: ["id"], | ||
| inputs: [ev.event_product("id")], | ||
| outputs: ["MCTruths"] | ||
| }, | ||
| cosmicgenerator: { | ||
| plugin: "MC_truth_algorithm", | ||
| duration_usec: 492, # Typical: 4926215 | ||
| inputs: ["id"], | ||
| inputs: [ev.event_product("id")], | ||
| outputs: ["MCTruths"] | ||
| }, | ||
| kr85: { | ||
| plugin: "MC_truth_algorithm", | ||
| duration_usec: 1643, | ||
| inputs: ["id"], | ||
| inputs: [ev.event_product("id")], | ||
| outputs: ["MCTruths"] | ||
| }, | ||
| generator: { | ||
| plugin: "three_tuple_algorithm", | ||
| duration_usec: 69616, | ||
| inputs: ["id"], | ||
| inputs: [ev.event_product("id")], | ||
| outputs: ["MCTruths", "BeamEvents", "beamsims"] | ||
| }, | ||
| ar42: { | ||
| plugin: "MC_truth_algorithm", | ||
| duration_usec: 148, | ||
| inputs: ["id"], | ||
| inputs: [ev.event_product("id")], | ||
| outputs: ["MCTruths"] | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.