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 <reconstruction/persistenceManager/PersistenceManager.h>
12#include <framework/datastore/StoreObjPtr.h>
13
14#include <TTree.h>
15#include <TFile.h>
16
17#include <memory>
18#include <map>
19#include <string>
20
21namespace Belle2 {
26 template<class T> class RootMergeable;
28}
29
30namespace Belle2::VariablePersistenceManager {
31
42 public:
47
58 void initialize(const std::string& fileName,
59 const std::string& treeName,
60 Variables& variables) override;
61
70 void addEntry(const EvaluatedVariables& evaluatedVariables) override;
71
78 void store() override;
79
80 private:
84 std::string m_fileName;
85
89 std::string m_treeName;
90
94 Variables m_variables;
95
99 int m_basketSize{1600};
100
104 std::shared_ptr<TFile> m_file{nullptr};
105
110
114 std::map<std::string, double> m_branchesDouble;
115 std::map<std::string, int> m_branchesInt;
116 std::map<std::string, bool> m_branchesBool;
117
124 void openFileWithGuards();
125
132 void registerBranches();
133
142 void updateBranch(const std::string& variableName,
143 const VariableType& value);
144 };
145
146} // namespace Belle2::VariablePersistenceManager
Wrap a root histogram or TNtuple to make it mergeable.
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.
Abstract base class for different kinds of events.