pub struct Tree { /* private fields */ }
Expand description
Tree of Collections for saving to a file.
Implementations
Returns new Tree
Name is the only required metadata.
Arguments
name
- string
Example
use calcify::Tree;
use calcify::Collection;
use calcify::Bin;
use calcify::ThreeVec;
let f_col: Collection<f64> = Collection::from(vec![0.0,0.0]);
let mut v3_col: Collection<ThreeVec> = Collection::empty();
for _i in 0..9999 {v3_col.push(ThreeVec::random(1.0));}
let col_hist: Collection<Bin> = v3_col.map(ThreeVec::r).hist(50);
let mut ttree = Tree::new("Test_Tree");
ttree.add_field("Desc", "This is a Tree for testing.");
ttree.add_branch("fcol", f_col, "f64");
ttree.add_branch("col_3v", v3_col, "ThreeVec");
ttree.add_branch("hist_3v", col_hist, "Bin");
pub fn add_branch<T: 'static + Serializable>(
&mut self,
key: &str,
b: Collection<T>,
t: &str
) -> Result<(), CalcifyError>
pub fn add_branch<T: 'static + Serializable>(
&mut self,
key: &str,
b: Collection<T>,
t: &str
) -> Result<(), CalcifyError>
Returns Branch from a Trees
Arguments
key
- String
Example
use calcify::Tree;
use calcify::Collection;
use calcify::Bin;
let f_col: Collection<f64> = Collection::from(vec![0.0,0.0]);
let b_col: Collection<Bin> = Collection::from(vec![Bin::new(0.0,1.0,10),Bin::new(1.0,2.0,10),Bin::new(2.0,3.0,10)]);
let mut ttree = Tree::new("Test_Tree");
ttree.add_branch("fcol", f_col, "f64").expect("KeyError");
ttree.add_branch("bCol", b_col, "Bin").expect("KeyError");
let ex_f_col: Collection<f64> = ttree.get_branch("fcol").unwrap().extract().unwrap();
let mut ex_b_col: Collection<Bin> = ttree.get_branch("bCol").unwrap().extract().unwrap();
assert_eq!(Collection::from(vec![0.0,0.0]),ex_f_col);
assert_eq!(Collection::from(vec![Bin::new(0.0,1.0,10),Bin::new(1.0,2.0,10),Bin::new(2.0,3.0,10)]),ex_b_col);
pub fn read_branch<T: Serializable + Deserializable>(
&mut self,
key: &str
) -> Result<Collection<T>, CalcifyError>
pub fn read_branch<T: Serializable + Deserializable>(
&mut self,
key: &str
) -> Result<Collection<T>, CalcifyError>
Returns Collection from a Trees
Arguments
key
- String
Example
use calcify::Tree;
use calcify::Collection;
use calcify::Bin;
let f_col: Collection<f64> = Collection::from(vec![0.0,0.0]);
let b_col: Collection<Bin> = Collection::from(vec![Bin::new(0.0,1.0,10),Bin::new(1.0,2.0,10),Bin::new(2.0,3.0,10)]);
let mut ttree = Tree::new("Test_Tree");
ttree.add_branch("fcol", f_col, "f64").expect("KeyError");
ttree.add_branch("bCol", b_col, "Bin").expect("KeyError");
let ex_f_col: Collection<f64> = ttree.read_branch("fcol").unwrap();
let mut ex_b_col: Collection<Bin> = ttree.read_branch("bCol").unwrap();
// read from buffer
ex_b_col = ttree.read_branch("bCol").unwrap();
assert_eq!(Collection::from(vec![0.0,0.0]),ex_f_col);
assert_eq!(Collection::from(vec![Bin::new(0.0,1.0,10),Bin::new(1.0,2.0,10),Bin::new(2.0,3.0,10)]),ex_b_col);