3.5.2. Observers

Observer

Operator

Output family length

\([\ \ ] = \observe{f}\ a\)

\(f: A \rightarrow \one\)

\(0\)

There are cases where a user may wish to inspect a data product without adjusting the data flow of the program. This is done by creating an algorithm called an observer, which may access a data product but create no data products. An example of this is writing ROOT histograms or trees that are not intended to be used in another framework program.

Note that, in a purely functional approach, it is unnecessary to invoke an observer as no data will be produced by it [1]. Phlex, however, supports observers as physicists rely on the ability to induce side effects to analyze physics data.

Unlike filters and predicates, observers (by definition) are allowed to be the most downstream algorithms of the graph.

3.5.2.1. Operator Signature

Operator

Allowed signature

\(f\)

void function_name(P1, Pn..., Rm...) [quals];

3.5.2.2. Registration Interface

The below shows how the \(\textit{histogram\_hits}\) operator in Fig. 3.1 would be registered in C++ [2]. It uses the resource<histogramming> interface to provide access to a putative histogramming resource (see Section 3.9).

class hits { ... };
void histogram_hits(hits const&, TH1F&) { ... }

PHLEX_REGISTER_ALGORITHMS(m, config)
{
  auto h_resource = m.resource<histogramming>();

  observe(histogram_hits, concurrency::serial)
    .family("GoodHits"_in("APA"), h_resource->make<TH1F>(...));
}

Note that the number of arguments presented to the family(...) call matches the number of input parameters of the registered algorithm histogram_hits. This indicates that each invocation of histogram_hits will be presented with one "GoodHits" data product and the TH1F resource.

Footnotes