3.5.1. Transforms¶
Transform |
Operator |
Output family length |
---|---|---|
\(b = \transform{f}\ a\) |
\(f: A \rightarrow B\) |
\(|b| = |a|\) |
The transform is the simplest HOF whose algorithms create data products. Specifically, the algorithm \(f\) is applied to each element of the input family \(a\), creating a corresponding data product in the output family \(b\):
where \(b_i = f\ a_i\). Note that the index set of the output family is the same as the index set of the input family.
3.5.1.1. Operator Signature¶
Operator |
Allowed signature |
---|---|
\(f\) |
|
The return_type
must model the created data-product type described in Section 3.3.2.
An algorithm may also create multiple data products by returning a std::tuple<T1, ..., Tn>
where each of the types T1, ..., Tn
models a created data-product type.
3.5.1.2. Registration Interface¶
To illustrate the different ways a transform’s algorithm can be registered with Phlex, we use the following classes and functions, which are presumably defined in some experiment libraries.
class geometry { ... };
class hits { ... };
class tracks { ... };
class vertices { ... };
class waveforms { ... };
hits find_hits(waveforms const&) { ... }
vertices make_vertices(geometry const&, tracks const&) { ... }
std::tuple<int, int> count_good_hits(hits const&) { ... }
// Return type: first number = number of good hits
// second number = number of all hits
Transform with one argument (default output product name)
PHLEX_REGISTER_ALGORITHMS(config)
{
transform("hit_finder", find_hits, concurrency::unlimited)
.family("Waveforms"_in("APA"));
}
Transform with one argument (user-specified output product name)
As shown in Fig. 3.1 and described in Section 3.4
PHLEX_REGISTER_ALGORITHMS(config)
{
products("GoodHits") =
transform("hit_finder", find_hits, concurrency::unlimited)
.family("Waveforms"_in("APA"));
}
Transform with two arguments (default output product name)
As shown in Fig. 3.1 and described in Section 3.4.1.1
PHLEX_REGISTER_ALGORITHMS(config)
{
products("Vertices") =
transform("vertex_maker", make_vertices, concurrency::unlimited)
.family("Geometry"_in("Job"), "GoodTracks"_in("APA"));
}
Transform creating two data products (user-specified output product names)
PHLEX_REGISTER_ALGORITHMS(config)
{
products("NumGoodHits", "NumAllHits") = // <= One name per tuple slot of return type
transform("hit_counter", count_good_hits, concurrency::unlimited)
.family("GoodHits"_in("APA"));
}