Skip to content

[skip-ci][hist] Document architecture for initial set of classes #19295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions hist/histv7/doc/CodeArchitecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Code Architecture

This document lists all classes, describes their responsibilities, and details how they fit together.

## Core Classes

These classes are involved when the user calls `Fill`.
The list is ordered "bottom-up" in terms of functionality.

### `RRegularAxis`, `RVariableBinAxis`, `RCategoricalAxis`

These classes implement a concrete axis type.
Their main task is to compute the linearized index for a single `Fill` argument:
```c++
RLinearizedIndex ComputeLinearizedIndex(double x);
```
The `bool` is used to indicate if the return value is valid.
Copy link
Member

@pcanal pcanal Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the switch from pair<size_t,bool> to RLinearizedIndex and with RLinearizedIndex not being described (at that point of reading). This sentence ("The bool ..") is lacking a bit of context.

For example, the argument may be outside the axis with the underflow and overflow bins disabled.
`RLinearizedIndex` is a simple struct with a `std::size_t index` and `bool valid`.
It is chosen over `std::optional` because it unifies the return value construction:
If outside the axis, the validity is just determined by the member property `fEnableFlowBins`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If outside the axis, the validity is still valid if flow bins have been enabled (as recorded by the member property `fEnableFlowBins`).


### `Internal::RAxes`

This class is responsible for managing a histogram's axis configuration.
It stores the axis objects as a `std::vector` of `std::variant`s.
Objects of this class are used internally and not exposed to the user.
Relevant functionality is available through user-facing classes such as `RHistEngine`.

The main function is
```c++
template <typename... A>
RLinearizedIndex ComputeGlobalIndex(const std::tuple<A...> &args) const;
```
that dispatches arguments to the individual `ComputeLinearizedIndex` and combines the results.
If any of the linearized indices is invalid, so will be the combination.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If any of the linearized indices is invalid, so is the combination.

maybe ... to match tenses.


### `RHistEngine`

This class combines an `RAxes` object and storage of bin contents in a `std::vector`.
During `Fill`, it calls `RAxes::ComputeLinearizedIndex` and then updates the bin content.
In contrast to `RHist`, this class supports direct concurrent filling via `FillAtomic`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use some more context and justification. (i.e. why this contrast/difference?).


### `RHistStats`

Manages the (global) histogram statistics, such as the number of entries.
It also keeps statistics of the unbinned values for each dimension.

### `RHist`

This class combines `RHistEngine`, with its axes and bin contents, and `RHistStats`.
During `Fill`, it delegates to `RHistEngine::Fill` but also updates the histogram statistics.

## Classes for Weighted Filling

### `RDoubleBinWithError`

A special bin content type that also accumulates the sum of weights squared.
It can be used as a template argument to `RHistEngine` and `RHist`.

### `RWeight`

A wrapper `struct` for a single `double` value, used for weighted filling to distinguish its type.
Objects of this type are passed by value.

## Auxiliary Classes

### `RBinIndex`

A single bin index, which is just an integer for normal bins.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the relation ship with RLinearizedIndex?

`Underflow()` and `Overflow()` are special values and not ordered with respect to others.
Copy link
Member

@pcanal pcanal Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not ordered with respect to others.

Why not? and/or why is it important?

Objects of this type are passed by value; most notably to `GetBinContent` and `SetBinContent`.

### `RBinIndexRange`

A range of `RBinIndex` from `begin` (inclusive) to `end` (exclusive).
The class exposes an iterator interface that can be used in range-based loops.