#include <boost/test/included/unit_test.hpp>
#include <filesystem>
#include <TFile.h>
#include "FriendUtils.h"
#include "FileUtils.h"
◆ BOOST_TEST_MODULE
#define BOOST_TEST_MODULE testFriendUtils |
◆ DOXYGEN_SHOULD_SKIP_THIS
#define DOXYGEN_SHOULD_SKIP_THIS |
◆ BOOST_AUTO_TEST_CASE() [1/3]
BOOST_AUTO_TEST_CASE |
( |
pure_root_without_ranges |
| ) |
|
91 createFile(
"friends-hybrid-step0-0.root", 0, 10);
92 createFile(
"friends-hybrid-step0-1.root", 10, 20);
95 auto chain = make_unique<TChain>(
"tree");
96 chain->Add(
"friends-hybrid-step0-0.root");
97 chain->Add(
"friends-hybrid-step0-1.root");
101 auto newTree = make_unique<TTree>(
"tree",
"");
104 for (
int i = 0; i < chain->GetEntries(); ++i) {
110 TFile
f(
"friends-hybrid-step1.root",
"RECREATE");
111 f.WriteObject(newTree.get(),
"tree");
116 auto tIn =
new TChain(
"tree");
117 tIn->Add(
"friends-hybrid-step1.root");
118 tIn->AddFriend(chain.get(),
"step0");
123 int index = -1, value = -1;
124 BOOST_REQUIRE( tIn->SetBranchAddress(
"index", &index) == 0 );
125 BOOST_REQUIRE( tIn->SetBranchAddress(
"value", &value) == 0 );
127 for (
int i = 0; i < tIn->GetEntries(); ++i) {
◆ BOOST_AUTO_TEST_CASE() [2/3]
BOOST_AUTO_TEST_CASE |
( |
slice |
| ) |
|
Tests ChainSlice
.
45 createFile(
"friends-ChainSlice-file0.root", 0, 10);
46 createFile(
"friends-ChainSlice-file1.root", 10, 20);
49 auto chain = make_unique<ChainSlice>(
"tree");
50 chain->Add(
"friends-ChainSlice-file0.root");
51 chain->Add(
"friends-ChainSlice-file1.root");
61 chain->SetBranchAddress(
"index", &index);
◆ BOOST_AUTO_TEST_CASE() [3/3]
BOOST_AUTO_TEST_CASE |
( |
slice_element |
| ) |
|
Tests SlicedFriendElement
.
This test uses two input files and checks that we can load a subset of them through another tree to which a SlicedFriendElement
has been added.
144 createFile(
"friends-SlicedFriendElement-step0-0.root", 0, 10);
145 createFile(
"friends-SlicedFriendElement-step0-1.root", 10, 20);
147 const int begin = 5, end = 15;
150 auto inputSlice = make_unique<ChainSlice>(
"tree");
151 inputSlice->Add(
"friends-SlicedFriendElement-step0-0.root");
152 inputSlice->Add(
"friends-SlicedFriendElement-step0-1.root");
153 inputSlice->SetBegin(begin);
154 inputSlice->SetEnd(end);
157 auto newTree = make_unique<TTree>(
"tree",
"step1");
158 SlicedFriendElement::AddTo(newTree.get(), inputSlice.get(),
"step0");
161 for (
int i = 0; i < inputSlice->GetEntries(); ++i) {
167 TFile
f(
"friends-SlicedFriendElement-step1.root",
"RECREATE");
168 f.WriteObject(newTree.get(),
"tree");
173 auto chainIn = make_unique<TChain>(
"tree");
174 chainIn->Add(
"friends-SlicedFriendElement-step1.root");
175 chainIn->GetEntry(0);
176 auto tIn = chainIn->GetTree();
177 auto friends = tIn->GetListOfFriends();
178 auto fe =
dynamic_cast<TFriendElement *
>(friends->At(0));
179 friends->Clear(
"nodelete");
180 auto chainslice = fe->GetTree();
181 chainIn->AddFriend(chainslice);
182 chainIn->GetEntry(0);
186 int index = -1, value = -1;
187 BOOST_REQUIRE( chainIn->SetBranchAddress(
"index", &index) == 0 );
188 BOOST_REQUIRE( chainIn->SetBranchAddress(
"value", &value) == 0 );
191 for (
int i = 0; i < chainIn->GetEntries(); ++i) {
200 auto chainIn = make_unique<ChainSlice>(
"tree");
201 chainIn->Add(
"friends-SlicedFriendElement-step1.root");
202 chainIn->GetEntry(0);
206 int index = -1, value = -1;
207 BOOST_REQUIRE( chainIn->SetBranchAddress(
"index", &index) == 0 );
208 BOOST_REQUIRE( chainIn->SetBranchAddress(
"value", &value) == 0 );
210 for (
int i = 0; i < chainIn->GetEntries(); ++i) {
◆ createFile()
void createFile |
( |
const char * |
name, |
|
|
int |
first, |
|
|
int |
last |
|
) |
| |
Creates a file with a tree, and fills the index
branch in the tree with numbers in [first, last).
24 TFile file(
name,
"RECREATE");
28 tree.Branch(
"index", &index);
29 tree.Branch(
"value", &value);
31 for (index = first; index < last; ++index) tree.Fill();
33 file.WriteObject(&tree,
"tree");