aegir-genie
GENIE neutrino event generation for the SHiP experiment's aegir framework.
Loading...
Searching...
No Matches
mc_particle_source.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 CERN for the benefit of the SHiP Collaboration
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5// mc_particle_source.hpp โ€” shared helper for event-generator sources
6//
7// Vendored unchanged from aegir (src/mc_particle_source.hpp) pending a shared
8// helper package; keep in sync with the original. LGPL-3.0-or-later, see
9// README.md ยง Licensing.
10//
11// Phlex 0.3.0 lets a source register its data-product providers implicitly:
12// a phlex::source implements create_providers(selector), returning the
13// provider bundles that satisfy the requested product. Every aegir event
14// generator publishes the same product โ€” the "mc_particles" collection
15// (std::vector<SHiP::MCParticle>) on the "event" layer โ€” so the bundle
16// construction is factored out here.
17
18#pragma once
19
20#include <SHiP/MCParticle.hpp>
21#include <functional>
22#include <string>
23#include <utility>
24#include <vector>
25
26#include "phlex/concurrency.hpp"
27#include "phlex/core/product_selector.hpp"
28#include "phlex/model/data_cell_index.hpp"
29#include "phlex/model/products.hpp"
30#include "phlex/source.hpp"
31
32namespace aegir {
33
34// Generator signature: produce the particles for a single data cell (event).
36 std::function<std::vector<SHiP::MCParticle>(phlex::data_cell_index const&)>;
37
38// Build the implicit-provider bundle(s) for a source emitting the
39// "mc_particles" product, honouring the framework's product selector. The
40// generator is invoked once per data cell and its result type-erased into a
41// Phlex product.
42inline phlex::detail::provider_bundles mc_particle_provider_bundles(
43 phlex::product_selector const& selector, mc_particle_generator generate,
44 phlex::concurrency max_concurrency) {
45 using namespace phlex::experimental;
46 using namespace phlex::detail;
47
48 provider_bundles bundles;
49 product_specification spec{algorithm_name::create("mc_particles"),
50 identifier{"particles"},
51 make_type_id<std::vector<SHiP::MCParticle>>()};
52 std::string const layer = "event";
53 std::string const stage = "CURRENT";
54
55 if (selector.match(spec, identifier{layer}, identifier{stage})) {
56 bundles.push_back(provider_bundle{
57 .provider_function =
58 [generate = std::move(generate)](phlex::data_cell_index const& id)
59 -> product_ptr { return product_for(generate(id)); },
60 .max_concurrency = max_concurrency,
61 .spec = std::move(spec),
62 .layer = layer,
63 .stage = stage});
64 }
65 return bundles;
66}
67
68} // namespace aegir
Definition genie_config.hpp:22
phlex::detail::provider_bundles mc_particle_provider_bundles(phlex::product_selector const &selector, mc_particle_generator generate, phlex::concurrency max_concurrency)
Definition mc_particle_source.hpp:42
std::function< std::vector< SHiP::MCParticle >(phlex::data_cell_index const &)> mc_particle_generator
Definition mc_particle_source.hpp:36