aegir
Phlex-based simulation framework for the SHiP experiment.
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// Phlex 0.3.0 lets a source register its data-product providers implicitly:
8// a phlex::source implements create_providers(selector), returning the
9// provider bundles that satisfy the requested product. Every aegir event
10// generator publishes the same product — the "mc_particles" collection
11// (std::vector<SHiP::MCParticle>) on the "event" layer — so the bundle
12// construction is factored out here.
13
14#pragma once
15
16#include <SHiP/MCParticle.hpp>
17#include <functional>
18#include <string>
19#include <utility>
20#include <vector>
21
22#include "phlex/concurrency.hpp"
23#include "phlex/core/product_selector.hpp"
24#include "phlex/model/data_cell_index.hpp"
25#include "phlex/model/products.hpp"
26#include "phlex/source.hpp"
27
28namespace aegir {
29
30// Generator signature: produce the particles for a single data cell (event).
32 std::function<std::vector<SHiP::MCParticle>(phlex::data_cell_index const&)>;
33
34// Build the implicit-provider bundle(s) for a source emitting the
35// "mc_particles" product, honouring the framework's product selector. The
36// generator is invoked once per data cell and its result type-erased into a
37// Phlex product.
38inline phlex::detail::provider_bundles mc_particle_provider_bundles(
39 phlex::product_selector const& selector, mc_particle_generator generate,
40 phlex::concurrency max_concurrency) {
41 using namespace phlex::experimental;
42 using namespace phlex::detail;
43
44 provider_bundles bundles;
45 product_specification spec{algorithm_name::create("mc_particles"),
46 identifier{"particles"},
47 make_type_id<std::vector<SHiP::MCParticle>>()};
48 std::string const layer = "event";
49 std::string const stage = "CURRENT";
50
51 if (selector.match(spec, identifier{layer}, identifier{stage})) {
52 bundles.push_back(provider_bundle{
53 .provider_function =
54 [generate = std::move(generate)](phlex::data_cell_index const& id)
55 -> product_ptr { return product_for(generate(id)); },
56 .max_concurrency = max_concurrency,
57 .spec = std::move(spec),
58 .layer = layer,
59 .stage = stage});
60 }
61 return bundles;
62}
63
64} // namespace aegir
Definition math_utils.hpp:12
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:38
std::function< std::vector< SHiP::MCParticle >(phlex::data_cell_index const &)> mc_particle_generator
Definition mc_particle_source.hpp:32