GCC Code Coverage Report


Directory: ./
File: src/iguana/algorithms/example/ExampleAlgorithm/Algorithm.h
Date: 2025-11-25 17:57:04
Coverage Exec Excl Total
Lines: 75.0% 3 0 4
Functions: 100.0% 3 0 3
Branches: 42.9% 6 0 14

Line Branch Exec Source
1 // ############################################################################
2 // # allow this header to be included only once
3 // ############################################################################
4 #pragma once
5
6 // ############################################################################
7 // # include `Algorithm.h`, which defines the base class `Algorithm`
8 // ############################################################################
9 #include "iguana/algorithms/Algorithm.h"
10
11 // ############################################################################
12 // # define the namespace
13 // # - all `iguana` code should be within the `iguana` namespace
14 // # - algorithms specific to an experiment or analysis may be put in a namespace within the `iguana` namespace
15 // # - here we use the `iguana::example` namespace
16 // # - for CLAS12-specific algorithms, use `iguana::clas12`
17 // ############################################################################
18 namespace iguana::example {
19
20 // ############################################################################
21 // # define the algorithm class
22 // # - it must inherit from `Algorithm`, which includes common methods and objects used by each algorithm
23 // # - it must also include a Doxygen docstring, typically defined by 3 forward slashes `///`
24 // # - algorithm classes have a standardized format for their docstring, please try to follow it and
25 // # keep it up-to-date with respect to the code
26 // # - see Doxygen documentation for more details, or see other algorithms
27 // ############################################################################
28 ///
29 /// @algo_brief{This is a template algorithm, used as an example showing how to write an algorithm.}
30 /// @algo_type_filter
31 ///
32 /// Provide a more detailed description of your algorithm here.
33 ///
34 /// @begin_doc_config{example/ExampleAlgorithm}
35 /// @config_param{exampleInt | int | an example `integer` configuration parameter}
36 /// @config_param{exampleDouble | double | an example `double` configuration parameter}
37 /// @end_doc
38 class ExampleAlgorithm : public Algorithm
39 {
40
41 // ############################################################################
42 // # this is a preprocessor macro call which generates boilerplate for the algorithm definition
43 // # - the arguments are:
44 // # - the class name, `ExampleAlgorithm`
45 // # - a unique, "full" name of the algorithm, used by `AlgorithmFactory`; typically is the
46 // # namespace with the class name, excluding the `iguana::` part, but you are free to choose any name
47 // # - NOTE: quotes are not used, and there is no need for a semicolon at the end of this call
48 // # - see `../AlgorithmBoilerplate.h` for details
49 // # - the macros are relatively modular, so if you want to use your own constructor or destructor, you may
50 // # do so, and use other preprocessor macros called within `DEFINE_IGUANA_ALGORITHM` to complete
51 // # the boilerplate public and private functions and members
52 // ############################################################################
53
6/14
✓ Branch 2 → 3 taken 4 times.
✗ Branch 2 → 6 not taken.
✗ Branch 5 → 7 not taken.
✓ Branch 5 → 8 taken 4 times.
✓ Branch 9 → 10 taken 4 times.
✗ Branch 9 → 32 not taken.
✓ Branch 10 → 11 taken 4 times.
✗ Branch 10 → 17 not taken.
✓ Branch 17 → 18 taken 4 times.
✗ Branch 17 → 40 not taken.
✓ Branch 24 → 25 taken 4 times.
✗ Branch 24 → 40 not taken.
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 39 not taken.
32 DEFINE_IGUANA_ALGORITHM(ExampleAlgorithm, example::ExampleAlgorithm)
54
55 public:
56
57 // ############################################################################
58 // # define `Start`, `Run`, and `Stop` for this algorithm
59 // # - each algorithm must have these methods (even if they do nothing)
60 // ############################################################################
61 void Start(hipo::banklist& banks) override;
62 bool Run(hipo::banklist& banks) const override;
63 void Stop() override;
64
65 // ############################################################################
66 // # define an additional `Run` function which takes `hipo::bank` parameters
67 // # - the parameters should be lvalue references, i.e., `hipo::bank&`, to avoid copying the banks
68 // # - if a bank is ONLY read, and not modified, you should use `const`, i.e., `hipo::bank const&`
69 // # - in this example, `particleBank` will be modified, so we use `hipo::bank&`
70 // # - be sure the function itself is also marked `const`
71 // # - you'll also need to write Doxygen docstrings for this function
72 // # - use `@run_function`, so the documentation understands this is a `Run` function
73 // # - use `@param [in]` for a bank that is only read (type should be `hipo::bank const&`)
74 // # - use `@param [out]` for a bank that is newly created (type should be `hipo::bank&`)
75 // # - use `@param [in,out]` for a bank that is read and mutated (type should be `hipo::bank&`)
76 // # - use `@run_function_returns_true` if the function does not use the `bool` return value, otherwise
77 // # use `@returns` and explain why the return value could be `false`
78 // ############################################################################
79 /// @run_function
80 /// @param [in,out] particleBank `REC::Particle` bank
81 /// @returns `false` if all particles are filtered out
82 bool Run(hipo::bank& particleBank) const;
83
84 // ############################################################################
85 // # additional public functions go here
86 // # - typically these are "action functions", which expose the primary operation of an algorithm
87 // # - these functions are _unique_ to each algorithm, and therefore are not defined in the
88 // # `Algorithm` base class
89 // # - their purpose is to allow the usage of the algorithm for users who _don't_ process full banks,
90 // # but rather process bank rows, or from some other data source
91 // # - try to keep the parameters and return types _friendly_ to language bindings; for example,
92 // # avoid "complicated" types and lvalue references
93 // # - don't forget the Doxygen docstrings
94 // # - the action function here is trivial, just to show an example
95 // # - you do not have to name it as `Filter`, but take a look at other algorithms and try to
96 // # keep some consistency, for example:
97 // # - `bool Filter` for a filtering type algorithm, such as fiducial cuts
98 // # - `Transform` for a transformation type algorithm, such as momentum corrections
99 // # - `Create` for a creation type algorithm, such as inclusive kinematic (x, Q2, etc.) reconstruction
100 // ############################################################################
101 /// @action_function{scalar filter} checks if the PDG `pid` is positive;
102 /// this is an example action function, please replace it with your own
103 /// @param pid the particle PDG to check
104 /// @returns `true` if `pid` is positive
105 bool Filter(int const pid) const;
106
107 private:
108
109 // ############################################################################
110 // # indices for the banks needed for this algorithm
111 // # - see `Algorithm::GetBankIndex` for details
112 // # - here, we just define one for the `REC::Particle` bank
113 // # - convention: they should start with `b_`
114 // ############################################################################
115 /// `hipo::banklist` index for the particle bank (as an example)
116 hipo::banklist::size_type b_particle;
117
118 // ############################################################################
119 // # configuration options
120 // # - their type may be:
121 // # - one of the allowed types in `option_t`, which is a `std::variant`
122 // # - `std::set`, used by `Algorithm::GetOptionSet`, which converts
123 // # a user's `std::vector` option to a `std::set`
124 // # - your own type, but you will have to set it in the `Start()` method
125 // # - here we show example `int` and `double` options
126 // # - convention: they should start with `o_`
127 // ############################################################################
128 /// Example integer configuration option
129 int o_exampleInt;
130 /// Example double configuration option
131 double o_exampleDouble;
132 };
133
134 }
135