Iguana 1.0.0
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 // ############################################################################
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 // ############################################################################
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 // ############################################################################
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 // ############################################################################
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 // ############################################################################
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 // ############################################################################
129 int o_exampleInt;
131 double o_exampleDouble;
132 };
133
134}
#define DEFINE_IGUANA_ALGORITHM(ALGO_NAME, ALGO_FULL_NAME)
Algorithm(std::string_view name)
Definition Algorithm.h:46
Algorithm: This is a template algorithm, used as an example showing how to write an algorithm.
Definition Algorithm.h:39
void Start(hipo::banklist &banks) override
Initialize this algorithm before any events are processed, with the intent to process banks.
void Stop() override
Finalize this algorithm after all events are processed.
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
bool Run(hipo::banklist &banks) const override
Run Function: Process an event's hipo::banklist
Example algorithms.
Definition Algorithm.h:18