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 | /// @brief_algo This is a template algorithm, used as an example showing how to write an algorithm. | ||
30 | /// | ||
31 | /// Provide a more detailed description of your algorithm here. | ||
32 | /// | ||
33 | /// @begin_doc_algo{example::ExampleAlgorithm | Filter} | ||
34 | /// @input_banks{REC::Particle} | ||
35 | /// @output_banks{REC::Particle} | ||
36 | /// @end_doc | ||
37 | /// | ||
38 | /// @begin_doc_config | ||
39 | /// @config_param{exampleInt | int | an example `integer` configuration parameter} | ||
40 | /// @config_param{exampleDouble | double | an example `double` configuration parameter} | ||
41 | /// @end_doc | ||
42 | class ExampleAlgorithm : public Algorithm | ||
43 | { | ||
44 | |||
45 | // ############################################################################ | ||
46 | // # this is a preprocessor macro call which generates boilerplate for the algorithm definition | ||
47 | // # - the arguments are: | ||
48 | // # - the class name, `ExampleAlgorithm` | ||
49 | // # - a unique, "full" name of the algorithm, used by `AlgorithmFactory`; typically is the | ||
50 | // # namespace with the class name, excluding the `iguana::` part, but you are free to choose any name | ||
51 | // # - NOTE: quotes are not used, and there is no need for a semicolon at the end of this call | ||
52 | // # - see `../AlgorithmBoilerplate.h` for details | ||
53 | // # - the macros are relatively modular, so if you want to use your own constructor or destructor, you may | ||
54 | // # do so, and use other preprocessor macros called within `DEFINE_IGUANA_ALGORITHM` to complete | ||
55 | // # the boilerplate public and private functions and members | ||
56 | // ############################################################################ | ||
57 |
5/12✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
28 | DEFINE_IGUANA_ALGORITHM(ExampleAlgorithm, example::ExampleAlgorithm) |
58 | |||
59 | public: | ||
60 | |||
61 | // ############################################################################ | ||
62 | // # define `Start`, `Run`, and `Stop` for this algorithm | ||
63 | // # - each algorithm must have these methods (even if they do nothing) | ||
64 | // ############################################################################ | ||
65 | void Start(hipo::banklist& banks) override; | ||
66 | void Run(hipo::banklist& banks) const override; | ||
67 | void Stop() override; | ||
68 | |||
69 | // ############################################################################ | ||
70 | // # additional public functions go here | ||
71 | // # - typically these are "action functions", which expose the primary operation of an algorithm | ||
72 | // # - these functions are _unique_ to each algorithm, and therefore are not defined in the | ||
73 | // # `Algorithm` base class | ||
74 | // # - their purpose is to allow the usage of the algorithm for users who _don't_ process full banks, | ||
75 | // # but rather process bank rows, or from some other data source | ||
76 | // # - try to keep the parameters and return types _friendly_ to language bindings; for example, | ||
77 | // # avoid "complicated" types and lvalue references | ||
78 | // # - don't forget the Doxygen docstrings | ||
79 | // # - the action function here is trivial, just to show an example | ||
80 | // # - you do not have to name it as `Filter`, but take a look at other algorithms and try to | ||
81 | // # keep some consistency, for example: | ||
82 | // # - `bool Filter` for a filtering type algorithm, such as fiducial cuts | ||
83 | // # - `Transform` for a transformation type algorithm, such as momentum corrections | ||
84 | // # - `Create` for a creation type algorithm, such as inclusive kinematic (x, Q2, etc.) reconstruction | ||
85 | // ############################################################################ | ||
86 | /// @action_function{scalar filter} checks if the PDG `pid` is positive; | ||
87 | /// this is an example action function, please replace it with your own | ||
88 | /// @param pid the particle PDG to check | ||
89 | /// @returns `true` if `pid` is positive | ||
90 | bool Filter(int const pid) const; | ||
91 | |||
92 | private: | ||
93 | |||
94 | // ############################################################################ | ||
95 | // # indices for the banks needed for this algorithm | ||
96 | // # - see `Algorithm::GetBankIndex` for details | ||
97 | // # - here, we just define one for the `REC::Particle` bank | ||
98 | // # - convention: they should start with `b_` | ||
99 | // ############################################################################ | ||
100 | /// `hipo::banklist` index for the particle bank (as an example) | ||
101 | hipo::banklist::size_type b_particle; | ||
102 | |||
103 | // ############################################################################ | ||
104 | // # configuration options | ||
105 | // # - their type may be: | ||
106 | // # - one of the allowed types in `option_t`, which is a `std::variant` | ||
107 | // # - `std::set`, used by `Algorithm::GetOptionSet`, which converts | ||
108 | // # a user's `std::vector` option to a `std::set` | ||
109 | // # - your own type, but you will have to set it in the `Start()` method | ||
110 | // # - here we show example `int` and `double` options | ||
111 | // # - convention: they should start with `o_` | ||
112 | // ############################################################################ | ||
113 | /// Example integer configuration option | ||
114 | int o_exampleInt; | ||
115 | /// Example double configuration option | ||
116 | double o_exampleDouble; | ||
117 | }; | ||
118 | |||
119 | } | ||
120 |