Skip to main content

gondola_core/database/
tracker_pedestal.rs

1//! Database access & entities for gaps-online-software
2//!
3//! A local .sqlite database is shipped with gaps-online-software,
4//! pre-populated with relevant meta data for the GAPS experiment.
5// This file is part of gaps-online-software and published 
6// under the GPLv3 license
7
8use crate::prelude::*;
9
10use crate::database::schema;
11use diesel::prelude::*;
12
13/// The db insert companion to TrackerStripPedestal
14#[derive(Debug,PartialEq, Clone, Insertable)]
15#[diesel(table_name = schema::tof_db_trackerstrippedestal)]
16#[allow(non_snake_case)]
17#[cfg_attr(feature="pybindings", pyclass)]
18struct NewTrackerStripPedestal {
19  pub strip_id            : i32,    
20  pub volume_id           : i64,    
21  pub utc_timestamp_start : i64,
22  pub utc_timestamp_stop  : i64,
23  pub name                : Option<String>,
24  pub pedestal_mean       : f32, 
25  pub pedestal_sigma      : f32, 
26  pub is_mean_value       : bool,
27}
28
29impl NewTrackerStripPedestal {
30  pub fn from(ped : &TrackerStripPedestal) -> Self {
31    Self {
32      strip_id            : ped.strip_id            ,    
33      volume_id           : ped.volume_id           ,    
34      utc_timestamp_start : ped.utc_timestamp_start ,
35      utc_timestamp_stop  : ped.utc_timestamp_stop  ,
36      name                : ped.name.clone()        ,
37      pedestal_mean       : ped.pedestal_mean       , 
38      pedestal_sigma      : ped.pedestal_sigma      , 
39      is_mean_value       : ped.is_mean_value       ,
40    }
41  }
42}
43
44#[cfg_attr(feature="pybindings", pyfunction)]
45pub fn create_trk_pedestal_table( db_path: &str, pedestals: Vec<TrackerStripPedestal>) { 
46  use schema::tof_db_trackerstrippedestal::dsl::*;
47  let mut conn = SqliteConnection::establish(db_path).ok().unwrap(); 
48  let mut _query_result = diesel::sql_query("
49      CREATE TABLE IF NOT EXISTS tof_db_trackerstrippedestal (
50          data_id INTEGER PRIMARY KEY AUTOINCREMENT,
51          strip_id INTEGER NOT NULL,
52          volume_id BIGINT NOT NULL,
53          utc_timestamp_start BIGINT NOT NULL,
54          utc_timestamp_stop BIGINT NOT NULL,
55          name TEXT,
56          pedestal_mean  FLOAT NOT NULL, 
57          pedestal_sigma FLOAT NOT NULL, 
58          is_mean_value BOOLEAN NOT NULL 
59      )
60  ").execute(&mut conn);
61  let mut new_peds = Vec::<NewTrackerStripPedestal>::new();
62  for p in pedestals {
63    let np = NewTrackerStripPedestal::from(&p);
64    new_peds.push(np);
65  }
66  _query_result = diesel::insert_into(tof_db_trackerstrippedestal)
67    .values(&new_peds)
68    .execute(&mut conn);
69}
70
71
72