8 #include "gtest/gtest.h" 14 TEST(TTreeReaderLeafs, LeafListCaseA) {
16 const char* str =
"This is a null-terminated string literal";
17 signed char SChar = 2;
18 unsigned char UChar = 3;
19 signed short SShort = 4;
22 unsigned int UInt = 7;
26 unsigned long long ULL = 11;
30 tree->
Branch(
"C", &str,
"C/C");
31 tree->
Branch(
"B", &SChar,
"B/B");
32 tree->
Branch(
"b", &UChar,
"b/b");
33 tree->
Branch(
"S", &SShort,
"S/S");
34 tree->
Branch(
"s", &UShort,
"s/s");
35 tree->
Branch(
"I", &SInt,
"I/I");
36 tree->
Branch(
"i", &UInt,
"i/i");
37 tree->
Branch(
"F", &Float,
"F/F");
38 tree->
Branch(
"D", &Double,
"D/D");
39 tree->
Branch(
"L", &SLL,
"L/L");
40 tree->
Branch(
"l", &ULL,
"l/l");
41 tree->
Branch(
"O", &Bool,
"O/O");
64 EXPECT_EQ(SChar, *trSChar);
65 EXPECT_EQ(UChar, *trUChar);
66 EXPECT_EQ(SShort, *trSShort);
67 EXPECT_EQ(UShort, *trUShort);
68 EXPECT_EQ(SInt, *trSInt);
69 EXPECT_EQ(UInt, *trUInt);
70 EXPECT_FLOAT_EQ(Float, *trFloat);
71 EXPECT_DOUBLE_EQ(Double, *trDouble);
72 EXPECT_EQ(SLL, *trSLL);
73 EXPECT_EQ(ULL, *trULL);
74 EXPECT_EQ(Bool, *trBool);
81 gInterpreter->ProcessLine(
"#include \"data.h\"", &error);
86 std::unique_ptr<TTree>
tree(
new TTree(
"T",
"test tree"));
87 tree->
Branch(
"Data", &data);
88 data.fArray =
new double[4]{12., 13., 14., 15.};
90 data.fUArray =
new float[2]{42., 43.};
92 data.fVec = { 17., 18., 19., 20., 21., 22.};
98 data.fVec.resize(3210, 1001.
f);
102 data.fVec.resize(2, 42.
f);
109 TEST(TTreeReaderLeafs, LeafList) {
111 ASSERT_NE(
nullptr,
tree.get());
121 EXPECT_EQ(4u, arr.GetSize());
126 EXPECT_DOUBLE_EQ(19., vec[2]);
127 EXPECT_DOUBLE_EQ(17., vec[0]);
130 EXPECT_FLOAT_EQ(17, *d32);
131 EXPECT_FLOAT_EQ(44, *f16);
134 EXPECT_FLOAT_EQ(1001.
f, vec[1]);
135 EXPECT_EQ(3210u, vec.
GetSize());
138 EXPECT_FLOAT_EQ(42.
f, vec[1]);
145 TTree*
tree =
new TTree(
"TTreeReaderLeafsTArrayD",
"In-memory test tree");
147 for (
int i = 0; i < arrD.
GetSize(); ++i)
148 arrD.
SetAt(i + 2., i);
149 tree->
Branch(
"arrD", &arrD);
163 EXPECT_DOUBLE_EQ(4., (*arr)[2]);
164 EXPECT_DOUBLE_EQ(2., (*arr)[0]);
void SetAt(Double_t v, Int_t i)
TTreeReader is a simple, robust and fast interface to read values from a TTree, TChain or TNtuple...
virtual Int_t Fill()
Fill all branches.
TEST(TTreeReaderLeafs, LeafListCaseA)
std::vector< std::vector< double > > Data
Extracts data from a TTree.
EEntryStatus SetEntry(Long64_t entry)
Set the next entry (or index of the TEntryList if that is set).
Extracts array data from a TTree.
virtual void ResetBranchAddresses()
Tell all of our branches to drop their current objects and allocate new ones.
Array of doubles (64 bits per element).
virtual Int_t Branch(TCollection *list, Int_t bufsize=32000, Int_t splitlevel=99, const char *name="")
Create one branch for each element in the collection.
std::unique_ptr< TTree > CreateTree()
A TTree object has a header with a name and a title.