Belle II Software development
ConcreteVariablesToNtuplePersistenceManager.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <memory>
12#include <map>
13#include <string>
14#include <TTree.h>
15#include <TFile.h>
16
17#include <reconstruction/persistenceManager/PersistenceManager.h>
18#include <framework/pcore/RootMergeable.h>
19#include <framework/datastore/StoreObjPtr.h>
20
21namespace Belle2::VariablePersistenceManager {
22
33 public:
38
49 void initialize(const std::string& fileName,
50 const std::string& treeName,
51 Variables& variables) override;
52
61 void addEntry(const EvaluatedVariables& evaluatedVariables) override;
62
69 void store() override;
70
71 private:
75 std::string m_fileName;
76
80 std::string m_treeName;
81
85 Variables m_variables;
86
90 int m_basketSize{1600};
91
95 std::shared_ptr<TFile> m_file{nullptr};
96
101
105 std::map<std::string, double> m_branchesDouble;
106 std::map<std::string, int> m_branchesInt;
107 std::map<std::string, bool> m_branchesBool;
108
115 void openFileWithGuards();
116
123 void registerBranches();
124
133 void updateBranch(const std::string& variableName,
134 const VariableType& value);
135 };
136
137} // namespace Belle2::VariablePersistenceManager
Type-safe access to single objects in the data store.
Definition StoreObjPtr.h:96
void updateBranch(const std::string &variableName, const VariableType &value)
Updates the branch buffer for a given variable with a new value.
void addEntry(const EvaluatedVariables &evaluatedVariables) override
Adds a single event's worth of variable data to the TTree.
std::map< std::string, double > m_branchesDouble
Maps of variable names to storage for double, int, and bool TTree branches.
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.
StoreObjPtr< RootMergeable< TTree > > m_tree
A store pointer to the RootMergeable wrapper for the TTree.
Abstract base class defining the interface for persisting variables.