Iguana LATEST
Implementation Guardian of Analysis Algorithms
Loading...
Searching...
No Matches
Algorithm.h
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// ############################################################################
18namespace 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 // ############################################################################
36 {
37
38 // ############################################################################
39 // # this is a preprocessor macro call which generates boilerplate for the algorithm definition
40 // # - the arguments are:
41 // # - the class name, `ExampleAlgorithm`
42 // # - a unique, "full" name of the algorithm, used by `AlgorithmFactory`; typically is the
43 // # namespace with the class name, excluding the `iguana::` part, but you are free to choose any name
44 // # - NOTE: quotes are not used, and there is no need for a semicolon at the end of this call
45 // # - see `../AlgorithmBoilerplate.h` for details
46 // # - the macros are relatively modular, so if you want to use your own constructor or destructor, you may
47 // # do so, and use other preprocessor macros called within `DEFINE_IGUANA_ALGORITHM` to complete
48 // # the boilerplate public and private functions and members
49 // ############################################################################
51
52 // ############################################################################
53 // # declare the "hook" functions that you will implement
54 // # - the `.cc` file explains what each of these are used for
55 // # - only declare the ones that you actually will override, otherwise you will
56 // # get 'undefined reference to vtable' errors during linking
57 // # - see the base-class `Algorithm` for additional hook functions (they end
58 // # with the word `Hook`), for example, `StopHook`, which is called after
59 // # all event processing (by `Algorithm::Stop`)
60 // ############################################################################
61 private: // hooks
62 void ConfigHook() override;
63 void StartHook(hipo::banklist& banks) override;
64 bool RunHook(hipo::banklist& banks) const override;
65
66 public:
67
68 // ############################################################################
69 // # define a `Run` function which takes `hipo::bank` parameters
70 // # - the parameters should be lvalue references, i.e., `hipo::bank&`, to avoid copying the banks
71 // # - if a bank is ONLY read, and not modified, you should use `const`, i.e., `hipo::bank const&`
72 // # - in this example, `particleBank` will be modified, so we use `hipo::bank&`
73 // # - be sure the function itself is also marked `const`
74 // # - you'll also need to write Doxygen docstrings for this function
75 // # - use `@run_function`, so the documentation understands this is a `Run` function
76 // # - use `@param [in]` for a bank that is only read (type should be `hipo::bank const&`)
77 // # - use `@param [out]` for a bank that is newly created (type should be `hipo::bank&`)
78 // # - use `@param [in,out]` for a bank that is read and mutated (type should be `hipo::bank&`)
79 // # - use `@run_function_returns_true` if the function does not use the `bool` return value, otherwise
80 // # use `@returns` and explain why the return value could be `false`
81 // ############################################################################
85 bool Run(hipo::bank& particleBank) const;
86
87 // ############################################################################
88 // # additional public functions go here
89 // # - typically these are "action functions", which expose the primary operation of an algorithm
90 // # - these functions are _unique_ to each algorithm, and therefore are not defined in the
91 // # `Algorithm` base class
92 // # - their purpose is to allow the usage of the algorithm for users who _don't_ process full banks,
93 // # but rather process bank rows, or from some other data source
94 // # - try to keep the parameters and return types _friendly_ to language bindings; for example,
95 // # avoid "complicated" types and lvalue references
96 // # - don't forget the Doxygen docstrings
97 // # - the action function here is trivial, just to show an example
98 // # - you do not have to name it as `Filter`, but take a look at other algorithms and try to
99 // # keep some consistency, for example:
100 // # - `bool Filter` for a filtering type algorithm, such as fiducial cuts
101 // # - `Transform` for a transformation type algorithm, such as momentum corrections
102 // # - `Create` for a creation type algorithm, such as inclusive kinematic (x, Q2, etc.) reconstruction
103 // ############################################################################
108 bool Filter(int const pid) const;
109
110 private:
111
112 // ############################################################################
113 // # indices for the banks needed for this algorithm
114 // # - see `Algorithm::GetBankIndex` for details
115 // # - here, we just define one for the `REC::Particle` bank
116 // # - convention: they should start with `b_`
117 // ############################################################################
119 hipo::banklist::size_type b_particle;
120
121 // ############################################################################
122 // # configuration options
123 // # - their type may be:
124 // # - one of the allowed types in `option_t`, which is a `std::variant`
125 // # - `std::set`, used by `Algorithm::GetOptionSet`, which converts
126 // # a user's `std::vector` option to a `std::set`
127 // # - your own type, but you will have to set it in the `StartHook()` method
128 // # - here we show example `int` and `double` options
129 // # - convention: they should start with `o_`
130 // ############################################################################
132 int o_exampleInt;
134 double o_exampleDouble;
135 };
136
137}
#define DEFINE_IGUANA_ALGORITHM(ALGO_NAME, ALGO_FULL_NAME)
Algorithm(std::string_view name)
Definition Algorithm.h:73
Algorithm: This is a template algorithm, used as an example showing how to write an algorithm.
Definition Algorithm.h:36
bool Filter(int const pid) const
Action Function: checks if the PDG pid is positive; this is an example action function,...
bool Run(hipo::bank &particleBank) const
Run Function: Process an event's hipo::bank objects
Example algorithms.
Definition Algorithm.h:18