Iguana 0.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 // ############################################################################
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 // ############################################################################
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 // ############################################################################
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 // ############################################################################
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 // ############################################################################
114 int o_exampleInt;
116 double o_exampleDouble;
117 };
118
119}
#define DEFINE_IGUANA_ALGORITHM(ALGO_NAME, ALGO_FULL_NAME)
Base class for all algorithms to inherit from.
Definition Algorithm.h:40
Algorithm: This is a template algorithm, used as an example showing how to write an algorithm.
Definition Algorithm.h:43
void Start(hipo::banklist &banks) override
Initialize this algorithm before any events are processed, with the intent to process banks
void Run(hipo::banklist &banks) const override
Run this algorithm for an event.
void Stop() override
Finalize this algorithm after all events are processed.
bool Filter(int const pid) const
Example algorithms.
Definition Algorithm.h:18