![]() |
Project
|
A generic writer interface for ROOT TTree objects. More...
#include <RootTreeWriter.h>
Classes | |
struct | BranchDef |
BranchDef is used to define the mapping between inputs and branches. More... | |
struct | DefaultKeyExtractor |
Public Types | |
enum struct | BranchVerbosity { Quiet , Medium , High } |
using | key_type = std::string |
using | IndexExtractor = std::function< size_t(o2::framework::DataRef const &)> |
using | BranchNameMapper = std::function< std::string(std::string, size_t)> |
using | CustomClose = std::function< void(TFile *file, TTree *tree)> |
Public Member Functions | |
RootTreeWriter ()=delete | |
default constructor forbidden | |
~RootTreeWriter () | |
a destructor making sure that the Writer is closed (if didn't happen before) | |
template<typename... Args> | |
RootTreeWriter (const char *filename, const char *treename, Args &&... args) | |
void | init (const char *filename, const char *treename, const char *treetitle=nullptr) |
void | setBranchName (size_t index, const char *branchName) |
template<typename ContextType > | |
void | operator() (ContextType &&context) |
void | close () |
void | autoSave () |
autosave the tree | |
bool | isClosed () const |
size_t | getStoreSize () const |
Static Public Member Functions | |
template<typename T > | |
static TBranch * | remapBranch (TBranch &branchRef, T **newdata) |
A generic writer interface for ROOT TTree objects.
The writer class is configured with the file name, the tree name and a variable list of branch definitions passed to the constructor.
The class is currently fixed to the DPL ProcessingContext and InputRecord for reading the input, but the implementation has been kept open for other interfaces.
Usage:
RootTreeWriter("file_name", "tree_name", BranchDef<type>{ "key", "branchname" }, ...// further input and branch config ) writer; writer(processingContext);
BranchDef
:const char*
is used as type. Data is written as a std::vector<char>
, this ensures separation on event basis as well as having binary data in parallel to ROOT objects in the same file, e.g. a binary data format from the reconstruction in parallel to MC labels. Definition at line 120 of file RootTreeWriter.h.
using o2::framework::RootTreeWriter::BranchNameMapper = std::function<std::string(std::string, size_t)> |
Definition at line 129 of file RootTreeWriter.h.
using o2::framework::RootTreeWriter::CustomClose = std::function<void(TFile* file, TTree* tree)> |
Definition at line 133 of file RootTreeWriter.h.
using o2::framework::RootTreeWriter::IndexExtractor = std::function<size_t(o2::framework::DataRef const&)> |
Definition at line 127 of file RootTreeWriter.h.
using o2::framework::RootTreeWriter::key_type = std::string |
Definition at line 124 of file RootTreeWriter.h.
|
strong |
Enumerator | |
---|---|
Quiet | |
Medium | |
High |
Definition at line 145 of file RootTreeWriter.h.
|
delete |
default constructor forbidden
|
inline |
a destructor making sure that the Writer is closed (if didn't happen before)
Definition at line 281 of file RootTreeWriter.h.
|
inline |
constructor
treename | name of file |
treename | name of tree to write variable argument list of branch definitions |
Definition at line 291 of file RootTreeWriter.h.
|
inline |
autosave the tree
Definition at line 379 of file RootTreeWriter.h.
|
inline |
write the tree and close the file the writer is invalid after calling close
Definition at line 355 of file RootTreeWriter.h.
|
inline |
Definition at line 394 of file RootTreeWriter.h.
|
inline |
Init the output file and tree.
filename | output file |
treename | output tree |
After setting up the tree, the branches will be created according to the branch definition provided to the constructor.
Definition at line 310 of file RootTreeWriter.h.
|
inline |
Definition at line 389 of file RootTreeWriter.h.
|
inline |
process functor It expects a context which is used by lambda capture in the snapshot function. Recursively process all inputs and fill branches individually from extracted objects.
Definition at line 343 of file RootTreeWriter.h.
|
inlinestatic |
A static helper function to change the type of a (yet unused) branch. Removes the old branch from the TTree system and creates a new branch. The function is useful for situations in which we want to transform data after the RootTreeWriter was created and change the type of the branch - such as in user callbacks. The function needs to be used with care. The user should ensure that "branch" is no longer used after a call to this function.
Definition at line 406 of file RootTreeWriter.h.
Set the branch name for a branch definition from the constructor argument list
index | position in the argument list |
branchName | (base)branch name |
If the branch definition handles multiple output branches, the getName callback of the definition is used to build the names of the output branches
Definition at line 324 of file RootTreeWriter.h.