Skip to content

Conversation

@PetrilloAtWork
Copy link
Contributor

@PetrilloAtWork PetrilloAtWork commented Oct 30, 2025

This PR contains an update of the quantity library in lardataalg.

The quantity library supports the creation of data types bound to a measure unit (e.g. Second) and handles scale conversions and consistency (for example, it is not allowed to add a pure number to a util::quantities::millisecond variable, and addition has severe restrictions). Including extensions in FHiCL parsing, it allows consistent variable dimensions from configuration to the inner code.

This PR allows the definition of operations between quantities with two different units, enabling math like the ratio of a voltage by a current (to yield a resistance type) or the product of a frequency and a time (yielding a pure number). Only quantity types are currently supported: point and interval types from this library are not (because I haven't gone through the thinking needed to understand what is correct and what not in that case).
Relationship between units must be explicitly declared.

Parsing is extended so that full unit names can be used in configuration (e.g. "5 millisecond" is now equivalent to "5 ms").

In addition, new quantities are added to electromagnetism.h, based on Ohm, Ampere and Farad. Added relations are Ohm×Ampere (Volt) and Farad×Volt (Coulomb).
Inter-header quantities relations are declared in both involved headers, conditionally to the fact that both headers are included by the user (e.g. to use the frequency × time operation, both spacetime.h and frequency.h need to be included; but auto f = 1 / 2_ms will fail if frequency.h is not loaded).

Unit tests exercising the new features and units are included, and Doxygen documentation is updated.

These features are going to be used in some of the ICARUS electronics simulation code currently in development.

Breaking change: util::quantities::concepts::details::is_quantity_v has been promoted to interface (util::quantities::concepts::is_quantity_v). This should not be an issue since normally user code does not dip fingers into details namespaces; lardataalg code is updated to reflect the change.

This code was developed and is based on version 10.00.06 (LArSoft v10_06_00).

…ities.

They provide direct information about the base unit of a quantity,
interval, point or unit.
…rent value type

Idiomatically mean to explicitly allow for narrowing assignments
(e.g. by explicitly converting a double-based quantity intoa float-based one
before assignment).
…ects

Allows multiplicative math between two quantity objects
(for example a millivolt quantity could be divided by a kiloohm one,
resulting into a microampere one).
Only binary operations are supported (e.g. no N/m/m = Pa).
Each quantity relation needs to be explicitly enabled.
Also introduced a unit test for them, and some relations among them
and optionally (when all relevant headers are included) relation RC = t.
Added support of product of quantities resulting into a scalar.
It now accepts extended units (e.g. "millisecond") too.
@FNALbuild
Copy link
Contributor

A new Pull Request was created by @PetrilloAtWork (Gianluca Petrillo) for develop.

It involves the following packages:

lardataalg

@LArSoft/level-2-managers, @LArSoft/level-1-managers can you please review it and eventually sign? Thanks.

cms-bot commands are listed here

@FNALbuild
Copy link
Contributor

The code-checks are being triggered in jenkins.

@FNALbuild
Copy link
Contributor

+code-checks

@lgarren lgarren moved this to Awaiting triage in LArSoft pull requests Oct 30, 2025
@knoepfel knoepfel moved this from Awaiting triage to Under discussion in LArSoft pull requests Nov 3, 2025
@knoepfel
Copy link
Member

@PetrilloAtWork, is there an intention for the units to be used within LArSoft itself and not just ICARUS (or SBN)?

@PetrilloAtWork
Copy link
Contributor Author

I haven't been aware of any people intending to use them, part of the problem being that people don't know about them.
I have been aware of many issues that would not have happened if that hadn't be the case, though.

@FNALbuild
Copy link
Contributor

Pull request #52 was updated. @LArSoft/level-1-managers, @LArSoft/level-2-managers can you please check and sign again.

@FNALbuild
Copy link
Contributor

The code-checks are being triggered in jenkins.

@FNALbuild
Copy link
Contributor

+code-checks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Under discussion

Development

Successfully merging this pull request may close these issues.

3 participants