Skip to main content

gluex_core/
lib.rs

1pub mod constants;
2pub mod detectors;
3pub mod enums;
4pub mod histograms;
5pub mod parsers;
6pub mod particles;
7pub mod run_periods;
8/// Filesystem and other shared utility helpers.
9pub mod utils;
10
11use thiserror::Error;
12
13/// Primary integer identifier type used throughout CCDB and RCDB.
14pub type Id = i64;
15
16/// Run number type as stored in CCDB and RCDB.
17pub type RunNumber = i64;
18
19/// REST versions of analysis reconstructions.
20pub type RESTVersion = usize;
21
22/// Unified error type for all `gluex-core` fallible APIs.
23#[derive(Error, Debug, Clone, PartialEq)]
24pub enum GlueXCoreError {
25    /// Input contained no digits from which to form a timestamp.
26    #[error("timestamp \"{0}\" has no digits")]
27    TimestampNoDigits(String),
28    /// Parsed timestamp was invalid according to the [`chrono`] crate.
29    #[error("invalid timestamp: {0}")]
30    TimestampChrono(String),
31    /// Histogram requires at least two edge values.
32    #[error("histogram edges must contain at least two values (found {len})")]
33    HistogramTooFewEdges { len: usize },
34    /// Edge value was NaN or infinite.
35    #[error("histogram edge at index {index} is not finite: {value}")]
36    HistogramNonFiniteEdge { index: usize, value: f64 },
37    /// Consecutive edge values were not strictly increasing.
38    #[error(
39        "histogram edges must be strictly increasing (edges[{index}]={left}, edges[{next_index}]={right})"
40    )]
41    HistogramNotStrictlyIncreasing {
42        index: usize,
43        next_index: usize,
44        left: f64,
45        right: f64,
46    },
47    /// Number of counts does not match number of bins.
48    #[error("counts length mismatch: expected {expected}, found {found}")]
49    HistogramCountLengthMismatch { expected: usize, found: usize },
50    /// Number of errors does not match number of bins.
51    #[error("errors length mismatch: expected {expected}, found {found}")]
52    HistogramErrorLengthMismatch { expected: usize, found: usize },
53    /// Number of weights does not match number of values.
54    #[error("weights length mismatch: expected {expected}, found {found}")]
55    HistogramWeightLengthMismatch { expected: usize, found: usize },
56    /// Uniform histogram requested with zero bins.
57    #[error("uniform histogram requires at least one bin")]
58    HistogramEmptyBinCount,
59    /// Uniform histogram limits were not finite and strictly increasing.
60    #[error(
61        "uniform histogram limits must be finite and strictly increasing (min={min}, max={max})"
62    )]
63    HistogramInvalidUniformLimits { min: f64, max: f64 },
64    /// Run number does not belong to any known run period.
65    #[error("Run number {0} not in range of any known run period")]
66    UnknownRunPeriod(RunNumber),
67    /// Could not parse run-period shorthand.
68    #[error("Could not parse run period from string {0}")]
69    RunPeriodParse(String),
70    /// No REST metadata exists for the run period.
71    #[error("Run period {0:?} is missing REST version metadata")]
72    MissingRESTVersions(crate::run_periods::RunPeriod),
73    /// Requested REST version is not defined for the run period.
74    #[error("REST version {requested} is not defined for run period {run_period:?}")]
75    UnknownRESTVersion {
76        run_period: crate::run_periods::RunPeriod,
77        requested: RESTVersion,
78    },
79}
80
81pub use crate::detectors::DetectorSystem;
82pub use crate::enums::Polarization;
83pub use crate::histograms::Histogram;
84pub use crate::particles::{Charge, Particle};
85pub use crate::run_periods::{RESTVersionSelection, RunPeriod};