Reading ROOT files into our data structures.
More...
#include <Reader.h>
|
template<typename T > |
TBranch * | attach (TTree *tree, const std::string &branch_name, T &obj) |
| Attach the input object to the TTree on the given branch. More...
|
|
|
TFile * | file_ |
| file being read
|
|
TTree * | event_tree_ |
| tree of events in the file
|
|
TTree * | run_tree_ |
| tree of runs in the file
|
|
std::map< std::string, TBranch * > | attached_ |
|
Reading ROOT files into our data structures.
If you are familiar with the ROOT-based Framework, this Reader effectively does tasks done by the framework::Event and framework::EventFile classes.
◆ Reader()
fire::io::root::Reader::Reader |
( |
const std::string & |
file_name | ) |
|
open input file for reading
- Exceptions
-
Exception | if file cannot be opened, a TTree named 'LDMX_Events' is not found, or if a TTree named 'LDMX_Run' is not found. |
After opening the file and retrieve the TTrees we will read, we turn off ROOT's "feature" of handling standard Unix signals.
- Parameters
-
[in] | file_name | file to open with ROOT |
◆ attach()
template<typename T >
TBranch * fire::io::root::Reader::attach |
( |
TTree * |
tree, |
|
|
const std::string & |
branch_name, |
|
|
T & |
obj |
|
) |
| |
|
inlineprivate |
Attach the input object to the TTree on the given branch.
- Exceptions
-
If the type is arithmetic (numeric_limits are specialized for it), then we use the SetAddress function for attaching to the branch; otherwise, we can use the SetObject method.
- Template Parameters
-
T | type of object to attach |
- Parameters
-
[in] | tree | TTree to attach to |
[in] | branch_name | name of branch to attach to |
[in] | obj | reference to object to attach |
- Returns
- pointer to branch that we attached to
◆ availableObjects()
Get the event objects available in the file.
We loop through the branches of the event TTree and parse their type names, object name, and pass name. We skip the branch named "EventHeader" to achieve the same behavior as h5::Reader.
- Returns
- vector of string pairs
{ obj_name, pass }
Implements fire::io::Reader.
◆ entries()
Number of entries in the file.
We get this from the number of entries in the event ttree.
- Returns
- number of entries in the file
Implements fire::io::Reader.
◆ load()
template<typename DataType >
void fire::io::root::Reader::load |
( |
const std::string & |
name, |
|
|
DataType & |
obj |
|
) |
| |
|
inline |
Load the data at the input name into the input object.
- See also
- transform for how we get the ROOT branch name from the input HDF5-style nested group names.
We choose the tree from the deduced branch name. If the branch name is "RunHeader", the we use the run tree ; otherwise, the event tree.
If the branch name isn't found in our 'attached_' map, then we use attach to attempt to attach it.
At the end, we load the data into memory using TBranch GetReadEntry to retrieve the current entry and increment it before providing it back to GetEntry.
- Template Parameters
-
DataType | type of data to load into |
- Parameters
-
[in] | name | name of data to load |
[in] | obj | reference to load into |
◆ load_into()
void fire::io::root::Reader::load_into |
( |
BaseData & |
d | ) |
|
|
finaloverridevirtual |
◆ name()
Get the name of the file.
We use ROOT's TFile rather than storing the name of the file ourselves.
- Returns
- full name of file currently reading
Implements fire::io::Reader.
◆ runs()
Number of runs in the file.
We get this from the number of runs in the run ttree.
- Returns
- number of runs in the file
Implements fire::io::Reader.
◆ transform()
pull out pass and object name, construct branch name
static caching map since this function is called so frequently
- Parameters
-
[in] | dir_name | HDF5-style (<pass>/<object>) group name of event object |
- Returns
- branch name in ROOT-framework-style (<object>_<pass>)
◆ type()
The documentation for this class was generated from the following files:
- include/fire/io/root/Reader.h
- src/fire/io/root/Reader.cxx