-
Notifications
You must be signed in to change notification settings - Fork 10
Add FORM-based source provider #379
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| #include "phlex/source.hpp" | ||
|
|
||
| #include "form/config.hpp" | ||
| #include "form/form.hpp" | ||
| #include "form/technology.hpp" | ||
|
|
||
| #include <iostream> | ||
| #include <memory> | ||
| #include <stdexcept> | ||
| #include <string> | ||
| #include <string_view> | ||
| #include <unordered_map> | ||
| #include <vector> | ||
|
|
||
| using namespace phlex; | ||
| using namespace phlex::experimental::literals; | ||
|
|
||
| PHLEX_REGISTER_PROVIDERS(s, config) | ||
| { | ||
| std::cout << "Registering FORM source providers...\n"; | ||
|
|
||
| // --- Extract configuration --- | ||
| std::string const input_file = config.get<std::string>("input_file"); | ||
| std::string const creator = config.get<std::string>("creator"); | ||
| std::string const tech_string = config.get<std::string>("technology", "ROOT_TTREE"); | ||
|
|
||
| std::cout << "Configuration:\n"; | ||
| std::cout << " input_file: " << input_file << "\n"; | ||
| std::cout << " creator: " << creator << "\n"; | ||
| std::cout << " technology: " << tech_string << "\n"; | ||
|
|
||
| // --- Resolve technology enum --- | ||
| std::unordered_map<std::string_view, int> const tech_lookup = { | ||
| {"ROOT_TTREE", form::technology::ROOT_TTREE}, | ||
| {"ROOT_RNTUPLE", form::technology::ROOT_RNTUPLE}, | ||
| {"HDF5", form::technology::HDF5}}; | ||
|
|
||
| auto it = tech_lookup.find(tech_string); | ||
| if (it == tech_lookup.end()) { | ||
| throw std::runtime_error("Unknown technology: " + tech_string); | ||
| } | ||
| int const technology = it->second; | ||
|
|
||
| // --- Build input config --- | ||
| form::experimental::config::output_item_config input_cfg; | ||
| form::experimental::config::tech_setting_config tech_cfg; | ||
| input_cfg.addItem("i", input_file, technology); | ||
| input_cfg.addItem("j", input_file, technology); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of debating what to hardcode ( here, placeholder
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current approach is simple and explicit for Prototype 0.1. Auto-discovery is the right long-term goal, but there are two concrete blockers that go beyond the scope of this PR:
I propose keeping the current approach for Prototype 0.1 and tracking auto-discovery as a follow-up issue once these blockers are resolved. |
||
|
|
||
| // --- Create shared form_interface --- | ||
| auto reader = std::make_shared<form::experimental::form_interface>(input_cfg, tech_cfg); | ||
|
|
||
| // --- Register providers --- | ||
| // FIXME: Prototype 0.1 -- product names and types hardcoded. | ||
| // product_query fields must be compile-time _id literals, not runtime strings. | ||
| // To add new products, add new s.provide() blocks below following the same pattern. | ||
|
|
||
| s.provide("provide_i", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this be needed for every data product we read from input? If so, we may want to think about a way to shorten or auto-generate these functions.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already noted in the FIXME comment — it's a known limitation of Prototype 0.1 that will be addressed as the type list grows.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here too I wouldn't mind a git issue |
||
| [reader, creator](data_cell_index const& id) -> int { | ||
| std::cout << "\n=== form_source: providing i ===\n"; | ||
| form::experimental::product_with_name pb{"i", nullptr, &typeid(int)}; | ||
| reader->read(creator, id.to_string(), pb); | ||
| if (!pb.data) { | ||
| throw std::runtime_error("FORM read returned null data for product: i"); | ||
| } | ||
| return *static_cast<int const*>(pb.data); | ||
barnaliy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }) | ||
| .output_product(product_query{.creator = "input"_id, .layer = "event"_id, .suffix = "i"_id}); | ||
|
|
||
| s.provide("provide_j", | ||
| [reader, creator](data_cell_index const& id) -> int { | ||
| std::cout << "\n=== form_source: providing j ===\n"; | ||
| form::experimental::product_with_name pb{"j", nullptr, &typeid(int)}; | ||
| reader->read(creator, id.to_string(), pb); | ||
| if (!pb.data) { | ||
| throw std::runtime_error("FORM read returned null data for product: j"); | ||
| } | ||
| return *static_cast<int const*>(pb.data); | ||
| }) | ||
| .output_product(product_query{.creator = "input"_id, .layer = "event"_id, .suffix = "j"_id}); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The two provider lambdas for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The duplication is not an oversight. |
||
|
|
||
| std::cout << "FORM source providers registered successfully\n"; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.