|
| 1 | +# Code Architecture |
| 2 | + |
| 3 | +This document lists all classes, describes their responsibilities, and details how they fit together. |
| 4 | + |
| 5 | +## Core Classes |
| 6 | + |
| 7 | +These classes are involved when the user calls `Fill`. |
| 8 | +The list is ordered "bottom-up" in terms of functionality. |
| 9 | + |
| 10 | +### `RRegularAxis`, `RVariableBinAxis`, `RCategoricalAxis` |
| 11 | + |
| 12 | +These classes implement a concrete axis type. |
| 13 | +Their main task is to compute the linearized index for a single `Fill` argument: |
| 14 | +```c++ |
| 15 | +RLinearizedIndex ComputeLinearizedIndex(double x); |
| 16 | +``` |
| 17 | +The `bool` is used to indicate if the return value is valid. |
| 18 | +For example, the argument may be outside the axis with the underflow and overflow bins disabled. |
| 19 | +`RLinearizedIndex` is a simple struct with a `std::size_t index` and `bool valid`. |
| 20 | +It is chosen over `std::optional` because it unifies the return value construction: |
| 21 | +If outside the axis, the validity is just determined by the member property `fEnableFlowBins`. |
| 22 | +
|
| 23 | +### `Internal::RAxes` |
| 24 | +
|
| 25 | +This class is responsible for managing a histogram's axis configuration. |
| 26 | +It stores the axis objects as a `std::vector` of `std::variant`s. |
| 27 | +Objects of this class are used internally and not exposed to the user. |
| 28 | +Relevant functionality is available through user-facing classes such as `RHistEngine`. |
| 29 | +
|
| 30 | +The main function is |
| 31 | +```c++ |
| 32 | +template <typename... A> |
| 33 | +RLinearizedIndex ComputeGlobalIndex(const std::tuple<A...> &args) const; |
| 34 | +``` |
| 35 | +that dispatches arguments to the individual `ComputeLinearizedIndex` and combines the results. |
| 36 | +If any of the linearized indices is invalid, so will be the combination. |
| 37 | + |
| 38 | +### `RHistEngine` |
| 39 | + |
| 40 | +This class combines an `RAxes` object and storage of bin contents in a `std::vector`. |
| 41 | +During `Fill`, it calls `RAxes::ComputeLinearizedIndex` and then updates the bin content. |
| 42 | +In contrast to `RHist`, this class supports direct concurrent filling via `FillAtomic`. |
| 43 | + |
| 44 | +### `RHistStats` |
| 45 | + |
| 46 | +Manages the (global) histogram statistics, such as the number of entries. |
| 47 | +It also keeps statistics of the unbinned values for each dimension. |
| 48 | + |
| 49 | +### `RHist` |
| 50 | + |
| 51 | +This class combines `RHistEngine`, with its axes and bin contents, and `RHistStats`. |
| 52 | +During `Fill`, it delegates to `RHistEngine::Fill` but also updates the histogram statistics. |
| 53 | + |
| 54 | +## Classes for Weighted Filling |
| 55 | + |
| 56 | +### `RDoubleBinWithError` |
| 57 | + |
| 58 | +A special bin content type that also accumulates the sum of weights squared. |
| 59 | +It can be used as a template argument to `RHistEngine` and `RHist`. |
| 60 | + |
| 61 | +### `RWeight` |
| 62 | + |
| 63 | +A wrapper `struct` for a single `double` value, used for weighted filling to distinguish its type. |
| 64 | +Objects of this type are passed by value. |
| 65 | + |
| 66 | +## Auxiliary Classes |
| 67 | + |
| 68 | +### `RBinIndex` |
| 69 | + |
| 70 | +A single bin index, which is just an integer for normal bins. |
| 71 | +`Underflow()` and `Overflow()` are special values and not ordered with respect to others. |
| 72 | +Objects of this type are passed by value; most notably to `GetBinContent` and `SetBinContent`. |
| 73 | + |
| 74 | +### `RBinIndexRange` |
| 75 | + |
| 76 | +A range of `RBinIndex` from `begin` (inclusive) to `end` (exclusive). |
| 77 | +The class exposes an iterator interface that can be used in range-based loops. |
0 commit comments