A container for many branches. More...
#include <Tree.h>
Public Member Functions | |
| template<typename DataType > | |
| Branch< DataType > & | branch (const std::string &branch_name) |
| Create a new branch on the tree. | |
| template<typename DataType > | |
| const Branch< DataType > & | get (const std::string &branch_name, bool write=false) |
| get a branch, this only really makes sense if reading | |
| template<class UnaryFunction > | |
| void | for_each (UnaryFunction body) |
| loop over all entries in the tree, executing the provided function on each call More... | |
| void | save () |
| end-of-event call back More... | |
| void | load () |
| start-of-event call back More... | |
Static Public Member Functions | |
| static Tree | load (const std::string &file_path, const std::string &tree_path) |
| static Tree | save (const std::string &file_path, const std::string &tree_path) |
| static Tree | inplace (const std::string &file_path, const std::string &tree_path) |
| static Tree | transform (const std::pair< std::string, std::string > &src, const std::pair< std::string, std::string > &dest) |
Private Member Functions | |
| Tree (const std::pair< std::string, std::string > &src, const std::pair< std::string, std::string > &dest) | |
| The tree constructor is private because it is complicated, use the static factory functions for accessing a Tree. | |
Private Attributes | |
| std::unordered_map< std::string, std::unique_ptr< BaseBranch > > | branches_ |
| the branches in this tree | |
| std::optional< std::size_t > | entries_ |
| the number of entries in this tree (if reading from a file) | |
| std::unique_ptr< Reader > | reader_ |
| reader if loading from a file | |
| std::unique_ptr< Writer > | writer_ |
| writer if writing to a file | |
| bool | inplace_ {false} |
| are we reading from and writing to the same file? | |
A container for many branches.
|
inline |
loop over all entries in the tree, executing the provided function on each call
auto& i_entry = tree.branch<int>("i_entry"); auto& two_i_entry = tree.branch<int>("two_i_entry"); tree.for_each([&]() { two_i_entry = 2(*i_entry); });
| void hdtree::Tree::load | ( | ) |
start-of-event call back
we go through and load each branch that is in this tree
| void hdtree::Tree::save | ( | ) |
end-of-event call back
basically, we go through and save+clear each branch that is in this tree
The 'clear' call is helpful so users can treat their handle to a Branch as if it is a local variable in the loop.
At the end, we also inform the writer (if there is one) that the number of entries in the tree has incremented.