Skip to main content

gluex_rcdb/
lib.rs

1//! `GlueX` RCDB access library with optional Python bindings.
2
3/// Condition expression builders and helpers.
4pub mod conditions;
5/// Run-selection context utilities.
6pub mod context;
7/// Value container utilities returned from queries.
8pub mod data;
9/// High-level database accessors.
10pub mod database;
11/// Lightweight structs that mirror RCDB tables.
12pub mod models;
13
14use thiserror::Error;
15
16use crate::models::ValueType as LocalValueType;
17use gluex_core::RunNumber as LocalRunNumber;
18
19/// Convenience alias for results returned from RCDB operations.
20pub type RCDBResult<T> = Result<T, RCDBError>;
21
22/// Errors that can occur while interacting with RCDB metadata or payloads.
23#[derive(Error, Debug)]
24pub enum RCDBError {
25    /// Wrapper around [`rusqlite::Error`].
26    #[error(transparent)]
27    SqliteError(#[from] rusqlite::Error),
28    /// Requested condition name does not exist.
29    #[error("condition type not found: {0}")]
30    ConditionTypeNotFound(String),
31    /// The `SQLite` file does not contain the expected schema version entry.
32    #[error("schema_versions table does not contain version 2")]
33    MissingSchemaVersion,
34    /// Fetch API requires at least one condition name.
35    #[error("fetch requires at least one condition name")]
36    EmptyConditionList,
37    /// Failed to resolve or canonicalize a filesystem path.
38    #[error(transparent)]
39    PathResolutionError(#[from] std::io::Error),
40    /// Timestamp parsing failed while decoding a `time` condition.
41    #[error(transparent)]
42    GlueXCoreError(#[from] gluex_core::GlueXCoreError),
43    /// Encountered a value type identifier we do not understand.
44    #[error("unknown RCDB value type identifier: {0}")]
45    UnknownValueType(String),
46    /// Predicate requested a condition with a mismatched type.
47    #[error("condition {condition_name} type mismatch: expected {expected:?}, actual {actual:?}")]
48    ConditionTypeMismatch {
49        /// Name of the offending condition.
50        condition_name: String,
51        /// Type requested by the predicate builder.
52        expected: LocalValueType,
53        /// Type stored in the database schema.
54        actual: LocalValueType,
55    },
56    /// `time` condition row was missing a `time_value` entry.
57    #[error("missing time_value for condition {condition_name} at run {run_number}")]
58    MissingTimeValue {
59        /// Name of the time-valued condition.
60        condition_name: String,
61        /// Run number missing the time value.
62        run_number: LocalRunNumber,
63    },
64    /// Required environment variable is not set.
65    #[error("missing {0} environment variable for RCDB connection")]
66    MissingConnectionEnv(String),
67}
68
69pub use crate::conditions::{BoolField, Expr, FloatField, IntField, StringField, TimeField};
70pub use crate::context::{RCDBContext, RunSelection};
71pub use crate::data::Value;
72pub use crate::database::RCDB;
73pub use crate::models::ValueType;
74pub use gluex_core::run_periods::RunPeriod;
75pub use gluex_core::RunNumber;