Logo ROOT  
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
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.
25template <typename T>
26struct TypedTreeReadBuffer final : public TreeReadBuffer {
27 operator double() override { return _value; }
28 operator int() override { return _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.
36template <typename T>
37std::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
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.
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
A TTree represents a columnar dataset.
Definition TTree.h:79
virtual ~TreeReadBuffer()=default
Helper for reading branches with various types from a TTree, and convert all to double.