![]() |
Belle II Software development
|
A PersistenceManager that writes variables to a ROOT TTree. More...
#include <ConcreteVariablesToNtuplePersistenceManager.h>
Public Member Functions | |
ConcreteVariablesToNtuplePersistenceManager () | |
Default constructor. | |
void | initialize (const std::string &fileName, const std::string &treeName, Variables &variables) override |
Initializes the manager by opening a ROOT file and preparing a TTree. | |
void | addEntry (const EvaluatedVariables &evaluatedVariables) override |
Adds a single event's worth of variable data to the TTree. | |
void | store () override |
Writes the current buffered data to disk. | |
Private Member Functions | |
void | openFileWithGuards () |
Safely opens the ROOT file specified by m_fileName . | |
void | registerBranches () |
Registers TTree branches for each variable in m_variables . | |
void | updateBranch (const std::string &variableName, const VariableType &value) |
Updates the branch buffer for a given variable with a new value. | |
Private Attributes | |
std::string | m_fileName |
Name of the ROOT file where TTree data is stored. | |
std::string | m_treeName |
Name of the TTree that will be created and filled. | |
Variables | m_variables |
The list of variables that will be written to the TTree. | |
int | m_basketSize {1600} |
Basket size for the TTree branches. | |
std::shared_ptr< TFile > | m_file {nullptr} |
Pointer to the ROOT file object. | |
StoreObjPtr< RootMergeable< TTree > > | m_tree |
A store pointer to the RootMergeable wrapper for the TTree. | |
std::map< std::string, double > | m_branchesDouble |
Maps of variable names to storage for double, int, and bool TTree branches. | |
std::map< std::string, int > | m_branchesInt |
Storage for int branches. | |
std::map< std::string, bool > | m_branchesBool |
Storage for bool branches. | |
A PersistenceManager that writes variables to a ROOT TTree.
This class manages the creation and population of a ROOT TTree for a given set of variables. It handles opening a ROOT file, booking TTree branches, and filling them with user-supplied data each event. The TTree can then be merged in a multi-process environment through the RootMergeable mechanism.
Definition at line 32 of file ConcreteVariablesToNtuplePersistenceManager.h.
Default constructor.
Definition at line 32 of file ConcreteVariablesToNtuplePersistenceManager.cc.
|
overridevirtual |
Adds a single event's worth of variable data to the TTree.
evaluatedVariables | Map of variable names to their values, which will be written to the TTree branches. |
Each call updates the branch buffers for the registered variables. The actual storage of these buffers occurs when store()
is called.
Implements PersistenceManager.
Definition at line 50 of file ConcreteVariablesToNtuplePersistenceManager.cc.
|
overridevirtual |
Initializes the manager by opening a ROOT file and preparing a TTree.
fileName | Name of the ROOT file to create or update. |
treeName | Name of the TTree to create. |
variables | List of variables that will be stored in the TTree. |
This method configures the persistence manager with file and tree names, and sets up the necessary memory structures. It does not actually write data; that is handled by addEntry()
.
Implements PersistenceManager.
Definition at line 38 of file ConcreteVariablesToNtuplePersistenceManager.cc.
|
private |
Safely opens the ROOT file specified by m_fileName
.
This function takes care of ensuring the file can be written to or created if it does not exist. Throws an exception on error.
Definition at line 74 of file ConcreteVariablesToNtuplePersistenceManager.cc.
|
private |
Registers TTree branches for each variable in m_variables
.
Initializes branch addresses for each variable type (double, int, bool). Also sets the basket size using m_basketSize
.
Definition at line 96 of file ConcreteVariablesToNtuplePersistenceManager.cc.
|
overridevirtual |
Writes the current buffered data to disk.
After populating branch buffers through addEntry()
, this function commits them to the ROOT file, ensuring data is safely stored.
Implements PersistenceManager.
Definition at line 59 of file ConcreteVariablesToNtuplePersistenceManager.cc.
|
private |
Updates the branch buffer for a given variable with a new value.
variableName | The name of the variable (branch). |
value | The new value to be stored in the branch buffer. |
Depending on the type of the variant, the appropriate map (m_branchesDouble, m_branchesInt, or m_branchesBool) is updated.
Definition at line 129 of file ConcreteVariablesToNtuplePersistenceManager.cc.
|
private |
Basket size for the TTree branches.
Affects I/O efficiency.
Definition at line 90 of file ConcreteVariablesToNtuplePersistenceManager.h.
|
private |
Storage for bool branches.
Definition at line 107 of file ConcreteVariablesToNtuplePersistenceManager.h.
|
private |
Maps of variable names to storage for double, int, and bool TTree branches.
Storage for double branches.
Definition at line 105 of file ConcreteVariablesToNtuplePersistenceManager.h.
|
private |
Storage for int branches.
Definition at line 106 of file ConcreteVariablesToNtuplePersistenceManager.h.
|
private |
Pointer to the ROOT file object.
Definition at line 95 of file ConcreteVariablesToNtuplePersistenceManager.h.
|
private |
Name of the ROOT file where TTree data is stored.
Definition at line 75 of file ConcreteVariablesToNtuplePersistenceManager.h.
|
private |
A store pointer to the RootMergeable wrapper for the TTree.
Definition at line 100 of file ConcreteVariablesToNtuplePersistenceManager.h.
|
private |
Name of the TTree that will be created and filled.
Definition at line 80 of file ConcreteVariablesToNtuplePersistenceManager.h.
|
private |
The list of variables that will be written to the TTree.
Definition at line 85 of file ConcreteVariablesToNtuplePersistenceManager.h.