ROOT
v6-32
Reference Guide
Loading...
Searching...
No Matches
TreeReadBuffer.h
Go to the documentation of this file.
1
/*
2
* Project: RooFit
3
* Authors:
4
* Stephan Hageboeck, CERN 2020
5
*
6
* Copyright (c) 2022, CERN
7
*
8
* Redistribution and use in source and binary forms,
9
* with or without modification, are permitted according to the terms
10
* listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11
*/
12
13
#ifndef RooFit_TreeReadBuffer_h
14
#define RooFit_TreeReadBuffer_h
15
16
#include <
TTree.h
>
17
18
struct
TreeReadBuffer
{
19
virtual
~TreeReadBuffer
() =
default
;
20
virtual
operator
double
() = 0;
21
virtual
operator
int
() = 0;
22
};
23
24
/// Helper for reading branches with various types from a TTree, and convert all to double.
25
template
<
typename
T>
26
struct
TypedTreeReadBuffer
final :
public
TreeReadBuffer
{
27
operator
double
()
override
{
return
_value
; }
28
operator
int
()
override
{
return
_value
; }
29
T
_value
;
30
};
31
32
/// Create a TreeReadBuffer to hold the specified type, and attach to the branch passed as argument.
33
/// \tparam T Type of branch to be read.
34
/// \param[in] branchName Attach to this branch.
35
/// \param[in] tree Tree to attach to.
36
template
<
typename
T>
37
std::unique_ptr<TreeReadBuffer>
createTreeReadBuffer
(
const
TString
&branchName,
TTree
&tree)
38
{
39
auto
buf =
new
TypedTreeReadBuffer<T>
();
40
tree.SetBranchAddress(branchName.
Data
(), &buf->_value);
41
return
std::unique_ptr<TreeReadBuffer>(buf);
42
}
43
44
#endif
TTree.h
createTreeReadBuffer
std::unique_ptr< TreeReadBuffer > createTreeReadBuffer(const TString &branchName, TTree &tree)
Create a TreeReadBuffer to hold the specified type, and attach to the branch passed as argument.
Definition
TreeReadBuffer.h:37
TString
Basic string class.
Definition
TString.h:139
TString::Data
const char * Data() const
Definition
TString.h:376
TTree
A TTree represents a columnar dataset.
Definition
TTree.h:79
double
int
TreeReadBuffer
Definition
TreeReadBuffer.h:18
TreeReadBuffer::~TreeReadBuffer
virtual ~TreeReadBuffer()=default
TypedTreeReadBuffer
Helper for reading branches with various types from a TTree, and convert all to double.
Definition
TreeReadBuffer.h:26
TypedTreeReadBuffer::_value
T _value
Definition
TreeReadBuffer.h:29
roofit
roofitcore
src
TreeReadBuffer.h
ROOT v6-32 - Reference Guide Generated on Tue May 19 2026 02:47:03 (GVA Time) using Doxygen 1.13.2