Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
TreeReadBuffer.h
Go to the documentation of this file.
1/// \cond ROOFIT_INTERNAL
2
3/*
4 * Project: RooFit
5 * Authors:
6 * Stephan Hageboeck, CERN 2020
7 *
8 * Copyright (c) 2022, CERN
9 *
10 * Redistribution and use in source and binary forms,
11 * with or without modification, are permitted according to the terms
12 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
13 */
14
15#ifndef RooFit_TreeReadBuffer_h
16#define RooFit_TreeReadBuffer_h
17
18#include <TTree.h>
19
20struct TreeReadBuffer {
21 virtual ~TreeReadBuffer() = default;
22 virtual operator double() = 0;
23 virtual operator int() = 0;
24};
25
26/// Helper for reading branches with various types from a TTree, and convert all to double.
27template <typename T>
29 operator double() override { return _value; }
30 operator int() override { return _value; }
31 T _value;
32};
33
34/// Create a TreeReadBuffer to hold the specified type, and attach to the branch passed as argument.
35/// \tparam T Type of branch to be read.
36/// \param[in] branchName Attach to this branch.
37/// \param[in] tree Tree to attach to.
38template <typename T>
39std::unique_ptr<TreeReadBuffer> createTreeReadBuffer(const TString &branchName, TTree &tree)
40{
41 auto buf = new TypedTreeReadBuffer<T>();
42 branchName.Data(), &buf->_value);
43 return std::unique_ptr<TreeReadBuffer>(buf);
44}
45
46#endif
47
48/// \endcond
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Basic string class.
Definition TString.h:139
A TTree represents a columnar dataset.
Definition TTree.h:79